JDK5 new features
Automatic boxing and unboxing
Generics
Enhanced for loop
Static Import
variable parameter
enumerate
Enumeration Overview
Refers to the value of the variable to be listed, the value of the variable is limited within a range of values enumerated. For example: one week only seven days, only 12 months a year and so on.
Recall singleton design pattern: singleton instance of a class has only one
Example much class is a class has multiple instances, but not an infinite number of examples, but the limited number of examples. This order is an enumeration class
java provides an enumeration class for us.
The format is: Only enum class of enumerated items
enum {public enum class name
1 enumeration, enumeration 2, 3 ... enumeration;
}
Precautions
Enumeration class that defines use keyword enum
All of the enumeration classes are subclasses of Enum
On the first line enumeration class must enumeration, enumeration semicolon after the last entry can be omitted, but if there are other things enumeration class, the semicolon can not be omitted. Please do not forget
Enum class can have a constructor, but it must be private, and it is also the default private. Usage of special enumeration: enumeration ( "");
Enum class can have abstract methods, but enumeration must override this method
Enumeration of use in a switch statement
Several common methods of enumeration class
int compareTo (E o)
String name()
int ordinal()
String toString()
<T> T valueOf(Class<T> type,String name)
values()
Although this method can not find, but each class has the enumeration method in the JDK documentation it through all the enumeration values Enumeration class is very convenient
JDK7 new features
Binary literals
Digital literal can appear underlined
The switch statement can use the string
Generics simplify
Abnormal merge multiple catch
try-with-resources statement
Binary literals
JDK7 start, we can finally be represented by a binary integer (byte, short, int, and long). The benefits of using binary literals that can make the code easier to understand. The syntax is very simple, as long as the increase in the value of the previous binary 0b or 0B
For example:
int x = ob110110
Digital literal can appear underlined
In order to enhance the readability of values, as we often data as a comma-delimited. _ JDK7 provides data separated.
For example:
int x = 100_1000;
Precautions:
It can not occur between decimal values and identity
It can not appear at the beginning and end values
It can not appear next to the decimal point
try-with-resources statement
format:
the try (java.lang.AutoCloseable must be a subclass object) {...}
benefit:
Resources released automatically, do not need to close () the
The need to close the resource section are defined here on ok
The main stream system object is a subclass of this interface (see for JDK7 API)
What are the main characteristics of Java SE 8 there?
? Lambda expressions, a new language features to function as a parameter or the code as data;
? Significantly increase and improve Java language features, add standard libraries, including the default method, a new java.util.stream package and Date-Time API;
? Compact Profiles Java SE platform includes pre-defined subset, so that programmers do not need to deploy the entire platform can be run on small devices;
? Including security updates Java Cryptography Architecture; restrictions doPrivileged; SSL / TLS Server Name Indication (SNI) Extension and enhanced key library;
? JavaFX update the document
? The new JavaScript engine Nashorn