(reproduced) Java context contexts, easy to understand

Source: Internet
Author: User

Reprinted from http://blog.csdn.net/xiaokui008/article/details/8454949

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 a few examples of Java used in the context (1) A class of Jndi javax.naming.InitialContext, which reads some configuration information for Jndi and contains the mapping information for the object and its registered name in Jndi. Take a look at the following code

InitialContext ic=new InitialContext ();

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 name "Jmx/invoker/rmiadaptor", which is registered by Jndi in InitialContext, is obtained rmiadaptor

Object. 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= newfilesystemxmlapplicationcontext ("Configuration.xml");

Object obj= Ctx.getbean ("object_name");

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. Translating the context into a "contextual" is just not intuitive, but it's not a big mistake. Let's take a look at the meaning of "context" in Chinese. We often say that obedient words can not be "taken out of context", but to contact its "contextual" view. For example, Xiao Li said to bachelor, "I Love You", the light to see this sentence also thought in the words of speech. But a look at the context-"Although I love you, but you are too poor, we still break up", the taste has completely changed. From this point of view, "context" also means "environment", that is, the language environment.

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.

(reproduced) Java context contexts, easy to understand

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.