java se 7 new features and enhancements
DESCRIPTION
Java SE 7 New Features and EnhancementsTRANSCRIPT
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)