Java SE 7 New Features &
Enhancements
Fu Cheng @alexcheng1982
Author of Understanding the Java 7 Author of technical articles on
Agenda
• Usefull tips
– Language
– IO
• No deep dive topics
Why Java Platform
Why Java
http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html
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
Why Java 7
• 5 years from Java SE 6 to Java SE 7
• New features
– JVM level
– Language level
– API
• Enhancements
– Performance
– Management
– Documentation
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
Sample
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
Exception Handling
• Multiple exception types in one catch clause
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
Sample
File copy example
Diamond Operator
• Use diamond (<>) operator to simply generic
objects creation
Old way
New way
Path
• java.nio.file.Path
– New abstraction for file path
– Say goodbye to using string for file path
– Type safe
Directory Stream
• java.nio.file.DirectoryStream
• List files in directory
• Provide better performance than “File.list” and “File.listFiles”
• Extend from Iterable
Directory Watcher
• Get notified when files changed in a directory
– Entry created, modified or deleted
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
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)

Java SE 7 New Features and Enhancements

  • 1.
    Java SE 7New Features & Enhancements Fu Cheng @alexcheng1982
  • 2.
    Author of Understandingthe Java 7 Author of technical articles on
  • 3.
    Agenda • Usefull tips –Language – IO • No deep dive topics
  • 4.
  • 5.
  • 6.
    Why Java • Easyto learn – Simple • Easy to use – Strong community – All kinds of third-party libraries • HARD to do things WRONG – Static typed – Rigid syntax
  • 7.
    Why Java 7 •5 years from Java SE 6 to Java SE 7 • New features – JVM level – Language level – API • Enhancements – Performance – Management – Documentation
  • 8.
    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
  • 9.
  • 10.
    Numeric Literals • Javaonly 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
  • 11.
    Exception Handling • Multipleexception types in one catch clause
  • 12.
    try-with-resources • Use tryclause 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
  • 13.
  • 14.
    Diamond Operator • Usediamond (<>) operator to simply generic objects creation Old way New way
  • 15.
    Path • java.nio.file.Path – Newabstraction for file path – Say goodbye to using string for file path – Type safe
  • 16.
    Directory Stream • java.nio.file.DirectoryStream •List files in directory • Provide better performance than “File.list” and “File.listFiles” • Extend from Iterable
  • 17.
    Directory Watcher • Getnotified when files changed in a directory – Entry created, modified or deleted
  • 18.
    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
  • 19.
    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)