Java 7의 새로운 기능
Java 7의 어떤 새로운 기능이 구현 될 예정입니까? 그리고 그들은 지금 무엇을하고 있습니까?
JDK 7 릴리스 노트의 Java SE 7 기능 및 개선 사항
다음은 OpenJDK 7 기능 페이지 의 Java 7 새로운 기능 요약입니다 .
vm JSR 292 : 동적 유형 언어 지원 (InvokeDynamic) 엄격한 클래스 파일 검사 lang JSR 334 : 작은 언어 향상 (Project Coin) 핵심 업그레이드 클래스 로더 아키텍처 URLClassLoader를 닫는 방법 동시성 및 컬렉션 업데이트 (jsr166y) i18n 유니 코드 6.0 로케일 향상 사용자 로케일 및 사용자 인터페이스 로케일 분리 ionet JSR 203 : Java 플랫폼 (NIO.2)을위한 새로운 I / O API zip / jar 아카이브 용 NIO.2 파일 시스템 공급자 SCTP (Stream Control Transmission Protocol) SDP (Sockets Direct Protocol) Windows Vista IPv6 스택 사용 TLS 1.2 sec Elliptic-curve cryptography (ECC) jdbc JDBC 4.1 Java 2D 용 클라이언트 XRender 파이프 라인 6u10 그래픽 기능을위한 새로운 플랫폼 API 생성 스윙을위한 Nimbus 룩앤필 스윙 JLayer 구성 요소 Gervill 사운드 신디사이저 [NEW] 웹 XML 스택 업데이트 관리 강화 MBeans [업데이트 됨]
Java 1.7의 새로운 기능에 대한 코드 예제
Try-with-resources 문
이:
BufferedReader br = new BufferedReader(new FileReader(path));
try {
return br.readLine();
} finally {
br.close();
}
된다 :
try (BufferedReader br = new BufferedReader(new FileReader(path)) {
return br.readLine();
}
닫을 리소스를 두 개 이상 선언 할 수 있습니다.
try (
InputStream in = new FileInputStream(src);
OutputStream out = new FileOutputStream(dest))
{
// code
}
숫자 리터럴의 밑줄
int one_million = 1_000_000;
스위치의 문자열
String s = ...
switch(s) {
case "quux":
processQuux(s);
// fall-through
case "foo":
case "bar":
processFooOrBar(s);
break;
case "baz":
processBaz(s);
// fall-through
default:
processDefault(s);
break;
}
이진 리터럴
int binary = 0b1001_1001;
일반 인스턴스 생성을위한 향상된 유형 추론
Map<String, List<String>> anagrams = new HashMap<String, List<String>>();
된다 :
Map<String, List<String>> anagrams = new HashMap<>();
다중 예외 포착
이:
} catch (FirstException ex) {
logger.error(ex);
throw ex;
} catch (SecondException ex) {
logger.error(ex);
throw ex;
}
된다 :
} catch (FirstException | SecondException ex) {
logger.error(ex);
throw ex;
}
SafeVarargs
이:
@SuppressWarnings({"unchecked", "varargs"})
public static void printAll(List<String>... lists){
for(List<String> list : lists){
System.out.println(list);
}
}
된다 :
@SafeVarargs
public static void printAll(List<String>... lists){
for(List<String> list : lists){
System.out.println(list);
}
}
Java Standard Edition (JSE 7)의 새로운 기능
JLayer 클래스로 구성 요소 장식 :
The JLayer class is a flexible and powerful decorator for Swing components. The JLayer class in Java SE 7 is similar in spirit to the JxLayer project project at java.net. The JLayer class was initially based on the JXLayer project, but its API evolved separately.
Strings in switch Statement:
In the JDK 7 , we can use a String object in the expression of a switch statement. The Java compiler generates generally more efficient bytecode from switch statements that use String objects than from chained if-then-else statements.
Type Inference for Generic Instance:
We can replace the type arguments required to invoke the constructor of a generic class with an empty set of type parameters (<>) as long as the compiler can infer the type arguments from the context. This pair of angle brackets is informally called the diamond. Java SE 7 supports limited type inference for generic instance creation; you can only use type inference if the parameterized type of the constructor is obvious from the context. For example, the following example does not compile:
List<String> l = new ArrayList<>(); l.add("A"); l.addAll(new ArrayList<>());
In comparison, the following example compiles:
List<? extends String> list2 = new ArrayList<>(); l.addAll(list2);
Catching Multiple Exception Types and Rethrowing Exceptions with Improved Type Checking:
In Java SE 7 and later, a single catch block can handle more than one type of exception. This feature can reduce code duplication. Consider the following code, which contains duplicate code in each of the catch blocks:
catch (IOException e) { logger.log(e); throw e; } catch (SQLException e) { logger.log(e); throw e; }
In releases prior to Java SE 7, it is difficult to create a common method to eliminate the duplicated code because the variable e has different types. The following example, which is valid in Java SE 7 and later, eliminates the duplicated code:
catch (IOException|SQLException e) { logger.log(e); throw e; }
The catch clause specifies the types of exceptions that the block can handle, and each exception type is separated with a vertical bar (|).
The java.nio.file package
The
java.nio.file
package and its related package, java.nio.file.attribute, provide comprehensive support for file I/O and for accessing the file system. A zip file system provider is also available in JDK 7.
Source: http://ohmjavaclasses.blogspot.com/
Java Programming Language Enhancements @ Java7
- Binary Literals
- Strings in switch Statement
- Try with Resources or ARM (Automatic Resource Management)
- Multiple Exception Handling
- Suppressed Exceptions
- underscore in literals
- Type Inference for Generic Instance Creation using Diamond Syntax
- Improved Compiler Warnings and Errors When Using Non-Reifiable Formal Parameters with Varargs Methods
Official reference
Official reference with java8
wiki reference
In addition to what John Skeet said, here's an overview of the Java 7 project. It includes a list and description of the features.
Note: JDK 7 was released on July 28, 2011, so you should now go to the official java SE site.
Language changes:
-Project Coin (small changes)
-switch on Strings
-try-with-resources
-diamond operator
Library changes:
-new abstracted file-system API (NIO.2) (with support for virtual filesystems)
-improved concurrency libraries
-elliptic curve encryption
-more incremental upgrades
Platform changes:
-support for dynamic languages
Below is the link explaining the newly added features of JAVA 7 , the explanation is crystal clear with the possible small examples for each features :
http://radar.oreilly.com/2011/09/java7-features.html
Using Diamond(<>) operator for generic instance creation
Map<String, List<Trade>> trades = new TreeMap <> ();
Using strings in switch statements
String status= “something”;
switch(statue){
case1:
case2:
default:
}
Underscore in numeric literals
int val 12_15; long phoneNo = 01917_999_720L;
Using single catch statement for throwing multiple exception by using “|” operator
catch(IOException | NullPointerException ex){
ex.printStackTrace();
}
No need to close() resources because Java 7 provides try-with-resources statement
try(FileOutputStream fos = new FileOutputStream("movies.txt");
DataOutputStream dos = new DataOutputStream(fos)) {
dos.writeUTF("Java 7 Block Buster");
} catch(IOException e) {
// log the exception
}
binary literals with prefix “0b” or “0B”
The following list contains links to the the enhancements pages in the Java SE 7.
Swing
IO and New IO
Networking
Security
Concurrency Utilities
Rich Internet Applications (RIA)/Deployment
Requesting and Customizing Applet Decoration in Dragg able Applets
Embedding JNLP File in Applet Tag
Deploying without Codebase
Handling Applet Initialization Status with Event Handlers
Java 2D
Java XML – JAXP, JAXB, and JAX-WS
Internationalization
java.lang Package
Multithreaded Custom Class Loaders in Java SE 7
Java Programming Language
Binary Literals
Strings in switch Statements
The try-with-resources Statement
Catching Multiple Exception Types and Rethrowing Exceptions with Improved Type Checking
Underscores in Numeric Literals
Type Inference for Generic Instance Creation
Improved Compiler Warnings and Errors When Using Non-Reifiable Formal Parameters with Varargs Methods
Java Virtual Machine (JVM)
Java Virtual Machine Support for Non-Java Languages
Garbage-First Collector
Java HotSpot Virtual Machine Performance Enhancements
JDBC
참고URL : https://stackoverflow.com/questions/213958/new-features-in-java-7
'programing tip' 카테고리의 다른 글
ImageView로 Android 페이드 인 및 페이드 아웃 (0) | 2020.09.18 |
---|---|
Oracle SQL Developer SQL 워크 시트 창에서 텍스트 인쇄 (0) | 2020.09.18 |
Java의 바로 가기 "또는 할당"(| =) 연산자 (0) | 2020.09.18 |
모델 김태연 (0) | 2020.09.17 |
C #의 스택 크기가 정확히 1MB 인 이유는 무엇입니까? (0) | 2020.09.16 |