From charlesreid1

Revision as of 16:08, 14 April 2012 by Admin (talk | contribs) (Created page with "=Getting Started= Download and install Java, if you need to. ==Hello World== This will walk through compiling and running a "Hello world" example in Java. ===The program=== ...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Getting Started

Download and install Java, if you need to.

Hello World

This will walk through compiling and running a "Hello world" example in Java.

The program

Here's a simple Java "Hello world" program:

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

Compiling

To compile this program, use the javac command:

$ javac HelloWorld.java

This will create a HelloWorld.class file, which is the Java executable.

Running

To run a Java executable, use the java command, and pass it the executable's filename without the extension:

$ java HelloWorld
Hello, world!