www.pickatutorial.com Computer Tutorials
Top eBooks: C/C++ | C# | Android | Mathematics | Database | Cloud | Graphics | Networking | Oracle | Hardware | AI
Top Tutorials: C/C++ | C#.NET | PHP MySQL | Java | Java Script | jQuery | HTML | xHTML | HTML5 | VB Script| CSS
Lessons Java Packages Bookmark and Share
Tutorial Home
Lesson 1
Lesson 2
Lesson 3
Lesson 4
Lesson 5
Lesson 6
Lesson 7
Lesson 8
Lesson 9
Lesson 10
Lesson 11
Lesson 12
Lesson 13
Lesson 14
Lesson 15
Lesson 16
Lesson 17
Lesson 18
Lesson 19
Lesson 20
Lesson 21
Lesson 22
Packages are named groups of related classes. In java the classes can be grouped together in packages. We can specify the package name using a package declaration:

package name ;

The package declaration must be the first (non-comment) line in the .java file. If a file contains a package declaration as above, the file must be in a subdirectory called name i.e. the directory name must match the package name.

We can access public classes in another (named) package using:


We can access the public fields and methods of such classes as under:


We can avoid having to include the package-name using import package-name.* or import package-name.class-name at the beginning of the file after the package declaration, if any. The former imports all of the classes in the package, and the later imports just the named class. We can have as many import statements as we need. We must still use the class-name to access the classes in the package, and class-name.field-or-method-name to access the fields and methods of the class; the only thing you can leave off is the package name.
Next >>> Lesson No. 10: Inheritance in Java

Home - Advertise - Contact - Disclaimer - About Us
© Since 2006 pickatutorial.com -- All Rights Reserved.