Hello World in Java

This example shows how to run a simple program in Java:

  public static void main(String[] args)
  {
    // Initialize some variables
    int foo = 3;
    int bar = 42;
 
    /* Print something to the console */
    System.out.println("foo: " + foo);
    System.out.println("bar: " + bar);
  }

Here's the output:

foo: 3
bar: 42