Java - Interview Questions and Answers on Path and ClassPath

Q1.  How to display and set the Class path in Unix ?

Ans. To display the current CLASSPATH variable, use these commands in UNIX (Bourne shell):

% echo $CLASSPATH

To delete the current contents of the CLASSPATH variable, 

In UNIX:      % unset CLASSPATH; export CLASSPATH

To set the CLASSPATH variable, 

In UNIX:      % CLASSPATH=/home/george/java/classes; export CLASSPATH


Q2.  What environment variables do I need to set on my machine in order to be able to run Java programs?


Ans. CLASSPATH and PATH are the two variables.


Q3.  Difference between PATH and CLASSPATH ?

Ans. PATH is the variable that holds the directories for the OS to look for executables. CLASSPATH is the variable that holds the directories for JVM to look for .class files ( Byte Code ).