- First create a source code then save the code in a file class name of program with .java extension Hello.java. Write the source code in Notepad, first choose the File Save As menu item. Then, in the Save As dialog box:
- Specify the folder (directory) where you'll save your file. In this example, the directory is Newfolder on the C drive.
- In the File name text field, type Hello.java.
- From the Save as type combo box, choose Text Documents (All Files).
- Compile the Source File into a .class File.
- Open "comand prompot" window. You can first start then run type cmd and then this console window is open
- The command prompt shows your current directory, show your current directory your home directory for Windows 7. To compile your source file then generate a byte code (.class file). For example, if your source directory is Newfolder on the C drive, type the following command at the prompt and press Enter:
- cd C:\Newfolder
- Now the prompt should change to C:\Newfolder.
- If you enter dir at the prompt, you should see your source file, as follows:
- C:\>cd Newfolder
- C:\Newfolder>dir Volume in drive C is System Volume Serial Number is F2E8-C8CC
- Directory of C:\myapplication
- Now you are ready to compile. At the prompt, type the following command and press Enter. javac Hello.java
- The compiler has generated a bytecode file, Hello.class. At the prompt, type dir to see the new file that was generated as follows: Now that you have a .class file, you can run your program. C:\Newfolder> java Hello
Now click Save, and exit Notepad.