Languages::Java

PIC Lab



There are generally two types of Java programs: applications and applets. An application contains a main function and runs on its own. An applet contains a paint method an runs within a web page. Each type is compiled differently.

Compiling an application:

  1. Use your favorite text editor (our favorite is jEdit, but Visual C++/J++, or at the worst, Notepad, will do) to type up your Java program and save it. Suppose the filename is hello.java.
  2. Open a command prompt window using Start -> Programs -> Command Prompt. On Windows NT/2000 this program is cmd.exe, on other systems it is command.exe.
  3. Change directories to where you saved your .java file. Example: cd pic20a.
  4. Type javac hello.java to compile your program. This will create the file hello.class
  5. Type java hello to run your application. Note that you do not type .class after the filename.

Compiling an applet:

  1. Follow steps 1-4 above.
  2. Use your text editor to create an html file with the following code: <applet code="hello.class" width=100 height=100>. Note you can change the width and height to whatever size you like. Save it as hello.html
  3. Type appletviewer hello.html to view the applet.

Reference:

Sun Microsystems has an excellent Java reference page (http://java.sun.com/products/jdk/1.2/docs/api/index.html) which details every method and field of every built-in class.

Feedback
PIC Lab home
up one level
UCLA Department of Mathematics
Program in Computing - PIC Lab
2817 Boelter Hall / 310-825-7267
This page last updated: July 03, 2001