• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

looking for .class-files in current directory by default?

 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In K&B I found the following

When searching for class files, the java and javac commands don't search the current directory by default

As long as I don't set a classpath using the -cp command that is not true on my machine. For example: the command "javac dir1\dir2\Father.java" works just fine, if the Father.java file needs a class-file that is in the current directory.

Does that always work? So, given the above scenario and a question in the exam, asking whether this command will compile the Father.java-file, will "compilation succeeds" be the correct answer?
[ May 18, 2007: Message edited by: Sasha Ruehmkorf ]
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
cd dir1
cd dir2
javac Father.java

That is the current directory and it will fail as long as it's not in the classpath.
 
Ranch Hand
Posts: 652
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Satou,
Can you give some examples and explain me?
 
Sasha Ruehmkorf
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Satou. If I change to dir2 and then invoking your command, compilation will fail, of course. In this case I need to type "javac -cp ..\.. Father.java", so that the compiler will find the class-files needed.

But will the given command in the given scenario in my first post always work? (at least it does on my machine)

nik, what exactly is it, that you don't understand?
[ May 18, 2007: Message edited by: Sasha Ruehmkorf ]
 
Sasha Ruehmkorf
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, got it:

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.


from http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/classpath.html

I think the quoted sentence in K&B is a bit misleading.
 
Remember to always leap before you look. But always take the time to smell the tiny ads:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic