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
PPTX
C++11 Multithreading - Futures
PDF
Advanced Java Practical File
PPTX
Kotlin coroutines and spring framework
PPT
Jug java7
DOCX
Advance Java Programs skeleton
PDF
Java 7 at SoftShake 2011
DOC
Ad java prac sol set
C++11 - STL Additions
C++11 Multithreading - Futures
Advanced Java Practical File
Kotlin coroutines and spring framework
Jug java7
Advance Java Programs skeleton
Java 7 at SoftShake 2011
Ad java prac sol set

What's hot (19)

PDF
Java 7 JUG Summer Camp
DOCX
PPTX
Kotlin – the future of android
PPTX
Java nio ( new io )
PDF
Kotlin @ Coupang Backend 2017
PDF
Application-Specific Models and Pointcuts using a Logic Meta Language
PDF
Java Programming - 06 java file io
PDF
Collections forceawakens
PPTX
PPTX
Adventures in TclOO
PPTX
Use of Apache Commons and Utilities
PPTX
Nice to meet Kotlin
PDF
If You Think You Can Stay Away from Functional Programming, You Are Wrong
PDF
JAVA NIO
PDF
JUnit5 and TestContainers
PDF
Java7 New Features and Code Examples
ODP
Java Concurrency
ODP
Finagle and Java Service Framework at Pinterest
PDF
ikh331-06-distributed-programming
Java 7 JUG Summer Camp
Kotlin – the future of android
Java nio ( new io )
Kotlin @ Coupang Backend 2017
Application-Specific Models and Pointcuts using a Logic Meta Language
Java Programming - 06 java file io
Collections forceawakens
Adventures in TclOO
Use of Apache Commons and Utilities
Nice to meet Kotlin
If You Think You Can Stay Away from Functional Programming, You Are Wrong
JAVA NIO
JUnit5 and TestContainers
Java7 New Features and Code Examples
Java Concurrency
Finagle and Java Service Framework at Pinterest
ikh331-06-distributed-programming
Ad

Similar to JDK1.7 features (20)

ODT
Best Of Jdk 7
PPTX
Java se7 features
PPTX
Java 7 Whats New(), Whats Next() from Oredev
PDF
New Features Of JDK 7
PDF
What`s new in Java 7
KEY
Back to the future with Java 7 (Geekout June/2011)
PPTX
Java 7 & 8 New Features
PPT
PPT
55 New Features in Java 7
ODP
From Java 6 to Java 7 reference
DOCX
Java 7 Dolphin manjula kollipara
KEY
Introduction to Java 7 (OSCON 2012)
ODP
Java 7: Quo vadis?
PPTX
Proposals for new function in Java SE 9 and beyond
PPT
Java SE 7 New Features and Enhancements
PPTX
Java 7, 8 & 9 - Moving the language forward
PDF
55 new things in Java 7 - Devoxx France
PDF
core java
PDF
Neal Gafter Java Evolution
PDF
wtf is in Java/JDK/wtf7?
Best Of Jdk 7
Java se7 features
Java 7 Whats New(), Whats Next() from Oredev
New Features Of JDK 7
What`s new in Java 7
Back to the future with Java 7 (Geekout June/2011)
Java 7 & 8 New Features
55 New Features in Java 7
From Java 6 to Java 7 reference
Java 7 Dolphin manjula kollipara
Introduction to Java 7 (OSCON 2012)
Java 7: Quo vadis?
Proposals for new function in Java SE 9 and beyond
Java SE 7 New Features and Enhancements
Java 7, 8 & 9 - Moving the language forward
55 new things in Java 7 - Devoxx France
core java
Neal Gafter Java Evolution
wtf is in Java/JDK/wtf7?
Ad

Recently uploaded (20)

PDF
sbt 2.0: go big (Scala Days 2025 edition)
PPTX
Internet of Everything -Basic concepts details
PDF
Architecture types and enterprise applications.pdf
PPT
Geologic Time for studying geology for geologist
PDF
A proposed approach for plagiarism detection in Myanmar Unicode text
PPTX
Modernising the Digital Integration Hub
PPTX
Microsoft Excel 365/2024 Beginner's training
DOCX
Basics of Cloud Computing - Cloud Ecosystem
PPT
What is a Computer? Input Devices /output devices
PPTX
Build Your First AI Agent with UiPath.pptx
PPTX
TEXTILE technology diploma scope and career opportunities
PDF
4 layer Arch & Reference Arch of IoT.pdf
PPTX
AI IN MARKETING- PRESENTED BY ANWAR KABIR 1st June 2025.pptx
PDF
How IoT Sensor Integration in 2025 is Transforming Industries Worldwide
PDF
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
PDF
Flame analysis and combustion estimation using large language and vision assi...
PDF
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
PDF
CloudStack 4.21: First Look Webinar slides
PPT
Module 1.ppt Iot fundamentals and Architecture
PDF
OpenACC and Open Hackathons Monthly Highlights July 2025
sbt 2.0: go big (Scala Days 2025 edition)
Internet of Everything -Basic concepts details
Architecture types and enterprise applications.pdf
Geologic Time for studying geology for geologist
A proposed approach for plagiarism detection in Myanmar Unicode text
Modernising the Digital Integration Hub
Microsoft Excel 365/2024 Beginner's training
Basics of Cloud Computing - Cloud Ecosystem
What is a Computer? Input Devices /output devices
Build Your First AI Agent with UiPath.pptx
TEXTILE technology diploma scope and career opportunities
4 layer Arch & Reference Arch of IoT.pdf
AI IN MARKETING- PRESENTED BY ANWAR KABIR 1st June 2025.pptx
How IoT Sensor Integration in 2025 is Transforming Industries Worldwide
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
Flame analysis and combustion estimation using large language and vision assi...
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
CloudStack 4.21: First Look Webinar slides
Module 1.ppt Iot fundamentals and Architecture
OpenACC and Open Hackathons Monthly Highlights July 2025

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