- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What are packages in Java?
Packages are used in Java in order to prevent naming conflicts, to control access, to make searching/locating and usage of classes, interfaces, enumerations and annotations easier, etc.
java.lang − bundles the fundamental classes.
java.io − classes for input, output functions are bundled in this package.
Programmers can define their own packages to bundle group of classes/interfaces, etc. It is a good practice to group related classes implemented by you so that a programmer can easily determine that the classes, interfaces, enumerations, and annotations are related.
Since the package creates a new namespace there won't be any name conflicts with names in other packages. Using packages, it is easier to provide access control and it is also easier to locate the related classes.
Executing a package
You need to compile the file with packages using –d option as −
C:\Sample>javac -d . PackageExample.java
After compiling, you can see the class files of the class created in the location com/mypackage/tutorialspoint.
- What are Packages in Perl?
- What are the packages in Python?
- Packages in Java
- Explain packages in Java
- What are various sub-packages in Python SciPy library?
- What are the best practices to keep in mind while using packages in Java?
- Types of packages in Java
- Advantages of using packages in Java
- How to compile packages in Java
- Creating and using packages in Java
- How many packages and classes are there in Java Standard Edition 8?
- Explain naming conventions for packages in java?
- Which packages contain Wrapper class in Java?
- Difference Between Packages and Interfaces in Java
- Packages in C#