recent study often see the context, did not understand the meaning of Chinese, a search to see this article, quite real, special turn
context in Java is so frequent, but its Chinese translation "context" is so strange and awkward, so many people do not understand the specific meaning of the context is what, so it is necessary to delve into the meaning of the word. let 's start with some examples from Java that use the context
(1) A class of Jndi javax.naming.InitialContext, which reads some configuration information for Jndi and contains mapping information for the object and its registered name in Jndi. Take a look at the following code
InitialContext IC=NewInitialContext ();
Rmiadaptor server=(rmiadaptor) ic.lookup ("jmx/invoker/rmiadaptor" );
This is the code for a remote call class that gets an Mbean in JBoss. In this case, the Rmiadaptor object is obtained through the name "Jmx/invoker/rmiadaptor" in the Jndi register in InitialContext. This is a bit like the map in the Java collection, and there is a string of key,key that reflects its object.
(2) Take a look at the most common lines of code in spring below. ApplicationContext is the information that contains the Configuration.xml configuration file, which allows the corresponding registered object to be obtained by Getbean name.
applicationcontext ctx = &NBSP, new Span style= "Vertical-align:baseline;background-color:transparent;color: #000000;" > filesystemxmlapplicationcontext ( " configuration.xml );
Object obj = ctx.getbean ( " object_name . Span style= "Vertical-align:baseline;background-color:transparent;color: #000000;" > "
from the above code, I can appreciate the meaning of the context: public information, environment, containers ..... So I think context is not intuitive to translate into contexts, according to the language use of the environment, translated into "Environment", "container" may be better.
PS:
The context is actually an abstract concept. Our common context is the PageContext in the servlet, which is used when accessing Jndi. People who have written these codes may be easier to understand, but their real role is connecting. For example, pagecontext his upper layer is a web container, the lower layer is the servlet class you wrote, and PageContext as the middle channel for the servlet to interact with the Web container. For example, to access the JNDI context, his upper level is the JNDI server (possibly remote), the lower level is your application, and his role is to establish a channel so that you can access the Jndi server, but also let the Jndi server accept your request, also play an interactive role.
Context Contextual Object