Tuesday, 11 November 2014

How to compile java file on cmd using javac command in Windows??

How to compile java file on cmd using javac command in Windows??

Step1:  First navigate to:

MyComputer -> Local Disk(C:) -> ProgramFiles -> Java - > jdk -> bin 
Now you will see a file named javac.exe in bin folder.

Step2: Now Copy the path of this folder and paste it on the notepad.






  NOTE: During the first Eight steps it should be taken care that your command prompt should not be open. If it is open close it first or else the changes might not be reflected in your command prompt.

Step3: Start -> Computer -> RightClick -> Properties

  Step 4: Now click on Advanced system settings

Step 5: Click on Environment Variables

Step6: Click on new.


Step 7: Now enter the name “PATH” and in value paste the path that was copied in Step 2 And Click OK

Step 8: You will see the variable path in the box. Click OK and exit from control Panel.

Step 9: Now run command prompt. Start -> cmd.

Step 10: Now compile your file using the command javac and provide the full path of the .java file.


Note: You might need to restart your computer if it does not work in the first go.
If even after this your javac command does not work then uninstall your JDK kit. Restart your computer and then reinstall the JDK kit and perform the above steps again.
If the problem still exists, then you need to change your JDK kit.


After successfully compiling your program you will see a *.class file on the same location as your  *.java file.

Now use the command "java" to execute your program:
eg: If the .class file after compiling is java1.class, then you use the command "java C:\ Users\Prakhar\Desktop\java1"

Happy to Help!!! Enjoy Coding!!!!


For any queries comment below...

No comments:

Post a Comment