Getting Started
Contents
Overview
Java programs are compiled into Java bytecodes, which are parsed and executed by an interpreter. Compilation happens just once; interpretation occurs each time the program is executed.
Types of Java programs include:
Type Milieu applications Command-line applets Java-enabled browsers servlets Application servers To compile and run Java programs download and install the Java 2 Platform, which includes both the JVM and the API.
HelloWorld Application
- Create a source file, HelloWorldApp.java:
class HelloWorldApp { public static void main(String[] args) { System.out.println("Hello World!"); } }- Generate a Java bytecode file, HelloWorldApp.class:
javac HelloWorldApp.java- From the command-line, run the program.
java HelloWorldApp 
HelloWorld Applet
- Acquire a Java-enabled Web browser such as HotJava, Mozilla, or Explorer.
- Create a source file, HelloWorld.java:
import java.applet.*; import java.awt.*; public class HelloWorld extends Applet { public void paint Graphics(g) { g.drawString("Hello world!", 50, 25); } }- Create an HTML file to accompany your applet, HelloWorld.html:
<html> <head> <title>The Hello World Applet</title> </head> <body> <applet code="HelloWorld.class"> </applet> </body> </html>- Generate a Java bytecode file, HelloWorld.class:
javac HelloWorld.java- Run the applet from an HTML file, HelloWorld.html: