• 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

Important - Information missing in K&B book

 
Ranch Hand
Posts: 358
Firefox Browser Redhat Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
While discussing "classpath" in 10th chapter, the authors say:

"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."


What if (for user-defined classes):
  • the user doesn't declares the "-classpath/-cp" during javac/java?
  • the user didn't use the environment variable CLASSPATH?


  • Hmm, they forgot to include this information:

    "If -classpath and -cp are not used and CLASSPATH is not set, the user class path consists of the current directory (.)"
     
    Ranch Hand
    Posts: 115
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I approve

    https://coderanch.com/t/263018/java-programmer-SCJP/certification/looking-class-files-current-directory

     
    Faisal Ahmad
    Ranch Hand
    Posts: 358
    Firefox Browser Redhat Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Oh! I never saw that post! Thanks for the link!
    And you are right saying "I think the quoted sentence in K&B is a bit misleading." I feel the same.
    Hope Bert answers!
     
    Greenhorn
    Posts: 22
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hmmm... I still have one doubt.

    According to this document :

    "The default class path is the current directory. Setting the CLASSPATH variable or using the -classpath command-line option overrides that default, so if you want to include the current directory in the search path, you must include "." in the new settings."

    On my machine (Mac OS X), I have the CLASSPATH set. However, the current directory still seems to be included in the class path. (CLASSPATH doesn't have the "." included)

    Am I reading this wrong?
     
    Kantutan Tayo
    Greenhorn
    Posts: 22
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Additional Explanation:

    CLASSPATH=/opt/junit

    current dir is myDir

    myDir
    |-- pkg1
    |-- MyClass.java




    According to the document I pointed out above, (as I interpret it) the current directory shouldn't be included if the CLASSPATH is set. Now, if i compile and run with the following:

    compile: javac pkg1/MyClass.java
    run: java pkg1.MyClass

    MyClass runs. But it shouldn't have found the MyClass.class because the current dir shouldn't have been in the class path (because CLASSPATH is set).

    So should I answer compiles or does NOT compile if I encounter such problem?
     
    Kantutan Tayo
    Greenhorn
    Posts: 22
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    the directory structure didn't come out right.

    let me try that again.

    MyClass.java is inside myDir/pkg1

     
    Kantutan Tayo
    Greenhorn
    Posts: 22
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Please help. Anyone?
     
    Be reasonable. You can't destroy everything. Where would you sit? How would you read a tiny ad?
    a bit of art, as a gift, that will fit in a stocking
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic