In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces what are the new features of JDK1.6, which can be used for reference by interested friends. I hope you will gain a lot after reading this article.
One: desktop class and SystemTray class
In JDK1.6, AWT adds two new classes: Desktop and SystemTray.
The former can be used to open the system default browser to browse the specified URL, open the system default mail client to send mail to the specified mailbox, open or edit files with the default application (for example, open files with the suffix txt with notepad), and print documents with the system default printer; the latter can be used to create a tray program in the system tray area.
Second, use JAXB2 to realize the mapping between objects and XML
JAXB is an acronym for Java Architecture for XML Binding, which converts a Java object into XML format, and vice versa.
We call the mapping between objects and relational databases ORM, but we can also call the mapping between objects and XML OXM (Object XML Mapping). It turns out that JAXB is part of Java EE, and in JDK1.6, SUN puts it into Java SE, which is the usual practice of SUN. The version of JAXB included in JDK1.6 is 2.0. compared to JSR 31, JAXB2 (JSR 222s) uses JDK5's new feature Annotation to identify classes and attributes to be bound, which greatly simplifies the workload of development.
In fact, in Java EE 5.0, EJB and Web Services also use Annotation to simplify development work. In addition, JAXB2 uses StAX (JSR 173) to process XML documents at the bottom. In addition to JAXB, we can also use XMLBeans and Castor to achieve the same function.
Three: understand StAX
StAX (JSR 173) is another API for dealing with XML documents besides DOM and SAX in JDK1.6.0.
The origin of StAX: there are two ways to process XML documents in JAXP1.3 (JSR 206): DOM (Document Object Model) and SAX (Simple API for XML).
Since both JAXB2 (JSR 222) and JAX-WS 2.0 (JSR 224) in JDK1.6.0 will be used by StAX, Sun decided to add StAX to the JAXP family and upgrade the version of JAXP to 1.4 (JAXP1.4 is the maintenance version of JAXP1.3). The version of JAXP in JDK1.6 is 1.4.
StAX is an acronym for The Streaming API for XML, an API.StAX that uses pull schema to parse (pull-parsing) XML documents by providing an API based on event iterator (Iterator) to allow programmers to control the parsing process of xml documents. The program traverses the event iterator to handle every parsing event, which can be seen as pulled by the program, that is, the program causes the parser to generate a parsing event and then handle it. It then causes the parser to generate the next parsing event, which loops until the document Terminator is reached
SAX is also based on events to deal with xml documents, but is parsed with push mode, parsing events are generated after the parser parses the entire xml document, and then pushed to the program to handle these events; DOM's approach is to map the entire xml document to a memory tree, so that you can easily get data from parent and child nodes as well as sibling nodes, but if the document is large, it will seriously affect performance.
Four: use Compiler API
Now we can use JDK1.6 's Compiler API (JSR 199) to dynamically compile Java source files, Compiler API combined with reflection function can dynamically generate Java code and compile and execute the code, which has the characteristics of dynamic language.
This feature is very useful for some applications that need dynamic compilation, such as JSP Web Server. When we manually modify JSP, we do not want to restart Web Server to see the effect. At this time, we can use Compiler API to dynamically compile JSP files. Of course, today's JSP Web Server also supports JSP hot deployment, and now JSP Web Server compiles code by calling javac through Runtime.exec or ProcessBuilder during run time. This approach requires us to generate another process to do the compilation work, which is not elegant enough and easy to make the code dependent on a specific operating system. Compiler API provides a richer way to do dynamic compilation through a set of easy-to-use standard API, and it is cross-platform.
Five: lightweight Http Server API
JDK1.6 provides a simple HttpServer API, based on which we can build our own embedded HttpServer, which supports Http and Https protocols, provides part of the implementation of HTTP1.1, and the part that is not implemented can be implemented by extending the existing HttpServer API. Programmers must implement the HttpHandler interface themselves, and HttpServer will call the callback method of the HttpHandler implementation class to handle client requests. We refer to an Http request and its response as an exchange, wrapped as a HttpExchange class, and HttpServer is responsible for passing the HttpExchange to the callback method of the HttpHandler implementation class.
VI: plug-in annotation processing API (Pluggable Annotation Processing API)
Plug-in annotation processing API (JSR 269) provides a standard set of API to handle Annotations (JSR 175)
In fact, JSR 269 is not only used to deal with Annotation, I think a more powerful function is that it establishes a model of the Java language itself, it maps method,package,constructor,type,variable, enum,annotation and other Java language elements to Types and Elements (what's the difference between the two?), thus mapping the semantics of the Java language into objects, we can see these classes under the javax.lang.model package. So we can use the API provided by JSR 269 to build a feature-rich metaprogramming (metaprogramming) environment.
JSR 269 uses Annotation Processor to process Annotation,Annotation Processor during compilation rather than at run time, which is equivalent to a compiler plug-in, so it is called plug-in annotation processing. If new Java code is generated when Annotation Processor processes Annotation (executing the process method), the compiler will call Annotation Processor again, and if new code is generated in the second processing, Annotation Processor will then be called until no new code is generated. Each execution of the process () method is called a "round" so that the entire Annotation processing process can be seen as a sequence of round.
JSR 269 is mainly designed as an API for Tools or containers. For example, we want to build an Annotation-based unit testing framework (such as TestNG) in which Annotation is used to identify test methods that need to be executed during testing.
Seven: develop console programs with Console
The java.io.Console class is provided in JDK1.6 to access character-based console devices. If your program wants to interact with cmd under Windows or Terminal under Linux, you can use the Console class instead. However, we don't always get an available Console, and whether a JVM has an available Console depends on the underlying platform and how the JVM is called. If JVM is started on an interactive command line (such as Windows's cmd) and the input and output are not redirected somewhere else, you can get an available Console instance.
Eight: support for scripting languages
Such as: ruby,groovy,javascript.
Nine: Common Annotations
Common annotations was originally part of the Java EE 5.0 (JSR 244) specification, but now SUN has put part of it into 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,Web Services) use Annotation partially instead of XML files to configure run parameters (or support declarative programming, such as EJB declarative transactions). If these technologies define their own Annotations separately for general purposes, it is obviously a bit repetitive, so It is valuable to define a common set of Annotation for other related Java technologies, which can not only avoid repeated construction, but also ensure the consistency of Java SE and Java EE technologies.
The following is a list of 10 Annotations Common Annotations Annotation Retention Target Description Generated Source ANNOTATION_TYPE,CONSTRUCTOR,FIELD,LOCAL_VARIABLE,METHOD,PACKAGE,PARAMETER,TYPE in Common Annotations 1.0for tagging the generated source code Resource Runtime TYPE,METHOD,FIELD for tagging dependent resources, and the container injects external resource dependencies accordingly. There are two ways, field-based injection and setter-based injection, for Resources Runtime TYPE to label multiple external dependencies at the same time. The container will PostConstruct Runtime METHOD all these external dependency injection methods that run after the container injects all dependencies for initialization after dependency injection. There is only one method that can be marked as PostConstruct PreDestroy Runtime METHOD. Before the object instance is about to be deleted from the container, the callback method to be executed should be marked as the PreDestroy RunAs Runtime TYPE method used to mark the security role used to execute the annotated class. This security role must be consistent with the Security role of Container. RolesAllowed Runtime TYPE,METHOD is used to label security roles that allow the execution of annotated classes or methods. This security role must be consistent with the Security role of Container. PermitAll Runtime TYPE,METHOD allows all roles to execute annotated classes or methods. DenyAll Runtime TYPE,METHOD does not allow any role to execute annotated classes or methods, indicating that this class or method cannot run DeclareRoles Runtime TYPE in the Java EE container to define security roles that can be verified by the application. IsUserInRole is usually used to verify security roles.
Note:
1. RolesAllowedrePermitAllrecoverDenyAll cannot be applied to a class or method at the same time.
two。 The RolesAllowed,PermitAll,DenyAll marked on the method overrides the RolesAllowed,PermitAll,DenyAll marked on the class.
3. Runas RolesAllowed.PermitAllDemyAll and DeclareRoles have not been added to Java SE 6.0yet.
4. The work of handling the above Annotations is done by the Java EE container. Java SE 6.0contains only the first five Annotations definition classes in the above table, not the engine to process these Annotations. This work can be done by Pluggable Annotation Processing API (JSR 269).
Thank you for reading this article carefully. I hope the article "what are the new features of JDK1.6" shared by the editor will be helpful to you? at the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.