Lab 01

Dr. Java Introduction

 

Objective:

 

Learn how to use a basic IDE called, “Dr. Java”, and write a very simple program step-by-step.

Steps:

  1. Open Dr. Java.
  2. Create a new project by going to the toolbar and clicking Project->New

  1. Right click and select New Folder and name the folder FirstProject  

 

  1. Double click the newly created folder (FirstProject), enter the File Name FirstProject, and finally select Save

 

  1. In the following window that should pop up click Ok

 

  1. Next go to File->New Java Class
  2. In the next dialog enter the Class name as HelloWorld and also click the checkbox Include Main Method

 

  1. It should now come up with some code.  In the top comments (indicated by /* … */) make sure to put your and your partner’s name

 

 

  1. Next below the comments enter “import java.util.Scanner;”. This code will allow us to use the Scanner object later to gain user input

 

 

  1. Inside of the main method / entry point (public static void main(String[] args) enter “System.out.println(“Hello World”);

 

  1. Next save the file by File->Save and make sure the file name is HelloWorld.

 

  1. If this is done correctly, then in your project view (left side bar) you should see this file under your [Source Files]

 

  1. Next click on Compile Project and then Run in the lower tool bar

 

  1. This should compile the code and in the console window it should say “Hello World”

 

  1. If this is not the case then check over the code that was entered to make sure there were not any syntax errors.  If there were then when you compile they should appear in the dialogs in the lower box, and will be highlighted in the source code.
  2. Next add the following code after “Hello World” but still inside the main method

  1. Save it, compile it, and run it.  You’ll now notice in the dialog box it waits for you to enter in some information.  Enter your name and it should print out “Greetings <YOUR NAME>”.

 

  1. The variable “keyboard” creates a new instance of an object Scanner.  This allows us to gain input from the user via the keyboard.  The statement “String name = keyboard.nextLine();” creates a variable called “name” of type String and then stores the entire line entered in by the user via the method “nextLine()”.  Finally “System.out.println("Greetings "+name);” outputs the salutation plus the contents of the variable “name”.
  2. Scanner has many methods that can be used to get input from the user.  For instance enter the following code after “System.out.println("Greetings "+name);”

  1. Save it, compile it, and run it.  Now you enter your name and the number of cats you own.  The print out should look similar to the following

 

  1. In this example a new variable of type int (integer / whole number)  is created and the scanner assigns the numeric value using the method “nextInt()”. 
  2. The contents of “numberOfCats” is printed out along with the additional phrase.
  3. Show this to the TA and make sure to submit it to the dropbox under both accounts.

 

 

Lab Report Questions:

  1. What is the name of the program that takes high-level code and transforms it into machine level code?
  2. Java creates code just before it is fully compiled to machine code.  What is this type of code called?
  3. What are some pros and cons of using Java?

Finally:

Upload the .java file to the dropbox