• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Class path query

 
Ranch Hand
Posts: 67
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

 
Bartender
Posts: 2418
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 67
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Perfect Ankit!
 
Ankit Gareta
Ranch Hand
Posts: 67
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Seetharaman and Himai.
reply
    Bookmark Topic Watch Topic
  • New Topic