What is package in JAVA?

What is package in JAVA?

Java packages help in organizing multiple modules.
It helps in resolving naming conflicts when different packages have classes with the same names.
The access level of the packages helps in protecting data from being used by the non-authorized classes.

Packages group together related classes and interfaces. Packages avoid name conflicts. Classes in java are group together in a package using "package" keyword.

Example:
package P1;
public class Class1
{
}
public class Class2
{
}

Advantages and disadvantages of using packages in Java.

Advantages:

1. Determination of a category of a file is simplified.
2. Name space collision is avoided.
3. Access restriction can be applied with the use of packages.
4. Java packages can be stored in compressed files called JAR files.

Disadvantages:

1. We cannot pass parameters to packages.
2. Change in a function needs to be reflected in all the functions that use the changed function and hence the whole package needs to be recompiled.
Java - == vs. method equals()
== vs. method equals() - The method equals() is used to compare the values of the Strings.....
What are Native methods?
What are Native methods? - Native methods are the methods implemented in other language like C. These methods can be used in Java...
What is Bytecode?
What is Bytecode? - The Java class file contains bytecode which is being interpreted by JVM. Bytecode is introduced in Java to...
Post your comment