Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java package

 
bala kan
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i know somewhat about packages concept..in 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
Bartender
Posts: 563
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should find most of your questions answered here, but come back if you have more.
 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 : Greetings.java resides in the package named myPackage and the Welcome class access it's method.

Greetings.java:


Welcome.java


As you are new here, I advise you to SearchFirst in JavaRanch and get good old discussions on the queries you have.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic