or drag border to resize
Best viewed with Firefox
Bitcoin donation, thank you
Post this site to

Java Fundamentals

Previous Next

2. Compile and run

To build class files from your source code you use a compiler.
You could download and install Oracle's Development Kit to do that.

Windows example :
In a console window ( Start, Run, cmd or R, cmd ) go to the directory that contains Simplest.java.
For example :
c: to drive C:
cd \ to root directory
cd work to directory work

"C:\Program Files\Java\jdk1.7.0_25\bin\javac.exe"  Simplest.java

( The first part, like C:\Program Files\Java\jdk1.7.0_25, depends on what version you have downloaded and where you've installed it.)

This will either result in the Simplest.class file or in error messages, if you've 'mishpeledd' something, omitted a  , have a  too many, mixed up lowercase,uppercase, etc....

The Simplest.class file contains Java instructions, bytecodes.
Put this file in the same directory/folder as the HTML file, Simplest.html .

Open the HTML file in your browser and see the applet run, if your Java Console security settings allow it.
Could be, you have to lookup the Java Console in the Control Panel. Then lower the security setting on its security tab, close and open the browser. Remember to set it back, when you're done.

Another way to test an applet, is by using Sun's appletviewer tool:

  "C:\Program Files\Java\jdk1.7.0_25\bin\appletviewer.exe" Simplest.html

Yes, the argument is the HTML file.
This, unlike a browser, ignores the rest of the HTML, though. Only convenient for testing the applet by itself.

Alternatively, you could use a tool (an IDE) like Eclipse. Working with Eclipse is explained in our Eclipse guide. (In Eclipse you don't have to provide the HTML file and you can run an applet by selecting the source file name, fe 'Simplest.java' and then choosing 'Run, Run As, Java Applet')

Another way to do development is by using Oracle's Netbeans tool. Make a new project by choosing File, New project
Java, Java application, Next
Name it and remove the check from Create Main Class
Then you choose
File, New File
Java, Applet, Next
Fill in the class name, f.e. Simplest, then click Finish
Now you can change the code in the editor and then compile and run it by choosing
Run, Run File

Running a stand-alone application, without a browser, with a 'main' method, is different. We deal with that in our lesson '36.Stand-alone application'. That would be something like
"C:\Program Files\Java\jdk1.6.0_02\bin\java" ClassWithMain (without the extension .class!)
In Eclipse : 'Run, Run As, Java Application'



Double-click to select or


Copyright © 2000-2014 System Exclusive & Multi Midi (NL) All rights reserved

Terms, conditions, disclaimer