CS 234 - Fall 2020 - Lab 01: Introduction

Objectives

The objectives of this lab are:

Prerequisites

Part 1: Editing, Compiling, and Running a Java Hello World Program

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.

Step 0. Close all applications on your computer.

Close all applications that may be running on your computer in order to make as much memory as possible available to Eclipse.

Step 1. Run the Eclipse IDE

 NOTE: Remember how to find this program because you're going to need it every week.

Step 2. Create the HelloWorld project.

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:
    Create Java Project 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:
    Create Java Class Window      Create Java Class Window

  • Input the following source code of the HelloWorld in the middle window as the following:

    Source Editor Window

    If this is NOT how your project looks, ask for help.
  • Step 3. Run the HelloWorld Program.

  • 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.

    Project Window Project Window

  • Step 4. Edit and Re-Run HelloWorld

    Part 2: Editing, Compiling, and Running a Java Hello World Program

    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.

    Extend the HelloWorld class to do the following:

    1. Use the Scanner class to read user's name
    2. Use the Date class to get today’s date and time
    3. 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].
    Hint: You will also need to use SimpleDateFormat class to show the output nicely.
    Here is a sample output of this part:

    Lab Result Submission

    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.