The package in java is actually the folder where the class is located, used to organize java files. Some Java classes with similar functions can be placed in the same package to facilitate organization and calling. Just declare the package with package.
If you use tools such as Eclipse, you can create the package directly in the project. If you write it manually, you can just create a folder in the project. Write java classes in the folder.
What is a package? (Recommended learning: java course )
In order to better organize classes, Java provides a package mechanism. Packages are containers of classes that separate class namespaces. If no package name is specified, all examples belong to a default unnamed package. Packages in Java generally contain related classes. For example, all classes related to transportation can be placed in a package named Transportation.
What is the purpose of the package?
As mentioned above, better organize classes to prevent duplicate class names in one space; indicate the hierarchical relationship between classes.
How to create a package?
If you don’t use IDE tools, creating a package is just a matter of creating a folder. After creating a new class, just add the package name at the beginning of the class;
It will be more convenient if you use IDE tools. new Package, just specify the package name.
We can define a package while creating a new class. The operation in Eclipse is as follows:
#The above is the detailed content of What is the package in java. For more information, please follow other related articles on the PHP Chinese website!