New Features of JDK 6

Source: Internet
Author: User

One of the new features of JDK 6: http://blog.csdn.net/Chinajash/category/258847.aspx? Pagenumber = 2desktop and systemtray y9b} ezawih
In JDK 6, two classes are added to AWT: desktop and systemtray. The former can be used to open the specified URL in the default browser of the system and open the default mail client to send emails to the specified mailbox, use the default application to open or edit files (for example, use NotePad to open files suffixed with txt), and print documents with the system's default printer; the latter can be used to create a program in the system tray area. new Feature 2 of JDK 6: jaing between objects and XML using jaxb2
Jaxb is short for Java architecture for XML binding. It can convert a Java object into XML format, and vice versa. We call the ORM ing between objects and relational databases An ORM. In fact, we can also call the oxing between objects and XML an oxm (object XML mapping ). originally, jaxb was part of Java ee. In jdk6, sun put it in Java SE, Which is Sun's consistent practice. Compared with JSR 31 2.0, jaxb2 (JSR 1.0) uses the Annotation Feature of jdk5 to identify the classes and attributes to be bound, this greatly simplifies the development workload. In fact, in Java EE 5.0, EJB and Web Services also simplify development through annotation. In addition, jaxb2 uses Stax (JSR 173) to process XML documents at the underlying layer. In addition to jaxb, we can also implement the same functions through xmlbeans and Castor. New feature 3 of JDK 6: Understanding Stax: Stax (JSR 173) is the source of apistax for processing XML documents in addition to Dom and sax in jdk6.0: In jaxp1.3 (JSR 206) there are two ways to process XML documents: Dom (Document Object Model) and SAX (Simple API for XML ). since jaxb2 (JSR 222) and JAX-WS 2.0 (JSR 224) in jdk6.0 both use Stax, sun decided to add Stax to the jaxp family, upgrade the version of JAXP to 1.4 (jaxp1.4 is the maintenance version of jaxp1.3 ). in JDK 6, the version of JAXP is 1.4 .. Stax is short for the streaming API for XML, an API that uses the PULL mode to parse XML documents. stax provides an iterator-based API for programmers to control the XML document parsing process. The program traverses this event iterator to process every parsing event, the parsing event can be viewed as pulled by a program, that is, the program prompts the parser to generate a parsing event and then process the event, and then promotes the parser to generate the next parsing event, such a loop occurs until the document Terminator is reached. Sax also processes XML documents based on events, but uses the push mode for parsing. The parser does not generate a parsing event after parsing the complete XML document, and then push it to the program to process these events. Dom maps the entire XML file to a memory tree, in this way, the data of the parent node, child node, and brother node can be easily obtained. However, if the document is large, the performance will be seriously affected. Jdk6's new feature 4: using the compiler API
Now we can use jdk6 'S Compiler API (JSR 199) to dynamically compile Java source files. With the reflection function, compiler API can dynamically generate and compile and execute Java code, A bit of Dynamic Language features. This feature is quite useful for some applications that require dynamic compilation, such as JSP web server. After we manually modify JSP, we do not want to restart the Web server to see the effect, at this time, we can use the compiler API to dynamically compile JSP files. Of course, the current JSP web server also supports hot JSP deployment, currently, JSP web server uses runtime.exe C or processbuilder to call javac to compile code. In this way, we need to generate another process to compile the code. It is not elegant enough and it is easy to make the code dependent on a specific operating system; the compiler API provides a richer range of methods for dynamic compilation through an easy-to-use standard API, and is cross-platform. New feature 5 of JDK 6: lightweight HTTP Server
JDK 6 provides a simple HTTP Server API. Based on this, we can build our own embedded HTTP server. It supports HTTP and HTTPS protocols and provides partial implementation of http1.1, the unimplemented part can be implemented by extending the existing HTTP Server API. programmers must implement the httphandler interface by themselves. httpserver calls the callback method of the httphandler implementation class to process client requests, here, an HTTP request and its response are called an exchange and packaged into an httpexchange class. httpserver is responsible for passing httpexchange to the callback method of the httphandler implementation class. new feature 6 of JDK 6: plug-in Annotation processing API (Pluggable annotation processing API) Plug-In annotation processing API (JSR 269) provides a set of standard APIs to process annotations (JSR 175 ), in fact, JSR 269 not only It is only used to process annotation. I think the more powerful feature is that it builds a model of the Java language itself. It uses method, package, constructor, type, variable, Enum, annotation and other Java language elements are mapped to types and elements (what is the difference between the two ?), To map the semantics of the Java language to an object, we can. lang. you can see these classes under the model package. therefore, we can use the APIS provided by JSR 269 to build a feature-rich metaprogramming environment. JSR 269 uses annotation processor to process annotation during compilation rather than during runtime. annotation processor is equivalent to a plug-in of the compiler, so it is called plug-in Annotation processing. if annotation processor generates a new Java code when processing annotation (the process method is executed), the compiler will call annotation processor again. If new code is generated during the second processing, the annotation processor will be called until no new code is generated. each execution of the process () method is called a "round", so that the entire annotation proces The Sing process can be considered as a round sequence. JSR 269 is mainly designed as an API for tools or containers. for example, we want to establish an annotation-based unit test framework (such as testng) and use annotation in the test class to identify the testing method to be executed during the test. Java. io. the console class is dedicated to accessing character-based console devices. if your program needs to interact with cmd in Windows or terminal in Linux, you can use the console class. however, we cannot always get the available console. Whether a JVM has an available console depends on the underlying platform and how the JVM is called. if the JVM is started in interactive command line (such as Windows cmd) and the input and output are not redirected to another place, an available console instance can be obtained. jdk6.0 new feature 8: console-based console Development
Java. io. the console class is dedicated to accessing character-based console devices. if your program needs to interact with cmd in Windows or terminal in Linux, you can use the console class. however, we cannot always get the available console. Whether a JVM has an available console depends on the underlying platform and how the JVM is called. if the JVM is started in interactive command line (such as Windows cmd) and the input and output are not redirected to another place, an available console instance can be obtained. new feature 9 of JDK 6: Common Annotations was originally part of the Java EE 5.0 (JSR 244) specification, and sun now adds a part of it to Java SE 6.0. with the addition of the annotation metadata function (JSR 175) to Java SE 5.0, many Java technologies (such as EJB and Web Services) the annotation part is used to replace the XML file to configure running parameters (or support Declarative Programming, such as EJB declarative transactions ), if these technologies define their own annotations for general purposes, it is obviously a bit repetitive. Therefore, it is valuable to define a set of public annotation for other related Java technologies, this avoids repeated construction and ensures consistency between Java SE and Java EE technologies. the following lists the 10 annotations common annotations in common annotations 1.0.
Annotation retention Target description
Generated source annotation_type, constructor, field, local_variable, method, package, parameter, type is used to mark the source code generated
Resource runtime type, method, field is used to mark the dependent resources. The Container injects external resource dependencies accordingly. There are two methods: field-based injection and setter-based injection.
Resources runtime type is used to mark multiple external dependencies at the same time. The Container injects all these external dependencies
Postconstruct runtime method indicates the method that runs after the container injects all dependencies for initialization after dependency injection. Only one method can be labeled as postconstruct.
Predestroy runtime method when the object instance is to be deleted from the container, the callback method to be executed must be marked as predestroy RunAs runtime type to indicate which security roles are used to execute the annotation class method, this security role must be consistent with the security role of container. Rolesallowed runtime type, which is used to mark the security role that allows the execution of the labeled class or method. This security role must be consistent with the security role of the container.
Permitall runtime type, method allows all roles to execute labeled classes or methods
Denyall runtime type, method does not allow any role to execute the labeled class or method, indicating that the class or method cannot run in the Java EE container
Declareroles runtime type is used to define security roles that can be verified by applications. isuserinrole is usually used to test security roles.
Note:
1. rolesallowed, permitall, and denyall cannot be applied to a class or method at the same time.

2. The rolesallowed, permitall, and denyall labels on the method will overwrite the rolesallowed, permitall, and denyall labels on the class.

3. RunAs, rolesallowed, permitall, denyall, and declareroles have not been added to Java SE 6.0.

4. the above annotations processing work is done by the Java EE container. Java SE 6.0 only contains the first five annotations definition classes in the table above, and does not contain engines for processing these annotations, this work can be done by the pluggable annotation processing API (JSR 269 ).

 

 

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.