Getting Started

 

 


 

Contents

  1. Overview
  2. HelloWorld Application
  3. HelloWorld Applet

 


 

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

  1. Create a source file, HelloWorldApp.java:

    class HelloWorldApp 
    {
        public static void main(String[] args) 
        {
            System.out.println("Hello World!"); 
        }
    }
    

  2. Generate a Java bytecode file, HelloWorldApp.class:

    javac HelloWorldApp.java

  3. From the command-line, run the program.

    java HelloWorldApp

 


 

HelloWorld Applet

  1. Acquire a Java-enabled Web browser such as HotJava, Mozilla, or Explorer.

  2. 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); 
        }
    }
    

  3. 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>
    

  4. Generate a Java bytecode file, HelloWorld.class:

    javac HelloWorld.java

  5. Run the applet from an HTML file, HelloWorld.html:


 

Home