File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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 Murach's Java Servlets and JSP this week in the Servlets 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: 720
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Class path query
 
Similar Threads
Is this question wrong right?This question is from scjp preparation book.
K&B doubt regarding question in Development chapter
Doubt at K&b chapter 10,question 11
Head First page 57 program
Class path query.