File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes java package Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "java package" Watch "java package" New topic

java package

bala kan
Ranch Hand

Joined: Aug 20, 2012
Posts: 44
i know somewhat about packages this concept, we can create classes of our own and put it in package.. then how to access and use those classes in our program.. please explain by giving a simple java program..

thanks in advance
Greg Brannon

Joined: Oct 24, 2010
Posts: 563
You should find most of your questions answered here, but come back if you have more.

Always learning Java, currently using Eclipse on Fedora.
Linux user#: 501795
John Jai

Joined: May 31, 2011
Posts: 1776
Welcome to the Ranch, Bala Kan.

Packages are used for logical grouping of Java classes. You can use the package members by importing them in your Java class. Read more on how to import them here - Using Package Members

Packages helps in distinguishing classes when you are bound to use two or more classes with the same name. Hence note that two classes with the same name can never be present inside a package.

Note that there are access modifiers that restrict package member usage. Also the Java class files should be present in the directory named after the package it's present.

Sample code : resides in the package named myPackage and the Welcome class access it's method.

As you are new here, I advise you to SearchFirst in JavaRanch and get good old discussions on the queries you have.
I agree. Here's the link:
subject: java package
It's not a secret anymore!