Talk:Java Programming/Understanding a Java Program

In later modules, we can do more advanced enhancements of this basic program:


 * put this in a package,, instead of the default package
 * Change the type of,   fields to java.awt.Point2D
 * Overload the constructor with a Distance(Point2D, Point2D) constructor
 * first constructor calls this((Point2D, Point2D)
 * copy arguments defensively since Point/Point2D are mutable.
 * Change Point to Point2D.Double and change the constructor to take doubles not ints and change main to parse doubles not ints.
 * define a new Point3D interface (extends Point2D) and Point3D.Double (extends Point2D.Double?) 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
 * use number formats for the points, distance
 * use internationalization/resource bundles for the text, number formats

--djb 18:26, 28 January 2006 (UTC)

Friendly to Newcomers
Could this example be a bit confusing to newbies to the language? --Mattylaws (talk) 12:44, 10 March 2010 (UTC)

Questions
How do you use the distance program in eclipse? It isn't obvious how points can be entered the command prompt seems unresponsive.

error
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)

This didn't compile for me until I changed:

...

To:

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)