Andreas Svenkson wrote:
Basically, imagine we are given a test-question where CLASSPATH is not explicitly set, and nor is -cp/-classpath used. Is it then guaranteed that the current working directory will be used as classpath? Is this a guaranteed behaviour across different plattforms?
Regards,
Andreas.
Ikpefua wrote:
OCPJP 6.
In Your Pursuit Towards Certification, NEVER Give Up.
Andreas Svenkson wrote:Hi guys.
I've been playing around a bit with the CLASSPATH env variable and the command line option and I've come to a conclusion, for which I would like to have confirmed if it is unversal or not (across different OSes).
Basically, I have found the following to be true, for both java and javac:
1) If -cp / -classpath is used at the commandline it will override the CLASSPATH env-variable (no news, this is true according to K&B too).
2) If -cp / -classpath is NOT used, and CLASSPATH is set, this will (obviously) be the classpath used.
3) If neither of the above are used/set (CLASSPATH is not set, nor is -cp used at the command line) then the classpath will default to your current working directory.
Number 3 has caused me a little headache. Since I had no idea it would be set to the current workingdirectory under the aforementioned circumstances, I kept wondering how the heck the class files could be found. This is also the rule I would like to have confirmed.
Basically, imagine we are given a test-question where CLASSPATH is not explicitly set, and nor is -cp/-classpath used. Is it then guaranteed that the current working directory will be used as classpath? Is this a guaranteed behaviour across different plattforms?
Regards,
Andreas.
SCJP 6.0 (88%)
Dragos Nica wrote:
Your first 2 points are correct.
For 3rd, thinks are a little bit different. Your assumption is correct but only for javac. If neither CLASSPATH env variable is set, nor command line -classpatch/ -cp is used , the java command will return an error as by default it doesn't "look" into working directory. This should be specified explicitly.
Regards,
Dragos
Andreas Svenkson wrote:I don't think you understand my question correctly, or maybe it is I who don't understand your answer.
But to clarify, on page 798 of K&B you can read the second sentence: "When searching for class files, the java and javac commands don't search the current directory by default."
What I am saying is that this is wrong (atleast from my point of view, on my OS), IF you assume that 1: you have NO CLASSPATH environment variable set, and 2: you do NOT invoke java/javac with the -cp/-classpath option - then your current directory WILL be the default classpath for java and javac.
// Andreas
Ikpefua wrote:
OCPJP 6.
In Your Pursuit Towards Certification, NEVER Give Up.
Andreas,
I understand you PERFECTLY.
It is you that is 'twisting' what you read in page 798 of K & B. "When searching for class files, the java and javac commands don't search the current directory by default. This is DERIVED from the heading in page 797 which says quote "Declaring AND Using Classpaths" you can see clearly that the statement is ALL about the declaration and use of classpaths.
I will now ask you a question, why did say this is wrong? if the statement is ALL about 'declaring and using classpaths' ???.
Now lets come to your theory....(REMEMBER That has NOTHING to do with the headline in page 797)..... after searching the classes that comes with the j2se, and you are standing in your current directory -in the command line- and in that SAME command line you are telling java to run a class -in the current directory- it will do JUST that!. Now your question is.... is this behaviour guaranteed in other platforms, my answer is this (That I Already Said Before) If this behaviour depended on platforms, the writers of K & B book or the java tutorials provided by Sun would have EXPLICITLY mentioned it.
Let me answer in another way, If this behaviour is NOT guaranteed in other platforms, the K & B book or the java tutorials provided by Sun, would have EXPLICITLY mentioned it.
The problem with this last statement of yours is that the 2 points you brought up in your first post (1:"Both java and javac use the same algorithms to search for classes " and 2: "Searching begins in the locations that contain the classes that come standard with J2SE.") and which I assume you were referring to, has nothing to do with the topic of this thread. I have never questioned these statements, they just don't have anything to do with how the CLASSPATH var is set, or if the -cp option is used. These 2 points apply under all circumstances, but it has nothing to do with my post.Andres wrote:
Ikpefua wrote:
OCPJP 6.
In Your Pursuit Towards Certification, NEVER Give Up.
Andreas wrote:
Ikpefua wrote:
OCPJP 6.
In Your Pursuit Towards Certification, NEVER Give Up.
Andreas wrote:
Ikpefua wrote:
OCPJP 6.
In Your Pursuit Towards Certification, NEVER Give Up.
Don't get me started about those stupid light bulbs. |