for a Java program to run alone, within the program class, it should have a main function or method just like in C++. To compile the program, you need to go to command prompt, browse to the directory where your class file is, and enter "javac Class.java" at the command prompt; whereas Class.java is the name of your class file. Once it compiles without error, you can run the program with "java Class.class" at the command prompt.
More info