my dog learned polymorphism*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Development Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Development" Watch "Development" New topic
Author

Development

swaraj gupta
Ranch Hand

Joined: Oct 22, 2010
Posts: 181

Source: KS && BB book:
When searching for class files, the java and javac commands don't search the current directory by default. You must tell them to search there. The way to tell java or javac to search in the current directory is to add a dot (.) to the classpath:

-classpath /com/foo/acct:/com/foo:.

........the dot (.) at the end of the declaration instructs java or javac to also search for class files in the current directory. (Remember, we're talking about class files—when you're telling javac which .java file to compile, javac looks in the current directory by default.)

The two BOLD letter parts of the above quote confusing me a bit, will anybody please clarify the situation here.


These are conclusions I have drawn. Please correct if I am wrong at any of these point:
1> javac searches the current directory for .java file by default.
2> javac DOES NOT search the current directory for supporting .class files needed for the compilation .java file by default.
3> java never searches the current directory by default.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18538
    
  40

swaraj gupta wrote:
1> javac searches the current directory for .java file by default.


javac doesn't use the classpath to find the .java file. It uses the location that you specify in the command line.

swaraj gupta wrote:
2> javac DOES NOT search the current directory for supporting .class files needed for the compilation .java file by default.


If you don't set the classpath (either environment or command line) then javac uses the current directory as the classpath.

swaraj gupta wrote:
3> java never searches the current directory by default.


If you don't set the classpath (either environment or command line) then the JVM uses the current directory as the classpath.


Henry
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Development
 
Similar Threads
class path question
Significance of dot(.) in classpath
javac -classpath com:. -g Foo.java Bar.java
K&B Chapter 10 Self Help Question 9
Questions about classpath on SCJP book.