Now save it in a file: click button “Save”, and make sure the name of the file
is MyPoint.java . The name of the file has to be the same as the name of the class
plus “. java ”. Capitalization is vital ! In Java, all names are case sensitive.
You also need to compile your code. Click button “Compile All”; in a few
moments, you should see this:
Last compile completed successfully.
If you do not see that, you have your first syntax error. Congratulations! You
will see many more syntax errors in your programming career. Get used to them;
they are a fact of life for every programmer. Just go back and make sure that you
typed class MyPoint exactly as we show it and that the file name is spelled cor-
rectly and has the right capitalization. Keep doing this until it compiles. Now you
can use MyPoint in the Interactions Pane.
The lower pane has three, and sometimes four, tabs. The leftmost tab is
“Interactions”. Click on it to bring back the Interactions Pane.
Type the following statements and expressions. Note that when you use a
semicolon, you do not see a result. Statements are terminated with semicolons;
expressions are not. Expressions have values; statements do not.
MyPoint p= new MyPoint();
5 * (p.x + p.y)
You now know enough to write classes in DrJava, compile them, and test them.
The Java console
When a Java program is running, error messages are printed in a special win-
dow, the Java console . Also, when one of the following statements is executed,
the value of the expression is placed in the Java console (and a new line is start-
ed, for println ):
System.out.println( expression );
System.out.print( expression );
When using DrJava, error messages and the values of expression s in such print
and println statements are also printed in the Interactions pane, interspersed
with lines that the user types and responses from DrJava.
One of the tabs in the lower pane is titled “Console”. Clicking this tab
changes the lower pane into the Java console; there, you will see error messages
and the values of expressions from print and println statements.