1))What is the difference between "path" and "classpath"? Ans:: We keep all "executable files"(like .exe files) and "batch files"(like .bat) in path variable. And we keep all jar files and class files in classpath variables. So path is set according to the .exe files & .bat files And classpath is set according to the .jar files & .class files.
Operating system tries to find .exe and .bat files in path and JVM tries to find all classes in classpath.
Chat with our AI personalities
first of all java program compilation purpose can totaly search in java classes in there classes not available the class so generate the error so avoid the that error javac next check the classpath and after path will be checked path also correct the progarm automatically process otherwise not run the programs.
PATH is required to locate "java" and "javac" command which is used to compile and run java classes
CLASSPATH is used by Classloaders to load classes.
java is object oriented language which work on classes and interfaces. To find the definitions of objects and method JVM (java virtual machine) compiler required class files or interface file. And compiler only search in set path locations. Hence to give reference of particular class in specific location we have to set the path every time to new application.
To set the Java classpath during compilation or execution of a Java program:
javac -cp <classpath> <source files>
java -cp <classpath> <main class>
if you are using the IDE then there is no need to set class path, ant you are using Command prompt to run the java program then you need to set the class path where the class (which is going to be used in your program) is actually located,use the following command:set calsspath=%classpath%;actual_path_of the class;we cancall more than two class by using this command by using separator (,)
In Windows:Copy the lib path of the java jdk from where it is installed.Open command promt.Type the following command.set CLASSPATH=Example:C:\>set classpath=C:\Java\jdk1.6.0_03\lib
Java Classpath is a parameter that tells the Java Virtual Machine or the Java Compiler, where to search for user-defined classes and packages on a computer.
Classpath is represented by "classpath" environment variable, not case sensitive, print its value in Linux echo $classpath in Windows echo %classpath% from java program use System.getProperty("java.classpath")
Make sure the environmental variables "classpath" and "path" are properly set. Also check if all requisite JARS are present in the projects build path. In case you are getting this during File input/output - check if the file is present in the appropriate location.