Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Packages

 
kallis kals
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai everybody I am new to this forum ,

I have a doubt in (packages) concept, i.e after we create our own package how to work with that package.Means how to import package, and make the classes in it work in some other class outside the package.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65113
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"kallis ch",

There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
JavaRanch Sheriff
 
Darryl Failla
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some of the rules or look will depend on your environment. Essentially, each package exists in a folder bearing the package name. These packages can be nested, and as they are, their folders will show the same leveling. The source code for each file will reside in its folder.

For the most part, the packages that you create should have their source folders in the "src" folder of your Java environment. When compiled, their class files will be set up in the Java "classes" folder using the same folder structure.

You can import classes from package to package using the "import" command and the folder structure (from the "classes" level) followed by the class name. Normal rules of accessability apply. You can only access public methods from outside the package.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic