More Tutorials
GETTING STARTED WITH JAVA

this document summarizes the steps necessary for preparing, compiling and running JAVA application using the Java Development Kit (JDK) utilities.

To compile your java source program, you will be using the Java Development Kit (JDK), a collection of programs run in UNIX and/or DOS command mode. These programs are freeware and can be downloaded from the Internet, if you wish to install them on your home computer. Versions of the JDK exist for most pllatforms, including Microsoft Windows, UNIX, and Macintosh. These utilities include:

The compiler program "javac" converts your source code into bytecode.

The program "java" loads and executes your bytecode after converting it to the machine code that is specific to your computer.

Executable files such as "javac","java" are run by typing their name followed by any required parameters. The parameters for the commands can be found using 'man' command on gemeni.csil.sfu.ca.

The typical steps are as following:

1. You can create a new Java document by either of the following two ways:

1.1 You can use any text editor in your personal directory on gemini.csil.sfu.ca (like vi, emacs), to create the Java document, save it as a text file with .java suffix. On simple Java Class document is as follows:

 

Program Hello.java

public class Hello

{ public static void main(String[] args)

{ System.out.println("Hello, CMPT470!");

}

}

 

1.2 Or, you can create the Hello.java document in any other machine, including your home PC, using any text editor, as Notepad, then use FTP to transfer the text file to gemini.csil.sfu.ca.

 

2. Log on to gemini.csil.sfu.ca: (in your case, replace tlie by your own Unix ID)

 

11: tlie_gemini% cd /WWW/users/tlie //change to your own personal directory /WWW/users/tlie

12: tlie_gemini% javac Hello.java //to compile Hello.java into Hellow.class

13: tlie_gemini% java Hello //to execute your first Java program

Hello, CMPT470!

 

Congradulations! Your have successfully compiled and executed your Java program.

More Tutorials