SlideShare uma empresa Scribd logo
1 de 19
Baixar para ler offline
SE 7 : What's New!

          Ayushman Jain
         JDT/Core committer
                      IBM




           © IBM 2011. Licensed under EPL v1.0
New features at a glance

●   Project Coin – small enhancement and new language
      features.
●   Support for dynamic languages.
●   Unicode 6.0 – new rupee symbol, brahmi script,
     emoticons.
●   New I/O and concurrent APIs.




                                       © IBM 2011. Licensed under EPL v1.0
Project coin features
●   Binary literals and underscores in literals.
• Strings in switch.
• @SafeVarargs - Varargs warnings.
• Diamond - improved type inference for generic instance
creation.
• Multi-catch and more precise rethrow.
• try-with-resources (formerly known as Automatic
Resource Management or ARM).


                                           © IBM 2011. Licensed under EPL v1.0
Strings in switch
●   When do you use a switch statement?
●   Valid case labels upto javaSE 6 can be
       –   Int constants
       –   Enum constants
●   String can also be constants!




                                    © IBM 2011. Licensed under EPL v1.0
Safe Varargs

●   Variable arity method - public static <T> List<T>
      java.util.Arrays.asList(T... a)
●   If T is the parameter type with variable arity and is also
       non-reifiable, a new warning on declaration of variable
       arity methods with parameter of type T.
●   A new annotation @SafeVarargs to suppress the
      warning at both declaration site and call site.




                                         © IBM 2011. Licensed under EPL v1.0
Reifiable types
●   A type whose type information is fully available at
      runtime, that is, a type that does not lose information
      in the course of type erasure.
●   Any type with type parameters is available to the JVM as
      the raw type because of type erasure.
●   So List<Number> and List<String> are both seen as List
      by the JVM.
●   Hence parameterized types are non-reifiable.
●   On the other hand, types such as “String” are reifiable.


                                         © IBM 2011. Licensed under EPL v1.0
Safe Varargs
●   A variable arity parameter of a generic type can cause
      heap pollution.
●   public static <T> List<T> java.util.Arrays.asList(T... a)
●   Heap pollution - A situation where a variable of a
     parameterized type refers to an object that is not of
     that parameterized type.
●   Usually, the method body is well behaved and only
      iterates over the elements.
●   Hence, unchecked warning is mostly a distraction.


                                          © IBM 2011. Licensed under EPL v1.0
@SafeVarargs

●   Annotation legal on static or final variable arity methods
      or constructors.
●   Not legal on
        –   Fixed arity methods or constructors.
        –   Variable arity methods or constructors that are
             neither final nor static.
●   Some java APIs already retrofitted with the annotation in
      JDK 7.


                                          © IBM 2011. Licensed under EPL v1.0
Binary Integer Literals and
    Underscores in numeric literals
●   Binary integer literals structured just like hex interger
      literals. Differences:
        –   Binary digits used instead of hex digits
        –   0b now used instead of 0x
●   In numeric literals, underscores now permitted as separators
       between digits.
●   Applies to literals in any base: binary, octal, hexadecimal, or
      decimal
●   Applies to both integer literals and floating point literals

                                               © IBM 2011. Licensed under EPL v1.0
Multi-catch and more precise
               rethrow

●   Different catch blocks performing the same action on the
      caught exception.
●   They can now be combined into one single catch block
      using Disjunctive types.
●   Disjunctive type = ExceptionA | ExceptionB | ....
●   Disjunctive types implicitly final.
●   Also, now only the actually thrown exception is now
      rethrown and not its parent type.

                                          © IBM 2011. Licensed under EPL v1.0
Try With Resources
●   Language & Library changes to
        –   Ease management of objects that require explicit
             freeing/disposal/destruction.
        –   Prevent resource leaks (handles, streams ...)
        –   A la Destructors in C++ (and others)
●   Library changes:
        –   A new interface java.lang.AutoCloseable.
        –   Libraries retrofitted to implement the new interface
        –   Facilities to manage suppressed exceptions on
             java.lang.Throwable
                                           © IBM 2011. Licensed under EPL v1.0
What is a Resource
●   Basically a final variable local to the try block.
●   Must be of type AutoCloseable.
●   Must be initialized in the resource section.
●   Language guarantees that every successfully
     initialized non-null resource will be “closed”.
●   Will be closed regardless of normal or abrupt
     completion.
●   In LIFC order: Last initialized first closed.
                                    © IBM 2011. Licensed under EPL v1.0
Suppressed exceptions

●   “Primary” exception will be the exception seen by a user
      supplied catch block.
●   Exception from close methods are added to the
      suppressed list of primary exception (unless it is the
      primary exception.)
●   An interested party can query and process suppressed
      exceptions. New APIs in class Throwable:
        –   public final void addSuppressed(Throwable);
        –   public final Throwable [] getSuppressed();

                                          © IBM 2011. Licensed under EPL v1.0
Diamond
●   Improved type inference for generic instance
      creation.
●   Before,
●   List<String> list = new ArrayList<String>();
●   Now,
●   List<String> list = new ArrayList<>();
●   Why not List<String> list = new ArrayList() ?


                                  © IBM 2011. Licensed under EPL v1.0
Support for dynamic languages
●   A growing interest in running programs written in
      dynamic languages on JVM.
●   Particularly scripting languages-JRuby,Jpython,Groovy.
●   Motivation – make implementation in such languages
     efficient and fast.
●   Current Problem - JVM instruction to invoke a method takes
      method descriptor as the argument
        –   Method descriptor is the method name, argument
             types and the return type.
●   Solution – new invokeDynamic instruction and dynamic
      linking through method handles.
                                          © IBM 2011. Licensed under EPL v1.0
JVM bytecode instructions
●   invokevirtual - Invokes a method on a class. This is the
      typical type of method invocation.
●   invokeinterface - Invokes a method on an interface.
●   invokestatic - Invokes a static method on a class. This is
      the only kind of invocation that lacks a receiver
      argument.
●   invokespecial - Invokes a method without reference to
      the type of the receiver.
●   invokedynamic - enables an implementer of a dynamic
      language to translate a method invocation into
      bytecode without having to specify a target type that
      contains the method.              © IBM 2011. Licensed under EPL v1.0
Method handles
●   Consider hypothetical dynamic language code
    function max (x,y) {
          if x.lessThan(y) then y else x }
●   To compile this for JVM
    MyObject function max (MyObject x,MyObject y) {
          if x.lessThan(y) then y else x }
●   Or use reflection.
●   With Java7, use method handles!


                                             © IBM 2011. Licensed under EPL v1.0
Use Eclipse for java 7

●   No builds available as of today.
●   Setup Eclipse to work for java 7 as described
     in http://wiki.eclipse.org/JDT_Core/Java7




                                  © IBM 2011. Licensed under EPL v1.0
Thank You!




             © IBM 2011. Licensed under EPL v1.0

Mais conteúdo relacionado

Mais procurados

Workin ontherailsroad
Workin ontherailsroadWorkin ontherailsroad
Workin ontherailsroad
Jim Jones
 
WorkinOnTheRailsRoad
WorkinOnTheRailsRoadWorkinOnTheRailsRoad
WorkinOnTheRailsRoad
webuploader
 

Mais procurados (20)

Functional Programming In Jdk8
Functional Programming In Jdk8 Functional Programming In Jdk8
Functional Programming In Jdk8
 
Functional programming with Java 8
Functional programming with Java 8Functional programming with Java 8
Functional programming with Java 8
 
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 02)
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 02) iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 02)
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 02)
 
New c sharp4_features_part_v
New c sharp4_features_part_vNew c sharp4_features_part_v
New c sharp4_features_part_v
 
