Monday 1 October 2012

How To Save, Compile, and Run your Java program

Below are the steps outlined below to save, compile, and run your Java program.

Saving a Java Program

You can use any editor or word processing program to create and edit a Java program, as long as it can save files in ASCII format. Java programs must be saved in a file whose name ends with the .java extension, so using your favorite ASCII editor and save the program to a file named DateApp.java.

Compiling a Java Program

The Java compiler translates Java source code into Java bytecodeswhich are components of a machine-level language for the Java virtual machine. Java bytecodes are interpreted and executed by the Java interpreter.
When you compile a Java source file, the compiler creates a file with the .class extension in the same folder as the source file. The compiler names the resulting .classfile after the class defined in the source file. For example, when you compile the DateApp class you created above, the compiler names the resulting class file DateApp.classafter the class, regardless of the name of the source file. Even if you were to save the DateApp class to a source file named Wow.java, the compiler would still create a file named DateApp.class. By convention, to alleviate confusion, Java source files are named for the class defined within.

Running a Java Application

Now, we can run our application using the Java interpreter. The program should display the current date and time.

No comments:

Post a Comment