Explore new features of JDK1.5

xiaoxiao2021-03-06  21

Explore new features of JDK1.5

Today, SUN has launched JDK 1.5 (named Tiger). These include 15 updated folding components from JSR and from JCP, nearly 100 relatively large upgrades. So many updates and changes, you may want to think I know what should I start to learn from it. In the previous release, all changes will be placed in the release manual. This article is from the Sun J2SE team, which introduces all new changes. Its main role is You have a rough understanding of JDK 1.5 before you understand the API. J2SE 1.5 features are mainly in the following points: · Simple development, scalability and performance, prosecution, and management, client (desktop), some small changes It will be placed in this article. Because they cannot be returned to the above class. The following will be described in detail.

Simple development you may have seen some new features about Java language. These changes include general types (generic types), metadata metadata, automatic packing (Enhanced Loop), enumeration ENUMBERATED TYPES, Static Import, C Style Formatted Input / Output Method (Simple Rmi Interface Generation). The default compilation in the JDK 1.5 beta is implemented by Javac 1.4. If you want to implement the new features of these languages, you must add-Source 1.5 this parameter.

The metadata characteristics in metadata J2SE 1.5 provide the ability to connect additional data into Java Class, Interface, Method, and Field, which can be identified by the Javac compiler or other tools, and can be saved according to configuration In the class file, and can discover the REFLECTION API of Java at runtime. One main reason for adding metadata to the Java platform is that development and running tools can get a foundation frame, making it possible to reduce the encoding and release. An additional effort is required. One tool can use these metadata information to generate additional code or provide additional information when testing. Instead of metadata tools, the sample code below creates a smart debugMedian, this Note will be simply displayed in subsequent debugging. We can see that most metadata tags make up a standard, fixed collection. Import java.lang.ANnotation. *; Import java.lang.reflect. *; @Retention (java.lang.annotation.RetentionPolicy.RUNTIME) @interface debug {boolean devbuild () default false; int counter ();} public class MetaTest {final boolean production = true; @debug (devbuild = production, counter = 1 PUBLIC VOID TESTMETHOD () {} public static void main (String [] args) {metatest mt = new metatest (); try {annotation [] a = mt.getClass () .getMethod ("TestMethod"). GetanNotations (); for (int i = 0; i

} Public class ping import () {public void ping () {}} metadata label method: public class ping {public @Remote void ping () {}} Generic Types Generic Types has been approved in Java Community, now It is already part of J2se 1.5. Generic Types first appears in the Collection class (Collection API). The following example is written in the standard and J2SE 1.4.1 library. ArrayList List = new arraylist (); list.add (0, New Integer (42)); int total = ((Integer) list (0)). INTVALUE (); you can see that we have to transform the Integer type in the last line. This is because Collection The API can only store objects. If not type of transitions, the program will take a ClassCastexception exception. Below we write the above example with generified collections Library: arraylist list = new arraylist ; list.add (0 New Integer (42)); int total = list.get (0) .intValue (); use the <> tag in the program to declare the CENERIFIED API. Used with generified

转载请注明原文地址:https://www.9cbs.com/read-43025.html

New Post(0)