CS 102 Lab 1: Introduction to CS 102

Synopsis:


 

Explanation of lab assignments and grading

Lab assignments are always group assignments, and are turned in via "turnin" command.  The grading criteria for lab assignments is:

0 point

Did not turn in or amount of work was insufficient

1 point

Made a reasonable attempt for most of the required exercises.

2 points

Clearly understood and correctly completed most of the required exercises.

3 points

Clearly understood and correctly completed all of the required exercises, and correctly answered all the required questions.

Introduction to compiling and running Java programs from console

  1. Open the "Terminal". You can find it in Applications > Accessories > Terminal.
  2. Create a Java source code named "HelloWorld.java". You do that by typing in the terminal nano HelloWorld.java.
  3. Copy the source code from here and paste it into the file you just created.
  4. Save the file. You do that by pressing Ctrl+X, then type Y when prompted and ENTER to complete the save.
  5. Check the file has been created by typing ls in the terminal.
  6. Compile the source code. You do that by typing javac HelloWorld.java.
  7. Check the class file HelloWorld.class has been created by typing ls in the terminal.
  8. Run the class file by typing java HelloWorld.
  9. You will see the output of the program.
    terminal

Introduction to Eclipse, a Java IDE

  1. Start up Eclipse.  In the terminal window type eclipse. Press ENTER.
  2. Eclipse should start now.  Select a workspace folder. Keep note of the project folder. You'll need it later. From the menu, select File > New > Project  In the Select a wizard window select Java > Java Project
  3. NewProject

  4. In the following window type in the project name. Click on NEXT.  
  5. The project name appears on the left side of the screen. Right-click on Project name, then New > Class.

    New Class

    This will open the source code editor in the center of the screen.

  6. Copy and paste the code from here into the source code editor, replacing all of the original source code.
  7. From the menu, select the Run button, then Run As > Java Application

    Run As

  8. The output of the program should appear in the bottom part of Eclipse.

Submitting the file(s)

Turning in your Java program using the turnin command 

  1. Using “ls” command to see what directories and files under current directory.
  2. Make sure your working directory contains what you want to submitUsing “cd DirectoryName” to change current working directory. For example, if you previously created a directory called cs102 as the workspace of Eclipse and have been putting your files there, then before you can successfully execute the turnin command you must first change into the cs102 directory by using the command in the terminal:
      
    cd cs102
  3. In the terminal window, type the following and press ENTER:
turnin -c cs102 -p lab1 HelloWorld.java

4.             To check that your program really was successfully turned in, type the following and press ENTER:

turnin -c cs102 -p lab1 -v 

5.             You have just turned your Java source code (HelloWorld.java).  Note that this is different from your program (HelloWorld.class).  We will never    

accept the .class files for grading, so make sure that the file you turned in has the .java extension.  

Write your first program

Modify the Hello World program in such a way it displays "Hello, [name]!" where name is a command-line argument passed to your program.