wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes The dot in CLASSPATH Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "The dot in CLASSPATH" Watch "The dot in CLASSPATH" New topic
Author

The dot in CLASSPATH

Lovish Setia
Greenhorn

Joined: Apr 09, 2013
Posts: 9
"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 "."
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11448
    
  16

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.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39478
    
  28
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.
Vineeth Menon
Ranch Hand

Joined: Aug 08, 2011
Posts: 71

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?


VM
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

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

Joined: Aug 08, 2011
Posts: 71

Ohh bummer, my bad...now I remember. Thanks for clearing it out Jeff
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39478
    
  28
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: The dot in CLASSPATH