I see the package in Java

zhaozj2021-02-12  150

I see the package in Java (1)

The following is my understanding of the concept of packaging in Java, not necessarily, I hope everyone will correct.

The package is wrapped in the information that the client should not be seen. Make the internal execution to the outside to see the outside, is a black box, the client does not need internal resources to reach his purpose. Let us analyze the packages from different angles.

From the end customer's point of view, .jar file is a package, they don't need to know how many .class files in the .class file, the functions and functions in each file, can also get the results of their hopes. There are WAR and EAR for J2ee except JAR. See the table below:

Jar

WAR

EAR

English

Java Archive File

Web Archive File

Enterprise Archive File

Contain content

Class, Properties file, is the smallest unit of the file package

Servlet, JSP page, JSP tag, JAR library file, HTML / XML document and other public resource files, such as pictures, audio files, etc.

In addition to including JAR, WAR, it also includes EJB components

Deployment

Application-Client.xml

Web.xml

Application.xml

level

small

in

Big

The following mainly analyzes the perspective of programmers:

Starting from a few keywords:

1. Package and Import allow us to do what is divided into a single global namespace, ensuring that we will not encounter the conflict of the name 1. Thus, Java encapsulates each Class file in a different namespace, making the external class with the class and the class associated with the class.

2, Private: The modified attribute or method can only be accessed and modified by the class itself, and cannot be obtained and referenced by any other class (including the subclass of this class). It provides the highest protection level.

3, Friendly: Does not specify that the access indicator is not a keyword description, which is the default, default element owns package access. Since a compilation unit can only be subordinate to a single package, all classes in a single compilation unit are automatically "friendly".

4, Protected: Members with protected modified can be quoted by three classes: 1) This class itself, 2) Sub with other classes of it in the same package, 3) in other packages class.

5, public (public): It has the likelihood of access to classes in all packets, as long as the classes in these other packages are referenced in the program using the import keyword in the program. It will cause safety and data package to decline with public modification.

Modifier

similar

Worship

Subclass

Versatility

Encapsulation level

public

Yes

Yes

Yes

Yes

1

protected

Yes

Yes

Yes

2

Frendly

Yes

Yes

3

Private

Yes

4

This visible access control provides a way for hidden implementation details, making the code level of the class, method, and attributes. With a package control and access control, it is only a means of encapsulation, thereby abstract four forms. That is the package, the encapsulation of the object, the package and attribute packages

转载请注明原文地址:https://www.9cbs.com/read-6149.html

New Post(0)