Sie sind auf Seite 1von 3

UG 20.

01: Introduction to Computers and Programming


Asian Institute of Technology
Handout 2: Lab 01 Instructions

September 2010
Information and Communication Technology
Instructor: Waheed Iqbal

Lab 1: Introduction to Linux and Java


Objectives
Introduce the Linux environment and basic shell commands.
Write, compile and execute a Hello World! Java program.
Understand the Eclipse IDE by creating a simple Java project, compiling, and running inside the
Eclipse IDE.

Credits: This lab uses material from C. Horstmanns Big Java, Fourth Edition (2010, Wiley).

Linux Basics
Ubuntu 9.10 is installed on the lab computers. Ubuntu is an open-source Linux-based operating system
alternative to Windows. We will learn the basic desktop environment and common shell commands. Please
login using the credentials provided by the lab instructor.
Play with the Ubuntu gnome desktop environment.
Launch a terminal (ApplicationAccessoriesT erminal) and practice the basic shell commands cd,
ls, pwd, whoami, and man.
Work with files and directories: touch, mkdir, cp, rm, and mv.
Use the synaptic package manager.

Java Hello World!


1. mkdir lab1 (Create directory lab1.)
2. cd lab1 (Switch to directory lab1.)
3. touch Hello.java (Create file Hello.java.)
4. gedit Hello.java (Open file to edit.)
5. Now type the following code:
public class Hello {
public static void main(String args[]) {
System.out.println("Hello World!");
}
}
6. Save Hello.java and exit from gedit.
7. javac Hello.java (Compile the Java program to JVM machine code. You should be able to see the
file Hello.class created in the lab1 directory).
8. java Hello (Start the JVM and ask it to execute your compiled Java program. The program should
produce Hello World! as an output.)

Java Hello World! Using the Eclipse IDE


Eclipse is an open-source Integrated Development Environment (IDE) that provides tools to manage workspaces
as well as to build, launch, and debug applications. We will use Eclipse 3.5 (Galileo) to develop our Java
projects.
1. Launch the Eclipse IDE installed in /opt/eclipse.
2. Create a new Java project (F ileN ewP roject)
3. Now select Java Project and press Next.
4. Enter project name HelloWorld and press Next.
5. Finally, press Finish. We have successfully created a Java project in Eclipse. Now we need to add a
class file containing our source code.
6. Create a new class (F ileN ewClass). Use the name Hello as the name of the class and press
Finish.
7. Type the body of the main method in the right place in the editor for the Hello.java source code file.
8. Compile and execute (RunRun)
Important! Did you see the differences between writing, compiling, and executing a Java program using
the command line and the Eclipse IDE? Put your observations in your lab report.

In-lab Exercises
Now you have enough knowledge to perform some of the exercises in the textbook. Please solve the following
exercises during the lab session and demonstrate your solutions to the lab instructor:
1. Exercise P1.1 on page 28
2. Exercise P1.9 on page 29
3. Exercise P1.10 on page 29

Homework Exercises
1. Suppose you need to list the contents of a directory in long listing format, sorted by the modification
time in reverse order. What parameters should you use with ls to perform this task? Hint: remember
the man command that gives you an online reference manual for Linux commands.
2. Implement Project 1.1 on page 30 in the textbook.
3. Download any non-trivial Java program from the Internet, compile it, and run it. You may use the
command line or the Eclipse IDE.
Show your work and describe any trouble you have in your lab report.

Submission Guidelines
Write a lab report in the format provided by the lab instructor. Your report should contain the following:
1. Your Hello World program and your observations on the command line and Eclipse environments.
2. Your solutions to the in-lab exercises.
3. Your solutions to the homework exercises.

For programs, provide the source code and output in your report. For homework exercise 3 (download and
run a program), provide the URL of the downloaded program, explain what you did to compile and execute,
and show a sample of the resulting output.
Submit a hard copy of your report to the lab instructor before the beginning of the next lab session.

Das könnte Ihnen auch gefallen