Java Tool Tutorials - Herong's Tutorial Notes
Dr. Herong Yang, Version 4.12, 2006

'java' - The Java Launcher

Part:   1   2  3  4 

Java Tool Tutorials

© 2006 Dr. Herong Yang

Latest updates:

  'javac' - The Java Compiler

  'java' - The Java Launcher

  'jdb' - The Java Debugger

  JAR File & 'jar' Tool

  Certificates and 'keytool'

  Installing J2SE 1.5.0

... Table of Contents

This chapter describes:

  • "java" Command
  • Hello.java - My First Application
  • "-classpath" - Specifying Class Path
  • "-jar" - Executable JAR Files
  • "-X" Options to Control Memory Size
  • "javaw" - Launching Java Applications without Console

"java" Command

"java": A command line tool that launches Java applications. It starts a Java virtual machine, loads the specified class, and invokes that class's main method. "java" has the following syntax:

java [options] class [arguments]

where "options" is a list of options; "class" is the full name of a Java class to be launched; "arguments" is a list of arguments to be passed to the main method of the class to be launched.

Another way of launching a Java class is to use the "-jar" option:

java [options] -jar file [arguments]

where "file" is a JAR file, which should contain a "Main-Class" attribute in the manifest file. The "Main-Class" attibute defines the Java class to be launched.

Commonly used options are:

  • "-help" - Displays a short help text.
  • "-verbose" - Generates verbose output to standard output.
  • "-version" - Prints the version information of the launcher.
  • "-classpath classpath" - Specifies a list of path names where the launcher will search for compiled type definitions. If "-classpath" is not specified, the current directory will be used as the class path.
  • "-Dproperty=value" - Defines a new system property, which can be accessed by the application.

Hello.java - My First Application

To test the Java launcher, I wrote the following Java file, Hello.java:

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

Here is what I did in a command window to compile Hello.java into Hello.class:

>javac Hello.java

>dir Hello.*
   416 Hello.class
   116 Hello.java

>java Hello
Hello world!

As you can see, launching a Java application is easy.

(Continued on next part...)

Part:   1   2  3  4 

Dr. Herong Yang, updated in 2006
Java Tool Tutorials - Herong's Tutorial Notes - 'java' - The Java Launcher