Showing posts with label Meta. Show all posts
What is package-info.java used for in Java
package-info.java is a special file which is used for generating package level documentations as well as keeping all package level annotations. For each package we can have one package-info file.
Here will see two different examples of package-info.java.
Package Documentation
For instance in a project, I have the following package-info.java for package javaexp.corejava.collection.
package-info.java
/**
* Tutorials and Samples form Java Collection framework.
*/
package javaexp.corejava.collection;
If we see the generated Javadocs we will notice the package level comments as well.
Package Level Annotation
We have the following entry, to mark the whole package deprecated.
package-info.java
@java.lang.Deprecated
package javaexp.corejava.oldcollection;
If we see the generated Javadoc we will see the package is marked as deprecated.
Summary
All though package-info.java is not must for java project, but it do add a lot of value specially if the code base is large and we want to generate package level documentations or say apply Annotations to all the classes in the packge.