Home > Articles

  • Print
  • + Share This

Java Standalone Applications

With Java, unlike LotusScript, you can create standalone applications that you can run from a command-line prompt. In Windows, this is similar to the concept of an EXE program module. Java standalone applications have a main routine that is invoked by the runtime environment.

I'll be using some standalone applications to illustrate some concepts in this chapter and elsewhere, so I'd like to show you how to create a simple Java standalone application. Here it is:

public class MyMain0 {
  public static void main(String args[ ]) {
    System.out.println("Hello, Java");
  } // end main
} // end class

This routine will print out "Hello, Java" to the Java debugging console. The key point to observe about the example is that you must have a public static void method called main with a single parameter that represents an array of String objects.

You need a Java compiler to convert the source code into a class file. You can use any Java IDE such as IBM's Visual Age for Java, Symantec's Visual Café, or some other compiler. If you are using the Sun JDK, the compiler is called javac. Here is the command line to compile the program to produce the class file:

javac MyMain0.java

When you have this class file, you can run the program by passing the class filename to the Java executable, as in

Java MyMain0

This will run the compiled class file and display the output. Some Java compilers might be able to actually compile the class file into an executable.

  • + Share This
  • 🔖 Save To Your Account

Related Resources

There are currently no related titles. Please check back later.