Centre for Advance Studies in Engineering (CASE)
Hand-out 8: Lab 08 Instructions
March 2014
Computer Science Department
Instructor: Shehreyar Rashid
Lab 8: Introduction to Java and Sockets
Objectives
Write, compile, and execute Java programs in Linux using command line.
Use an IDE to write, compile, and execute Java programs in Linux.
Learn to write client-server application using Sockets.
Credits: This lab uses material from Silberschatz, Galvin, Gagne Operating System Concepts,
8th Edition (2011, Wiley).
Java Program Using Command Line
In this section, we learn to write, compile, and execute a Java program in Ubuntu (Linux). We have download JDK and Netbeans in to lab computers. The lab instructor will help you to know the locations for the JDK, and Netbeans IDE to download and work.
1.
2.
3.
4.
Open a terminal and go to the directory containing JDK. tar xvzf (decompress the file into a folder). mv jdk1.7.0 13 ~/jdk1.7 (move the folder into your home directory). gedit ~/.bashrc (bashrc file contains verious commands and environment variables for the shell). 5. Type in the following command at the end of the file: export JAVA_HOME=~/jdk1.7/bin/java export PATH=$PATH:~/jdk1.7/bin
6. Save and exit from gedit.
7. source ~/.bashrc (make sure the newly declared environment variables are available for the current terminal).
8. Now create a File named \Hello.java" and type in the following code: public class Hello
{
public static void main(String[] args)
{
System.out.println("Hello World!");
}
}
9. Save and exit from gedit.
10. javac Hello.java (compile a java source code into a byte code).
11. java Hello (execute a java program).
12. Task! Now modify your program and print “Hello World!” 10 times using a for loop.
13. Task! Now create another java program which prints n!.
CS 2203: Operating Systems
Centre for Advance Studies in Engineering (CASE)
Hand-out 8: Lab 08