SE-1011 Software Development 1
Introduction to using Eclipse for Java program development

Overview

The Java Development Environment we’ll be using in this course is composed of  two main components (which are already pre-installed on your laptops):

  1. The first component is the JDK (Java Developer’s Kit), which is actually a collection of various tools and utilities that you, the developer, need to build, debug, and analyze Java applications, such as the Java language compiler (javac). The JDK also includes numerous Java runtime libraries as well as the Java VM (Virtual Machine) – the “engine” that interprets and executes compiled Java code.
     

  2. The second component is the Eclipse, an integrated development environment (IDE), that centralizes a lot of the aspects of creating Java programs - like editing, compiling, running, and debugging. Eclipse handles a lot of detail regarding the invocation of the JDK tools (such as the compiler); while this is a great convenience, at the same time, it can make it difficult for a beginning user to grasp all that going on during the creation of a Java application. Eclipse is a sophisticated application, so we'll start off slowly by learning only the most essential aspects of Java program development.

    Handy Bookmark:
    http://java.sun.com - starting point for the Sun Microsystems website concerned with all things Java
     

Creating a Java program in Eclipse

There are 5 parts to this lab. Read each part through, following the instructions carefully and recording the required information as directed. Ask for help when you need it.

Part 1

To begin, follow the step-by-step instructions found here.


At the very bottom of the file, insert the following block comment:

/*
Results from Part 1:
Results from Part 2:
Results from Part 3:
Results from Part 4:
Results from Part 5:
*/

Copy the output shown in the Console and paste it after the Results from Part 1: line in the comment. When you are finished, demonstrate the output of the program to your instructor.

Part 2

In the line

System.out.println("Hello, World!");

remove the semi-colon at the end of the line. Note all changes to the user interface (there are several) that occur as a result. Briefly describe your observations after Results from Part 2: in the comment. Look at the output that appears in the Problems pane. Copy and paste this output into the block comment, following your observations.

Part 3

Above the "public class..." statement, insert the following, exactly as written:

import java.util.Scanner;

Next, replace the line

System.out.println("Hello, World!");

with the following lines (we'll discuss what they all mean later):

System.out.print("Enter a radius: ");
Scanner kbdReader = new Scanner(System.in);
String input = kbdReader.nextLine();
Scanner stringReader = new Scanner(input);
double radius = stringReader.nextDouble();
double area = Math.PI * radius * radius;
System.out.println("The area of a circle with radius " + radius + " is: " + area );

Run the program (correct any errors you may have introduced copying the above code). Run it several times, entering various values for the radius. Does the output make sense to you? Is it correct?

From one of your tests, copy the results of the output shown in the Console and paste it after the Results from Part 3: line in the comment.

Run the program again, but this time, don't enter any value for radius - just press Enter. Record your observations in the comment.

Part 4

After the "import java.util.Scanner;" line, add the following:

import javax.swing.JOptionPane;

Replace the lines between the braces in the main method with the following:

String input = JOptionPane.showInputDialog("Enter a radius:");
Scanner stringReader = new Scanner(input);
double radius = stringReader.nextDouble();
double area = Math.PI * radius * radius;
JOptionPane.showMessageDialog(null, "The area of a circle with radius " + radius + " is: " + area );

Run the program. Note the differences compared to the behavior of the program in Part 3. Record your observations after the Results from Part 4: line in the comment.

Run the program again, but this time, don't enter any value for radius - just press OK. Record your observations in the comment.

Run the program one last time, but this time, don't enter any value for radius - just press Cancel. Record your observations in the comment. How does the behavior differ from pressing OK with no value entered?

Part 5

Asking for help when you need it, modify the program from either part 3 or part 4 to prompt the user for a rectangle's base and height, compute the rectangle's area, and output the result. Run the program, copy the output shown in the Console and paste it after the Results from Part 5: line in the comment. Be sure to save this final version of the file.
 

Lab Submission (due by end of lab)

Submit your assignment by upload your .java file via WebCT (assignment "Lab 2: Intro to Eclipse").

Be sure to keep copies of your file, in case something gets lost.

Your grade will be based on the following criteria: