SlideShare a Scribd company logo
A view of possible small language changes
Java 7.0 change summary
CHANGE BULLETIN BOARD
 Better Integer Literal
 Improved type inference
 Enum comparison
 String switch
 Chained invocations &
Extension methods
 Improved catch clauses
 Array notation for Map, List
 Self type(this)
 Automatic Resource
Management
 New I/O 2 (NIO2)
Libraries
 Fork Join Framework
 Miscellaneous Things
•What is better Integer Literal ?
 Before JDK1.7
Binary literals
Int mask=0b101010101010;
 Proposed in JDK1.7
With underscores for clarity
int mask =0b1010_1010_1010 ;
long big =9_234_345_087_780L;
•Improved type inference?
 Before JDK1.7
 Constructors
Map<String,
List<String>> anagrams
= new HashMap<String,
List<String>>();
 Proposed in Jdk1.7
 Constructors
Map<String, List<String>>
anagrams = new
HashMap<>();
•Improved type inference(cont)
 Before JDK1.7
 Argument Positions
public <E> Set<E> emptySet() { … }
void timeWaitsFor(Set<Man> people)
{ … }
// * Won't compile!
timeWaitsFor(Collections.emptySet());
 Proposed in Jdk1.7
 Argument Positions
public <E> Set<E> emptySet() { … }
void timeWaitsFor(Set<Man> people) {
… }
// OK
timeWaitsFor(Collections.<Man>empt
ySet());
•What is new Enum Comparison?
 Before JDK1.7
enum Size { SMALL, MEDIUM, LARGE }
if (mySize.compareTo(yourSize) >= 0)
System.out.println(“
You can wear my pants.”);
 Proposed in Jdk1.7
enum Size { SMALL, MEDIUM,
LARGE }
if (mySize > yourSize)
System.out.println(“Y
ou can wear my
pants.”);
What is new Switch Case?
 Before JDK1.7
static boolean
booleanFromString(String s)
{
if (s.equals("true"))
{
return true;
} else if (s.equals("false"))
{
return false;
} else
{ throw new
IllegalArgumentException(s);
}
}
 Proposed in Jdk1.7
static boolean
booleanFromString(String
s) {
switch(s) {
case "true":
return true;
case "false":
return false;
default:
throw new
IllegalArgumentException(
s);
}
}
Chained invocations
 Before JDK1.7 (chained)
class Builder {
void setSomething(Something x)
{ … }
void setOther(Other x) { … }
Thing result() { … }
}
Builder builder = new Builder();
builder.setSomething(something);
builder.setOther(other);
Thing thing = builder.result();
 Proposed in Jdk1.7
class Builder {
void setSomething(Something x)
{ … }
void setOther(Other x) { … }
Thing result() { … }
}
Thing thing = new Builder()
.setSomething(something)
.setOther(other)
.result();
Extension Methods
 Before JDK1.7
import java.util.Collections;
List<String> list = …;
Collections.sort(list);
 Proposed in Jdk1.7
import static java.util.Collections.sort;
List<String> list = …;
list.sort();
•Improved catch clauses : Catching multiple types
 Before JDK1.7
try
{
return klass.newInstance();
}catch (InstantiationException e)
{
throw new AssertionError(e);
}catch (IllegalAccessException e)
{
throw new AssertionError(e);
}
 Proposed in Jdk1.7
try {
return klass.newInstance();
} catch (InstantiationException |
IllegalAccessException e) {
throw new AssertionError(e);
}
•Improved catch clauses : rethrown exceptions
 Before JDK1.7
try {
// Throws several types
doable.doit();
}
catch (Throwable ex) {
logger.log(ex);
throw ex; // Error: Throwable not
declared
}
 Proposed in Jdk1.7
try {
// Throws several types
doable.doit();
}
catch (final Throwable ex) {
logger.log(ex);
throw ex;
// OK: Throws the same several types
}
•Array notation for Map, List change
 Before JDK1.7
void swap(List<String>
list, int i, int j)
{
String s1 = list.get(i);
list.set(i,list.get(j));
list.set(j, s1);
}
 Proposed in Jdk1.7
void swap(List<String>
list, int i, int j)
{
String s1 = list[i];
list[i] = list[j];
list[j] = s1;
}
•Array notation for Map, List change(cont)
 Before JDK1.7
Map<Input,Output> cache = …;
Output cachedComputation(Input in) {
Output out = cache.get(in);
if (out == null) {
out = computation(input);
cache.put(in, out);
}
return out;
}
 Proposed in Jdk1.7
Map<Input,Output> cache = …;
Output cachedComputation(Input
in) {
Output out = cache[in];
if (out == null) {
out = computation(input);
cache[in] = out;
}
return out;
}
•What is Self type(this)?
 Before JDK1.7
class Buffer {
Buffer flip() { … }
Buffer position(int newPos) { … }
Buffer limit(int newLimit) { … }
}
class ByteBuffer extends Buffer {
ByteBuffer put(byte data) { … }
}
public static void main(String args) {
ByteBuffer buf = ...;
buf.flip().position(12); // OK
buf.flip().put(12); // Error }
 Proposed in Jdk1.7
class Buffer {
this flip() { … }
this position(int newPos) { … }
this limit(int newLimit) { … }
}
class ByteBuffer extends Buffer {
this put(byte data) { … }
}
public static void main(String args) {
ByteBuffer buf = ...;
buf.flip().position(12); // OK
buf.flip().put(12); // is fine now}
•Why Automatic Resource Management?
 Before JDK1.7
InputStream in = new FileInputStream(src);
try
{
OutputStream out = new FileOutputStream(dest);
try
{
byte[] buf = new byte[8192];
int n;
while (n = in.read(buf)) >= 0) out.write(buf, 0, n);
} finally {
out.close();
}} finally {
in.close();
}
•Why Automatic Resource Management?(cont)
 Proposed JDK1.7
try (InputStream in = new FileInputStream(src),
OutputStream out = new FileOutputStream(dest))
{
byte[] buf = new byte[8192];
int n;
while (n = in.read(buf)) >= 0)
out.write(buf, 0, n);
}
New superinterface java.lang.AutoCloseable
 All AutoCloseable and by extension java.io.Closeable types useable with try-with-
resources
 anything with a void close() method is a candidate
 JDBC 4.1 retrefitted as AutoCloseable too
What is New I/O 2 (NIO2) Libraries? (JSR 203)
Original Java I/O APIs presented challenges for developers
 Not designed to be extensible
 Many methods do not throw exceptions as expected
 rename() method works inconsistently
 Developers want greater access to file metadata
Java NIO2 solves these problems
Features of NIO2 (cont)
 Path is a replacement for File
 (Biggest impact on developers)
 Better directory support
 (list() method can stream via iterator)
 Entries can be filtered using regular expressions in API
 Symbolic link support
 java.nio.file.Filesystem
 interface to a filesystem (FAT, ZFS, Zip archive, network,
etc)
 java.nio.file.attribute package Access to file metadata
Features of NIO2 (cont)
Path Class introduction
 Equivalent of java.io.File in the new API Immutable
 Have methods to access and manipulate Path
 Few ways to create a Path - From Paths and FileSystem
//Make a reference to the path
Path home = Paths.get(“/home/fred”);
//Resolve tmp from /home/fred -> /home/fred/tmp
Path tmpPath = home.resolve(“tmp”);
//Create a relative path from tmp -> ..
Path relativePath = tmpPath.relativize(home)
File file = relativePath.toFile();
Introuction Fork Join Framework
Goal is to take advantage of multiple processor
 Designed for task that can be broken down into smaller
pieces
Eg. Fibonacci number fib(10) = fib(9) + fib(8)
 Typical algorithm that uses fork join
if I can manage the task
perform the task
else
fork task into x number of smaller/similar task
join the results
Introuction Fork Join Framework (cont)
Key Classes
 ForkJoinPool
Executor service for running ForkJoinTask
 ForkJoinTask
The base class for forkjoin task
 RecursiveAction
A subclass of ForkJoinTask
A recursive resultless task
Implements compute() abstract method to perform
calculation
 RecursiveTask
Similar to RecursiveAction but returns a result
Introuction Fork Join Framework (cont)
ForkJoin Example – Fibonacci
public class Fibonacci extends RecursiveTask<Integer>
{
private final int number;
public Fibonacci(int n) { number = n; }
@Override protected Integer compute() {
switch (number) {
case 0: return (0);
case 1: return (1);
default:
Fibonacci f1 = new Fibonacci(number – 1);
Fibonacci f2 = new Fibonacci(number – 2);
f1.fork(); f2.fork();
return (f1.join() + f2.join());
}
}
}
Introuction Fork Join Framework (cont)
ForkJoin Example – Fibonacci
ForkJoinPool pool = new ForkJoinPool();
Fibonacci r = new Fibonacci(10);
pool.submit(r);
while (!r.isDone()) {
//Do some work
...
}
System.out.println("Result of fib(10) = "+ r.get());
•Miscellaneous Things
 InvokeDynamic Bytecode
 Security
 Eliptic curve cryptography
 TLS 1.2
 JAXP 1.4.4
 JAX-WS 2.2
 JAXB 2.2
 ClassLoader architecture changes
 close() for URLClassLoader
 Javadoc support for CSS

More Related Content

PPTX
C++11 - STL Additions
GlobalLogic Ukraine
 
PPTX
C++11 Multithreading - Futures
GlobalLogic Ukraine
 
PDF
Advanced Java Practical File
Soumya Behera
 
PPTX
Kotlin coroutines and spring framework
Sunghyouk Bae
 
PPT
Jug java7
Dmitry Buzdin
 
DOCX
Advance Java Programs skeleton
Iram Ramrajkar
 
PDF
Java 7 at SoftShake 2011
julien.ponge
 
DOC
Ad java prac sol set
Iram Ramrajkar
 
C++11 - STL Additions
GlobalLogic Ukraine
 
C++11 Multithreading - Futures
GlobalLogic Ukraine
 
Advanced Java Practical File
Soumya Behera
 
Kotlin coroutines and spring framework
Sunghyouk Bae
 
Jug java7
Dmitry Buzdin
 
Advance Java Programs skeleton
Iram Ramrajkar
 
Java 7 at SoftShake 2011
julien.ponge
 
Ad java prac sol set
Iram Ramrajkar
 

What's hot (19)

PDF
Java 7 JUG Summer Camp
julien.ponge
 
DOCX
srgoc
Gaurav Singh
 
PPTX
Kotlin – the future of android
DJ Rausch
 
PPTX
Java nio ( new io )
Jemin Patel
 
PDF
Kotlin @ Coupang Backend 2017
Sunghyouk Bae
 
PDF
Application-Specific Models and Pointcuts using a Logic Meta Language
ESUG
 
PDF
Java Programming - 06 java file io
Danairat Thanabodithammachari
 
PDF
Collections forceawakens
RichardWarburton
 
PPTX
NIO and NIO2
Balamurugan Soundararajan
 
PPTX
Adventures in TclOO
Donal Fellows
 
PPTX
Use of Apache Commons and Utilities
Pramod Kumar
 
PPTX
Nice to meet Kotlin
Jieyi Wu
 
PDF
If You Think You Can Stay Away from Functional Programming, You Are Wrong
Mario Fusco
 
PDF
JAVA NIO
오석 한
 
PDF
JUnit5 and TestContainers
Sunghyouk Bae
 
PDF
Java7 New Features and Code Examples
Naresh Chintalcheru
 
ODP
Java Concurrency
Carol McDonald
 
ODP
Finagle and Java Service Framework at Pinterest
Pavan Chitumalla
 
PDF
ikh331-06-distributed-programming
Anung Ariwibowo
 
Java 7 JUG Summer Camp
julien.ponge
 
Kotlin – the future of android
DJ Rausch
 
Java nio ( new io )
Jemin Patel
 
Kotlin @ Coupang Backend 2017
Sunghyouk Bae
 
Application-Specific Models and Pointcuts using a Logic Meta Language
ESUG
 
Java Programming - 06 java file io
Danairat Thanabodithammachari
 
Collections forceawakens
RichardWarburton
 
Adventures in TclOO
Donal Fellows
 
Use of Apache Commons and Utilities
Pramod Kumar
 
Nice to meet Kotlin
Jieyi Wu
 
If You Think You Can Stay Away from Functional Programming, You Are Wrong
Mario Fusco
 
JAVA NIO
오석 한
 
JUnit5 and TestContainers
Sunghyouk Bae
 
Java7 New Features and Code Examples
Naresh Chintalcheru
 
Java Concurrency
Carol McDonald
 
Finagle and Java Service Framework at Pinterest
Pavan Chitumalla
 
ikh331-06-distributed-programming
Anung Ariwibowo
 
Ad

Similar to JDK1.7 features (20)

PDF
New Features Of JDK 7
Deniz Oguz
 
