CS 102 Lab 1: Introduction to CS 102
- Date: Wednesday, January 13th, 2009
- Location: SEL 2250 (CS Lab)
- Instructor: Rigel Gjomemo, ABM Musa
Synopsis:
- What you
will learn today:
- Explanation
of lab assignments and grading.
- Introduction to compiling and running Java programs from console.
- Introduction
to Eclipse, a Java IDE.
- Submitting files.
- What you will do today: write your first program
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
- Open the "Terminal". You
can find it in Applications > Accessories > Terminal.
- Create a Java source code named
"HelloWorld.java". You do that by typing in the terminal nano HelloWorld.java.
- Copy the source code from here and paste it into the file you just created.
- Save the file. You do that by pressing Ctrl+X, then type Y when prompted and ENTER to complete the save.
- Check the file has been created by typing ls in the terminal.
- Compile the source code. You do that by typing javac HelloWorld.java.
- Check the class file HelloWorld.class has been created by typing ls in the terminal.
- Run the class file by typing java HelloWorld.
- You will see the output of the program.

Introduction to Eclipse,
a Java IDE
- Start up Eclipse. In the terminal window type eclipse. Press ENTER.
- 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
- In the following window type in the project name. Click on NEXT.
- The project name appears on the left side of the screen.
Right-click on Project name, then New > Class.
This will open the source code editor in the center of the screen.
- Copy and
paste the code from
here into the
source code editor, replacing all of the original source code.
- From the
menu, select the Run button, then Run As > Java Application.
-
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
- Using “ls”
command to see what directories and files under current directory.
- Make
sure your working directory contains what you want to submit. Using
“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
- 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.