Packages in Java
Packages in Java
Built-in Packages
There are 14 built-in packages in Java. These packages consist of a
large number of classes which are a part of Java API. Some of the
commonly used built-in packages are:
1) java.lang: Contains language support classes(e.g. classed
which defines primitive data types, math operations). This package
is automatically imported hence called as default package.
2) java.io: Contains classed for supporting input / output
operations.
3) java.util: Contains utility classes which implement data
structures like Linked List, Dictionary and support ; for Date / Time
operations.
4) java.applet: Contains classes for creating Applets.
5) java.awt: Contain classes for implementing the components for
graphical user interfaces (like button, menus etc).
6) java.net: Contain classes for supporting networking
operations.
Other library packages are beans, math, nio, rmi, security, sql, text,
time
User-defined packages
These are the packages that are defined by the user. First, we
create the package e.g. myPackage. Then create
the MyClass inside it with the first statement being the package
myPackage.
Important points:
1. Every class is part of some package.
2. If no package is specified, the classes in the file goes into a
special unnamed package (the same unnamed package for all
files).
3. All classes/interfaces are part of some package. Multiple classes
can specify the same package name.
https://www.youtube.com/watch?v=6U_1IbgJlEE