This week's book giveaway is in the Web Services forum.
We're giving away four copies of Microservices in Action and have Morgan Bruce & Paulo A. Pereira on-line!
See this thread for details.
Win a copy of Microservices in Action this week in the Web Services forum!
  • 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:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

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


 
Rancher
Posts: 3352
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
Rancher
Posts: 3352
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!