Steps in Creating, Compiling and Executing a Java Program
1. Write the source code in Notepad or a "java envirionment", save as name.java
To use the command prompt window (black window)
2. Open the command prompt window from Accesories or from the run command on the start menu by writing "cmd"
3. The window opens in a file/folder location. To change the location:
A. C: to change to the C: (local computer) drive
B. cd.. to drop back on directory (ie, c:/javafiles/html after the cd.. will be c:/javafiles)
C. cd javafiles to move for the javafiles directory
4. Additional commands: to list all the items within the folder write the command dir
to list selected items in a folder write a command such as dir *.java (for all .java source listings)
5. To compile the java program (source code) once you are in its folder the command is:
javac ProgramName.java
This creates a byte code version of the program called; ProgramName.class
6. To execute the compiled program (class file) within the folers the command is:
java ProgramName
Summary of command used:
cd parameter (change directory)
examples: cd .. (up or back one directory)
cd javafiles change to javafiles
dir (list directory)
examples: dir (lists entire directory
dir *.java (lists all xxx.java files in directory)
javac PgmName.java (creates the byte code PgmName.class file)
Java PgmName (runs the PgmName.class file)
|