aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Class path query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Class path query" Watch "Class path query" New topic
Author

Class path query

Ankit Gareta
Ranch Hand

Joined: Mar 28, 2011
Posts: 67

Hi All,

OCP Java SE 6 Programmer practice exam --> practice exam 4 --> Question No 7


can any one explain me why answer D is wrong?

Thanks in Advance.


OCPJP 6 (91%)
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

to compile option A is correct OK, then you need to run ...

now your question is why option D is incorrect.
from oracle documents:

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.


I strongly suggest you to compile as in option A then analyze the output ;)

For more detail: classpath

Himai Minh
Ranch Hand

Joined: Jul 29, 2012
Posts: 812
    
    1
Hi Ankit Buddy,
java -cp pack.jar means java will search through the directories inside pack.jar to look for pack.client.Client. But this Client class is not in jar. The directory pack/client/Client is under $ROOT directory. Java needs to search $ROOT directory to find pack.client.Client.

Instead of D, G will work because java -cp .:pack.jar includes the current directory $ROOT.
Ankit Gareta
Ranch Hand

Joined: Mar 28, 2011
Posts: 67

Thanks Seetharaman and Himay for your very helpful reply..

so what i understand is , when we want to run the class file, at that time we need that class file and the related class file that used by it.
so in this case, If i run with command "java -cp . pack.client.Client" that will not run because it can't find the bank class.

please , correct me if i am wrong.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Perfect Ankit!
Ankit Gareta
Ranch Hand

Joined: Mar 28, 2011
Posts: 67

Thanks Seetharaman and Himai.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Class path query