PPTX
Java 7 Whats New(), Whats Next() from Oredev
Mattias Karlsson
 
PDF
PostgreSQL and PL/Java
Peter Eisentraut
 
PDF
Ejb3 Dan Hinojosa
Dan Hinojosa
 
PPTX
Entity Framework: Nakov @ BFU Hackhaton 2015
Svetlin Nakov
 
PDF
Apache Beam de A à Z
Paris Data Engineers !
 
PDF
Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...
julien.ponge
 
PDF
Silicon Valley JUG: JVM Mechanics
Azul Systems, Inc.
 
PDF
Scala is java8.next()
daewon jeong
 
PPTX
Java 7, 8 & 9 - Moving the language forward
Mario Fusco
 
PDF
Workshop "Can my .NET application use less CPU / RAM?", Yevhen Tatarynov
Fwdays
 
PPTX
Java 7 & 8 New Features
Leandro Coutinho
 
PDF
JVM Mechanics: When Does the JVM JIT & Deoptimize?
Doug Hawkins
 
PDF
Clojure - A new Lisp
elliando dias
 
PPTX
Java
박 경민
 
ODP
Lambda Chops - Recipes for Simpler, More Expressive Code
Ian Robertson
 
PPTX
Столпы функционального программирования для адептов ООП, Николай Мозговой
Sigma Software
 
PDF
What's new in Python 3.11
Henry Schreiner
 
PPTX
Introduction to Client-Side Javascript
Julie Iskander
 
PPTX
Parallel Processing
RTigger
 
New Features Of JDK 7
Deniz Oguz
 
Java 7 Whats New(), Whats Next() from Oredev
Mattias Karlsson
 
PostgreSQL and PL/Java
Peter Eisentraut
 
Ejb3 Dan Hinojosa
Dan Hinojosa
 
Entity Framework: Nakov @ BFU Hackhaton 2015
Svetlin Nakov
 
Apache Beam de A à Z
Paris Data Engineers !
 
Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...
julien.ponge
 
Silicon Valley JUG: JVM Mechanics
Azul Systems, Inc.
 
Scala is java8.next()
daewon jeong
 
Java 7, 8 & 9 - Moving the language forward
Mario Fusco
 
Workshop "Can my .NET application use less CPU / RAM?", Yevhen Tatarynov
Fwdays
 
Java 7 & 8 New Features
Leandro Coutinho
 
JVM Mechanics: When Does the JVM JIT & Deoptimize?
Doug Hawkins
 
Clojure - A new Lisp
elliando dias
 
Lambda Chops - Recipes for Simpler, More Expressive Code
Ian Robertson
 
Столпы функционального программирования для адептов ООП, Николай Мозговой
Sigma Software
 
What's new in Python 3.11
Henry Schreiner
 
Introduction to Client-Side Javascript
Julie Iskander
 
Parallel Processing
RTigger
 
Ad

Recently uploaded (20)

PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
PPTX
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
PPTX
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
PPTX
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 
PDF
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PPTX
Agile Chennai 18-19 July 2025 | Emerging patterns in Agentic AI by Bharani Su...
AgileNetwork
 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
PDF
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
PDF
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
PDF
Software Development Methodologies in 2025
KodekX
 
PPTX
Simple and concise overview about Quantum computing..pptx
mughal641
 
PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
PPTX
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
PDF
AI-Cloud-Business-Management-Platforms-The-Key-to-Efficiency-Growth.pdf
Artjoker Software Development Company
 
PDF
Get More from Fiori Automation - What’s New, What Works, and What’s Next.pdf
Precisely
 
PDF
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
PDF
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 
PDF
Doc9.....................................
SofiaCollazos
 
PDF
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Agile Chennai 18-19 July 2025 | Emerging patterns in Agentic AI by Bharani Su...
AgileNetwork
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
Software Development Methodologies in 2025
KodekX
 
Simple and concise overview about Quantum computing..pptx
mughal641
 
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
AI-Cloud-Business-Management-Platforms-The-Key-to-Efficiency-Growth.pdf
Artjoker Software Development Company
 
Get More from Fiori Automation - What’s New, What Works, and What’s Next.pdf
Precisely
 
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 
Doc9.....................................
SofiaCollazos
 
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 

