Java package Features and rules for use

Features of a Java package
  • The protected members of the classes can be accessed by each other in the same package.
  • It resolves the naming collision for the types it contains.
  • A package may have the following types.
    • Interfaces
    • Classes
    • Enumerated types
    • Annotations

Naming convention (Rules) for using  the packages
  • Package names are written in all lowercase to avoid conflict with the names of classes or interfaces.
  • The directory name must be same as the name of package that is created using "package" keyword in the source file.
  • Before running a program, the class path must be picked up till the main directory (or package) that is used in the program.
  • If we are not including any package in our java source file then the source file automatically goes to the default package.
  • In general, we start a package name begins with the order from top to bottom level.
  • In case of the internet domain, the name of the domain is treated in reverse (prefix) order. 

0 comments:

Post a Comment

 

learn java programming Copyright © 2011-2012 | Powered by appsackel.org