Sunday, May 2, 2010

PATH and CLASSPATH

PATH and CLASSPATH

The following are the general programming errors, which I think every beginning java programmer would come across. Here is a solution on how to solve the problems when running on a Microsoft Windows Machine.
1. ‘javac’ is not recognized as an internal or external command, operable program or batch file
When you get this error, you should conclude that your operating system cannot find the compiler (javac). To solve this error you need to set the PATH variable.
How to set the PATH Variable?
Firstly the PATH variable is set so that we can compile and execute programs from any directory without having to type the full path of the command. To set the PATH of jdk on your system (Windows XP), add the full path of the jdk\bin directory to the PATH variable. Set the PATH as follows on a Windows machine:
a. Click Start > Right Click “My Computer” and click on “Properties”
b. Click Advanced > Environment Variables.
c. Add the location of bin folder of JDK installation for PATH in User Variables and System Variables. A typical value for PATH is:
C:\jdk\bin (jdk
If there are already some entries in the PATH variable then you must add a semicolon and then add the above value (Version being replaced with the version of JDK). The new path takes effect in each new command prompt window you open after setting the PATH variable.
2. Exception in thread “main” java.lang.NoClassDefFoundError: HelloWorld
If you receive this error, java cannot find your compiled byte code file, HelloWorld.class.If both your class files and source code are in the same working directory and if you try running your program from the current working directory than, your program must get executed without any problems as, java tries to find your .class file is your current directory. If your class files are present in some other directory other than that of the java files we must set the CLASSPATH pointing to the directory that contain your compiled class files.CLASSPATH can be set as follows on a Windows machine:
a. Click Start > Right Click “My Computer” and click on “Properties”
b. Click Advanced > Environment Variables.
Add the location of classes’ folder containing all your java classes in User Variables.
If there are already some entries in the CLASSPATH variable then you must add a semicolon and then add the new value . The new class path takes effect in each new command prompt window you open after setting the CLASSPATH variable.

Java 1.5

The Java 1.5 released in September 2004.
Goals
Less code complexity
Better readability
More compile-time type safety
Some new functionality (generics, scanner)

New Features
Enhanced for loop
Enumerated types
Autoboxing & unboxing
Generic types
Scanner
Variable number of arguments (varargs)
Static imports
Annotations

No comments: