This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Beginner package help please Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Beginner package help please" Watch "Beginner package help please" New topic
Author

Beginner package help please

Frank Metzger
Greenhorn

Joined: Aug 04, 2011
Posts: 6
I am working an example from a book, the topic is on packages. The code listed below compiles fine if "package BookPack" is commented out. If package BookPack is not commented out I get the following pre-compile error: class, interface or enum expected. The book suggests, "create the package directories below your current development directory. Well I think my development directory is the one that contains the .java file I'm working with, in this case that is hsbookdemo.java. The path is listed here: C:\Documents and Settings\DS\My Documents\NetBeansProjects\HSBookDemo\src\hsbookdemo Now, how do I create a package directory? And where is below? Is the package directory placed here: C:\....\HSBookDemo\src\hsbookdemo\bookpackage. Where bookpackage is the package directory.

The book also says, " to put the class files into the appropriate directories". I found class files in this path: C:\....\HSBookDemo\build\classes\hsbookdemo[b] This path has the files: [b] HSBookDemo.rs, HSBookDemo.class, Book.class. The book finally says,"execute the programs from the development directory". Does any of this mean I have to use the command prompt with: java BookPack.BookDemo. If so, I gave up with the command prompt along time ago and downloaded an IDE. I use the NetBeans IDE. The code is listed below:


The output works out fine, I don't think it is needed, but here it is anyway.

Srikanth Madasu
Ranch Hand

Joined: Sep 10, 2008
Posts: 48

Your class is already under the package - hsbookdemo and you already had that in the very first line of your class. so you don't need the second package.

And regarding your question to create new package in IDE just right click on your project name and select new package.

Hope this helps!


If it's easy.. then everybody would do it!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Beginner package help please