• 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

javac & classpath

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My understanding about classpath is that it tells the JVM where to find the .class files... But SCJP 5 Exam Study Guide, tells that it can also be used with the javac compliler invocation (Ref: Chapter 10: Development) as below:
javac -classpath <path>
I am not able to understand the significance of the above invocation, since .class files donot have any role to play at the time of compilation( it is only the .java files that come in this scenario).
Can somebody clarify me the significance of javac -classpath <path>

Thanks.
 
Ranch Hand
Posts: 513
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, your source files will almost always depend on other classes, many of which will not be available to you in source form. For example, you probably have the Java standard library classes (HashSet, Thread, etc) only in the form of .class files. So the compiler will need the classpath to those classes in order to figure out whether you're using those classes correctly (e.g. using the correct types when invoking their methods).
 
Kelvin Chenhao Lim
Ranch Hand
Posts: 513
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, if your source file uses a class that has no corresponding .class file in the classpath, javac will search the provided classpath for an appropriate .java file and compile that too. This is one of the less well-known uses of the classpath for javac, and this is actually the basis for K&B Chapter 10 Self Test Question 10 (page 796).
 
Kaushik ChandraSekhar
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank You very much Kelvin..
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic