Pages

Monday, January 14, 2013

Java Programming Errors

1. 'javac' is not recognized as an internal or external command, operable program or batch file.

When trying to compile a java code from command line, there is a possibility that you might get this error.
The solution to this is to add the path variable to environmental variables.

Steps:
1.Go to Control Panel > System
2.Click on Advanced System Settings on the left.
3.Under Advanced Tab, Click on Environmental Variables.
4.Under User Variables(If you want to define for the current user only) or Under System Variables(If you want to define for all users),Click on New.
5.Set Variable Name to PATH(Case sensitive) and Variable value to C:\Program Files\Java\jdk1.6.0_38\bin(the exact path to the javac.exe) file.
6. Now go the folder where the .java file is located.
7. Type the commmand "javac filename.java" . A .class file with the same name will be created. This means that the java file is compiled.
8. Now type the command "java filename(without the extension .java)". The file will run and print the output if any.