Wednesday, April 26, 2006

How to compile a Java program

How to Compile and Run a Java Program


Everytime you make a Java program, you will follow the same 3 steps:
Create a source file. This is the file where you write the java code. This file can be written in any text editor (such as Notepad on Windows or Xemacs on UNIX). This file must be saved with a .java extension.Note: the Java compiler is case-sensitive so you must capitalize consistently. HelloWorld is not the same as helloworld.
Compile the source file. The compiler, javac, takes your source file and translates it into bytecode.
Bring up the Command Prompt
Windows XP- Start Menu->Accessories->"Command Prompt"
Windows 95/98/2000/NT/ME - Start menu->"MS-DOS Prompt"
UNIX - Open eterm or xterm
Move into the directory that contains your source file(s)
Type cd dirname to change directories (where dirname is in the name of the directory you want to go into and is located in the current directory).
Type ls in UNIX or dir in DOS (Windows) to list the contents of the current directory.
Type ../ to move up (back) a directory.
Type javac filename
filename should be the name of your .java source file(s)
If you have errors trying to compile, see our FAQ Page.
Run the program. Since we are dealing only with Applets in this guide, there are 2 options for running your program. We can either view the applet with the AppletViewer or embed our applet on a website and view it in a java-enabled web browser.
Web -
Create a web page
For help see Basic HTML or use this basic template.
Make sure that you set the source of the Applet to the name of your compiled class files. I.E. In the

0 Comments:

Post a Comment

<< Home