Dr Java Tutorial

The goal of this tutorial is to introduce Dr Java IDE, learn to type Java Syntax and execute Java Program.

Steps

  1. Open Dr. Java IDE
    • See Desktop for shortcut icon OR
    • Click on KMenu > Applications > Seas Menu > drjava



  2. In the interactions pane write a sequence of Java commands that will calculate area of circle
    • Declare a constant called PI equal to 3.14
    • Declare variable called radius and intialize radius to 3.0
    • What are data types for identifiers PI and radius?
    • Print answer as follows: Area of the circle is =

  3. Create a folder called Program1. Download and Save the file Hello.java to your created folder.

  4. Open file Hello.java
    • Open the Hello.java file using the "Open" icon.
    • Contents of Hello.java
      • Every Java program begins with the word class followed by the class name which is same as filename i.e. Hello 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, which is a Java Syntax rule.
      • 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 main is the entry point of your program and when it executes it prints "Hello World" in the "interactions" pane.

  5. Compiling your program
    • Click the “Compile” icon that is located on the top of the screen. (Or press F5)
    • You must see the Compilation complete message in the "Compiler Output" tab that is located at the bottom of the screen (See Image)
    • Hello.class contains machine code (known as byte code) that is independent of the any computer hardware
    • If you open the folder/directory where you saved Hello.java, select "All Files" and then you should be able to see Hello.class file in the folder. Do not try to open this file using Dr Java or any text editor, if you do you will see a bunch of garbage.

  6. Executing/Running your program
    • 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
    • During the execution phase the Java Virtual Machine translates the byte code into the machine code that processor understands
    • The machine code is then executed on your computer
    • You can also execute your program using the command java Hello in the "interactions" pane in Dr Java
  7. What if there are errors in your code?
  8. Editing your files
    • In file Hello.java, edit you file such that program output says "Java Rocks!!"
    • Compile and Run your program to test your output.

  9. Adding and Removing jar file

  10. Changing Settings
    • In order to change any settings (fonts, colors, compiler options, etc...) of DrJava programming environment go to Edit > Preferences
    • For example, if you want to display the line numbers, under Preferences > Display Options check the “Show All Line Numbers” box.You should be able to see line numbers per line.

  11. For any kind of help, consult

Working with DrJava at home

If you want to work with DrJava at home, then there are various resources that explain how to install Java & DrJava to any operating system (Windows, Mac, Linux...).