You are on page 1of 4

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

sec jd<c clien 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.

s&ort, int, and #on

* can also <e e@pressed usin& the <inar$

s&ort aS&ort / $s&ort'0.10100001010001010

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*.

7& 'nderscores in (umeric "iterals


(n Java SE 7 and later, an$ num<er of underscore characters ' _* can appear an$5here <et5een di&its in a numerical literal. This feature ena<les $ou, for e@ample, to separate &roups of di&its in numeric literals, 5hich can improve the reada<ilit$ of $our code. %ore: 'pgrade class-loader architecture /odifications to the -lass0oader 7P( and implementation to avoid deadloc)s in non%hierarchical class% loader topolo&ies )ethod to close a '*"%lass"oader 7 method that frees the underl$in& resources, such as open files, held <$ a . 0-lass0oader %oncurrency and collections updates ($sr+,,y! 7 li&ht5ei&ht for)6join frame5or), fle@i<le and reusa<le s$nchroni9ation <arriers, transfer Bueues, concurrent lin)ed dou<le%ended Bueues, and thread%local pseudo%random num<er &enerators (nternationali9ation 'nicode ,&.p&rade the supported version of .nicode to 2.4 "ocale enhancement .p&rade the java.util.0ocale class to support (ETC =-P ,7 'Ta&s for (dentif$in& 0an&ua&es* and .T '0ocal Data /ar)up 0an&ua&e* Separate user locale and user-interface locale .p&rade the handlin& of locales to separate formattin& locales from user%interface lan&ua&e locales I./ and (et0orking JS* 1-2: )ore ne0 I./ 3#Is for the Java platform ((I/&1! 8e5 7P(s for files$stem access, scala<le as$nchronous (6O operations, soc)et%channel <indin& and confi&uration, and multicast data&rams (I/&1 filesystem provider for 4ip.$ar archives 7 full$%functional and supported 8(O.! files$stem provider for 9ip and jar files S%5# (Stream %ontrol 5ransmission #rotocol! 7n implementation%specific 7P( for the Stream -ontrol Transmission Protocol on Solaris S # (Sockets irect #rotocol! (mplementation%specific support for relia<le, hi&h%performance net5or) streams over (nfini<and connections on Solaris and 0inu@ 'se the 6indo0s Vista I#v, stack .p&rade the net5or)in& code to use the :indo5s ;ista (Pv2 stac), 5hen availa<le, in preference to the le&ac$ :indo5s stac) 5"S +&1 7dd support for Transport 0a$er Securit$ version 1.! ' C- D!,2* Security 7 %ryptography Elliptic-curve cryptography (E%%! 7 porta<le implementation of the standard Elliptic -urve -r$pto&raphic 'E--* al&orithms, so that all Java applications can use E-- out%of%the%<o@ ata8ase %onnectivity J 9% :&+ .p&rade to JD=- ,.1 and o5set 1.1 %lient ;*ender pipeline for Java 1 7 ne5 Java!D &raphics pipeline <ased upon the >11 > ender e@tension, 5hich provides access to much of the functionalit$ of modern ?P.s %reate ne0 platform 3#Is for ,u+- graphics features -reate ne5 platform 7P(s for features ori&inall$ implemented in the 2u14 release# Translucent and shaped 5indo5s, and heav$5ei&ht6li&ht5ei&ht component mi@in& (im8us look-and-feel for S0ing 7 ne@t%&eneration cross%platform loo)%and%feel for S5in& S0ing J"ayer component 7dd the S5in&0a<s J>0a$er component decorator to the platform <ervill sound synthesi4er

+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