Look at the class web page at www.cs.umb.edu/it115 (or /cs115), follow various links
Download DrJava, using link “DrJava Web Page” on class web page
Follow the DrJava Tutorial linked to the class web page, steps 1-9: Here is the core of it:
1. Create a folder called Program1
o All files for this tutorial can be found at this website and saved to the above folder you created
2. Save the file Hello.java to Program1 folder
3. Open Dr. Java IDE (see image)
o Click on KMenu > Applications > Seas Menu > drjava
4. Open file Hello.java
o Open the hello.java file using the "Open" icon.
o Click the “Save” icon that is located on the top left side of the screen. (Or press Ctrl + S)
o Contents of Hello.java
§ Every Java program begins with the word class followed by the class name and curly { } to to indicate the start and end of the class behavior
§ Important : The file name must have the same name as your class. (In this case, it should be Hello)
§ Notice color highlighting on certain words. The ones on blue color is the Java Syntax. The ones in green color are some comments for us to know details about the program or particular line. The comments start with "//" or start with "/*" and end with "*/", which tell the Java compiler that this should be ignored and not be part of the java program.
§ For now ignore what the meaning the syntax such as "public static void main(String[] args)". The only thing you need to know is that when the program executes it prints "Hello World" in the "interactions" tab.
5. Compiling your program
o Click the “Compile” icon that is located on the top of the screen. (Or press F5)
o You must see the Compilation complete message in the "Compiler Output" tab that is located at the bottom of the screen (See Image)
o Hello.class contains machine code (known as byte code) that is independent of the any computer hardware
o If you open the Program1 folder/directory, you should be able to see Hello.class file in the folder.
6. Executing/Running your program
o Click the “Run” icon that is located on the top right side of the screen. (Or press F2)
§ You should Hello World print in "Interactions" tab
o During the execution phase the Java Virtual Machine translates the byte code into the machine code that processor understands
o The machine code is then executed on your computer
o You can also execute your program using the command java Hello in the "interactions" tab in Dr Java
Welcome to DrJava. Working directory is
S:\Javaprojects\Program1 |
7. What if there are errors in your code?
o Try erasing the semi colon (;) in your program. (Located at the end of the “System.out.println(...)” line)
o Now try to compile your program again
o In the "Compiler Output" tab you see:
1 error found: |
o Click on the "Reset" icon to clear the error message.
o Fix the semi colon and the program should compile again.
8. Editing your files
o In file Hello.java, add another line that reads:
§ System.out.println("We are in room Moore 207");
o Put the above statement after line System.out.printl("Hello World");
9. Repeat steps 4-6 for program Square.java
o Remove the file Hello.java by clicking on the "Close" icon.
o Save Square.java to Program1 folder and open this file using "Open" icon. Then click save.
o Compile and Run the program (steps 4 and 5) and observe the output - What does the program do ?
Now try it on code relevant to our project:
Find and download NumberGuess3.java, using link “Code for all Chapters” on the class web page, then “ch05”.
Compile and run it
Edit it to accept and print digits, for project 1’s problem 2.