Java programming experience

Source: Internet
Author: User

Original link http://blog.sina.com.cn/s/blog_530abec50100i1f0.html

Java Miscellaneous (5)

Originally, j2se was expected to end with only the fourth article, but the moderator likes to stick the post for a long time so that everyone can browse and make the younger brother feel more responsible, and be sure to pursue the best and better, therefore, I decided to write a few more articles about some of the commonly used experiences for discussion and discussion. This article is about the XML parsing package and JavaSwing, and next I will talk about the java. Security Package about the Java sandbox security mechanism and RMI mechanism, and then enter the J2EE part. Now I have made such a plan. If the update is a little slow due to busy internships, I hope you will forgive me!

1.XML parsing in Java
I believe everyone is familiar with XML, meaning a scalable markup language. It is also a data carrier that appears in a tree. Later, the data gradually becomes information, the difference is that information can include variable states, so that the practice of hard encoding for the program is changed to hard encoding for the unified interface, and the variable state is stored as information in XML. In this way, the only task to implement scaling by changing the state is to add a piece of text information to the XML, and the Code does not need to be modified or re-compiled. This flexibility was unexpected when XML was born.

Of course, if the interface needs to be able to extract the information configured in XML, the program needs to be able to parse the standard XML file. in Java, of course, we need to improve the support for this behavior. The two packages I intend to talk about are org. W3C. Dom and javax. xml. parsers and. (You can browse the interfaces and class definitions in these packages)

The javax. xml. parsers package is simple and has no interfaces. The two factories have two Resolvers. Obviously, there are two ways to parse XML: Dom parsing and sax parsing. In essence, no one is good or not, but the idea of implementation is different. Example of an XML file:
<? XMLVersion = "1.0"Encoding = UTF-8">
<Root>
<ChildName = "kitty">
ACat
</Child>
</Root>

The idea of Dom Parsing is to store the entire tree chart into the memory. You only need to search for the node on the tree to read its attributes and content, the advantage is that all nodes can be repeatedly searched and used in the memory. The disadvantage is that the corresponding memory space needs to be consumed.

The idea of natural sax Parsing is to overcome the disadvantages of Dom. Based on the basic idea of event triggering, we searched down in sequence and encountered what events were triggered before the element and what actions were taken afterwards. Because you need to write the processing scheme to trigger the event, you need to use another Custom Handler in the org. xml. Sax. helpers package. Its advantage is of course that it does not need to read the entire package into the memory. The disadvantage is that it can only be searched in sequence, and it has to be repeated after it is completed.

You can easily guess which J2EE framework is used, obviously Dom. Similar to struts, The Hibernate framework configuration file is a small part of configuration information after all, and needs to be searched frequently to read, of course, the DOM method will be used (in fact, the DOM structure is used internally to store node information ). No matter what framework is used, it is really difficult to find the technology to parse XML using sax. If anyone knows, please let me learn.

Now that the resolution method is available, a storage location for resolution is required. I don't know if you have found that the org. W3C. Dom package does not implement all classes with interfaces. Here I want to talk about how Java parses XML, which is the responsibility of JDK. The W3C organization maintains and defines XML standards. Therefore, the W3C determines what an XML structure is like and does not care how Java implements it, this defines the rules that should be followed by all XML storage structures. This is Org. w3C. the purpose of all interfaces in the Dom. In my opinion, a simple understanding of interfaces is the principle that implementers must abide.

The structure of the entire XML file is called document, the child element is called element, and node, nodelist, text, entity, characterdata, cdatasection, and other interfaces related to nodes are also called, they can all find the corresponding meaning in the middle of the XML syntax. Because the basic XML syntax is not explained here, we will not introduce it much. If you are interested, I can also write a special post on XML syntax rules to share with you.

2.JavaSwing
Swing is a love-and-hate thing. The cute thing is that it is easier to get started. It is more powerful than AWT, the hateful thing is that the complicated interface compilation workload is huge. I have written over 3000 lines of swing interfaces, and I feel that the user experience is not so good. More than 6000 lines have been written recently. As there are more functional modules, the overall effect is just as general. The most profound word is: tired!As a result, swing is not widely used in real-world projects, and too many interface technologies can replace it. I was forced to write this article, but no one wrote it in the helpless group. Who did not enter the region?

Although swing is slowly being ignored, especially as B/S is slowly drowning C/S, I am very willing to stand out as swing. The knowledge of each technology is by no means a follow-up of fashion. Those who really like Java should have a good understanding of swing. I believe many students are learning about it. Probably from JDKMany university teachers who have come in 1.1 and 1.2 may be the least familiar with it.

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.