Java SE 7 Features and Enhancements
Java SE 7 Features and Enhancements
Java Platform, Standard Edition 7 is a major feature release. This document includes information on features and enhancements in Java SE 7 and in JDK 7, Oracle's implementation of Java SE 7.
vm lan& core
JS !"!# Support for d$namicall$%t$ped lan&ua&es '(nvo)eD$namic* Strict class%file chec)in& JS ++,# Small lan&ua&e enhancements 'Project -oin*
.p&rade class%loader architecture /ethod to close a . 0-lass0oader -oncurrenc$ and collections updates 'jsr122$* .nicode 2.4 0ocale enhancement Separate user locale and user%interface locale JS !4+# /ore ne5 (6O 7P(s for the Java platform '8(O.!* 8(O.! files$stem provider for 9ip6jar archives S-TP 'Stream -ontrol Transmission Protocol* SDP 'Soc)ets Direct Protocol* .se the :indo5s ;ista (Pv2 stac) T0S 1.! Elliptic%curve cr$pto&raph$ 'E--* JD=- ,.1 > ender pipeline for Java !D -reate ne5 platform 7P(s for 2u14 &raphics features 8im<us loo)%and%feel for S5in& S5in& J0a$er component ?ervill sound s$nthesi9er .pdate the >/0 stac) Enhanced /=eans
i13n
ione t
5e< m& mt
Virtual machine : Support for dynamically-typed languages (Invoke ynamic! E@tensions to the J;/, the Java lan&ua&e, and the Java SE 7P( to support the implementation of d$namicall$%t$ped lan&ua&es at performance levels near to that of the Java lan&ua&e itself. interface injection # the a<ilit$ to modif$ classes at runtime so that the$ can implement ne5 interfaces %% this is a feature that is common in d$namicall$ t$ped lan&ua&es. Ao5ever, implementers of compilers for d$namicall$ t$ped lan&ua&es have found it difficult to meet the J;/ <$tecode reBuirements for method invocation. These features ena<le implementers of compilers for d$namicall$ t$ped lan&ua&es, that is, the people 5ho develop compilers for lan&ua&es such as J u<$ and J$thon, to &enerate <$tecode that runs e@tremel$ fast in the J;/. Cor e@ample, the J u<$ compiler &enerates <$tecode that performs 5ell in the J;/, <ut the J u<$ <$tecode 5ill run even faster 5hen the J u<$ compiler is modified to use the invokedynamic <$tecode and method handles. Strict class-file checking class files of version D1 'SE 7* or later must <e verified 5ith the t$pe chec)in& verifierE the ;/ must not fail over to the old inferencin& verifier.
major 45 45 46 47 48 49 50 51
minor Java platform version 3 1.0 3 1.1 0 1.2 0 1.3 0 1.4 0 1.5 0 1.6 1 1.7
major version number of the class file format being used. J2SE 7 = 51 (0 !! he "# J2SE $.0 = 50 (0 !2 he "#
J2SE 5.0 = %& (0 !1 he "# J'( 1.% = %) (0 !0 he "# J'( 1.! = %7 (0 2* he "# J'( 1.2 = %$ (0 2E he "# J'( 1.1 = %5 (0 2' he ". "anguage: Small language enhancements (#ro$ect %oin! 7 set of small lan&ua&e chan&es intended to simplif$ common, da$%to%da$ pro&rammin& tas)s# 1. Strin&s in s5itch statements, !. tr$%5ith%resources statements, The tr$%5ith%resources statement is a tr$ statement that declares one or more resources. 7 resource is as an o<ject that must <e closed after the pro&ram is finished 5ith it. The tr$%5ith% resources statement ensures that each resource is closed at the end of the statement. 7n$ o<ject that implements java.lan&.7uto-losea<le, 5hich includes all o<jects 5hich implement java.io.-losea<le, can <e used as a resource. The follo5in& e@ample reads the first line from a file. (t uses an instance of BufferedReader to read data from the file. BufferedReader is a resource that must <e closed after the pro&ram is finished 5ith it# static Strin read!irst"ine!rom!i#e$Strin %at&' t&ro(s )*+,ce%tion try $BufferedReader .r / ne( BufferedReader$ne( !i#eReader$%at&''' return .r.read"ine$'0 1 1 +. improved t$pe inference for &eneric instance creation 'FdiamondF*, Gou can replace the t$pe ar&uments reBuired to invo)e the constructor of a &eneric class 5ith an empt$ set of t$pe parameters '23* as lon& as the compiler can infer the t$pe ar&uments from the conte@t. This pair of an&le <rac)ets is informall$ called the diamond. Cor e@ample, consider the follo5in& varia<le declaration# /apHStrin&, 0istHStrin&II m$/ap J ne5 Aash/apHStrin&, 0istHStrin&II'*E (n Java SE 7, $ou can su<stitute the parameteri9ed t$pe of the constructor 5ith an empt$ set of t$pe parameters '23*# /apHStrin&, 0istHStrin&II m$/ap J ne5 Aash/apHI'*E , (mproved -ompiler :arnin&s and Errors :hen .sin& 8on% eifia<le Cormal Parameters 5ith ;arar&s /ethods D. <etter inte&ral literals, and the inte&ral t$pes '.yte, num<er s$stem.
2. improved e@ception handlin& 'multi%catch* (n Java SE 7 and later, a sin&le catc& <loc) can handle more than one t$pe of e@ception. This feature can reduce code duplication and lesse9n the temptation to catch an overl$ <road e@ception. catch '(OE@ception e@* K lo&&er.lo&'e@*E thro5 e@E catch 'SL0E@ception e@* K lo&&er.lo&'e@*E thro5 e@E M (n releases prior to Java SE 7, it is difficult to create a common method to eliminate the duplicated code <ecause the varia<le e@ has different t$pes. The follo5in& e@ample, 5hich is valid in Java SE 7 and later, eliminates the duplicated code# catch '(OE@ceptionNSL0E@ception e@* K lo&&er.lo&'e@*E thro5 e@E M The catc& clause specifies the t$pes of e@ceptions that the <loc) can handle, and each e@ception t$pe is separated 5ith a vertical <ar '4*.
+D
Drop the old, proprietar$, encum<ered sound s$nthesi9er in favor of ?ervill, a s$nthesi9er created as a proposal for the 7udio S$nthesis En&ine Project 6e8 'pdate the ;)" stack .p&rade the components of the >/0 stac) to the most recent sta<le versions# J7>P 1.,, J7>= !.!a, and J7>%:S !.! )anagement Enhanced )9eans Enhancements to the e@istin& com.sun.mana&ement /=eans to report the recent -P. load of the 5hole s$stem, the -P. load of the J;/ process, and to send J/> notifications 5hen ?- events occur 'this feature previousl$ included an enhanced J/> 7&ent, <ut that 5as dropped due to lac) of time* eferred to J = > or later JS* 1?:: "anguage and V) support for modular programming Enhancements to the Java lan&ua&e and virtual%machine specifications to support modular pro&rammin&, at <oth compile time and run time 3nnotations on Java types 7n e@tension to the Java annotation s$nta@ to permit annotations on an$ occurrence of a t$pe "anguage support for collections 0iteral e@pressions for immuta<le lists, sets, and maps, and inde@in&%access s$nta@ for lists and maps "am8da 0am<da e@pressions 'informall$, FclosuresF* and defender methods for the Java pro&rammin& lan&ua&e )odulari4ation (#ro$ect Jigsa0! 7 simple, lo5%level module s$stem focused upon the &oal of modulari9in& the JDK, and the application of that s$stem to the JDK itself S0ing application frame0ork 7n 7P( to define the <asic structure of a t$pical S5in& application, there<$ eliminatin& lots of <oilerplate code and providin& a much%improved initial developer e@perience S0ing J ate#icker component 7dd the S5in&0a<s J>DatePic)er component to the platform