Vishals Saxena

+ Follow
since Feb 02, 2009
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Vishals Saxena

Hey Jia Tan Thanks alot!!
though you answered to Vyas but it really helped me......
Thanks alot!!!....again!!
Hello Ruben Soto
or anyone.......

Yeah That I know too but see the Question no. 11 on pg. 817 of
SCJP 6 Kathy Sierra....... ( that Getjar .something something ) and look at its
option " A. " it doesnt set any class path for java command and i tried it at my home too and I suceeded in running it!!!
Please explain
Thank you
Hey you should buy SCJP 6 by Kathy Sierra & Bert Bates........
Its and awesome book!!!

Youll love it when ull study it!!!
Yes It made me confused too ....that

JVM needs to find the same classes as the javac( java compiler ) needs to find!!!

But now its more clear to me and its true!!!

you just mugup this statement its really true and
as of your qustion

see here Getjar class is using the static variable of the Foo class
and Foo class is in myApp you must have read in K.Sierra's book
that when we create a jar file the directory structure is preserved in that file!!!

so here as the javac ( java compiler ) needs to find Foo class either class paths will work
the one given in option a of the book i.e
a) javac -cp MyJar.jar

as well as
javac -cp . or javac
( because as you can see in question the System.out.println statement is using fully qualified class name that is myApp.Foo so the javac will search in current directory that is test and will find myApp/ also javac command searches for the class in current directory by default )

as for the java command
if you say
java -cp MyJar.jar GetJar
it wont find GetJar.class as it is not in the MyJar.jar file........phew!!!

and java Getjar will work because it will find both Getjar.class as well as myApp.Foo class

( PS: I am little confused about last statement that java command doesnt search for classes in current directory by default then why it gets executed??? )
maybe im forgetting something

Cheers for whatever youve understood!!! ???

9 years ago