Please refer to the original text: https://bbs.csdn.net/topics/392062347
Jdk5 new Features
1. Automatic box packing and unpacking
2. Enumeration
3. Static Import
4. Variable parameters
5. Inner Province
is a default processing method of the Java language for Bean class properties and events. For example, there is a property in Class A so that we can get its value by Getname,setname or set a new value. The Name property is accessed through Getname/setname, which is the default rule. Java provides a set of Getter,setter methods used by the API to access a property that allows you to not need to know the rules, which are stored in the package Java.beans.
The general practice is to obtain the BeanInfo information of an object through the class Introspector, and then beaninfo to get the descriptor of the property (PropertyDescriptor), through which the property descriptor can obtain a corresponding getter/ Setter method, and then we can invoke these methods through the reflection mechanism.
6. Generic type
7. For-each Cycle
Jdk6 new Features
1. Desktop class and Systemtray class
AWT has added two new mines: Desktop,systemtray.
Desktop can be used to open the system default browser specified URL, open the system default mail client to send mail to the specified mail account, open or edit the file with default application (for example, open TXT file with Notepad), print the document with the system default printer
Systemtray can be used to create a tray program in the system tray area
2. Use JAXB2 to implement mapping between object and XML
That is, the mapping between objects and XML (OXM), and the same functionality can be achieved through XMLBeans and Castor.
3, StAX
Stax is the streaming API for XML abbreviation, a api.stax that leverages the pull mode parsing (pull-parsing) XML document to allow programmers to control the parsing of XML documents by providing an API based on event iterators (Iterator) , the program iterates through the event iterator to handle each parse event, and the parsing event can be seen as a program pull out, that is, the program causes the parser to generate a parse event and then process the event, which then causes the parser to produce the next parse event, so that it loops until the document terminator is encountered;
Sax is also based on the event-handling XML document, but it is the use of Push mode parsing, the parser parses the complete XML document before the parse event is generated and then pushed to the program to handle these events; The DOM takes the whole XML document to a memory tree. This makes it easy to get the data for the parent and child nodes as well as the sibling node, but if the document is large, it can seriously affect performance.
4. Using the compiler API
Using JDK6 's Compiler API to dynamically compile Java source files, the Compiler API, combined with the reflection function, enables the dynamic generation of Java code and the compilation of the code.
5. Lightweight HTTP Server API
6. Plug-in annotation processing API
7. Develop console program with console
8. Support for scripting languages such as: Ruby,groovy,javascript
9, Common Annotations
Jdk7 new Features
1. You can use a string in switch
2. Automatic judgment of generic type
3. Custom Auto-shutdown class (implement Autocloseable interface)
4. New tools for environmental information (methods in System)
5, Boolean type reversal, NULL pointer security, parameter and bitwise operation
equals between 6, two Char
7, the security of the subtraction
Other than that:
1. Enhanced support for Java Collections (collections)
list<string> list=["item"]; Adding elements to the list collection
String Item=list[0]; Get an element from the list collection
set<string> set={"Item"}; Add a meta to the Set collection object
map<string,integer> map={"key": 1}; To add an object to the Map collection
int value=map["key"]; Get an object from the Map collection
However, after testing it yourself, you cannot create a collection by using the method above.
2, int supports binary data
3, in the Try catch exception catch, a catch can write multiple exception types
Connection conn = null;
try {
Class.forName ("Com.mysql.jdbc.Driver");
conn = Drivermanager.getconnection ("", "" "," ");
} catch (classnotfoundexception| SQLException ex) {
Ex.printstacktrace ();
}
4. Try catch closes automatically after resource definition in try Catch
Try (BufferedReader in = new BufferedReader (New FileReader ("In.txt"));
BufferedWriter out = new BufferedWriter (New FileWriter ("OUT.txt"))) {
int charread;
while ((Charread = In.read ())! =-1) {
System.out.printf ("%c", (char) charread);
Out.write (Charread);
}
} catch (IOException ex) {
Ex.printstacktrace ();
}
Jdk8 new Features
1, the default method of the interface
Java 8 allows us to add a non-abstract method implementation to the interface, just use the default keyword, which is also called the extension method, the example is as follows:
Public interface Formula {
Double calculate (int a);
Default double sqrt (int a) {
Return Math.sqrt (a);
}
}
The formula interface also defines the Sqrt method in addition to the Calculate method, implementing a subclass of the formula interface that only implements a calculate method, and the default method sqrt will be used directly on the subclass.
Formula Formula = new Formula () {
@Override
public double Calculate (int a) {
return sqrt (A * 100);
}
};
System.out.println (formula.calculate (100)); 100.0
System.out.println (FORMULA.SQRT (16)); 4.0
The formula in this article is implemented as an instance of an anonymous class that is very
2. Lambda expression
list<string> names = Arrays.aslist ("Tom", "Jace", "Mike");
Collections.sort (names, new comparator<string> () {
@Override
public int Compare (string O1, string O2) {
Return O2.compareto (O1);
}
});
You only need to pass a list object to the static method Collections.sort and a comparer to specify the order. It is common practice to create an anonymous comparer object and then pass it to the sort method.
A more concise syntax, lambda expression, is provided in Java 8:
Collections.sort (names, (string A, string B), {
Return B.compareto (a);
});
You can also be more concise:
Collections.sort (names, (string A, string b), B.compareto (a));
Remove curly braces and return keyword
Collections.sort (names, (b), B.compareto (a));
The Java compiler can automatically derive the parameter type, so you can no longer write the type again.
3. Functional Interface
How does a lambda expression be represented in the Java type System?
Each lambda expression corresponds to a type, usually an interface type. The "Functional interface" refers to an interface that contains only an abstract method, and each lambda expression of that type is matched to this abstract method. Because the default method is not an abstract method, you can also add a default method to your own functional interface.
We can use lambda expressions as an interface type for an abstract method to ensure that our interfaces must meet this requirement, and you only need to add @functionalinterface annotations to your interface. The compiler will make an error if it finds that there are more than one abstract method for the interface that annotated the annotation. That is, an interface with an functionalinterface annotation callout can have only one abstract method.
For example:
@FunctionalInterface
Public interface Converter<f, t> {
T convert (F from);
}
converter<string, integer> Converter = (from)-integer.valueof (from);
Integer converted = Converter.convert ("123");
System.out.println (converted);
The above code does not require @functionalinterface annotations and is correct.
4. Methods and constructor references
The above code can also be represented by a static method reference:
converter<string, integer> Converter = integer::valueof;
Integer converted = Converter.convert ("123");
System.out.println (converted);
JAVA8 allows the use of: keyword to pass a method or constructor reference, the above code shows how to reference a static method, we can also refer to an object's method:
public class Person {
String FirstName;
String LastName;
Person () {
}
Public person (string firstName, String lastName) {
This.firstname = FirstName;
This.lastname = LastName;
}
}
Specifies an object factory interface that is used to create the person object:
Public interface Personfactory<p extends person> {
P Create (String fisrtname, string lastName);
}
Create Person Object
personfactory<person> personfactory = person::new;
Person person = personfactory.create ("Peter", "Parker");
We only need to use person::new to get a reference to the person class constructor, and the Java compiler will automatically select the appropriate constructor based on the signature of the Personfactory.create method.
5. Lambda Scope
It is similar to accessing the outer scope and older versions of anonymous objects in a lambda expression. You can directly access the outer local variables labeled final, or the fields of the instance and the static variables.
6. Accessing Local variables
We can access the outer local variables directly in the lambda expression
final int num = 1;
Converter<integer, string> stringconverter = (from)-string.valueof (from + num);
Stringconverter.convert (2);
But unlike anonymous objects, the variable num here can be declared as final, and the code is also correct.
7. Accessing object fields and static variables
Unlike local bad, lambda internal fields for instances and static variables are readable and writable. This behavior is consistent with the anonymous object:
static int outerstaticnum;
int outernum;
public void Testscopes () {
Converter StringConverter1 = (from) {
Outernum = 23;
Return string.valueof (from);
};
Converter StringConverter2 = (from) {
Outerstaticnum = 72;
Return string.valueof (from);
};
}
8, the default method of Access interface
9. Date API
10. Annotation Annotations
Feature comparison of JDK 5~8