File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes javac command and -cp . Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "javac command and -cp ." Watch "javac command and -cp ." New topic

javac command and -cp .

Cyril Bil

Joined: Oct 10, 2011
Posts: 9
Hi guys.
I have this code:

Is there a difference between :

javac my/path/to/java/


javac -cp . my/path/to/java/

Because I have the same result : compilation of the 2 classes

Thanks ;)

Stephan van Hulst

Joined: Sep 20, 2010
Posts: 4632

Yes, in the first case the class path is determined by the CLASSPATH environmental variable, or if it's not set, then the current directory is used for the class path.

The second case explicitly sets the class path to the current directory, overriding the CLASSPATH variable if it is set.

The mind is a strange and wonderful thing. I'm not sure that it will ever be able to figure itself out, everything else, maybe. From the atom to the universe, everything, except itself.
I agree. Here's the link:
subject: javac command and -cp .
It's not a secret anymore!