This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
While we are giving path,it means we are giving the path of jre for complie my source.
now when its done,it produce .class file which is the machine code for jvm so we give the class path to system32 as jvm resides inside that system 32.
path and classpath are two different things. as the name suggests classpath is class search path. this is the list of directories where your compiled .class files are located.
now path variable is the list of directories containing the executables. for example i have following commandline invokation java -classpath=c:/; HelloWorld
now for this to run successfully you need to tell commandline where is the location of java binary. for this you use path variable. you set path variable to your jdk bin directory. but remember path variable is not limited to java or javac binaries. for any executable you can use it.
after you have set path for jdk binaries , supppose that HelloWorld class file is located in say c drive and you are in d drive. now you have to tell java binary where YOUR class file(s) is/are located. for this we have -classpath switch. now java will search for c:/ directory and will find HelloWorld class file there and will run it
Agree. One more thing about classpaths: You will hear advice about how to set a system classpath, but the correct advice is: Don’t. Never set a classpath, because it will vary from application to application. You may need to alter an already‑existing classpath, but that is something different.
the 'path' environment variable is use by the operating system (OS). When you type a command, like "dir", the OS searches every directory listed in the path for that executable/binary. Hopefully, it finds it. For example, I don't really want to type
every time I need to grep a file. And since there are a ton of programs in that /home/hci/gnu directory (chown, cp, du, make, mv...), I can put that directory in my path. So then I only have to type "cp ..." and Unix knows to look (among other places) in that directory. It finds 'cp' there, and then fires it up.
classpath is similar, but it is used by the JVM when trying to find .class files.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors