SlideShare ist ein Scribd-Unternehmen logo
1 von 28
Java SE 7 {finally}

2011-08-18
Andreas Enbohm

© 2004 Capgemini - All rights reserved
Java SE 7

A evolutionary evolement of Java
6 years since last update
Some things left out, will briefly discuss this at the end
Oracle really pushing Java forward
- a lot political problems with Sun made Java 7 postphoned
several times
Java still growing (1.42%), #1 most used language according to
TIOBE with 19.4% (Aug 2011)
My top 10 new features (not ordered in any way )

Sida 2
15 januari 2014
© 2009 Capgemini - All rights reserved
Java SE 7 – Language Changes

Number 1:
Before :

Sida 3
15 januari 2014
© 2009 Capgemini - All rights reserved

Try-with-resources Statement (or ARM-blocks)

static String readFirstLineFromFileWithFinallyBlock(String path)
throws IOException {
BufferedReader br = new BufferedReader(new FileReader(path));
try {
return br.readLine();
} finally {
if (br != null) {
try {
br.close();
} catch (IOException ignore){
//do nothing
}
}
}
}
Java SE 7 – Language Changes

Number 1:

Try-with-resources Statement (or ARM-blocks)

With Java 7:
static String readFirstLineFromFile(String path) throws IOException {
try (BufferedReader br = new BufferedReader(new FileReader(path))) {
return br.readLine();
}
}

Sida 4
15 januari 2014
© 2009 Capgemini - All rights reserved
Java SE 7 – Language Changes

Number 1 - NOTE:
The try-with-resources statement is a try statement that declares one or more resources. A
resource is as an object that must be closed after the program is finished with it.
The try-with-resources statement ensures that each resource is closed at the end of the
statement.
Any object that implements java.lang.AutoCloseable, which includes all objects which
implement java.io.Closeable, can be used as a resource.

Sida 5
15 januari 2014
© 2009 Capgemini - All rights reserved
Java SE 7 – Language Changes

Number 2:

Strings in switch Statements

public String getTypeOfDayWithSwitchStatement(String dayOfWeekArg) {
String typeOfDay;
switch (dayOfWeekArg) {
case "Monday":
typeOfDay = "Start of work week";
break;
case "Tuesday":
case "Wednesday":
case "Thursday":
typeOfDay = "Midweek";
break;
case "Friday":
typeOfDay = "End of work week";
break;
case "Saturday":
case "Sunday":
typeOfDay = "Weekend";
break;
default:
throw new IllegalArgumentException("Invalid day of the week: " + dayOfWeekArg);
}
return typeOfDay;
}
Sida 6
15 januari 2014
© 2009 Capgemini - All rights reserved
Java SE 7 – Language Changes

Number 2 - NOTE:
The Java compiler generates generally more efficient bytecode from switch statements that
use String objects than from chained if-then-else statements.

Sida 7
15 januari 2014
© 2009 Capgemini - All rights reserved
Java SE 7 – Language Changes

Number 3:
Before :

Catching Multiple Exception Types

try {
…
} catch (IOException ex) {
logger.log(ex);
throw ex;
} catch (SQLException ex) {
logger.log(ex);
throw ex;
}

Difficult to eliminate code duplication due to different exceptions!
Sida 8
15 januari 2014
© 2009 Capgemini - All rights reserved
Java SE 7 – Language Changes

Number 3:

Catching Multiple Exception Types

With Java 7 :
try {
…
} catch (IOException|SQLException ex) {
logger.log(ex);
throw ex;
}

Sida 9
15 januari 2014
© 2009 Capgemini - All rights reserved
Java SE 7 – Language Changes

Number 3 - NOTE: Catching Multiple Exception Types
Bytecode generated by compiling a catch block that handles multiple
exception types will be smaller (and thus superior) than
compiling many catch blocks that handle only one exception type
each.

Sida 10
15 januari 2014
© 2009 Capgemini - All rights reserved
Java SE 7 – Language Changes

Number 4:

Type Inference for Generic Instance Creation

Before:
Map<String, List<String>> myMap = new HashMap<String, List<String>>();

How many times have you sworn about this duplicated code? 

Sida 11
15 januari 2014
© 2009 Capgemini - All rights reserved
Java SE 7 – Language Changes

Number 4:

Type Inference for Generic Instance Creation

With Java 7:
Map<String, List<String>> myMap = new HashMap<>();

Sida 12
15 januari 2014
© 2009 Capgemini - All rights reserved
Java SE 7 – Language Changes

Number 4 - NOTE: Type Inference for Generic Instance Creation
Writing new HashMap() (without diamond operator) will still use the
raw type of HashMap (compiler warning)

Sida 13
15 januari 2014
© 2009 Capgemini - All rights reserved
Java SE 7 – Language Changes

Number 5:

Underscores in Numeric Literals

long creditCardNumber = 1234_5678_9012_3456L;
long socialSecurityNumber = 1977_05_18_3312L;
float pi = 3.14_15F;
long hexBytes = 0xFF_EC_DE_5E;
long hexWords = 0xCAFE_BABE;
long maxLong = 0x7fff_ffff_ffff_ffffL;
long bytes = 0b11010010_01101001_10010100_10010010;

Sida 14
15 januari 2014
© 2009 Capgemini - All rights reserved
Java SE 7 – Language Changes

Number 5 - NOTE: Underscores in Numeric Literals
You can place underscores only between digits; you cannot place
underscores in the following places:

At the beginning or end of a number
Adjacent to a decimal point in a floating point literal
Prior to an F or L suffix

In positions where a string of digits is expected

Sida 15
15 januari 2014
© 2009 Capgemini - All rights reserved
Java SE 7 – Concurrent Utilities

Number 6:

Fork/Join Framework (JSR 166)

” a lightweight fork/join framework with flexible and reusable
synchronization barriers, transfer queues, concurrent linked
double-ended queues, and thread-local pseudo-random-number
generators.”

Sida 16
15 januari 2014
© 2009 Capgemini - All rights reserved
Java SE 7 – Concurrent Utilities

Number 6:

Fork/Join Framework (JSR 166)

if (my portion of the work is small enough)
do the work directly
else
split my work into two pieces invoke the two pieces and
wait for the results

Sida 17
15 januari 2014
© 2009 Capgemini - All rights reserved
Java SE 7 – Concurrent Utilities

Number 6:

Sida 18
15 januari 2014
© 2009 Capgemini - All rights reserved

Fork/Join Framework (JSR 166)
Java SE 7 – Concurrent Utilities

Number 6:

Fork/Join Framework (JSR 166)

New Classes
•

ForkJoinTask

•

RecursiveTask

•

RecursiveAction

•

ThreadLocalRandom

•

ForkJoinPool

Sida 19
15 januari 2014
© 2009 Capgemini - All rights reserved
Java SE 7 – Filesystem API

Number 7:

NIO 2 Filesystem API (Non-Blocking I/O)

Better supports for accessing file systems such and support for
custom file systems (e.g. cloud file systems)

Access to metadata such as file permissions
More effecient support when copy/moving files
Enchanced Exceptions when working on files, i.e.
file.delete() now throws IOException (not just Exception)

Sida 20
15 januari 2014
© 2009 Capgemini - All rights reserved
Java SE 7 – JVM Enhancement

Number 8:

Invoke Dynamic (JSR292)

Support for dynamic languages so their performance levels is near to
that of the Java language itself

At byte code level this means a new operand (instruction) called
invokedynamic
Make is possible to do efficient method invocation for dynamic
languages (such as JRuby) instead of statically (like Java) .
Huge performance gain

Sida 21
15 januari 2014
© 2009 Capgemini - All rights reserved
Java SE 7 – JVM Enhancement

Number 9:

G1 and JVM optimization

G1 more predictable and uses multiple cores better than CMS
Tiered Compilation –Both client and server JIT compilers are
used during starup
NUMA optimization - Parallel Scavenger garbage collector has
been extended to take advantage of machines with NUMA (~35%
performance gain)
Escape Analysis - analyze the scope of a new object's and decide
whether to allocate it on the Java heap
Sida 22
15 januari 2014
© 2009 Capgemini - All rights reserved
Java SE 7 – JVM Enhancement

Number 9:

Escape Analysis

public class Person {
private String name; private int age;
public Person(String personName, int personAge) {
name = personName; age = personAge; }
public Person(Person p) {
this(p.getName(), p.getAge());
}
}
public class Employee {
private Person person; // makes a defensive copy to protect against modifications by caller
public Person getPerson() {
return new Person(person)
};
public void printEmployeeDetail(Employee emp) {
Person person = emp.getPerson(); // this caller does not modify the object, so defensive copy was unnecessary
System.out.println ("Employee's name: " + person.getName() + "; age: " + person.getAge()); }
}
Sida 23
15 januari 2014
© 2009 Capgemini - All rights reserved
Java SE 7 - Networking
Number 10: Support for SDP 
Socket Direct Protocol (SDP) enables JVMs to use Remote Direct
Memory Access (RDMA). RDMA enables moving data directly
from the memory of one computer to another computer,
bypassing the operating system of both computers and resulting
in significant performance gains.
The result is High throughput and Low latency (minimal delay
between processing input and providing output) such as you
would expect in a real-time application.

Sida 24
15 januari 2014
© 2009 Capgemini - All rights reserved
Java SE 7 - Networking

Number 10 - NOTE: Support for SDP
The Sockets Direct Protocol (SDP) is a networking protocol
developed to support stream connections over InfiniBand fabric.

Solaris 10 5/08 has support for InfiniBand fabric (which enables
RDMA). On Linux, the InfiniBand package is called OFED
(OpenFabrics Enterprise Distribution).

Sida 25
15 januari 2014
© 2009 Capgemini - All rights reserved
Java SE 7

A complete list of all new features can be seen on
http://www.oracle.com/technetwork/java/javase/jdk7-relnotes418459.html

Sida 26
15 januari 2014
© 2009 Capgemini - All rights reserved
Java SE 8
Some features where left out in Java 7; most important are Project
Lambda (closures) and Project Jigsaw (modules) targeted for
Java 8 (late 2012)
Lambdas (and extension methods) will probably be the biggest single
change ever made on the JVM. Will introduce a powerful
programming model, however it comes with a great deal of
complexity as well.
Modules will made it easier to version modules (no more JAR-hell)
and introduce a new way of defining classpaths
Sida 27
15 januari 2014
© 2009 Capgemini - All rights reserved
Java SE 7 & 8

Questions?

Sida 28
15 januari 2014
© 2009 Capgemini - All rights reserved

Weitere ähnliche Inhalte

Andere mochten auch

Systems Of The Body
Systems Of The BodySystems Of The Body
Systems Of The BodyToekneeH
 
Psm 280 A Best Practices In Advancing Customer Marketing Innovations
Psm 280 A Best Practices In Advancing Customer Marketing  InnovationsPsm 280 A Best Practices In Advancing Customer Marketing  Innovations
Psm 280 A Best Practices In Advancing Customer Marketing InnovationsCameron Tew
 
Casco insurance claims handling, If P&C insurance case study
Casco insurance claims handling, If P&C insurance case studyCasco insurance claims handling, If P&C insurance case study
Casco insurance claims handling, If P&C insurance case studyMihails Galuška
 
Debt Management, Collection on Ultimus BPM platform
Debt Management, Collection on Ultimus BPM platformDebt Management, Collection on Ultimus BPM platform
Debt Management, Collection on Ultimus BPM platformMihails Galuška
 
People Jam!
People Jam!People Jam!
People Jam!anshul2
 
Hippocrates 2.0
Hippocrates 2.0Hippocrates 2.0
Hippocrates 2.0Cristiano
 
Супермаркет услуг interinformer.com (для продавцов)
Супермаркет услуг interinformer.com (для продавцов)Супермаркет услуг interinformer.com (для продавцов)
Супермаркет услуг interinformer.com (для продавцов)Mihails Galuška
 
Hol webinar summary
Hol webinar summaryHol webinar summary
Hol webinar summaryCameron Tew
 
Elconceptodedisciplinaescolar.roberto l´hotelleríe
Elconceptodedisciplinaescolar.roberto l´hotelleríeElconceptodedisciplinaescolar.roberto l´hotelleríe
Elconceptodedisciplinaescolar.roberto l´hotelleríeRonald Heisele
 
CASCO insurance claims handling
CASCO insurance claims handlingCASCO insurance claims handling
CASCO insurance claims handlingMihails Galuška
 
Medical Science Liaison Webinarv 2009
Medical Science Liaison  Webinarv  2009Medical Science Liaison  Webinarv  2009
Medical Science Liaison Webinarv 2009Cameron Tew
 
Sales Force Short Version
Sales Force Short VersionSales Force Short Version
Sales Force Short VersionCameron Tew
 

Andere mochten auch (15)

Systems Of The Body
Systems Of The BodySystems Of The Body
Systems Of The Body
 
Psm 280 A Best Practices In Advancing Customer Marketing Innovations
Psm 280 A Best Practices In Advancing Customer Marketing  InnovationsPsm 280 A Best Practices In Advancing Customer Marketing  Innovations
Psm 280 A Best Practices In Advancing Customer Marketing Innovations
 
Casco insurance claims handling, If P&C insurance case study
Casco insurance claims handling, If P&C insurance case studyCasco insurance claims handling, If P&C insurance case study
Casco insurance claims handling, If P&C insurance case study
 
Debt Management, Collection on Ultimus BPM platform
Debt Management, Collection on Ultimus BPM platformDebt Management, Collection on Ultimus BPM platform
Debt Management, Collection on Ultimus BPM platform
 
People Jam!
People Jam!People Jam!
People Jam!
 
Hippocrates 2.0
Hippocrates 2.0Hippocrates 2.0
Hippocrates 2.0
 
Супермаркет услуг interinformer.com (для продавцов)
Супермаркет услуг interinformer.com (для продавцов)Супермаркет услуг interinformer.com (для продавцов)
Супермаркет услуг interinformer.com (для продавцов)
 
Hol webinar summary
Hol webinar summaryHol webinar summary
Hol webinar summary
 
Test
TestTest
Test
 
Concurrency gotchas
Concurrency gotchasConcurrency gotchas
Concurrency gotchas
 
Elconceptodedisciplinaescolar.roberto l´hotelleríe
Elconceptodedisciplinaescolar.roberto l´hotelleríeElconceptodedisciplinaescolar.roberto l´hotelleríe
Elconceptodedisciplinaescolar.roberto l´hotelleríe
 
Java basics
Java basicsJava basics
Java basics
 
CASCO insurance claims handling
CASCO insurance claims handlingCASCO insurance claims handling
CASCO insurance claims handling
 
Medical Science Liaison Webinarv 2009
Medical Science Liaison  Webinarv  2009Medical Science Liaison  Webinarv  2009
Medical Science Liaison Webinarv 2009
 
Sales Force Short Version
Sales Force Short VersionSales Force Short Version
Sales Force Short Version
 

Ähnlich wie Java7 Features

Java7 - Top 10 Features
Java7 - Top 10 FeaturesJava7 - Top 10 Features
Java7 - Top 10 FeaturesAndreas Enbohm
 
Java 9 features
Java 9 featuresJava 9 features
Java 9 featuresshrinath97
 
Introduction to node.js by Ran Mizrahi @ Reversim Summit
Introduction to node.js by Ran Mizrahi @ Reversim SummitIntroduction to node.js by Ran Mizrahi @ Reversim Summit
Introduction to node.js by Ran Mizrahi @ Reversim SummitRan Mizrahi
 
Node.js primer for ITE students
Node.js primer for ITE studentsNode.js primer for ITE students
Node.js primer for ITE studentsQuhan Arunasalam
 
Building Effective Apache Geode Applications with Spring Data GemFire
Building Effective Apache Geode Applications with Spring Data GemFireBuilding Effective Apache Geode Applications with Spring Data GemFire
Building Effective Apache Geode Applications with Spring Data GemFireJohn Blum
 
Dynamic Hadoop Clusters
Dynamic Hadoop ClustersDynamic Hadoop Clusters
Dynamic Hadoop ClustersSteve Loughran
 
JAVA introduction and basic understanding.pptx
JAVA  introduction and basic understanding.pptxJAVA  introduction and basic understanding.pptx
JAVA introduction and basic understanding.pptxprstsomnath22
 
JavaOne 2014: Java vs JavaScript
JavaOne 2014:   Java vs JavaScriptJavaOne 2014:   Java vs JavaScript
JavaOne 2014: Java vs JavaScriptChris Bailey
 
Better Code: Concurrency
Better Code: ConcurrencyBetter Code: Concurrency
Better Code: ConcurrencyPlatonov Sergey
 
Get ready for FRC 2015: Intro to Java 5 through 8 updates and Eclipse
Get ready for FRC 2015: Intro to Java 5 through 8 updates and EclipseGet ready for FRC 2015: Intro to Java 5 through 8 updates and Eclipse
Get ready for FRC 2015: Intro to Java 5 through 8 updates and EclipseJeanne Boyarsky
 
Programming in java ppt
Programming in java  pptProgramming in java  ppt
Programming in java pptMrsRLakshmiIT
 
Java History - MyExamCloud Presentation
Java History - MyExamCloud PresentationJava History - MyExamCloud Presentation
Java History - MyExamCloud PresentationGanesh P
 
Compile ahead of time. It's fine?
Compile ahead of time. It's fine?Compile ahead of time. It's fine?
Compile ahead of time. It's fine?Dmitry Chuyko
 
Defcon 22 - Stitching numbers - generating rop payloads from in memory numbers
Defcon 22 - Stitching numbers - generating rop payloads from in memory numbersDefcon 22 - Stitching numbers - generating rop payloads from in memory numbers
Defcon 22 - Stitching numbers - generating rop payloads from in memory numbersAlexandre Moneger
 
Java vs. Java Script for enterprise web applications - Chris Bailey
Java vs. Java Script for enterprise web applications - Chris BaileyJava vs. Java Script for enterprise web applications - Chris Bailey
Java vs. Java Script for enterprise web applications - Chris BaileyJAXLondon_Conference
 
Application Architecture For The Cloud
Application Architecture For The CloudApplication Architecture For The Cloud
Application Architecture For The CloudSteve Loughran
 
Java and OpenJDK: disecting the ecosystem
Java and OpenJDK: disecting the ecosystemJava and OpenJDK: disecting the ecosystem
Java and OpenJDK: disecting the ecosystemRafael Winterhalter
 

Ähnlich wie Java7 Features (20)

Java7 - Top 10 Features
Java7 - Top 10 FeaturesJava7 - Top 10 Features
Java7 - Top 10 Features
 
Java 9 features
Java 9 featuresJava 9 features
Java 9 features
 
Introduction to node.js by Ran Mizrahi @ Reversim Summit
Introduction to node.js by Ran Mizrahi @ Reversim SummitIntroduction to node.js by Ran Mizrahi @ Reversim Summit
Introduction to node.js by Ran Mizrahi @ Reversim Summit
 
Node.js primer for ITE students
Node.js primer for ITE studentsNode.js primer for ITE students
Node.js primer for ITE students
 
Building Effective Apache Geode Applications with Spring Data GemFire
Building Effective Apache Geode Applications with Spring Data GemFireBuilding Effective Apache Geode Applications with Spring Data GemFire
Building Effective Apache Geode Applications with Spring Data GemFire
 
Dynamic Hadoop Clusters
Dynamic Hadoop ClustersDynamic Hadoop Clusters
Dynamic Hadoop Clusters
 
JAVA introduction and basic understanding.pptx
JAVA  introduction and basic understanding.pptxJAVA  introduction and basic understanding.pptx
JAVA introduction and basic understanding.pptx
 
JavaOne 2014: Java vs JavaScript
JavaOne 2014:   Java vs JavaScriptJavaOne 2014:   Java vs JavaScript
JavaOne 2014: Java vs JavaScript
 
Better Code: Concurrency
Better Code: ConcurrencyBetter Code: Concurrency
Better Code: Concurrency
 
Get ready for FRC 2015: Intro to Java 5 through 8 updates and Eclipse
Get ready for FRC 2015: Intro to Java 5 through 8 updates and EclipseGet ready for FRC 2015: Intro to Java 5 through 8 updates and Eclipse
Get ready for FRC 2015: Intro to Java 5 through 8 updates and Eclipse
 
NodeJS
NodeJSNodeJS
NodeJS
 
Java7
Java7Java7
Java7
 
Programming in java ppt
Programming in java  pptProgramming in java  ppt
Programming in java ppt
 
Programming in java ppt
Programming in java  pptProgramming in java  ppt
Programming in java ppt
 
Java History - MyExamCloud Presentation
Java History - MyExamCloud PresentationJava History - MyExamCloud Presentation
Java History - MyExamCloud Presentation
 
Compile ahead of time. It's fine?
Compile ahead of time. It's fine?Compile ahead of time. It's fine?
Compile ahead of time. It's fine?
 
Defcon 22 - Stitching numbers - generating rop payloads from in memory numbers
Defcon 22 - Stitching numbers - generating rop payloads from in memory numbersDefcon 22 - Stitching numbers - generating rop payloads from in memory numbers
Defcon 22 - Stitching numbers - generating rop payloads from in memory numbers
 
Java vs. Java Script for enterprise web applications - Chris Bailey
Java vs. Java Script for enterprise web applications - Chris BaileyJava vs. Java Script for enterprise web applications - Chris Bailey
Java vs. Java Script for enterprise web applications - Chris Bailey
 
Application Architecture For The Cloud
Application Architecture For The CloudApplication Architecture For The Cloud
Application Architecture For The Cloud
 
Java and OpenJDK: disecting the ecosystem
Java and OpenJDK: disecting the ecosystemJava and OpenJDK: disecting the ecosystem
Java and OpenJDK: disecting the ecosystem
 

Kürzlich hochgeladen

Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 

Kürzlich hochgeladen (20)

Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 

