Meaningless Drivel is fun!*
The moose likes Beginning Java and the fly likes Significance of 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 "Significance of dot(.) in classpath " Watch "Significance of dot(.) in classpath " New topic
Author

Significance of dot(.) in classpath

Catherine austin
Ranch Hand

Joined: Jul 20, 2011
Posts: 43
"The way to tell java or javac to search in current directory is to add a dot(.) to classpath".

Can any one explain what does this exactly mean?
According to i read earlier , the Following code:

> -classpath /com/foo/acct: /com/foo

Here the directory /com will NOT be searched .

I grasped that by using dot(.) we can refer to /com as follows :

-classpath /com/foo/acct:/com/foo.
Am i right? Kindly clear my confusion ..
I shall gratefull to you

fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11154
    
  16

your PATH and CLASSPATH are lists of directories - nothing more. they are separated in the list by a semicolon (on windows).

Usually, when you are working in java, your .java files are in a different directory than where your java.exe (or other executable depending on your OS) lives. so you will be in C:\home\fred\java\source. If you set up your PATH correctly, the OS will search all the directories in your path to see if that .exe is in one, and if so, it will run it.

CLASSPATH works in a similar fashion, except it is used by the JVM to find where your .class files are. so no matter what directory you are sitting in, if you type "java fred", the JVM will search all the directories listed in your CLASSPATH to find the "fred.class" file.

You can put a dot in your classpath to tell the JVM to always look in whatever directory you are currently sitting in when you call java. so if you are here:

c:\home\fred\java\classes, the JVM will look there, so long as you have a dot in your classpath. Note that if you don't have a classpath defined at all, the jvm looks in the current directory by default.

so, if you don't have a CLASSPATH defined (which is usually recommended for beginners), or if you have a dot in your CLASSPATH, you'll probably be fine.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Puneet Soni
Greenhorn

Joined: Aug 08, 2008
Posts: 18

. is a convention in linux for present directory.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11154
    
  16

Puneet Soni wrote:. is a convention in linux for present directory.

it's not just linix
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Significance of dot(.) in classpath
 
Similar Threads
NoClassDefFoundError
Development
Classpath
Another classPath doubt
javac and classpath Self Test question: why does it work?