1.2.1 Creating and Running the Echo Application


By following the steps on this page, you can create and use a stand-alone Java application that echoes the command line argument twice.
  1. Create a Java Source File
  2. Compile the Java Code
  3. Run the Java Program

Create a Java Source File
Create a file named Echo.java with the Java code shown here:
class Echo {
  public static void main (String[] args) {
    System.out.println(args[0]);
    System.out.println(args[0]);
  }
}

Compile the Java Code
To compile the source file, you type (in a Unix or DOS shell) on the command line:
javac Echo.java
If compilation succeeds, the compiler creates a file named Echo.class. This file contains the bytecodes of your application, i.e. the code that is suitable for the hypothetical system called Virtual Java Machine to run your program on. If compilation fails, make sure you typed in and named the program exactly as shown above.

Run the Java Program
To run the above Java application (under Unix or DOS shell), you type on the command line:
java Echo hello
And the program displays on the standard output:
hello
hello