Packages - What Is A Package
Introduction
Packages are used to organize a set of related classes. Conceptually, you can think of packages as being similar to different folders on your computer. Just as you might keep your documents in different folders based on their type or purpose, Java packages help you group related classes together to avoid naming conflicts and to control access. In fact, Java packages require that the directory structure of your project matches the package structure.
Package Structure Requirements
Let's say you have a class named MyClass in your main project folder. if you wanted to place it in a package named example.hello, you would need:
- A folder named "example" inside your main project folder.
- Inside the "example" folder, create another folder named "hello".
- Place your MyClass.java file inside the "hello" folder.
Now, how do you actually declare that MyClass is part of the example.hello package?
ByteBrawl
0