Java / Package
Package is a collection of related classes and interfaces. Related classes will have the package defined using package keyword.
package packageName.subpackageName;
Any java class/interface will have the package declaration as the first statement.
package is optional however it is common practice to place the java class under a package.
java.lang package and no import statement is necessary.
No. the unused imports are ignored if the corresponding imported class/package is not used.
IO. | NIO. |
Stream oriented. | Buffer oriented. |
Blocking IO. | Non blocking IO. |
No Selectors. | Selectors available. |
The import allows the Java programmer to access classes of a package without package qualification whereas the static import feature allows accessing the static members of a class without the class qualification.
The import provides accessibility to classes and interfaces whereas static import provides accessibility to static members of the class.
Yes. One can import the same package or same class multiple times. JVM will internally load the class only once no matter how many times one imports the same class.
The java.lang package is always imported by default.
No. One will have to import the sub packages explicitly.
Yes. Otherwise it will produce compilation error.
Java module is a new feature in Java 9 via the Java Platform Module System (JPMS). JPMS Is also referred to as Java Jigsaw or Project Jigsaw.
A Java Module is a mechanism to package up your Java application and Java packages into Java modules. A Java module can specify which of the Java packages it contains that should be visible to other Java modules using this module. A Java module must also specify which other Java modules is requires to do its job.