Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript 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
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Packages

 
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: 3883
35
  • 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: 3883
35
  • 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.
 
    Bookmark Topic Watch Topic
  • New Topic