Google
 

 

up previous next contents
Up: 2. Day 2: The Previous: 2.1 Introduction Next: 2.3 Variables, constants, and   Contents

Subsections

2.2 First Steps with Java

2.2.1 Java Commands and Utilities

  • javac - the Java compiler
  • java - the Java bytecode interpreter (JVM)
  • appletviewer - lets you view applets without a browser
  • jdb - the Java debugger
  • javadoc - a utility that lets you generate documentation from your Java source code and the Javadoc comments you place in your source code
  • jar - Java archive utility (similar to the Unix tar command)

2.2.2 A first application

  • Assuming you have the JDK downloaded/installed, create a first Java application:
    public class Hello
    {
      public static void main(String[] args)
      {
        System.out.println( "Hello, world" );
      }
    }
    
  • Save the file as Hello.java.
  • Compile the file to Java bytecode:
        javac Hello.java
    
  • Run the program:
        java Hello
    

2.2.3 main

  • When you run a Java application, the system locates and runs the main method for that class.
  • The main method must be public, static, and void.
  • The main method must accept a single argument of type String[].
  • The arguments in the String array passed to main are program arguments, or command-line arguments.
  • An application can have any number of main methods, because each class can have one.
  • This is good, because each class can have a main method that tests it's own code.