Talk:Java Programming/Understanding a Java Program
Page contents not supported in other languages.
Appearance
From Wikibooks, open books for an open world
Latest comment: 15 years ago by Mattylaws in topic Friendly to Newcomers
In later modules, we can do more advanced enhancements of this basic program:
- put this in a package,
org.wikibooks.java.distance
, instead of the default package 0% developed as of Jan 28, 2006 - Change the type of
a
,b
fields to java.awt.Point2D 0% developed as of Jan 28, 2006 - Overload the constructor with a Distance(Point2D, Point2D) constructor 0% developed as of Jan 28, 2006
- first constructor calls this((Point2D, Point2D) 0% developed as of Jan 28, 2006
- copy arguments defensively since Point/Point2D are mutable. 0% developed as of Jan 28, 2006
- Change Point to Point2D.Double and change the constructor to take doubles not ints and change main to parse doubles not ints. 0% developed as of Jan 28, 2006
- define a new Point3D interface (extends Point2D) and Point3D.Double (extends Point2D.Double?) 0% developed as of Jan 28, 2006 class to show how the Distance program can work with other Points
- Add exception handling around the String->number parsing and array indexing in main 0% developed as of Jan 28, 2006
- use number formats for the points, distance 0% developed as of Jan 28, 2006
- use internationalization/resource bundles for the text, number formats 0% developed as of Jan 28, 2006
--djb 18:26, 28 January 2006 (UTC) Reply
Could this example be a bit confusing to newbies to the language? --Mattylaws (talk) 12:44, 10 March 2010 (UTC) Reply
Questions
[edit source ]How do you use the distance program in eclipse? It isn't obvious how points can be entered the command prompt seems unresponsive.
jc@JCMAIN:~/java$ javac Distance.java Distance.java:1: 'class' or 'interface' expected { ^ 1 error
- Any ideas? 161.112.83.102 10:40, 7 October 2007 (UTC) Reply
This didn't compile for me until I changed:
...
privatestaticintintValue(Stringdata) { returnInteger.parseInt(data); } }
To:
privatestaticintintValue(Stringdata) { returnjava.lang.Integer.parseInt(data); } }
That said I really don't know what I'm doing here, and just got the idea to try that off of some random googling. Should the page be changed, or maybe there's a better fix. --Keithonearth (talk) 19:09, 21 August 2009 (UTC) Reply