COMMON ERROR MESSAGES ON MICROSOFT WINDOWS SYSTEM
FLOW OF THE PROGRAM DURING COMPILATION AND EXECUTION :
JAVA IS PLATFORM INDEPENDENT :
COMPILER PROBLEMS :
1. ‘Javac’ is not recognised as an internal or external command, operable program or batch file.
If you receive this error , windows cannot find the compiler ( that is Javac)
so , you should tell the windows to find the compiler(Javac) by setting up the path.
suppose you installed the jdk setup file in c-drive , then , set the path in command prompt as
c:\program files\Java\jdk1.6.0\bin;.; and press enter. now the windows will know where the compiler ( Javac ) is.
To ensure the path , which you have set correct or not , then type in the command prompt as
echo %path% and press enter then it will show you the path you have given to the windows.
RUNTIME PROBLEMS :
CLASSPATH : If you receive this error ,
Exception in thread “main” java.lang.NoClassDefFoundError: HelloWorldApp(example program )
consider, that you have written a Java code and saved it in a ‘d’ drive in Java programs then you have to set the classpath for your program execution in command prompt .
- you need not be set the classpath if you were in the same drive and in the same folder where your’e .class file is present .
- if not , you were in another drive in command prompt then you should set the classpath for the program execution
To do so, you have to tell the windows where the .class file is by setting up the classpath ( if you were in another dirve )
set classpath=d:\Javaprograms;.; press enter
To ensure the classpath then type
echo %classpath% press enter
NOTE: To compile a program path setting is required and to run a program classpath setting is required . So to avoid this extra typing each time when you compile or run a program , set path permanently by the following way.
PERMANENT PATH SETTING :
Updating the PATH Environment Variable (Optional)
You can run the JDK without setting the PATH environment variable, or you can optionally set it so that you can conveniently run the JDK executable files (javac.exe, java.exe, javadoc.exe, and so forth) from any directory without having to type the full path of the command. If you do not set the PATH variable, you need to specify the full path to the executable file every time you run it, such as:
C:\> “C:\Program Files\Java\jdk1.7.0\bin\javac” MyClass.java
It is useful to set the PATH variable permanently so it will persist after rebooting.
To set the PATH variable permanently, add the full path of the jdk1.7.0\bin directory to the PATH variable. Typically, this full path looks something like C:\Program Files\Java\jdk1.7.0\bin. Set the PATH variable as follows on Microsoft Windows:
Click Start, then Control Panel, then System.
Click Advanced, then Environment Variables.
Add the location of the bin folder of the JDK installation for the PATH variable in System Variables. The following is a typical value for the PATH variable:
- Running a Command Prompt from a Java program in Windows (stackoverflow.com)
- Path Setting (daniweb.com)
- Runtime Classpath vs Compile-Time Classpath (java.dzone.com)