COMP 212 Lab 1: Java Syntax & DrJava
This tutorial covers:
- DrJava: a home-grown, user-friendly, GUI Java development environment that
looks and behaves very much like DrScheme.
- Basic Java syntax using DrJava as a learning tool.
DrJava
DrJava is a user-friendly integrated development environment (IDE) developed
by the Rice Programming Language Team (PLT) group. DrJava provides
a way to edit and save java code with key words highlighting, curly brace matching,
and an interactive environment to manipulate objects and test code without having
to write the main method. DrJava can be downloaded freely from drjava.org.
Running DrJava
Click on the appropriate menu item in Windows to start DrJava. You should see a GUI development
environment that looks very similar to DrScheme. Here are the functions
of the four subwindows in the GUI.
The top half of the GUI constitutes the Definitions window. You type
in all the class definitions here. After you type in some code, you need
to click on the save button before you can compile your code. All the
classes in the Definitions window will be saved in a single file. There
should only be one public class in the Definitions window, and the saved file
should have the same name as that of the public class with the extension .java.
The bottom half of the GUI comprises three tabbed windows.
- Interactions window: this is where you can type in any valid Java statement.
Usually, you would type in code to instantiate objects of classes defined
in the Definitions window, and call their methods to check whether or not
they perform correctly. Typing a valid Java expression terminated with
a semi-colon and then pressing the Return (Enter) key, will cause DrJava to
evaluate the expression but NOT printing the result. If you want DrJava
to print the value of the result in the Interactions window, you should press
Return without terminating the expression with a semi-colon. There is
a menu item to reset (i.e. clear) the Interactions window. Another
way to clear the Interactions window is to force a re-compile by editing the
Definitions window.
- Compiler Output window: Every time you compile your code, DrJava will display
all compile error messages here. Clicking on an error message will highlight
the line where the error is suspected to take place in the Definitions window.
If there is no compile error, DrJava will declare success in this window.
- Console Output window: All console output will be printed in this window.
Java Syntax
Lecture note #3 contains a syntax summary
of the most common Java constructs.
Download the following Java file: TestFruit.java.
Open it in DrJava. Compile and fix all errors.