[UMN logo]

CSCI 5106: Programming Languages
Using Java (Quick Guide)


I am going to assume that you have used Java already in earlier courses and within a Unix environment. As you probably know already, Java programs run on a virtual machine. Thus, to execute these programs, you first compile them, producing a byte code file that you then execute using a virtual machine emulator or a byte code interpreter.

To clarify the above observation, suppose you have stored the following Java program in a file called HelloWorld.java:

import java.io.DataInputStream;

class HelloWorld
{ public static void main(String[] args)
{ 
  System.out.println("Hello World");
}
}
You would then compile this using the command
% javac HelloWorld.java
%
Read % as the prompt symbol here. As indicated, the compilation would end without errors in this case and will produce a bytecode file in HelloWorld.class. To execute this code, you would invoke the following command with the accompanying results:
% java HelloWorld
Hello World
%
In general, your code will build on class definitions available from other locations. To permit the use of such definitions, you have to set the CLASSPATH variable to include all the relevant paths. I assume that you are familiar with these details. If not, ask a question about it on the class discussion forum and someone will help you out.


Created by gopalan atsign cs dot umn dot edu. Maintained by ngopalan atsign umn dot edu and evw atsign umn dot edu. Last modified: August 30, 2019.


The views and opinions expressed in this page are strictly those of the page author(s). The contents of this page have not been reviewed or approved by the University of Minnesota.