Python's dynamic nature (rough slides, November 2004)
Python's dynamic nature (rough slides, November 2004)Python's dynamic nature (rough slides, November 2004)
Python's dynamic nature (rough slides, November 2004)
 
Posedge vhdl training_4
Posedge vhdl training_4Posedge vhdl training_4
Posedge vhdl training_4
 
Learning typescript
Learning typescriptLearning typescript
Learning typescript
 
Enriching EMF Models with Scala (quick overview)
Enriching EMF Models with Scala (quick overview)Enriching EMF Models with Scala (quick overview)
Enriching EMF Models with Scala (quick overview)
 
New c sharp4_features_part_iv
New c sharp4_features_part_ivNew c sharp4_features_part_iv
New c sharp4_features_part_iv
 
C-Sharp 6.0 ver2
C-Sharp 6.0 ver2C-Sharp 6.0 ver2
C-Sharp 6.0 ver2
 
Core Java Tutorial
Core Java TutorialCore Java Tutorial
Core Java Tutorial
 
php app development 1
php app development 1php app development 1
php app development 1
 
Introduction to Clojure
Introduction to ClojureIntroduction to Clojure
Introduction to Clojure
 
Grooming with Groovy
Grooming with GroovyGrooming with Groovy
Grooming with Groovy
 
Core java
Core javaCore java
Core java
 
C++ to java
C++ to javaC++ to java
C++ to java
 
Moose Meta-Modeling Infrastructure
Moose Meta-Modeling InfrastructureMoose Meta-Modeling Infrastructure
Moose Meta-Modeling Infrastructure
 
Basic Java Programming
Basic Java ProgrammingBasic Java Programming
Basic Java Programming
 
Workin ontherailsroad
Workin ontherailsroadWorkin ontherailsroad
Workin ontherailsroad
 
WorkinOnTheRailsRoad
WorkinOnTheRailsRoadWorkinOnTheRailsRoad
WorkinOnTheRailsRoad
 

Destaque

Skb 3 menteri tentang hari libur nasional dan cuti bers
Skb 3 menteri tentang hari libur nasional dan cuti bersSkb 3 menteri tentang hari libur nasional dan cuti bers
Skb 3 menteri tentang hari libur nasional dan cuti bers
saslirais
 
Permenakertrans no 20 tahun 2012
Permenakertrans no 20 tahun 2012Permenakertrans no 20 tahun 2012
Permenakertrans no 20 tahun 2012
saslirais
 
Parental Involvement Mod 3
Parental Involvement Mod 3Parental Involvement Mod 3
Parental Involvement Mod 3
tim stapley
 
I am legend
I am legendI am legend
I am legend
trisha81
 
Pergub no 189_ump dki 2013
Pergub no 189_ump dki 2013Pergub no 189_ump dki 2013
Pergub no 189_ump dki 2013
saslirais
 
How to Make Your Jewelry Shop POP! 7 Steps to Extraordinary Retail Success
How to Make Your Jewelry Shop POP!  7 Steps to Extraordinary Retail SuccessHow to Make Your Jewelry Shop POP!  7 Steps to Extraordinary Retail Success
How to Make Your Jewelry Shop POP! 7 Steps to Extraordinary Retail Success
Pamela Danziger
 
Umk 2011 jabar
Umk 2011   jabarUmk 2011   jabar
Umk 2011 jabar
saslirais
 

Destaque (17)

Skb 3 menteri tentang hari libur nasional dan cuti bers
Skb 3 menteri tentang hari libur nasional dan cuti bersSkb 3 menteri tentang hari libur nasional dan cuti bers
Skb 3 menteri tentang hari libur nasional dan cuti bers
 
Permenakertrans no 20 tahun 2012
Permenakertrans no 20 tahun 2012Permenakertrans no 20 tahun 2012
Permenakertrans no 20 tahun 2012
 
Whats new in Java 7
Whats new in Java 7Whats new in Java 7
Whats new in Java 7
 
