Undocumented JAVA : Classpath vs path

The current Java developers start using eclipse from the day 1 and often forget the basic idea of path and classpath. Of even I have seen some experienced developers making such mistakes in understanding the basic difference.

Let me start by putting some words that can make sence.

Path: This is used by the OS to locate the executables. Any path defined inside this will refer to the location of the path. For e.g., if you want to have javac available to the entire shell/command prompt then you can set the path to the bin directory in the path.

I am assuming that the JAVA_HOME environment variable is pointing to your JDK installation folder.

Unix: set PATH=$PATH:$JAVA_HOME/bin
Windows: set PATH=%PATH%;%JAVA_HOME%\bin

This is good practice to use the existing values something like x = x + "new value" cos we also preserve the existing path that was set for other runtime applications.

This is mainly used by the JDK and the JRE. JDK will use this setting for compiling and the JRE will use this for the execution of the byte codes. Now, let me make this point more clear in the understandable terms, If you are using a 3rd party API, i.e., any classes referred outside the JDK/JRE you need to include these classes using the classpath.

Compile time (JDK): If you want to compile a servlet code then you need to include the servlet jars in the classpath.

Runtime (JRE): For loading a particular driver in JDBC you need to put the driver files in the classpath before running.

So, the point is very clear, most of the developers use the set of class files that are required to run also in the compile time environment. As it is it would not have any impact on the output. I just made a note for all to know the need to place the correct files during compile and runtime.

Please post your comments and that should encourage me in posting more on "
Undocumented JAVA"


Popular posts from this blog

Java SSL/TLS Testing Tool: Cipher Suite

Undocumented JAVA: Web Application: Deploy to the Cloud – Part 1

XML basics