java se 7 new features and enhancements

19
Java SE 7 New Features & Enhancements Fu Cheng @alexcheng1982

Upload: fu-cheng

Post on 25-Jun-2015

1.816 views

Category:

Technology


5 download

DESCRIPTION

Java SE 7 New Features and Enhancements

TRANSCRIPT

Page 1: Java SE 7 New Features and Enhancements

Java SE 7 New Features & Enhancements

Fu Cheng @alexcheng1982

Page 2: Java SE 7 New Features and Enhancements

Author of Understanding the Java 7 Author of technical articles on

Page 3: Java SE 7 New Features and Enhancements

Agenda

• Usefull tips– Language– IO

• No deep dive topics

Page 4: Java SE 7 New Features and Enhancements

Why Java Platform

Page 5: Java SE 7 New Features and Enhancements

Why Java

http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html

Page 6: Java SE 7 New Features and Enhancements

Why Java

• Easy to learn– Simple

• Easy to use– Strong community– All kinds of third-party libraries

• HARD to do things WRONG– Static typed– Rigid syntax

Page 7: Java SE 7 New Features and Enhancements

Why Java 7

• 5 years from Java SE 6 to Java SE 7• New features

– JVM level– Language level– API

• Enhancements– Performance– Management– Documentation

Page 8: Java SE 7 New Features and Enhancements

String in Switch

• “switch” statement • Prior to Java 7

– Can only use data type compatible with integer in “switch”

• Java 7– String type is allowed

• Under the hood– Switch by string hash code

Page 9: Java SE 7 New Features and Enhancements

Sample

Page 10: Java SE 7 New Features and Enhancements

Numeric Literals

• Java only supports literals of primitive types– List & map literals – Java SE 8 (maybe)

• Binary literals– Prefixed with 0b or 0B

• 0b001001

• Underscores in literals– Align for readability

• 5_6.3_4

Page 11: Java SE 7 New Features and Enhancements

Exception Handling

• Multiple exception types in one catch clause

Page 12: Java SE 7 New Features and Enhancements

try-with-resources

• Use try clause to manage resources– “finally” not required– Resource released automatically

• Make you own resource manageable by try clause– Implement java.lang.AutoCloseable– “close”method invoked automatically

Page 13: Java SE 7 New Features and Enhancements

Sample

File copy example

Page 14: Java SE 7 New Features and Enhancements

Diamond Operator

• Use diamond (<>) operator to simply generic objects creation

Old way

New way

Page 15: Java SE 7 New Features and Enhancements

Path• java.nio.file.Path

– New abstraction for file path– Say goodbye to using string for file path– Type safe

Page 16: Java SE 7 New Features and Enhancements

Directory Stream• java.nio.file.DirectoryStream• List files in directory• Provide better performance than “File.list” and “File.listFiles”• Extend from Iterable

Page 17: Java SE 7 New Features and Enhancements

Directory Watcher• Get notified when files changed in a directory

– Entry created, modified or deleted

Page 18: Java SE 7 New Features and Enhancements

Those Not Included• JSR 292 – “invokedynamic” instruction• Concurrency utilities

– Fork/join framework– Phaser

• I18N– Unicode 6.0– IETF BCP 47

• NIO.2– Zip/jar file system– Async I/O

• JDBC 4.1

Page 19: Java SE 7 New Features and Enhancements

Future of Java• Productivity

– Enhanced for loop (Java SE 5)– try-with-resources (Java SE 7)– Diamond operator (Java SE 7)– Lambda expression (Java SE 8)

• Performance– Fork/join framework (Java SE 7)– Collection framework enhancements (Java SE 8)

• Modularization– Project Jigsaw (Java SE 8)