Parental Involvement Mod 3
Parental Involvement Mod 3Parental Involvement Mod 3
Parental Involvement Mod 3
 
Millionaires: Do They Still Live Next Door, or Have They Moved?
Millionaires:  Do They Still Live Next Door, or Have They Moved?Millionaires:  Do They Still Live Next Door, or Have They Moved?
Millionaires: Do They Still Live Next Door, or Have They Moved?
 
I am legend
I am legendI am legend
I am legend
 
Pergub no 189_ump dki 2013
Pergub no 189_ump dki 2013Pergub no 189_ump dki 2013
Pergub no 189_ump dki 2013
 
DroidCon 2011: Developing HTML5 and hybrid Android apps using Phonegap
DroidCon 2011: Developing HTML5 and hybrid Android apps using PhonegapDroidCon 2011: Developing HTML5 and hybrid Android apps using Phonegap
DroidCon 2011: Developing HTML5 and hybrid Android apps using Phonegap
 
How to Make Your Jewelry Shop POP! 7 Steps to Extraordinary Retail Success
How to Make Your Jewelry Shop POP!  7 Steps to Extraordinary Retail SuccessHow to Make Your Jewelry Shop POP!  7 Steps to Extraordinary Retail Success
How to Make Your Jewelry Shop POP! 7 Steps to Extraordinary Retail Success
 
Luxury: The Business of Happiness
Luxury:  The Business of HappinessLuxury:  The Business of Happiness
Luxury: The Business of Happiness
 
The 40 Year Reunion
The 40 Year ReunionThe 40 Year Reunion
The 40 Year Reunion
 
Beauty in new luxury style final
Beauty in new luxury style finalBeauty in new luxury style final
Beauty in new luxury style final
 
Collaborative and agile development of mobile applications
Collaborative and agile development of mobile applicationsCollaborative and agile development of mobile applications
Collaborative and agile development of mobile applications
 
1965 1970 form photos
1965 1970 form photos1965 1970 form photos
1965 1970 form photos
 
How to train the jdt dragon
How to train the jdt dragonHow to train the jdt dragon
How to train the jdt dragon
 
Parental involvement
Parental involvementParental involvement
Parental involvement
 
Umk 2011 jabar
Umk 2011   jabarUmk 2011   jabar
Umk 2011 jabar
 

Semelhante a Whats new in Java 7

Unit 1 Core Java for Compter Science 3rd
Unit 1 Core Java for Compter Science 3rdUnit 1 Core Java for Compter Science 3rd
Unit 1 Core Java for Compter Science 3rd
prat0ham
 

Semelhante a Whats new in Java 7 (20)

Working with XSLT, XPath and ECMA Scripts: Make It Simpler with Novell Identi...
Working with XSLT, XPath and ECMA Scripts: Make It Simpler with Novell Identi...Working with XSLT, XPath and ECMA Scripts: Make It Simpler with Novell Identi...
Working with XSLT, XPath and ECMA Scripts: Make It Simpler with Novell Identi...
 
Learn To Code: Introduction to java
Learn To Code: Introduction to javaLearn To Code: Introduction to java
Learn To Code: Introduction to java
 
Java platform
Java platformJava platform
Java platform
 
Unit 1 Core Java for Compter Science 3rd
Unit 1 Core Java for Compter Science 3rdUnit 1 Core Java for Compter Science 3rd
Unit 1 Core Java for Compter Science 3rd
 
Graal VM: Multi-Language Execution Platform
Graal VM: Multi-Language Execution PlatformGraal VM: Multi-Language Execution Platform
Graal VM: Multi-Language Execution Platform
 
Class_01.pptx
Class_01.pptxClass_01.pptx
Class_01.pptx
 
java notes.pdf
java notes.pdfjava notes.pdf
java notes.pdf
 
Web sphere administration
Web sphere administrationWeb sphere administration
Web sphere administration
 
Comp102 lec 3
Comp102   lec 3Comp102   lec 3
Comp102 lec 3
 
What is Java Technology (An introduction with comparision of .net coding)
What is Java Technology (An introduction with comparision of .net coding)What is Java Technology (An introduction with comparision of .net coding)
What is Java Technology (An introduction with comparision of .net coding)
 
01 Variables
01 Variables01 Variables
01 Variables
 
OOPC_Unit-I.pdf
OOPC_Unit-I.pdfOOPC_Unit-I.pdf
OOPC_Unit-I.pdf
 
Introduction to Erlang Programming Language
Introduction to Erlang Programming LanguageIntroduction to Erlang Programming Language
Introduction to Erlang Programming Language
 
Java
JavaJava
Java
 
Java notes | All Basics |
Java notes | All Basics |Java notes | All Basics |
Java notes | All Basics |
 
Java_Roadmap.pptx
Java_Roadmap.pptxJava_Roadmap.pptx
Java_Roadmap.pptx
 
Compilation v. interpretation
Compilation v. interpretationCompilation v. interpretation
Compilation v. interpretation
 
New c sharp4_features_part_vi
New c sharp4_features_part_viNew c sharp4_features_part_vi
New c sharp4_features_part_vi
 
Core java
Core javaCore java
Core java
 
Owner - Java properties reinvented.
Owner - Java properties reinvented.Owner - Java properties reinvented.
Owner - Java properties reinvented.
 

Último

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Último (20)

Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 

