Anda di halaman 1dari 2

What is PATH and CLASSPATH in Java - Path vs ClassPath What is PATH and CLASSPATH in Java PATH and CLASSPATH

are two most important environment variable of Java environment which is used to find JD binaries used to compile and run Java in windows and Linu! and class files which are compile Java b"te codes# $rom m" personal e!perience % can sa" that PATH and CLASSPATH are two most problematic thin& for be&inners in Java pro&rammin& lan&ua&e due to two reasons' first because in most of Java courses nobod" tell details of What is PATH and CLASSPATH( What does PATH and CLASSPATH do( What is meanin& of settin& PATH and CLASSPATH( What happens if we do not set them( Difference between PATH vs CLASSPATH in Java or simpl" How Classpath wor)s in Java etc# These basic *uestion which answers most of details about PATH and CLASSPATH in Java are mostl" not answered until Java pro&rammer itself ac*uire these )nowled&e( Thin&s ma" been chan&ed now da"s but important of PATH and CLASSPATH is still hi&h# +ost common cause of dreaded error li)e ,ava#lan&#-oClassDef$ound.rror and ,ava#lan&#Class-ot$ound.!ception are incorrect or misconfi&ured CLASSPATH in Java#

Difference between PATH and CLASSPATH in Java Here are some of the common difference between PATH vs CLASSPATH in Java / 01+ain difference between PATH and CLASSPATH is that PATH is an environment variable which is used to locate JD binaries li)e 2,ava2 or 2,avac2 command used to run ,ava pro&ram and compile ,ava source file# 3n the other hand CLASSPATH environment variable is used b" S"stem or Application ClassLoader to locate and load compile Java b"tecodes stored in #class file# 41 %n order to set PATH in Java "ou need to include JD 5H3+.6bin director" in PATH environment variable while in order to set CLASSPATH in Java "ou need to include all those director" where "ou have put either "our #class file or JA7 file which is re*uired b" "our Java application# 81 Another si&nificant difference between PATH and CLASSPATH is that PATH can not be overridden b" an" Java settin&s but CLASSPATH can be overridden b" providin& command line option -classpath or -cp to both 2,ava2 and 2,avac2 commands or b" usin& Class-Path attribute in +anifest file inside JA7 archive# 91 PATH environment variable is used b" operatin& s"stem to find an" binar" or command t"ped in shell( this is true for both Windows and Linu! environment while CLASSPATH is onl" used b" Java ClassLoaders to load class files# These were some notable difference between PATH vs CLASSPATH in Java and the" are worth rememberin& to debu& and troubleshoot Java related issues# How to set PATH and CLASSPATH in Windows and :ni! What is PATH and CLASSPATH in Java ( Difference between them%f "ou are familiar with D3S operatin& s"stem and how to use command prompt in Windows or shell in Linu! settin& PATH and CLASSPATH is trivial e!ercise# ;oth PATH and CLASSPATH are environment variable and can be set usin& e!port in Linu! and usin& set )e"word in D3S and Windows as shown below/ Command to set PATH in Windows

set PATH<=PATH='C/>Pro&ram $iles>Java>JD 0#?#4@>bin Command to set PATH in :-%A6Linu! e!port PATH < BCPATHD/6opt6Java6JD 0#?#0E6bin Loo) at the difference between two commands( in Linu! use colonF/1 as separator and in Windows use semi-colonF'1 as separator# Command to set CLASSPATH in windows set CLASSPATH<=CLASSPATH='C/>Pro&ram $iles>Java>JD 0#?#4@>lib Command to set CLASSPATH in :ni!6Linu! e!port CLASSPATH< BCCLASSPATHD/6opt6Java6JD 0#?#0E6lib Also donGt for&et to include current director"( denoted b" dotF#1 to include in CLASSPATH( this will ensure that it will loo) first on current director" and if it found the class it will use that even if that class also e!ists in another director" which e!ists in CLASSPATH#