Help coderanch get a
new server
by contributing to the fundraiser
  • 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

Packages

 
Greenhorn
Posts: 11
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Trying to work with packages to learn Access Modifiers and the ins an out.

<DIR>          A - //same as the package






How do I run this from command prompt.

From what I understood I would I would use javac from c:Programming\Java javac A.B.java

then tried this

C:\Programming\Java\SCJP>javac -cp \A B.java

C:\Programming\Java\SCJP>java -cp \A B
Error: Could not find or load main class B

what am I missing


 
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

what am I missing  


The full class name is A.B
In the SCJP folder, enter: java -cp . A.B
The -cp . sets the classpath to the current folder (that is the default if the CLASSPATH environment variable is  not set)
 
Chad McAte
Greenhorn
Posts: 11
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok this is what I misunderstood. The book states while talking about packages, that if my class files where located in a subdirectory of my current folder Java would search the subdirectories automatically for the giving class.
What they meant is that once you point java to the directory that has the defined package folder it will search the package folder and all its subdirectories for the given class.

TYVM for the help.



 
Norm Radder
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

point java to the directory that has the defined package folder it will search the package folder and all its subdirectories for the given class.  


Java will use the package paths as provided by you on the commandline or in the program.  They must match the class files locations.
 
Are you okay? You look a little big. Maybe this tiny ad will help:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic