Win a copy of Murach's Java Programming this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Packages  RSS feed

 
Chad McAte
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


 
Norm Radder
Rancher
Posts: 2041
26
  • 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: 2041
26
  • 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.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!