• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Packages  RSS feed

 
Greenhorn
Posts: 11
1
  • Mark post as helpful
  • send pies
  • 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


 
Master Rancher
Posts: 3270
33
  • Mark post as helpful
  • send pies
  • 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
  • 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
Master Rancher
Posts: 3270
33
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!