Whats new in Java 7

  • 1. SE 7 : What's New! Ayushman Jain JDT/Core committer IBM © IBM 2011. Licensed under EPL v1.0
  • 2. New features at a glance ● Project Coin – small enhancement and new language features. ● Support for dynamic languages. ● Unicode 6.0 – new rupee symbol, brahmi script, emoticons. ● New I/O and concurrent APIs. © IBM 2011. Licensed under EPL v1.0
  • 3. Project coin features ● Binary literals and underscores in literals. • Strings in switch. • @SafeVarargs - Varargs warnings. • Diamond - improved type inference for generic instance creation. • Multi-catch and more precise rethrow. • try-with-resources (formerly known as Automatic Resource Management or ARM). © IBM 2011. Licensed under EPL v1.0
  • 4. Strings in switch ● When do you use a switch statement? ● Valid case labels upto javaSE 6 can be – Int constants – Enum constants ● String can also be constants! © IBM 2011. Licensed under EPL v1.0
  • 5. Safe Varargs ● Variable arity method - public static <T> List<T> java.util.Arrays.asList(T... a) ● If T is the parameter type with variable arity and is also non-reifiable, a new warning on declaration of variable arity methods with parameter of type T. ● A new annotation @SafeVarargs to suppress the warning at both declaration site and call site. © IBM 2011. Licensed under EPL v1.0
  • 6. Reifiable types ● A type whose type information is fully available at runtime, that is, a type that does not lose information in the course of type erasure. ● Any type with type parameters is available to the JVM as the raw type because of type erasure. ● So List<Number> and List<String> are both seen as List by the JVM. ● Hence parameterized types are non-reifiable. ● On the other hand, types such as “String” are reifiable. © IBM 2011. Licensed under EPL v1.0
  • 7. Safe Varargs ● A variable arity parameter of a generic type can cause heap pollution. ● public static <T> List<T> java.util.Arrays.asList(T... a) ● Heap pollution - A situation where a variable of a parameterized type refers to an object that is not of that parameterized type. ● Usually, the method body is well behaved and only iterates over the elements. ● Hence, unchecked warning is mostly a distraction. © IBM 2011. Licensed under EPL v1.0
  • 8. @SafeVarargs ● Annotation legal on static or final variable arity methods or constructors. ● Not legal on – Fixed arity methods or constructors. – Variable arity methods or constructors that are neither final nor static. ● Some java APIs already retrofitted with the annotation in JDK 7. © IBM 2011. Licensed under EPL v1.0
  • 9. Binary Integer Literals and Underscores in numeric literals ● Binary integer literals structured just like hex interger literals. Differences: – Binary digits used instead of hex digits – 0b now used instead of 0x ● In numeric literals, underscores now permitted as separators between digits. ● Applies to literals in any base: binary, octal, hexadecimal, or decimal ● Applies to both integer literals and floating point literals © IBM 2011. Licensed under EPL v1.0
  • 10. Multi-catch and more precise rethrow ● Different catch blocks performing the same action on the caught exception. ● They can now be combined into one single catch block using Disjunctive types. ● Disjunctive type = ExceptionA | ExceptionB | .... ● Disjunctive types implicitly final. ● Also, now only the actually thrown exception is now rethrown and not its parent type. © IBM 2011. Licensed under EPL v1.0
  • 11. Try With Resources ● Language & Library changes to – Ease management of objects that require explicit freeing/disposal/destruction. – Prevent resource leaks (handles, streams ...) – A la Destructors in C++ (and others) ● Library changes: – A new interface java.lang.AutoCloseable. – Libraries retrofitted to implement the new interface – Facilities to manage suppressed exceptions on java.lang.Throwable © IBM 2011. Licensed under EPL v1.0
  • 12. What is a Resource ● Basically a final variable local to the try block. ● Must be of type AutoCloseable. ● Must be initialized in the resource section. ● Language guarantees that every successfully initialized non-null resource will be “closed”. ● Will be closed regardless of normal or abrupt completion. ● In LIFC order: Last initialized first closed. © IBM 2011. Licensed under EPL v1.0
  • 13. Suppressed exceptions ● “Primary” exception will be the exception seen by a user supplied catch block. ● Exception from close methods are added to the suppressed list of primary exception (unless it is the primary exception.) ● An interested party can query and process suppressed exceptions. New APIs in class Throwable: – public final void addSuppressed(Throwable); – public final Throwable [] getSuppressed(); © IBM 2011. Licensed under EPL v1.0
  • 14. Diamond ● Improved type inference for generic instance creation. ● Before, ● List<String> list = new ArrayList<String>(); ● Now, ● List<String> list = new ArrayList<>(); ● Why not List<String> list = new ArrayList() ? © IBM 2011. Licensed under EPL v1.0
  • 15. Support for dynamic languages ● A growing interest in running programs written in dynamic languages on JVM. ● Particularly scripting languages-JRuby,Jpython,Groovy. ● Motivation – make implementation in such languages efficient and fast. ● Current Problem - JVM instruction to invoke a method takes method descriptor as the argument – Method descriptor is the method name, argument types and the return type. ● Solution – new invokeDynamic instruction and dynamic linking through method handles. © IBM 2011. Licensed under EPL v1.0
  • 16. JVM bytecode instructions ● invokevirtual - Invokes a method on a class. This is the typical type of method invocation. ● invokeinterface - Invokes a method on an interface. ● invokestatic - Invokes a static method on a class. This is the only kind of invocation that lacks a receiver argument. ● invokespecial - Invokes a method without reference to the type of the receiver. ● invokedynamic - enables an implementer of a dynamic language to translate a method invocation into bytecode without having to specify a target type that contains the method. © IBM 2011. Licensed under EPL v1.0
  • 17. Method handles ● Consider hypothetical dynamic language code function max (x,y) { if x.lessThan(y) then y else x } ● To compile this for JVM MyObject function max (MyObject x,MyObject y) { if x.lessThan(y) then y else x } ● Or use reflection. ● With Java7, use method handles! © IBM 2011. Licensed under EPL v1.0
  • 18. Use Eclipse for java 7 ● No builds available as of today. ● Setup Eclipse to work for java 7 as described in http://wiki.eclipse.org/JDT_Core/Java7 © IBM 2011. Licensed under EPL v1.0
  • 19. Thank You! © IBM 2011. Licensed under EPL v1.0