CH2 – Declaring Variables And Assignment

In this exercise you do not create an actual Java program. Instead you use DrJava’s Interactions Pane. The Interactions Pane allows you to type Java statements and quickly see the results without writing a complete program.

  1. Open DrJava and expand the Interactions Pane.


    DrJava Interactions Pane.

  2. Type the following lines.
> String message;
> int x;
> String firstName;
> String lastName;
> int hour, minute;
  1. Now type the following assignment statements.
> message = "hello";
> hour = 11;
> minute = 59;
> firstName = "James";
> lastName = "Brannan";
  1. Type the following to see the results of the assignment.
> message
> hour + ":" + minute
> firstName
> lastName
  1. Type the following line and review the result. Note that all three lines should be on the same line when printing multiple statements in the DrJava Interactions Pane.
> System.out.print(hour); System.out.print(":"); System.out.println(minute);

It is important to remember that this is DrJava’s Interaction pane. This pane is designed for learning Java statements. You are executing isolated statements and reviewing the result. You are not writing a complete Java program. For more information on the Interactions Pane, refer to DrJava’s online help page.

For more experience declaring and assigning variables, watch this video by LearningLad.