JDK1.7 features

  • 1. A view of possible small language changes Java 7.0 change summary
  • 2. CHANGE BULLETIN BOARD  Better Integer Literal  Improved type inference  Enum comparison  String switch  Chained invocations & Extension methods  Improved catch clauses  Array notation for Map, List  Self type(this)  Automatic Resource Management  New I/O 2 (NIO2) Libraries  Fork Join Framework  Miscellaneous Things
  • 3. •What is better Integer Literal ?  Before JDK1.7 Binary literals Int mask=0b101010101010;  Proposed in JDK1.7 With underscores for clarity int mask =0b1010_1010_1010 ; long big =9_234_345_087_780L;
  • 4. •Improved type inference?  Before JDK1.7  Constructors Map<String, List<String>> anagrams = new HashMap<String, List<String>>();  Proposed in Jdk1.7  Constructors Map<String, List<String>> anagrams = new HashMap<>();
  • 5. •Improved type inference(cont)  Before JDK1.7  Argument Positions public <E> Set<E> emptySet() { … } void timeWaitsFor(Set<Man> people) { … } // * Won't compile! timeWaitsFor(Collections.emptySet());  Proposed in Jdk1.7  Argument Positions public <E> Set<E> emptySet() { … } void timeWaitsFor(Set<Man> people) { … } // OK timeWaitsFor(Collections.<Man>empt ySet());
  • 6. •What is new Enum Comparison?  Before JDK1.7 enum Size { SMALL, MEDIUM, LARGE } if (mySize.compareTo(yourSize) >= 0) System.out.println(“ You can wear my pants.”);  Proposed in Jdk1.7 enum Size { SMALL, MEDIUM, LARGE } if (mySize > yourSize) System.out.println(“Y ou can wear my pants.”);
  • 7. What is new Switch Case?  Before JDK1.7 static boolean booleanFromString(String s) { if (s.equals("true")) { return true; } else if (s.equals("false")) { return false; } else { throw new IllegalArgumentException(s); } }  Proposed in Jdk1.7 static boolean booleanFromString(String s) { switch(s) { case "true": return true; case "false": return false; default: throw new IllegalArgumentException( s); } }
  • 8. Chained invocations  Before JDK1.7 (chained) class Builder { void setSomething(Something x) { … } void setOther(Other x) { … } Thing result() { … } } Builder builder = new Builder(); builder.setSomething(something); builder.setOther(other); Thing thing = builder.result();  Proposed in Jdk1.7 class Builder { void setSomething(Something x) { … } void setOther(Other x) { … } Thing result() { … } } Thing thing = new Builder() .setSomething(something) .setOther(other) .result();
  • 9. Extension Methods  Before JDK1.7 import java.util.Collections; List<String> list = …; Collections.sort(list);  Proposed in Jdk1.7 import static java.util.Collections.sort; List<String> list = …; list.sort();
  • 10. •Improved catch clauses : Catching multiple types  Before JDK1.7 try { return klass.newInstance(); }catch (InstantiationException e) { throw new AssertionError(e); }catch (IllegalAccessException e) { throw new AssertionError(e); }  Proposed in Jdk1.7 try { return klass.newInstance(); } catch (InstantiationException | IllegalAccessException e) { throw new AssertionError(e); }
  • 11. •Improved catch clauses : rethrown exceptions  Before JDK1.7 try { // Throws several types doable.doit(); } catch (Throwable ex) { logger.log(ex); throw ex; // Error: Throwable not declared }  Proposed in Jdk1.7 try { // Throws several types doable.doit(); } catch (final Throwable ex) { logger.log(ex); throw ex; // OK: Throws the same several types }
  • 12. •Array notation for Map, List change  Before JDK1.7 void swap(List<String> list, int i, int j) { String s1 = list.get(i); list.set(i,list.get(j)); list.set(j, s1); }  Proposed in Jdk1.7 void swap(List<String> list, int i, int j) { String s1 = list[i]; list[i] = list[j]; list[j] = s1; }
  • 13. •Array notation for Map, List change(cont)  Before JDK1.7 Map<Input,Output> cache = …; Output cachedComputation(Input in) { Output out = cache.get(in); if (out == null) { out = computation(input); cache.put(in, out); } return out; }  Proposed in Jdk1.7 Map<Input,Output> cache = …; Output cachedComputation(Input in) { Output out = cache[in]; if (out == null) { out = computation(input); cache[in] = out; } return out; }
  • 14. •What is Self type(this)?  Before JDK1.7 class Buffer { Buffer flip() { … } Buffer position(int newPos) { … } Buffer limit(int newLimit) { … } } class ByteBuffer extends Buffer { ByteBuffer put(byte data) { … } } public static void main(String args) { ByteBuffer buf = ...; buf.flip().position(12); // OK buf.flip().put(12); // Error }  Proposed in Jdk1.7 class Buffer { this flip() { … } this position(int newPos) { … } this limit(int newLimit) { … } } class ByteBuffer extends Buffer { this put(byte data) { … } } public static void main(String args) { ByteBuffer buf = ...; buf.flip().position(12); // OK buf.flip().put(12); // is fine now}
  • 15. •Why Automatic Resource Management?  Before JDK1.7 InputStream in = new FileInputStream(src); try { OutputStream out = new FileOutputStream(dest); try { byte[] buf = new byte[8192]; int n; while (n = in.read(buf)) >= 0) out.write(buf, 0, n); } finally { out.close(); }} finally { in.close(); }
  • 16. •Why Automatic Resource Management?(cont)  Proposed JDK1.7 try (InputStream in = new FileInputStream(src), OutputStream out = new FileOutputStream(dest)) { byte[] buf = new byte[8192]; int n; while (n = in.read(buf)) >= 0) out.write(buf, 0, n); } New superinterface java.lang.AutoCloseable  All AutoCloseable and by extension java.io.Closeable types useable with try-with- resources  anything with a void close() method is a candidate  JDBC 4.1 retrefitted as AutoCloseable too
  • 17. What is New I/O 2 (NIO2) Libraries? (JSR 203) Original Java I/O APIs presented challenges for developers  Not designed to be extensible  Many methods do not throw exceptions as expected  rename() method works inconsistently  Developers want greater access to file metadata Java NIO2 solves these problems
  • 18. Features of NIO2 (cont)  Path is a replacement for File  (Biggest impact on developers)  Better directory support  (list() method can stream via iterator)  Entries can be filtered using regular expressions in API  Symbolic link support  java.nio.file.Filesystem  interface to a filesystem (FAT, ZFS, Zip archive, network, etc)  java.nio.file.attribute package Access to file metadata
  • 19. Features of NIO2 (cont) Path Class introduction  Equivalent of java.io.File in the new API Immutable  Have methods to access and manipulate Path  Few ways to create a Path - From Paths and FileSystem //Make a reference to the path Path home = Paths.get(“/home/fred”); //Resolve tmp from /home/fred -> /home/fred/tmp Path tmpPath = home.resolve(“tmp”); //Create a relative path from tmp -> .. Path relativePath = tmpPath.relativize(home) File file = relativePath.toFile();
  • 20. Introuction Fork Join Framework Goal is to take advantage of multiple processor  Designed for task that can be broken down into smaller pieces Eg. Fibonacci number fib(10) = fib(9) + fib(8)  Typical algorithm that uses fork join if I can manage the task perform the task else fork task into x number of smaller/similar task join the results
  • 21. Introuction Fork Join Framework (cont) Key Classes  ForkJoinPool Executor service for running ForkJoinTask  ForkJoinTask The base class for forkjoin task  RecursiveAction A subclass of ForkJoinTask A recursive resultless task Implements compute() abstract method to perform calculation  RecursiveTask Similar to RecursiveAction but returns a result
  • 22. Introuction Fork Join Framework (cont) ForkJoin Example – Fibonacci public class Fibonacci extends RecursiveTask<Integer> { private final int number; public Fibonacci(int n) { number = n; } @Override protected Integer compute() { switch (number) { case 0: return (0); case 1: return (1); default: Fibonacci f1 = new Fibonacci(number – 1); Fibonacci f2 = new Fibonacci(number – 2); f1.fork(); f2.fork(); return (f1.join() + f2.join()); } } }
  • 23. Introuction Fork Join Framework (cont) ForkJoin Example – Fibonacci ForkJoinPool pool = new ForkJoinPool(); Fibonacci r = new Fibonacci(10); pool.submit(r); while (!r.isDone()) { //Do some work ... } System.out.println("Result of fib(10) = "+ r.get());
  • 24. •Miscellaneous Things  InvokeDynamic Bytecode  Security  Eliptic curve cryptography  TLS 1.2  JAXP 1.4.4  JAX-WS 2.2  JAXB 2.2  ClassLoader architecture changes  close() for URLClassLoader  Javadoc support for CSS