We have discussed about path variable in the previous tutorial.Java compiler(javac) converts *.java file into *.class file.Now this byte code is converted into machine code by the JVM. Classpath variable is used by the JVM to search *.class files in different directories.
Note:JVM searches for .class files contained in rt.jar package.
Exception in thread “main” java.lang.NoClassDefFoundError
Often the beginners of java face this error. After compiling the program successfully when you run it : C:\java> java Hello C:\java>Exception in thread “main”java.lang.NoClassDefFoundError:Hello The above message is displayed on the screen.It means that JVM was not able to find *.class file or simply the byte code. Even after setting the PATH and CLASSPATH variable correctly this error occurs. Do you know where the problem is? It lies in the CLASSPATH variable.In the CLASSPATH there should be .;set the classpath in environment variable in the following manner: name=CLASSPATH Value=.;C:\Program Files\Java\jdk1.6.0_18\lib;
… yes.. a dot .. it means, that JVM will search for classes bytecode in the current directory ! The beginners of java get discouraged by such problems.No need to worry the team at programmingbulls is always there to help you.