Java7 Features

  • 1. Java SE 7 {finally} 2011-08-18 Andreas Enbohm © 2004 Capgemini - All rights reserved
  • 2. Java SE 7 A evolutionary evolement of Java 6 years since last update Some things left out, will briefly discuss this at the end Oracle really pushing Java forward - a lot political problems with Sun made Java 7 postphoned several times Java still growing (1.42%), #1 most used language according to TIOBE with 19.4% (Aug 2011) My top 10 new features (not ordered in any way ) Sida 2 15 januari 2014 © 2009 Capgemini - All rights reserved
  • 3. Java SE 7 – Language Changes Number 1: Before : Sida 3 15 januari 2014 © 2009 Capgemini - All rights reserved Try-with-resources Statement (or ARM-blocks) static String readFirstLineFromFileWithFinallyBlock(String path) throws IOException { BufferedReader br = new BufferedReader(new FileReader(path)); try { return br.readLine(); } finally { if (br != null) { try { br.close(); } catch (IOException ignore){ //do nothing } } } }
  • 4. Java SE 7 – Language Changes Number 1: Try-with-resources Statement (or ARM-blocks) With Java 7: static String readFirstLineFromFile(String path) throws IOException { try (BufferedReader br = new BufferedReader(new FileReader(path))) { return br.readLine(); } } Sida 4 15 januari 2014 © 2009 Capgemini - All rights reserved
  • 5. Java SE 7 – Language Changes Number 1 - NOTE: The try-with-resources statement is a try statement that declares one or more resources. A resource is as an object that must be closed after the program is finished with it. The try-with-resources statement ensures that each resource is closed at the end of the statement. Any object that implements java.lang.AutoCloseable, which includes all objects which implement java.io.Closeable, can be used as a resource. Sida 5 15 januari 2014 © 2009 Capgemini - All rights reserved
  • 6. Java SE 7 – Language Changes Number 2: Strings in switch Statements public String getTypeOfDayWithSwitchStatement(String dayOfWeekArg) { String typeOfDay; switch (dayOfWeekArg) { case "Monday": typeOfDay = "Start of work week"; break; case "Tuesday": case "Wednesday": case "Thursday": typeOfDay = "Midweek"; break; case "Friday": typeOfDay = "End of work week"; break; case "Saturday": case "Sunday": typeOfDay = "Weekend"; break; default: throw new IllegalArgumentException("Invalid day of the week: " + dayOfWeekArg); } return typeOfDay; } Sida 6 15 januari 2014 © 2009 Capgemini - All rights reserved
  • 7. Java SE 7 – Language Changes Number 2 - NOTE: The Java compiler generates generally more efficient bytecode from switch statements that use String objects than from chained if-then-else statements. Sida 7 15 januari 2014 © 2009 Capgemini - All rights reserved
  • 8. Java SE 7 – Language Changes Number 3: Before : Catching Multiple Exception Types try { … } catch (IOException ex) { logger.log(ex); throw ex; } catch (SQLException ex) { logger.log(ex); throw ex; } Difficult to eliminate code duplication due to different exceptions! Sida 8 15 januari 2014 © 2009 Capgemini - All rights reserved
  • 9. Java SE 7 – Language Changes Number 3: Catching Multiple Exception Types With Java 7 : try { … } catch (IOException|SQLException ex) { logger.log(ex); throw ex; } Sida 9 15 januari 2014 © 2009 Capgemini - All rights reserved
  • 10. Java SE 7 – Language Changes Number 3 - NOTE: Catching Multiple Exception Types Bytecode generated by compiling a catch block that handles multiple exception types will be smaller (and thus superior) than compiling many catch blocks that handle only one exception type each. Sida 10 15 januari 2014 © 2009 Capgemini - All rights reserved
  • 11. Java SE 7 – Language Changes Number 4: Type Inference for Generic Instance Creation Before: Map<String, List<String>> myMap = new HashMap<String, List<String>>(); How many times have you sworn about this duplicated code?  Sida 11 15 januari 2014 © 2009 Capgemini - All rights reserved
  • 12. Java SE 7 – Language Changes Number 4: Type Inference for Generic Instance Creation With Java 7: Map<String, List<String>> myMap = new HashMap<>(); Sida 12 15 januari 2014 © 2009 Capgemini - All rights reserved
  • 13. Java SE 7 – Language Changes Number 4 - NOTE: Type Inference for Generic Instance Creation Writing new HashMap() (without diamond operator) will still use the raw type of HashMap (compiler warning) Sida 13 15 januari 2014 © 2009 Capgemini - All rights reserved
  • 14. Java SE 7 – Language Changes Number 5: Underscores in Numeric Literals long creditCardNumber = 1234_5678_9012_3456L; long socialSecurityNumber = 1977_05_18_3312L; float pi = 3.14_15F; long hexBytes = 0xFF_EC_DE_5E; long hexWords = 0xCAFE_BABE; long maxLong = 0x7fff_ffff_ffff_ffffL; long bytes = 0b11010010_01101001_10010100_10010010; Sida 14 15 januari 2014 © 2009 Capgemini - All rights reserved
  • 15. Java SE 7 – Language Changes Number 5 - NOTE: Underscores in Numeric Literals You can place underscores only between digits; you cannot place underscores in the following places: At the beginning or end of a number Adjacent to a decimal point in a floating point literal Prior to an F or L suffix In positions where a string of digits is expected Sida 15 15 januari 2014 © 2009 Capgemini - All rights reserved
  • 16. Java SE 7 – Concurrent Utilities Number 6: Fork/Join Framework (JSR 166) ” a lightweight fork/join framework with flexible and reusable synchronization barriers, transfer queues, concurrent linked double-ended queues, and thread-local pseudo-random-number generators.” Sida 16 15 januari 2014 © 2009 Capgemini - All rights reserved
  • 17. Java SE 7 – Concurrent Utilities Number 6: Fork/Join Framework (JSR 166) if (my portion of the work is small enough) do the work directly else split my work into two pieces invoke the two pieces and wait for the results Sida 17 15 januari 2014 © 2009 Capgemini - All rights reserved
  • 18. Java SE 7 – Concurrent Utilities Number 6: Sida 18 15 januari 2014 © 2009 Capgemini - All rights reserved Fork/Join Framework (JSR 166)
  • 19. Java SE 7 – Concurrent Utilities Number 6: Fork/Join Framework (JSR 166) New Classes • ForkJoinTask • RecursiveTask • RecursiveAction • ThreadLocalRandom • ForkJoinPool Sida 19 15 januari 2014 © 2009 Capgemini - All rights reserved
  • 20. Java SE 7 – Filesystem API Number 7: NIO 2 Filesystem API (Non-Blocking I/O) Better supports for accessing file systems such and support for custom file systems (e.g. cloud file systems) Access to metadata such as file permissions More effecient support when copy/moving files Enchanced Exceptions when working on files, i.e. file.delete() now throws IOException (not just Exception) Sida 20 15 januari 2014 © 2009 Capgemini - All rights reserved
  • 21. Java SE 7 – JVM Enhancement Number 8: Invoke Dynamic (JSR292) Support for dynamic languages so their performance levels is near to that of the Java language itself At byte code level this means a new operand (instruction) called invokedynamic Make is possible to do efficient method invocation for dynamic languages (such as JRuby) instead of statically (like Java) . Huge performance gain Sida 21 15 januari 2014 © 2009 Capgemini - All rights reserved
  • 22. Java SE 7 – JVM Enhancement Number 9: G1 and JVM optimization G1 more predictable and uses multiple cores better than CMS Tiered Compilation –Both client and server JIT compilers are used during starup NUMA optimization - Parallel Scavenger garbage collector has been extended to take advantage of machines with NUMA (~35% performance gain) Escape Analysis - analyze the scope of a new object's and decide whether to allocate it on the Java heap Sida 22 15 januari 2014 © 2009 Capgemini - All rights reserved
  • 23. Java SE 7 – JVM Enhancement Number 9: Escape Analysis public class Person { private String name; private int age; public Person(String personName, int personAge) { name = personName; age = personAge; } public Person(Person p) { this(p.getName(), p.getAge()); } } public class Employee { private Person person; // makes a defensive copy to protect against modifications by caller public Person getPerson() { return new Person(person) }; public void printEmployeeDetail(Employee emp) { Person person = emp.getPerson(); // this caller does not modify the object, so defensive copy was unnecessary System.out.println ("Employee's name: " + person.getName() + "; age: " + person.getAge()); } } Sida 23 15 januari 2014 © 2009 Capgemini - All rights reserved
  • 24. Java SE 7 - Networking Number 10: Support for SDP  Socket Direct Protocol (SDP) enables JVMs to use Remote Direct Memory Access (RDMA). RDMA enables moving data directly from the memory of one computer to another computer, bypassing the operating system of both computers and resulting in significant performance gains. The result is High throughput and Low latency (minimal delay between processing input and providing output) such as you would expect in a real-time application. Sida 24 15 januari 2014 © 2009 Capgemini - All rights reserved
  • 25. Java SE 7 - Networking Number 10 - NOTE: Support for SDP The Sockets Direct Protocol (SDP) is a networking protocol developed to support stream connections over InfiniBand fabric. Solaris 10 5/08 has support for InfiniBand fabric (which enables RDMA). On Linux, the InfiniBand package is called OFED (OpenFabrics Enterprise Distribution). Sida 25 15 januari 2014 © 2009 Capgemini - All rights reserved
  • 26. Java SE 7 A complete list of all new features can be seen on http://www.oracle.com/technetwork/java/javase/jdk7-relnotes418459.html Sida 26 15 januari 2014 © 2009 Capgemini - All rights reserved
  • 27. Java SE 8 Some features where left out in Java 7; most important are Project Lambda (closures) and Project Jigsaw (modules) targeted for Java 8 (late 2012) Lambdas (and extension methods) will probably be the biggest single change ever made on the JVM. Will introduce a powerful programming model, however it comes with a great deal of complexity as well. Modules will made it easier to version modules (no more JAR-hell) and introduce a new way of defining classpaths Sida 27 15 januari 2014 © 2009 Capgemini - All rights reserved
  • 28. Java SE 7 & 8 Questions? Sida 28 15 januari 2014 © 2009 Capgemini - All rights reserved