• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

classpath

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what is meant by classpath in java.. why do we use and is there any difference between set path and classpath..
please explain me in detail

thanks in advance
 
Ranch Hand
Posts: 88
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
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.

experts correct me if i am wrong
 
Ranch Hand
Posts: 924
1
Netbeans IDE Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Marshal
Posts: 76456
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See How to set the Classpath in the JavaRanch FAQ.
 
lowercase baba
Posts: 13073
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

/home/hci/gnu/bin/grep

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.
 
I claim this furniture in the name of The Ottoman Empire! You can keep this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic