• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

The dot in CLASSPATH

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Note that you must have ‘.’ in your CLASSPATH in order for the files to compile."



The above line is from the book THINKING IN JAVA please can anyone explain what does it means and one thing more when i checked CLASSPATH on my laptop it was just showing "."
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
technically, that is not true. You do not even have to have a CLASSPATH at all. But if you do, you want a dot.

CLASSPATH basically tells java where to find your .class files. If there is no CLASSPATH set, it will by default look in the current directory (I am assuming you are on a command line).

If you have a CLASSPATH variable set, it will ONLY look in the directories listed there. Odds are pretty good that most of the time, you will want to look in the current directory. and that is what the dot means - current directory, whatever that is at the time.
 
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Most of the time you are better off not setting a system classpath at all. If somebody has told you to set a system classpath, they are mistaken.
 
Ranch Hand
Posts: 91
IntelliJ IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Welcome to the Ranch

Most of the time you are better off not setting a system classpath at all. If somebody has told you to set a system classpath, they are mistaken.



Why is that Campbell??? I thought if we set the class path, we can run the Java code from anywhere within the system, but if we do not set it we have to run from the bin directory where Java is installed right?
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Vineeth Menon wrote:

Campbell Ritchie wrote:Welcome to the Ranch

Most of the time you are better off not setting a system classpath at all. If somebody has told you to set a system classpath, they are mistaken.



Why is that Campbell??? I thought if we set the class path, we can run the Java code from anywhere within the system, but if we do not set it we have to run from the bin directory where Java is installed right?



If you're just writing small educational programs, and they all live in the same place, and all have the same simple classpath needs, and you don't run any other Java apps, then that's fine. Beyond that though, each project will be in its own location, and have its own set of classes and its own set of 3rd-party libraries, so each one will have different classpath needs. A single, system-wide classpath becomes useless. Each project will typically have a config file and/or startup script that sets the classpath for that app.

And no, you don't need to run from the bin directory where Java is installed, regardless of whether you do or do not set CLASSPATH. You're thinking of PATH, which is separate. It's fine to include Java's bin directory on your PATH.
 
Vineeth Menon
Ranch Hand
Posts: 91
IntelliJ IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ohh bummer, my bad...now I remember. Thanks for clearing it out Jeff
 
Campbell Ritchie
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Vineeth Menon wrote: . . . I thought if we set the class path, we can run the Java code from anywhere within the system, but if we do not set it we have to run from the bin directory where Java is installed right?

That is not a classpath. That sounds like a PATH.

Every app may have a particular location where .class files necessary for it can be found. Each app will have a different location for its dependencies. So you want a different classpath for each large app. When you are using small apps, and only require code in the current directory, that is where the JVM will look, as long as no other classpath is set.
 
Rototillers convert rich soil into dirt. Please note that this tiny ad is not a rototiller:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic