Package in Java

Publié le: 10 juillet 2025
sur la chaîne: Codevibe
65
3

Java provides a mechanism for partitioning the class name space into more manageable chunks. This mechanism is the package. The package is both a naming and a visibility control mechanism. You can define classes inside a
package that are not accessible by code outside that package. You can also define class members that are exposed only to other members of the same define class members that are exposed only to other members of the same package. This allows your classes to have intimate knowledge of each other, but not expose that knowledge to the rest of the world.
To create a package is quite easy: simply include a package command as the first statement in a Java source file.
Any classes declared within that file will belong to the specified package. The package statement defines a name space in which classes are stored. If you omit the package statement, the class names are put into the default package, which has no name.
Java uses file system directories to store packages, and that is the approach assumed by the examples in this book. For example, the .class files for any classes you declare to be part of mypackage must be stored in a directory called mypackage. Remember that case is significant, and directory name must match the package name exactly.


Sur cette page du site, vous pouvez voir la vidéo en ligne Package in Java durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur Codevibe 10 juillet 2025, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 65 fois et il a aimé 3 téléspectateurs. Bon visionnage!