SlideShare a Scribd company logo
1 of 11
Just to drink a cup of coffee
refence guide: from java 6 to java 7 (SE)
Syntax
Compiler infers the generic type parameters
Improving variables declarations
Numbers litterals
Improving numebr reading (really?)
String switch
Exception
Catch more exceptions
Avoiding code redundancy
Try with resources
Avoiding “if/try/catch/finally nightmare”
Multithread
Fork and Join Framework
Parallel computing
NIO
deleteIfExists, …
...and a lot of stuff
File Watcher
Java Typed
java.lang.invoke
Not typed language are easy
Compiler infer the generic type parameters
Java 6
bject> objects = new LinkedList<MyObject>();
Java 7
List<MyObject> objects = new Lin
Numbers
Java 6
int i = 1000;
int j =1000000
Java 7
int i = 1_000;
int j = 1_000_000;
Wrong syntax
int x = _1_000_000;
String switch
Java 6
String a,b,c;
if (a.equals(b)) {
} else if (a.equals(c)) {
}
Java 7
String a,b,c;
switch (a) {
b:
break;
c:
break;
}
Catch more exceptions
Java 6
try {
...
} catch(NumberFormatException e) {
logError(e);
} catch(NullPointerException e) {
logError(e);
}
Java 7
try {
...
} catch(NumberFormatException |
logError(e);
}
Try with resources
(implements Closeable or AutoCloseable)
Java 6
FileReader r = null;
try{
r = new FileReader(file);
BufferedReader reader = new BufferedReader(r);
String line = reader.readLine();
while (line != null) {
lines.add(line);
line = reader.readLine();
}
} catch(IOException e) {
logError(e);
} finally {
if (r!=null) r.close();
}
Java 7
try(BufferedReader reader = new BufferedReader(
String line = reader.readLine();
while (line != null) {
lines.add(line);
line = reader.readLine();
}
}
Join Fork Framework
more powerfull than the code described here [http://www.oracle.com/technetwork/articles/java/fork-join-422606.ht
Java 6
FutureTask<String> myFutureAction = new FutureTask<String>(
new Callable<String>()
{
public MyObject call() {
Return ...;
}
});
ExecutorService executor = Executors.newFixedThreadPool(1);
FutureTask<Object> futureOne = new FutureTask<Object>(myFutureAction);
executor.execute(future);
…//sleep
executor.shutdown();
Java 7
public class ForkAction extends RecursiveAct
ParamObject from = null;
ForkAction(ParamObject from, ParamObject to)
this.from=from;
...
}
@Override
public MyObject compute() {
...
}
}
...
ForkJoinPool forkJoinPool = new ForkJoinPool
forkJoinPool.invoke(new ForkAction(from, to)
NIO deleteIfExists, ...
Java 6
try {
Files.delete(path);
} catch(NoSuchFileException e){}
Java 7
Files.deleteIfExists(path);
and a lot of stuff
Files.createSymbolicLink(...)
Files.copy(...)
Files.move(...)
NIO WatcherService
Java 6
while (true) {
File myDir = …
pollForChanges(myDir);
}
public void pollForChanges(File myDir) {
//list dir
//use apache common io
}
Java 7
Path pathToWatch = Paths.get("/tmp");
PathToWatch.register(FileSystems.getDefault(
while (true) {
WatchKey key = watchService.take();
}
NIO WatcherService
Java 6
while (true) {
File myDir = …
pollForChanges(myDir);
}
public void pollForChanges(File myDir) {
//list dir
//use apache common io
}
Java 7
Path pathToWatch = Paths.get("/tmp");
PathToWatch.register(FileSystems.getDefault(
while (true) {
WatchKey key = watchService.take();
}
java.lang.invoke
Java 6
class MyClass {
public void myMethod(int i, String j) {
...
}
}
...
Class<?>[] argTypes = new Class[] { int.class, String.class };
meth = MyClass.class. getDeclaredMethod("myMethod", argTypes);
meth.invoke(new MyClass(), 2, "EFG");
Java 7
class MyClass {
public void myMethod(int i, String j) {
...
}
}
...
MethodHandle mh;
MethodType desc = MethodType.methodType(v
mh = MethodHandles.lookup().findVirtual(M
mh.invokeExact(new MyClass(), 1, "ABCDE")

More Related Content

What's hot

Modern Programming in Java 8 - Lambdas, Streams and Date Time API
Modern Programming in Java 8 - Lambdas, Streams and Date Time APIModern Programming in Java 8 - Lambdas, Streams and Date Time API
Modern Programming in Java 8 - Lambdas, Streams and Date Time APIGanesh Samarthyam
 
Java7 New Features and Code Examples
Java7 New Features and Code ExamplesJava7 New Features and Code Examples
Java7 New Features and Code ExamplesNaresh Chintalcheru
 
Getting started with Java 9 modules
Getting started with Java 9 modulesGetting started with Java 9 modules
Getting started with Java 9 modulesRafael Winterhalter
 
Monitoring distributed (micro-)services
Monitoring distributed (micro-)servicesMonitoring distributed (micro-)services
Monitoring distributed (micro-)servicesRafael Winterhalter
 
What is new in java 8 concurrency
What is new in java 8 concurrencyWhat is new in java 8 concurrency
What is new in java 8 concurrencykshanth2101
 
DevNexus 2020: Discover Modern Java
DevNexus 2020: Discover Modern JavaDevNexus 2020: Discover Modern Java
DevNexus 2020: Discover Modern JavaHenri Tremblay
 
Porting Applications From Oracle To PostgreSQL
Porting Applications From Oracle To PostgreSQLPorting Applications From Oracle To PostgreSQL
Porting Applications From Oracle To PostgreSQLPeter Eisentraut
 
50 new features of Java EE 7 in 50 minutes
50 new features of Java EE 7 in 50 minutes50 new features of Java EE 7 in 50 minutes
50 new features of Java EE 7 in 50 minutesAntonio Goncalves
 

What's hot (20)

Core Java - Quiz Questions - Bug Hunt
Core Java - Quiz Questions - Bug HuntCore Java - Quiz Questions - Bug Hunt
Core Java - Quiz Questions - Bug Hunt
 
JVM
JVMJVM
JVM
 
Sailing with Java 8 Streams
Sailing with Java 8 StreamsSailing with Java 8 Streams
Sailing with Java 8 Streams
 
Modern Programming in Java 8 - Lambdas, Streams and Date Time API
Modern Programming in Java 8 - Lambdas, Streams and Date Time APIModern Programming in Java 8 - Lambdas, Streams and Date Time API
Modern Programming in Java 8 - Lambdas, Streams and Date Time API
 
Java Concurrency by Example
Java Concurrency by ExampleJava Concurrency by Example
Java Concurrency by Example
 
Java 7 & 8
Java 7 & 8Java 7 & 8
Java 7 & 8
 
Java 5 and 6 New Features
Java 5 and 6 New FeaturesJava 5 and 6 New Features
Java 5 and 6 New Features
 
Java concurrency questions and answers
Java concurrency questions and answers Java concurrency questions and answers
Java concurrency questions and answers
 
Java7 New Features and Code Examples
Java7 New Features and Code ExamplesJava7 New Features and Code Examples
Java7 New Features and Code Examples
 
Java7
Java7Java7
Java7
 
55 New Features in Java 7
55 New Features in Java 755 New Features in Java 7
55 New Features in Java 7
 
Java 7 New Features
Java 7 New FeaturesJava 7 New Features
Java 7 New Features
 
Getting started with Java 9 modules
Getting started with Java 9 modulesGetting started with Java 9 modules
Getting started with Java 9 modules
 
Monitoring distributed (micro-)services
Monitoring distributed (micro-)servicesMonitoring distributed (micro-)services
Monitoring distributed (micro-)services
 
Ad java prac sol set
Ad java prac sol setAd java prac sol set
Ad java prac sol set
 
What is new in java 8 concurrency
What is new in java 8 concurrencyWhat is new in java 8 concurrency
What is new in java 8 concurrency
 
Java after 8
Java after 8Java after 8
Java after 8
 
DevNexus 2020: Discover Modern Java
DevNexus 2020: Discover Modern JavaDevNexus 2020: Discover Modern Java
DevNexus 2020: Discover Modern Java
 
Porting Applications From Oracle To PostgreSQL
Porting Applications From Oracle To PostgreSQLPorting Applications From Oracle To PostgreSQL
Porting Applications From Oracle To PostgreSQL
 
50 new features of Java EE 7 in 50 minutes
50 new features of Java EE 7 in 50 minutes50 new features of Java EE 7 in 50 minutes
50 new features of Java EE 7 in 50 minutes
 

Similar to From Java 6 to Java 7 reference

Clojure - A new Lisp
Clojure - A new LispClojure - A new Lisp
Clojure - A new Lispelliando dias
 
Java 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from OredevJava 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from OredevMattias Karlsson
 
Introduction to clojure
Introduction to clojureIntroduction to clojure
Introduction to clojureAbbas Raza
 
Java Performance Tuning
Java Performance TuningJava Performance Tuning
Java Performance TuningMinh Hoang
 
New Features Of JDK 7
New Features Of JDK 7New Features Of JDK 7
New Features Of JDK 7Deniz Oguz
 
4Developers 2015: Programowanie synchroniczne i asynchroniczne - dwa światy k...
4Developers 2015: Programowanie synchroniczne i asynchroniczne - dwa światy k...4Developers 2015: Programowanie synchroniczne i asynchroniczne - dwa światy k...
4Developers 2015: Programowanie synchroniczne i asynchroniczne - dwa światy k...PROIDEA
 
The Mayans Lost Guide to RxJava on Android
The Mayans Lost Guide to RxJava on AndroidThe Mayans Lost Guide to RxJava on Android
The Mayans Lost Guide to RxJava on AndroidFernando Cejas
 
Java 7 new features
Java 7 new featuresJava 7 new features
Java 7 new featuresShivam Goel
 
To inject or not to inject: CDI is the question
To inject or not to inject: CDI is the questionTo inject or not to inject: CDI is the question
To inject or not to inject: CDI is the questionAntonio Goncalves
 
Java tut1 Coderdojo Cahersiveen
Java tut1 Coderdojo CahersiveenJava tut1 Coderdojo Cahersiveen
Java tut1 Coderdojo CahersiveenGraham Royce
 

Similar to From Java 6 to Java 7 reference (20)

Clojure - A new Lisp
Clojure - A new LispClojure - A new Lisp
Clojure - A new Lisp
 
Java 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from OredevJava 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from Oredev
 
Java 7 & 8 New Features
Java 7 & 8 New FeaturesJava 7 & 8 New Features
Java 7 & 8 New Features
 
Nantes Jug - Java 7
Nantes Jug - Java 7Nantes Jug - Java 7
Nantes Jug - Java 7
 
55j7
55j755j7
55j7
 
Introduction to clojure
Introduction to clojureIntroduction to clojure
Introduction to clojure
 
Java Performance Tuning
Java Performance TuningJava Performance Tuning
Java Performance Tuning
 
Java
JavaJava
Java
 
New Features Of JDK 7
New Features Of JDK 7New Features Of JDK 7
New Features Of JDK 7
 
4Developers 2015: Programowanie synchroniczne i asynchroniczne - dwa światy k...
4Developers 2015: Programowanie synchroniczne i asynchroniczne - dwa światy k...4Developers 2015: Programowanie synchroniczne i asynchroniczne - dwa światy k...
4Developers 2015: Programowanie synchroniczne i asynchroniczne - dwa światy k...
 
The Mayans Lost Guide to RxJava on Android
The Mayans Lost Guide to RxJava on AndroidThe Mayans Lost Guide to RxJava on Android
The Mayans Lost Guide to RxJava on Android
 
Java 7 new features
Java 7 new featuresJava 7 new features
Java 7 new features
 
To inject or not to inject: CDI is the question
To inject or not to inject: CDI is the questionTo inject or not to inject: CDI is the question
To inject or not to inject: CDI is the question
 
JavaFXScript
JavaFXScriptJavaFXScript
JavaFXScript
 
What`s new in Java 7
What`s new in Java 7What`s new in Java 7
What`s new in Java 7
 
Java Tutorial
Java TutorialJava Tutorial
Java Tutorial
 
Java tut1
Java tut1Java tut1
Java tut1
 
Java tut1 Coderdojo Cahersiveen
Java tut1 Coderdojo CahersiveenJava tut1 Coderdojo Cahersiveen
Java tut1 Coderdojo Cahersiveen
 
Java tut1
Java tut1Java tut1
Java tut1
 
Javatut1
Javatut1 Javatut1
Javatut1
 

More from Giacomo Veneri

Giacomo Veneri Thesis 1999 University of Siena
Giacomo Veneri Thesis 1999 University of SienaGiacomo Veneri Thesis 1999 University of Siena
Giacomo Veneri Thesis 1999 University of SienaGiacomo Veneri
 
Giiacomo Veneri PHD Dissertation
Giiacomo Veneri PHD Dissertation Giiacomo Veneri PHD Dissertation
Giiacomo Veneri PHD Dissertation Giacomo Veneri
 
Industrial IoT - build your industry 4.0 @techitaly
Industrial IoT - build your industry 4.0 @techitalyIndustrial IoT - build your industry 4.0 @techitaly
Industrial IoT - build your industry 4.0 @techitalyGiacomo Veneri
 
Preparing Java 7 Certifications
Preparing Java 7 CertificationsPreparing Java 7 Certifications
Preparing Java 7 CertificationsGiacomo Veneri
 
Pattern recognition on human vision
Pattern recognition on human visionPattern recognition on human vision
Pattern recognition on human visionGiacomo Veneri
 
Bayesain Hypothesis of Selective Attention - Raw 2011 poster
Bayesain Hypothesis of Selective Attention - Raw 2011 posterBayesain Hypothesis of Selective Attention - Raw 2011 poster
Bayesain Hypothesis of Selective Attention - Raw 2011 posterGiacomo Veneri
 
Raw 2009 -THE ROLE OF LATEST FIXATIONS ON ONGOING VISUAL SEARCH A MODEL TO E...
Raw 2009 -THE ROLE OF LATEST FIXATIONS ON ONGOING VISUAL SEARCH  A MODEL TO E...Raw 2009 -THE ROLE OF LATEST FIXATIONS ON ONGOING VISUAL SEARCH  A MODEL TO E...
Raw 2009 -THE ROLE OF LATEST FIXATIONS ON ONGOING VISUAL SEARCH A MODEL TO E...Giacomo Veneri
 
Eracle project poster_session_efns
Eracle project poster_session_efnsEracle project poster_session_efns
Eracle project poster_session_efnsGiacomo Veneri
 
Cibernetica, modelli computazionali e tecnologie informatiche
Cibernetica, modelli computazionali e tecnologie  informatiche Cibernetica, modelli computazionali e tecnologie  informatiche
Cibernetica, modelli computazionali e tecnologie informatiche Giacomo Veneri
 
EVA – EYE TRACKING - STIMULUS INTEGRATED SEMI AUTOMATIC CASE BASE SYSTEM
EVA – EYE TRACKING - STIMULUS INTEGRATED SEMI AUTOMATIC CASE  BASE SYSTEMEVA – EYE TRACKING - STIMULUS INTEGRATED SEMI AUTOMATIC CASE  BASE SYSTEM
EVA – EYE TRACKING - STIMULUS INTEGRATED SEMI AUTOMATIC CASE BASE SYSTEMGiacomo Veneri
 
THE ROLE OF LATEST FIXATIONS ON ONGOING VISUAL SEARCH
THE ROLE OF LATEST FIXATIONS ON ONGOING VISUAL SEARCH THE ROLE OF LATEST FIXATIONS ON ONGOING VISUAL SEARCH
THE ROLE OF LATEST FIXATIONS ON ONGOING VISUAL SEARCH Giacomo Veneri
 
Evaluating Human Visual Search Performance by Monte Carlo methods and Heurist...
Evaluating Human Visual Search Performance by Monte Carlo methods and Heurist...Evaluating Human Visual Search Performance by Monte Carlo methods and Heurist...
Evaluating Human Visual Search Performance by Monte Carlo methods and Heurist...Giacomo Veneri
 
Giacomo Veneri 2012 phd dissertation
Giacomo Veneri 2012 phd dissertationGiacomo Veneri 2012 phd dissertation
Giacomo Veneri 2012 phd dissertationGiacomo Veneri
 

More from Giacomo Veneri (17)

Giacomo Veneri Thesis 1999 University of Siena
Giacomo Veneri Thesis 1999 University of SienaGiacomo Veneri Thesis 1999 University of Siena
Giacomo Veneri Thesis 1999 University of Siena
 
Giiacomo Veneri PHD Dissertation
Giiacomo Veneri PHD Dissertation Giiacomo Veneri PHD Dissertation
Giiacomo Veneri PHD Dissertation
 
Industrial IoT - build your industry 4.0 @techitaly
Industrial IoT - build your industry 4.0 @techitalyIndustrial IoT - build your industry 4.0 @techitaly
Industrial IoT - build your industry 4.0 @techitaly
 
Preparing Java 7 Certifications
Preparing Java 7 CertificationsPreparing Java 7 Certifications
Preparing Java 7 Certifications
 
Pattern recognition on human vision
Pattern recognition on human visionPattern recognition on human vision
Pattern recognition on human vision
 
Advanced java
Advanced javaAdvanced java
Advanced java
 
Bayesain Hypothesis of Selective Attention - Raw 2011 poster
Bayesain Hypothesis of Selective Attention - Raw 2011 posterBayesain Hypothesis of Selective Attention - Raw 2011 poster
Bayesain Hypothesis of Selective Attention - Raw 2011 poster
 
Raw 2009 -THE ROLE OF LATEST FIXATIONS ON ONGOING VISUAL SEARCH A MODEL TO E...
Raw 2009 -THE ROLE OF LATEST FIXATIONS ON ONGOING VISUAL SEARCH  A MODEL TO E...Raw 2009 -THE ROLE OF LATEST FIXATIONS ON ONGOING VISUAL SEARCH  A MODEL TO E...
Raw 2009 -THE ROLE OF LATEST FIXATIONS ON ONGOING VISUAL SEARCH A MODEL TO E...
 
Eracle project poster_session_efns
Eracle project poster_session_efnsEracle project poster_session_efns
Eracle project poster_session_efns
 
Dal web 2 al web 3
Dal web 2 al web 3Dal web 2 al web 3
Dal web 2 al web 3
 
Il web 2.0
Il web 2.0Il web 2.0
Il web 2.0
 
Cibernetica, modelli computazionali e tecnologie informatiche
Cibernetica, modelli computazionali e tecnologie  informatiche Cibernetica, modelli computazionali e tecnologie  informatiche
Cibernetica, modelli computazionali e tecnologie informatiche
 
Giacomo Veneri Thesis
Giacomo Veneri ThesisGiacomo Veneri Thesis
Giacomo Veneri Thesis
 
EVA – EYE TRACKING - STIMULUS INTEGRATED SEMI AUTOMATIC CASE BASE SYSTEM
EVA – EYE TRACKING - STIMULUS INTEGRATED SEMI AUTOMATIC CASE  BASE SYSTEMEVA – EYE TRACKING - STIMULUS INTEGRATED SEMI AUTOMATIC CASE  BASE SYSTEM
EVA – EYE TRACKING - STIMULUS INTEGRATED SEMI AUTOMATIC CASE BASE SYSTEM
 
THE ROLE OF LATEST FIXATIONS ON ONGOING VISUAL SEARCH
THE ROLE OF LATEST FIXATIONS ON ONGOING VISUAL SEARCH THE ROLE OF LATEST FIXATIONS ON ONGOING VISUAL SEARCH
THE ROLE OF LATEST FIXATIONS ON ONGOING VISUAL SEARCH
 
Evaluating Human Visual Search Performance by Monte Carlo methods and Heurist...
Evaluating Human Visual Search Performance by Monte Carlo methods and Heurist...Evaluating Human Visual Search Performance by Monte Carlo methods and Heurist...
Evaluating Human Visual Search Performance by Monte Carlo methods and Heurist...
 
Giacomo Veneri 2012 phd dissertation
Giacomo Veneri 2012 phd dissertationGiacomo Veneri 2012 phd dissertation
Giacomo Veneri 2012 phd dissertation
 

Recently uploaded

Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 

Recently uploaded (20)

Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 

From Java 6 to Java 7 reference

  • 1. Just to drink a cup of coffee refence guide: from java 6 to java 7 (SE) Syntax Compiler infers the generic type parameters Improving variables declarations Numbers litterals Improving numebr reading (really?) String switch Exception Catch more exceptions Avoiding code redundancy Try with resources Avoiding “if/try/catch/finally nightmare” Multithread Fork and Join Framework Parallel computing NIO deleteIfExists, … ...and a lot of stuff File Watcher Java Typed java.lang.invoke Not typed language are easy
  • 2. Compiler infer the generic type parameters Java 6 bject> objects = new LinkedList<MyObject>(); Java 7 List<MyObject> objects = new Lin
  • 3. Numbers Java 6 int i = 1000; int j =1000000 Java 7 int i = 1_000; int j = 1_000_000; Wrong syntax int x = _1_000_000;
  • 4. String switch Java 6 String a,b,c; if (a.equals(b)) { } else if (a.equals(c)) { } Java 7 String a,b,c; switch (a) { b: break; c: break; }
  • 5. Catch more exceptions Java 6 try { ... } catch(NumberFormatException e) { logError(e); } catch(NullPointerException e) { logError(e); } Java 7 try { ... } catch(NumberFormatException | logError(e); }
  • 6. Try with resources (implements Closeable or AutoCloseable) Java 6 FileReader r = null; try{ r = new FileReader(file); BufferedReader reader = new BufferedReader(r); String line = reader.readLine(); while (line != null) { lines.add(line); line = reader.readLine(); } } catch(IOException e) { logError(e); } finally { if (r!=null) r.close(); } Java 7 try(BufferedReader reader = new BufferedReader( String line = reader.readLine(); while (line != null) { lines.add(line); line = reader.readLine(); } }
  • 7. Join Fork Framework more powerfull than the code described here [http://www.oracle.com/technetwork/articles/java/fork-join-422606.ht Java 6 FutureTask<String> myFutureAction = new FutureTask<String>( new Callable<String>() { public MyObject call() { Return ...; } }); ExecutorService executor = Executors.newFixedThreadPool(1); FutureTask<Object> futureOne = new FutureTask<Object>(myFutureAction); executor.execute(future); …//sleep executor.shutdown(); Java 7 public class ForkAction extends RecursiveAct ParamObject from = null; ForkAction(ParamObject from, ParamObject to) this.from=from; ... } @Override public MyObject compute() { ... } } ... ForkJoinPool forkJoinPool = new ForkJoinPool forkJoinPool.invoke(new ForkAction(from, to)
  • 8. NIO deleteIfExists, ... Java 6 try { Files.delete(path); } catch(NoSuchFileException e){} Java 7 Files.deleteIfExists(path); and a lot of stuff Files.createSymbolicLink(...) Files.copy(...) Files.move(...)
  • 9. NIO WatcherService Java 6 while (true) { File myDir = … pollForChanges(myDir); } public void pollForChanges(File myDir) { //list dir //use apache common io } Java 7 Path pathToWatch = Paths.get("/tmp"); PathToWatch.register(FileSystems.getDefault( while (true) { WatchKey key = watchService.take(); }
  • 10. NIO WatcherService Java 6 while (true) { File myDir = … pollForChanges(myDir); } public void pollForChanges(File myDir) { //list dir //use apache common io } Java 7 Path pathToWatch = Paths.get("/tmp"); PathToWatch.register(FileSystems.getDefault( while (true) { WatchKey key = watchService.take(); }
  • 11. java.lang.invoke Java 6 class MyClass { public void myMethod(int i, String j) { ... } } ... Class<?>[] argTypes = new Class[] { int.class, String.class }; meth = MyClass.class. getDeclaredMethod("myMethod", argTypes); meth.invoke(new MyClass(), 2, "EFG"); Java 7 class MyClass { public void myMethod(int i, String j) { ... } } ... MethodHandle mh; MethodType desc = MethodType.methodType(v mh = MethodHandles.lookup().findVirtual(M mh.invokeExact(new MyClass(), 1, "ABCDE")