Eclipse is an integrated development environment (IDE) for Java, C++, and other languages. It combines software resources for editing, compiling and running programs. In this IDE Java programs consist of two parts:
The Eclipse Java project combines precompiled code from the Java class libraries with the code compiled from your Java source program, thereby increasing the functionality of your code. This lab will take you through the steps required to edit, compile, and run Java programs.
- the Java code itself, which contains the text of your source program and
- a project, which contains the Java bytecode that will be executed when you run your program.
Close all applications that may be running on your computer in order to make as much memory as possible available to Eclipse.
NOTE: Remember how to find this program because you're going to need it every week.
Once you have Eclipse running, create a new project and configure it according to the following directions:Click on the "Create a java project" link in the Package Explorer window or right click on that window then select NEW then Java project. Enter the name of your project, i.e. "HelloWorld". The "Location" text box should indicate that your project will be stored on the desktop. In the project JRE setting, make sure at least one Java SE version is selected, default to JavaSE-1.8 if you followed instructions on the Prerequisites section. During this step, you should see something like the following window:
Click on Finish to create the project. In the Package Explorer window, right click on the "src" item, then select "New" and then Class. Next, crete the HelloWorld java class with a static main method similar to the following figures:
Input the following source code of the HelloWorld in the middle window as the following:
If this is NOT how your project looks, ask for help.
To compile and run HelloWorld.java, right click on the HelloWorld project on the Package Explorer, then select Run As, then select 1 Java Application. Eclipse will automatically compile the application into Java bytecode and then interpret the bytecode all in one step. As a result, something like the following Java Output window should appear on your desktop.
To Do:Change the name of the class in HelloWorld.java to Lab01 and then save the file.
System Error:Eclipse will detect and complain about this error right away. This time you should get an error message in the Java Output window which says:
You can fix this error by changing the class name back to HelloWorld (spelled EXACTLY that way) and then saving and re-running the program.
NOTE: If a Java program's file name does not match the name of the public class that is defined within the file, it won't run properly.
To Do: Delete the semicolon after the System.out.println() statement.
Syntax Error:This time you should get an error message in the Problems window which says:
Syntax error, insert ";" to complete BlockStatements Lab01.java /HelloWorld/src line 9 Java Problem
To Do: Modify the HelloWorld class with the following code. Rerun and observe the output.
public class HelloWorld extends Object // Class header { // Start class body private String greeting = "Hello World!"; public void greet() // Method definition { // Start method body System.out.println(greeting); // Output statement } // greet() // End method body public static void main(String args[]) // Method header { HelloWorld hwApp; // declare hwApp = new HelloWorld(); // create hwApp.greet(); // Method call } // main() } // HelloWorld // End class body
This time you should get the same output as the previous version.
In this part, we will practice using Scanner class to read input from the console and working with Date Time using two Java utility classes: Date and SimpleDateFormat. Then we use the input values to output our greeting message to console.
- Scanner class document and tutorial: java.util.Scanner
https://www.javatpoint.com/Scanner-class- Date class document and tutorial: java.util.Date
https://www.javatpoint.com/java-util-date- SimpleDateFormat class document and tutorial: java.text.SimpleDateFormat
https://www.javatpoint.com/java-simpledateformat- System.out.println document and tutorial: java.text.SimpleDateFormat
https://www.javatpoint.com/system-out-println-in-javaExtend the HelloWorld class to do the following:
Hint: You will also need to use SimpleDateFormat class to show the output nicely.
- Use the Scanner class to read user's name
- Use the Date class to get today’s date and time
- Output the greeting string including the user’s name and today' date and time as the following format:
Welcome [user’s name]. Today is [date] and the time is [time].
Here is a sample output of this part:
You need to submit the results of the following sections:
1. Part 1 - Step 4: Capture the output windows
(either Console or Problems) of Eclipse for every
To Do items.
2. Part 2: Compress the whole Eclipse source code in
zip format using Export function
Submit your captured image results of Part 1 and the
compressed source code of Part 2 to D2L class course.