Thursday, 15 December 2016

Difference between PATH and CLASSPATH in Java

Here are some of the common difference between PATH vs CLASSPATH in Java :

1) PATH is an environment variable which is used to locate JDK binaries like "java" or "javac" command used to run java program and compile java source file. CLASSPATH, an environment variable is used by Java to locate and load compile Java bytecodes stored in the .class file.

2) In order to set PATH in Java, you need to include JDK_HOME/bin directory in PATH environment variable while in order to set CLASSPATH in Java you need to include all those directories where you have put either your .class file or JAR file which is required by your Java application.

3) Another significant difference between PATH and CLASSPATH is that PATH can not be overridden by any Java settings but CLASSPATH can be overridden by providing command line option -classpath or -cp to both "java" and "javac" commands.

4) PATH environment variable is used by operating system to find any binary or command typed in the shell, this is true for both Windows and Linux environment while CLASSPATH is only used by Java ClassLoaders to load class files.

These are some notable difference between PATH vs CLASSPATH in Java.
How to set PATH and CLASSPATH in Windows and Unix
Use command prompt in Windows or shell in Linux to set PATH and CLASSPATH . Both PATH and CLASSPATH are environment variable and can be set using 
set keyword in DOS and Windows and export command in Linux

Command to set PATH in Windows

set PATH=%PATH%;C:\Program Files\Java\JDK1.6.20\bin

Command to set PATH in UNIX/Linux

export PATH = ${PATH}:/opt/Java/JDK1.6.18/bin

In Linux use a colon(:) as a 
separator and in Windows use semi-colon(;) as a separator.

Command to set CLASSPATH in windows

set CLASSPATH=%CLASSPATH%;C:\Program Files\Java\JDK1.6.20\lib

Command to set CLASSPATH in Unix/Linux

export CLASSPATH= ${CLASSPATH}:/opt/Java/JDK1.6.18/lib

1 comment:

  1. Excellent post on Java!!!Everyone are repeating the same concept in their blog, but here I get a chance to know new things in Java programming language. I will also suggest your content to my friends to know about recent features of Java.
    java j2ee training
    core java training in chennai


Related Posts Plugin for WordPress, Blogger...