SlideShare a Scribd company logo
What’s New in Java 7?




                 copyright 2011 Trainologic LTD
What’s new in Java 7?



              New Features in Java 7

• Dynamic Languages Support.
• Project Coin.
• Fork/Join Library.
• NIO2.

• Most important features (e.g., lambda functions,
  modularization) are deferred to Java 8.




                             4
                                                copyright 2011 Trainologic LTD
What’s new in Java 7?



            New Bytecode Instruction

• Java 7 introduces a change in the JVM bytecode
  instructions.
• This has not been done in many releases.
• The new bytecode instruction available in Java 7 is:
  invokedynamic.




                             4
                                                 copyright 2011 Trainologic LTD
What’s new in Java 7?



          Dynamic Languages Support

• Java 6 introduced the Scripting API for scripting support
  for dynamic languages.
• Although you can create now applications that will run
  scripts in many languages (e.g., Jython, Groovy,
  JavaScript) compilation of dynamic languages is a
  problem.
• Now, why is that?




                             4
                                                 copyright 2011 Trainologic LTD
What’s new in Java 7?



          Dynamic Languages Support

• The current bytecode instructions only provide method
  invocations that are strongly types (i.e., types of
  arguments must be know in advance).
• That makes a burden on compilers for dynamic
  languages and often results in performance degradation
  and poor generated code.
• The new mechanism allows for dynamically generated
  methods to be added and invoked.




                              4
                                                  copyright 2011 Trainologic LTD
What’s new in Java 7?



                        Project Coin

• Project Coin introduces changes to the syntax of the
  Java language.
• Note that these are not major changes as were done in
  Java 5.


• Let’s see what it is about…




                                4
                                                copyright 2011 Trainologic LTD
What’s new in Java 7?



                        Project Coin

• Project Coin includes:
   • Support for strings in switch statements.
   • Binary numeric literals.
   • Improved type inference.
   • Multi-catch.
   • Precise rethrow.
   • ARM (Automatic Resource Management).




                             4
                                                 copyright 2011 Trainologic LTD
What’s new in Java 7?



                  Switch on Strings

• The current JVM does not allow switch on non integer
  types.
• I.e., only int, short, byte, char and Enum are allowed.
• The new version will also support Strings.

• Now, this was done without altering the bytecode.
• I.e., by using compilation techniques.

• Let’s see an example…



                             4
                                                 copyright 2011 Trainologic LTD
What’s new in Java 7?



                              Example

• Switch on strings:
      switch (str) {
      case "a":
               System.out.println("is a");
               break;
      case "bcd":
               System.out.println("string is bcd");
               break;
      default:
               System.out.println("couldn't match");
      }




                                     21
                                                       copyright 2011 Trainologic LTD
What’s new in Java 7?



                          Binary Literals

• Currently Java supports only decimal, octal and
  hexadecimal numeric literals.
• Java 7 supports also binary literals:



      int a = 0b0101;
      int b = 0b1010;
      System.out.println(a+b);




                                 21
                                                copyright 2011 Trainologic LTD
What’s new in Java 7?



               Improved Type Inference

• While the Java compiler will not provide extensive type
  inference (as in Scala), a minor inference improvement
  is introduced in Java 7:




      List<String> strings = new ArrayList<>();




                                     21
                                                  copyright 2011 Trainologic LTD
What’s new in Java 7?



                        Multi-Catch

• One of the annoying things about exception handling in
  Java is the need to duplicate exception handling code
  for different exception types.
• This is addressed in Java 7 as mulit-catch.

• Let’s see it in action:




                             21
                                                copyright 2011 Trainologic LTD
What’s new in Java 7?



                              Example

      private static void f() throws SQLException {

      }
      private static void g() throws IOException {

      }

      private static void multicatch() {
         try {
               f();
               g();
         } catch (SQLException | IOException e) {
               System.out.println("got either exception");

          }

      }




                                     21
                                                             copyright 2011 Trainologic LTD
What’s new in Java 7?



                         Precise Rethrow

• Currently the following code will not compile:

     public void foo() throws IOException, SQLException {
            try {
                 // do something that may throw IOException or
                 // SQLException
            } catch (Exception e) {
                 // do something
                 throw(e);
            }
      }




                                       29
                                                                 copyright 2011 Trainologic LTD
What’s new in Java 7?



                          Safe Re-throw

• The syntax to allow this is with the final keyword:

     public void foo() throws IOException, SQLException {
            try {
                 // do something that may throw IOException or
                 // SQLException
            } catch (final Exception e) {
                 // do something
                 throw(e);
            }
      }




                                       30
                                                                 copyright 2011 Trainologic LTD
What’s new in Java 7?



                            ARM

• Automatic Resource Management will allow you to
  specify a resource (AutoClosable type) to use with the
  try-catch block.
• When you exist the try-catch block the close() method
  will be invoked automatically.


• Let’s see it in action…




                             21
                                                copyright 2011 Trainologic LTD
What’s new in Java 7?



                     Try with Resources

     static class MyClass implements AutoCloseable {
        @Override
        public void close() throws Exception {
              System.out.println("Close was called");

         }
     }

     private static void trywith() {
        MyClass resource1 = new MyClass();
        MyClass resource2 = new MyClass();
        try (resource1; resource2) {
              System.out.println("in try");
        } catch (Exception e) {
              System.out.println("in catch");
        }

     }




                                      29
                                                        copyright 2011 Trainologic LTD
What’s new in Java 7?



                  Concurrency Utils

• Doug Lea, the founder of the excellent
  java.util.concurrent introduces (through JSR 166) the
  following new features:
    • Fork/Join framework.
    • TransferQueue.
    • ThreadLocalRandom.
    • Phasers.




                             18
                                                copyright 2011 Trainologic LTD
What’s new in Java 7?



                        Fork/Join

• The basic idea of the Fork/Join framework is that many
  tasks can be split to several concurrent threads, and the
  result should be merged back.


• Let’s take a look at an example…




                             19
                                                 copyright 2011 Trainologic LTD
What’s new in Java 7?



                                 Fork/Join

• Instead of doing it single-threaded, the idea of fork/join
  is to split the operation to several (depends on the # of
  cores) concurrent threads.

      public class Fibonacci extends RecursiveTask<Integer> {
       private final int n;

          public Fibonacci(int n) { this.n = n;}
          protected Integer compute() {
                   if (n <= 1)
                      return n;
                   Fibonacci f1 = new Fibonacci(n - 1);
                   f1.fork();
                   Fibonacci f2 = new Fibonacci(n - 2);
                   return f2.compute() + f1.join();
            }
      }


                                         20
                                                                copyright 2011 Trainologic LTD
What’s new in Java 7?



                               Example

• The Main class:

      public class Main {
       public static void main(String[] args) {
                 ForkJoinPool pool = new ForkJoinPool(3);
                 Fibonacci fibonacci = new Fibonacci(20);
                 pool.execute(fibonacci);
                 System.out.println(fibonacci.join());

          }
      }




                                      21
                                                            copyright 2011 Trainologic LTD
What’s new in Java 7?



                        TransferQueue

• A BlockingQueue on which the producers await for a
  consumer to take their elements.
• Usage scenarios are typically message passing
  applications.




                             22
                                                  copyright 2011 Trainologic LTD
What’s new in Java 7?



                         Phasers

• “Beam me up, Scotty!”
• A Phaser is quite similar to CyclicBarrier and
  CountDownLatch but is more powerful and flexible.
• A Phaser has an associated phase-number which is of
  type int.
• A Phaser has a number of unarrived parties. Unlike
  CyclicBarrier and CountDownLatch, this number is
  dynamic.




                             23
                                                   copyright 2011 Trainologic LTD
What’s new in Java 7?



                        Phasers

• A Phaser supports operations for
  arriving, awaiting, termination, deregistration and
  registration.
• When all the parties arrive, the Phaser advances
  (increments its phase-number).
• Phasers also supports ForkJoinTasks!




                             24
                                                 copyright 2011 Trainologic LTD
What’s new in Java 7?



                        NIO.2

• JSR 203 adds new APIs to the NIO package.
• Main features:
   • Filesystem API.
   • Asynchronous Channels.




                          25
                                              copyright 2011 Trainologic LTD
What’s new in Java 7?



                        Filesystem API

• At the heart of the new filesystem API stands the Path
  class.
• An instance of Path can be thought of as an improved
  version of a File instance.
• Also, File now provides a method for legacy code
  named: toPath().


• Let’s explore this class…




                                26
                                                copyright 2009 Trainologic LTD
What’s new in Java 7?



                           Path

• Path is an abstract representation of an hierarchical
  path from the filesystem provider.
• For regular filesystems, a Path is interoperable with File.
• For other providers (e.g., ZipFileSystemProvider) there
  is no analogy.
• A Path instance also supports symbolic links and
  provides the method: readSymbolicLink().




                             26
                                                  copyright 2009 Trainologic LTD
What’s new in Java 7?



                        Path Methods

• Interesting methods:
   • getRoot().
   • isAbsolute().
   • startsWith(), endsWith().
   • normalize() – removes ‘..’ and ‘.’.
   • copyTo() , moveTo().
   • newByteChannel(), newOutputStream().

• And of-course, ‘watch’ methods.


                             26
                                            copyright 2009 Trainologic LTD
What’s new in Java 7?



                        Watchable

• Path implements the Watchable interface.
• This allows for registering watchers that are interested
  in events on the Path.
• Example for events:
   • OVERFLOW, ENTRY_CREATE, ENTRY_DELETE, ENTRY
      _MODIFY.


• Let’s see an example for logging which files are deleted
  on a given directory…




                             26
                                                 copyright 2009 Trainologic LTD
What’s new in Java 7?



                              Example



      FileSystem fs = FileSystems.getDefault();
      WatchService ws = fs.newWatchService();

      Path path = fs.getPath("c:todeletewatch");
      path.register(ws, StandardWatchEventKind.ENTRY_DELETE);
      while(true) {
               WatchKey e = ws.take();
               List<WatchEvent<?>> events = e.pollEvents();
               for (WatchEvent<?> watchEvent : events) {
                        Path ctx = (Path) watchEvent.context();
                        System.out.println("deleted: " + path);
               }
      }




                                     21
                                                                  copyright 2011 Trainologic LTD
What’s new in Java 7?



                        Not Included

• The following (promised) features were not included in
  Java 7:
• Lambda and Closures.
• Refied Generics.
• Modularization.
• Annotations on Java types.
• Collections literals.




                             38
                                               copyright 2011 Trainologic LTD
What’s new in Java 7?



                          Java 8?

• So, what is intended for Java 8?
• Well, JSR 337 (Java 8) promises the following:
   • Annotations on types.
   • Lambdas.
   • Parallel collections and support for lambdas in
      collections.
    • Date & time APIs.
    • Module system.



                             38
                                                 copyright 2011 Trainologic LTD
What’s new in Java 7?



             Proposed Lambda Syntax

• Following is the current state of JSR 335 (Lambda
  expressions for Java):

                                          Lambda for Runnable


  executor.submit( #{ System.out.println("Blah") } );


  Collections.sort(people, #{ Person x, Person y ->
       x.getLastName().compareTo(y.getLastName()
  ) });




                            38
                                                 copyright 2011 Trainologic LTD

More Related Content

What's hot

Java SE 8 best practices
Java SE 8 best practicesJava SE 8 best practices
Java SE 8 best practices
Stephen Colebourne
 
Support formation vidéo : OCA Java SE 8 Programmer (1Z0-808) (2)
Support formation vidéo : OCA Java SE 8 Programmer (1Z0-808) (2)Support formation vidéo : OCA Java SE 8 Programmer (1Z0-808) (2)
Support formation vidéo : OCA Java SE 8 Programmer (1Z0-808) (2)
SmartnSkilled
 
55 New Features in Java SE 8
55 New Features in Java SE 855 New Features in Java SE 8
55 New Features in Java SE 8
Simon Ritter
 
모던자바의 역습
모던자바의 역습모던자바의 역습
모던자바의 역습
DoHyun Jung
 
Java 9, JShell, and Modularity
Java 9, JShell, and ModularityJava 9, JShell, and Modularity
Java 9, JShell, and Modularity
Mohammad Hossein Rimaz
 
ScalaMatsuri 2016 ドワンゴアカウントシステムを支えるScala技術
ScalaMatsuri 2016 ドワンゴアカウントシステムを支えるScala技術ScalaMatsuri 2016 ドワンゴアカウントシステムを支えるScala技術
ScalaMatsuri 2016 ドワンゴアカウントシステムを支えるScala技術
Seitaro Yuuki
 
Automatic Migration of Legacy Java Method Implementations to Interfaces
Automatic Migration of Legacy Java Method Implementations to InterfacesAutomatic Migration of Legacy Java Method Implementations to Interfaces
Automatic Migration of Legacy Java Method Implementations to Interfaces
Raffi Khatchadourian
 
The Java memory model made easy
The Java memory model made easyThe Java memory model made easy
The Java memory model made easy
Rafael Winterhalter
 
Ahead-Of-Time Compilation of Java Applications
Ahead-Of-Time Compilation of Java ApplicationsAhead-Of-Time Compilation of Java Applications
Ahead-Of-Time Compilation of Java Applications
Nikita Lipsky
 
Java Course 7: Text processing, Charsets & Encodings
Java Course 7: Text processing, Charsets & EncodingsJava Course 7: Text processing, Charsets & Encodings
Java Course 7: Text processing, Charsets & Encodings
Anton Keks
 
Java tutorials
Java tutorialsJava tutorials
Java tutorialssaryu2011
 
Modern Java Workshop
Modern Java WorkshopModern Java Workshop
Modern Java Workshop
Simon Ritter
 
Java Course 4: Exceptions & Collections
Java Course 4: Exceptions & CollectionsJava Course 4: Exceptions & Collections
Java Course 4: Exceptions & Collections
Anton Keks
 
Java - OOPS and Java Basics
Java - OOPS and Java BasicsJava - OOPS and Java Basics
Java - OOPS and Java Basics
Victer Paul
 
Java Course 3: OOP
Java Course 3: OOPJava Course 3: OOP
Java Course 3: OOP
Anton Keks
 
Core java
Core javaCore java
Core java
kasaragaddaslide
 
Introduction to new features in java 8
Introduction to new features in java 8Introduction to new features in java 8
Java Tutorial
Java TutorialJava Tutorial
Java Tutorial
Singsys Pte Ltd
 
Benefits of OSGi in Practise
Benefits of OSGi in PractiseBenefits of OSGi in Practise
Benefits of OSGi in Practise
David Bosschaert
 

What's hot (20)

Java SE 8 best practices
Java SE 8 best practicesJava SE 8 best practices
Java SE 8 best practices
 
Support formation vidéo : OCA Java SE 8 Programmer (1Z0-808) (2)
Support formation vidéo : OCA Java SE 8 Programmer (1Z0-808) (2)Support formation vidéo : OCA Java SE 8 Programmer (1Z0-808) (2)
Support formation vidéo : OCA Java SE 8 Programmer (1Z0-808) (2)
 
55 New Features in Java SE 8
55 New Features in Java SE 855 New Features in Java SE 8
55 New Features in Java SE 8
 
모던자바의 역습
모던자바의 역습모던자바의 역습
모던자바의 역습
 
Java 9, JShell, and Modularity
Java 9, JShell, and ModularityJava 9, JShell, and Modularity
Java 9, JShell, and Modularity
 
ScalaMatsuri 2016 ドワンゴアカウントシステムを支えるScala技術
ScalaMatsuri 2016 ドワンゴアカウントシステムを支えるScala技術ScalaMatsuri 2016 ドワンゴアカウントシステムを支えるScala技術
ScalaMatsuri 2016 ドワンゴアカウントシステムを支えるScala技術
 
Automatic Migration of Legacy Java Method Implementations to Interfaces
Automatic Migration of Legacy Java Method Implementations to InterfacesAutomatic Migration of Legacy Java Method Implementations to Interfaces
Automatic Migration of Legacy Java Method Implementations to Interfaces
 
The Java memory model made easy
The Java memory model made easyThe Java memory model made easy
The Java memory model made easy
 
Ahead-Of-Time Compilation of Java Applications
Ahead-Of-Time Compilation of Java ApplicationsAhead-Of-Time Compilation of Java Applications
Ahead-Of-Time Compilation of Java Applications
 
Java Course 7: Text processing, Charsets & Encodings
Java Course 7: Text processing, Charsets & EncodingsJava Course 7: Text processing, Charsets & Encodings
Java Course 7: Text processing, Charsets & Encodings
 
Java tutorials
Java tutorialsJava tutorials
Java tutorials
 
Modern Java Workshop
Modern Java WorkshopModern Java Workshop
Modern Java Workshop
 
Java Course 4: Exceptions & Collections
Java Course 4: Exceptions & CollectionsJava Course 4: Exceptions & Collections
Java Course 4: Exceptions & Collections
 
Java - OOPS and Java Basics
Java - OOPS and Java BasicsJava - OOPS and Java Basics
Java - OOPS and Java Basics
 
Java Course 3: OOP
Java Course 3: OOPJava Course 3: OOP
Java Course 3: OOP
 
Core java
Core javaCore java
Core java
 
Introduction to new features in java 8
Introduction to new features in java 8Introduction to new features in java 8
Introduction to new features in java 8
 
Java Tutorial
Java TutorialJava Tutorial
Java Tutorial
 
2 P Seminar
2 P Seminar2 P Seminar
2 P Seminar
 
Benefits of OSGi in Practise
Benefits of OSGi in PractiseBenefits of OSGi in Practise
Benefits of OSGi in Practise
 

Viewers also liked

Data information and information system
Data information and information systemData information and information system
Data information and information systemnripeshkumarnrip
 
IEA - Queimadas na Amazônia e seus efeitos no ecossistema e na saúde da popul...
IEA - Queimadas na Amazônia e seus efeitos no ecossistema e na saúde da popul...IEA - Queimadas na Amazônia e seus efeitos no ecossistema e na saúde da popul...
IEA - Queimadas na Amazônia e seus efeitos no ecossistema e na saúde da popul...
Instituto de Estudos Avançados - USP
 
The good parts in scalaz
The good parts in scalazThe good parts in scalaz
The good parts in scalaz
Kobib9
 
черонобыльская аэс
черонобыльская аэсчеронобыльская аэс
черонобыльская аэсWINDOSILL
 
IEA - Produção de etanol celulósico empregando enzimas fúngicas
IEA - Produção de etanol celulósico empregando enzimas fúngicasIEA - Produção de etanol celulósico empregando enzimas fúngicas
IEA - Produção de etanol celulósico empregando enzimas fúngicas
Instituto de Estudos Avançados - USP
 
Risk assesment
Risk assesmentRisk assesment
Risk assesmentviva07071
 
IT kontraktsstrategi - Dataforeningens IT-kontraktsdag 2013
IT kontraktsstrategi - Dataforeningens IT-kontraktsdag 2013IT kontraktsstrategi - Dataforeningens IT-kontraktsdag 2013
IT kontraktsstrategi - Dataforeningens IT-kontraktsdag 2013
Thor Jusnes
 
IEA - I Workshop em pressão intracraniana - Parte 6
IEA - I Workshop em pressão intracraniana - Parte 6IEA - I Workshop em pressão intracraniana - Parte 6
IEA - I Workshop em pressão intracraniana - Parte 6
Instituto de Estudos Avançados - USP
 

Viewers also liked (9)

Data information and information system
Data information and information systemData information and information system
Data information and information system
 
IEA - Queimadas na Amazônia e seus efeitos no ecossistema e na saúde da popul...
IEA - Queimadas na Amazônia e seus efeitos no ecossistema e na saúde da popul...IEA - Queimadas na Amazônia e seus efeitos no ecossistema e na saúde da popul...
IEA - Queimadas na Amazônia e seus efeitos no ecossistema e na saúde da popul...
 
The good parts in scalaz
The good parts in scalazThe good parts in scalaz
The good parts in scalaz
 
черонобыльская аэс
черонобыльская аэсчеронобыльская аэс
черонобыльская аэс
 
IEA - Produção de etanol celulósico empregando enzimas fúngicas
IEA - Produção de etanol celulósico empregando enzimas fúngicasIEA - Produção de etanol celulósico empregando enzimas fúngicas
IEA - Produção de etanol celulósico empregando enzimas fúngicas
 
Risk assesment
Risk assesmentRisk assesment
Risk assesment
 
IT kontraktsstrategi - Dataforeningens IT-kontraktsdag 2013
IT kontraktsstrategi - Dataforeningens IT-kontraktsdag 2013IT kontraktsstrategi - Dataforeningens IT-kontraktsdag 2013
IT kontraktsstrategi - Dataforeningens IT-kontraktsdag 2013
 
IEA - I Workshop em pressão intracraniana - Parte 6
IEA - I Workshop em pressão intracraniana - Parte 6IEA - I Workshop em pressão intracraniana - Parte 6
IEA - I Workshop em pressão intracraniana - Parte 6
 
Pitch
PitchPitch
Pitch
 

Similar to Java 7 - What's New?

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
Mattias Karlsson
 
Java7
Java7Java7
Java 7 & 8
Java 7 & 8Java 7 & 8
Java 7 & 8
Ken Coenen
 
New Features Of JDK 7
New Features Of JDK 7New Features Of JDK 7
New Features Of JDK 7
Deniz Oguz
 
What to expect from Java 9
What to expect from Java 9What to expect from Java 9
What to expect from Java 9
Ivan Krylov
 
Introduction of Java 8 with emphasis on Lambda Expressions and Streams
Introduction of Java 8 with emphasis on Lambda Expressions and StreamsIntroduction of Java 8 with emphasis on Lambda Expressions and Streams
Introduction of Java 8 with emphasis on Lambda Expressions and Streams
Emiel Paasschens
 
Features java9
Features java9Features java9
Features java9
srmohan06
 
Groovy DSLs (JavaOne Presentation)
Groovy DSLs (JavaOne Presentation)Groovy DSLs (JavaOne Presentation)
Groovy DSLs (JavaOne Presentation)Jim Driscoll
 
Java 9 features
Java 9 featuresJava 9 features
Java 9 features
shrinath97
 
Back to the future with Java 7 (Geekout June/2011)
Back to the future with Java 7 (Geekout June/2011)Back to the future with Java 7 (Geekout June/2011)
Back to the future with Java 7 (Geekout June/2011)
Martijn Verburg
 
Java 7 & 8 New Features
Java 7 & 8 New FeaturesJava 7 & 8 New Features
Java 7 & 8 New Features
Leandro Coutinho
 
Inside IBM Java 7
Inside IBM Java 7Inside IBM Java 7
Inside IBM Java 7
Tim Ellison
 
Java7 - Top 10 Features
Java7 - Top 10 FeaturesJava7 - Top 10 Features
Java7 - Top 10 Features
Andreas Enbohm
 
What’s expected in Java 9
What’s expected in Java 9What’s expected in Java 9
What’s expected in Java 9
Gal Marder
 
Java/Servlet/JSP/JDBC
Java/Servlet/JSP/JDBCJava/Servlet/JSP/JDBC
Java/Servlet/JSP/JDBC
FAKHRUN NISHA
 
Rapid Network Application Development with Apache MINA
Rapid Network Application Development with Apache MINARapid Network Application Development with Apache MINA
Rapid Network Application Development with Apache MINA
trustinlee
 
Java solution
Java solutionJava solution
Java solution
1Arun_Pandey
 
From Java 6 to Java 7 reference
From Java 6 to Java 7 referenceFrom Java 6 to Java 7 reference
From Java 6 to Java 7 reference
Giacomo Veneri
 
Java Course 15: Ant, Scripting, Spring, Hibernate
Java Course 15: Ant, Scripting, Spring, HibernateJava Course 15: Ant, Scripting, Spring, Hibernate
Java Course 15: Ant, Scripting, Spring, Hibernate
Anton Keks
 

Similar to Java 7 - What's New? (20)

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
 
Java7
Java7Java7
Java7
 
Java 7 & 8
Java 7 & 8Java 7 & 8
Java 7 & 8
 
New Features Of JDK 7
New Features Of JDK 7New Features Of JDK 7
New Features Of JDK 7
 
55j7
55j755j7
55j7
 
What to expect from Java 9
What to expect from Java 9What to expect from Java 9
What to expect from Java 9
 
Introduction of Java 8 with emphasis on Lambda Expressions and Streams
Introduction of Java 8 with emphasis on Lambda Expressions and StreamsIntroduction of Java 8 with emphasis on Lambda Expressions and Streams
Introduction of Java 8 with emphasis on Lambda Expressions and Streams
 
Features java9
Features java9Features java9
Features java9
 
Groovy DSLs (JavaOne Presentation)
Groovy DSLs (JavaOne Presentation)Groovy DSLs (JavaOne Presentation)
Groovy DSLs (JavaOne Presentation)
 
Java 9 features
Java 9 featuresJava 9 features
Java 9 features
 
Back to the future with Java 7 (Geekout June/2011)
Back to the future with Java 7 (Geekout June/2011)Back to the future with Java 7 (Geekout June/2011)
Back to the future with Java 7 (Geekout June/2011)
 
Java 7 & 8 New Features
Java 7 & 8 New FeaturesJava 7 & 8 New Features
Java 7 & 8 New Features
 
Inside IBM Java 7
Inside IBM Java 7Inside IBM Java 7
Inside IBM Java 7
 
Java7 - Top 10 Features
Java7 - Top 10 FeaturesJava7 - Top 10 Features
Java7 - Top 10 Features
 
What’s expected in Java 9
What’s expected in Java 9What’s expected in Java 9
What’s expected in Java 9
 
Java/Servlet/JSP/JDBC
Java/Servlet/JSP/JDBCJava/Servlet/JSP/JDBC
Java/Servlet/JSP/JDBC
 
Rapid Network Application Development with Apache MINA
Rapid Network Application Development with Apache MINARapid Network Application Development with Apache MINA
Rapid Network Application Development with Apache MINA
 
Java solution
Java solutionJava solution
Java solution
 
From Java 6 to Java 7 reference
From Java 6 to Java 7 referenceFrom Java 6 to Java 7 reference
From Java 6 to Java 7 reference
 
Java Course 15: Ant, Scripting, Spring, Hibernate
Java Course 15: Ant, Scripting, Spring, HibernateJava Course 15: Ant, Scripting, Spring, Hibernate
Java Course 15: Ant, Scripting, Spring, Hibernate
 

Recently uploaded

Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
RinaMondal9
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
James Anderson
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 

Recently uploaded (20)

Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 

Java 7 - What's New?

  • 1. What’s New in Java 7? copyright 2011 Trainologic LTD
  • 2. What’s new in Java 7? New Features in Java 7 • Dynamic Languages Support. • Project Coin. • Fork/Join Library. • NIO2. • Most important features (e.g., lambda functions, modularization) are deferred to Java 8. 4 copyright 2011 Trainologic LTD
  • 3. What’s new in Java 7? New Bytecode Instruction • Java 7 introduces a change in the JVM bytecode instructions. • This has not been done in many releases. • The new bytecode instruction available in Java 7 is: invokedynamic. 4 copyright 2011 Trainologic LTD
  • 4. What’s new in Java 7? Dynamic Languages Support • Java 6 introduced the Scripting API for scripting support for dynamic languages. • Although you can create now applications that will run scripts in many languages (e.g., Jython, Groovy, JavaScript) compilation of dynamic languages is a problem. • Now, why is that? 4 copyright 2011 Trainologic LTD
  • 5. What’s new in Java 7? Dynamic Languages Support • The current bytecode instructions only provide method invocations that are strongly types (i.e., types of arguments must be know in advance). • That makes a burden on compilers for dynamic languages and often results in performance degradation and poor generated code. • The new mechanism allows for dynamically generated methods to be added and invoked. 4 copyright 2011 Trainologic LTD
  • 6. What’s new in Java 7? Project Coin • Project Coin introduces changes to the syntax of the Java language. • Note that these are not major changes as were done in Java 5. • Let’s see what it is about… 4 copyright 2011 Trainologic LTD
  • 7. What’s new in Java 7? Project Coin • Project Coin includes: • Support for strings in switch statements. • Binary numeric literals. • Improved type inference. • Multi-catch. • Precise rethrow. • ARM (Automatic Resource Management). 4 copyright 2011 Trainologic LTD
  • 8. What’s new in Java 7? Switch on Strings • The current JVM does not allow switch on non integer types. • I.e., only int, short, byte, char and Enum are allowed. • The new version will also support Strings. • Now, this was done without altering the bytecode. • I.e., by using compilation techniques. • Let’s see an example… 4 copyright 2011 Trainologic LTD
  • 9. What’s new in Java 7? Example • Switch on strings: switch (str) { case "a": System.out.println("is a"); break; case "bcd": System.out.println("string is bcd"); break; default: System.out.println("couldn't match"); } 21 copyright 2011 Trainologic LTD
  • 10. What’s new in Java 7? Binary Literals • Currently Java supports only decimal, octal and hexadecimal numeric literals. • Java 7 supports also binary literals: int a = 0b0101; int b = 0b1010; System.out.println(a+b); 21 copyright 2011 Trainologic LTD
  • 11. What’s new in Java 7? Improved Type Inference • While the Java compiler will not provide extensive type inference (as in Scala), a minor inference improvement is introduced in Java 7: List<String> strings = new ArrayList<>(); 21 copyright 2011 Trainologic LTD
  • 12. What’s new in Java 7? Multi-Catch • One of the annoying things about exception handling in Java is the need to duplicate exception handling code for different exception types. • This is addressed in Java 7 as mulit-catch. • Let’s see it in action: 21 copyright 2011 Trainologic LTD
  • 13. What’s new in Java 7? Example private static void f() throws SQLException { } private static void g() throws IOException { } private static void multicatch() { try { f(); g(); } catch (SQLException | IOException e) { System.out.println("got either exception"); } } 21 copyright 2011 Trainologic LTD
  • 14. What’s new in Java 7? Precise Rethrow • Currently the following code will not compile: public void foo() throws IOException, SQLException { try { // do something that may throw IOException or // SQLException } catch (Exception e) { // do something throw(e); } } 29 copyright 2011 Trainologic LTD
  • 15. What’s new in Java 7? Safe Re-throw • The syntax to allow this is with the final keyword: public void foo() throws IOException, SQLException { try { // do something that may throw IOException or // SQLException } catch (final Exception e) { // do something throw(e); } } 30 copyright 2011 Trainologic LTD
  • 16. What’s new in Java 7? ARM • Automatic Resource Management will allow you to specify a resource (AutoClosable type) to use with the try-catch block. • When you exist the try-catch block the close() method will be invoked automatically. • Let’s see it in action… 21 copyright 2011 Trainologic LTD
  • 17. What’s new in Java 7? Try with Resources static class MyClass implements AutoCloseable { @Override public void close() throws Exception { System.out.println("Close was called"); } } private static void trywith() { MyClass resource1 = new MyClass(); MyClass resource2 = new MyClass(); try (resource1; resource2) { System.out.println("in try"); } catch (Exception e) { System.out.println("in catch"); } } 29 copyright 2011 Trainologic LTD
  • 18. What’s new in Java 7? Concurrency Utils • Doug Lea, the founder of the excellent java.util.concurrent introduces (through JSR 166) the following new features: • Fork/Join framework. • TransferQueue. • ThreadLocalRandom. • Phasers. 18 copyright 2011 Trainologic LTD
  • 19. What’s new in Java 7? Fork/Join • The basic idea of the Fork/Join framework is that many tasks can be split to several concurrent threads, and the result should be merged back. • Let’s take a look at an example… 19 copyright 2011 Trainologic LTD
  • 20. What’s new in Java 7? Fork/Join • Instead of doing it single-threaded, the idea of fork/join is to split the operation to several (depends on the # of cores) concurrent threads. public class Fibonacci extends RecursiveTask<Integer> { private final int n; public Fibonacci(int n) { this.n = n;} protected Integer compute() { if (n <= 1) return n; Fibonacci f1 = new Fibonacci(n - 1); f1.fork(); Fibonacci f2 = new Fibonacci(n - 2); return f2.compute() + f1.join(); } } 20 copyright 2011 Trainologic LTD
  • 21. What’s new in Java 7? Example • The Main class: public class Main { public static void main(String[] args) { ForkJoinPool pool = new ForkJoinPool(3); Fibonacci fibonacci = new Fibonacci(20); pool.execute(fibonacci); System.out.println(fibonacci.join()); } } 21 copyright 2011 Trainologic LTD
  • 22. What’s new in Java 7? TransferQueue • A BlockingQueue on which the producers await for a consumer to take their elements. • Usage scenarios are typically message passing applications. 22 copyright 2011 Trainologic LTD
  • 23. What’s new in Java 7? Phasers • “Beam me up, Scotty!” • A Phaser is quite similar to CyclicBarrier and CountDownLatch but is more powerful and flexible. • A Phaser has an associated phase-number which is of type int. • A Phaser has a number of unarrived parties. Unlike CyclicBarrier and CountDownLatch, this number is dynamic. 23 copyright 2011 Trainologic LTD
  • 24. What’s new in Java 7? Phasers • A Phaser supports operations for arriving, awaiting, termination, deregistration and registration. • When all the parties arrive, the Phaser advances (increments its phase-number). • Phasers also supports ForkJoinTasks! 24 copyright 2011 Trainologic LTD
  • 25. What’s new in Java 7? NIO.2 • JSR 203 adds new APIs to the NIO package. • Main features: • Filesystem API. • Asynchronous Channels. 25 copyright 2011 Trainologic LTD
  • 26. What’s new in Java 7? Filesystem API • At the heart of the new filesystem API stands the Path class. • An instance of Path can be thought of as an improved version of a File instance. • Also, File now provides a method for legacy code named: toPath(). • Let’s explore this class… 26 copyright 2009 Trainologic LTD
  • 27. What’s new in Java 7? Path • Path is an abstract representation of an hierarchical path from the filesystem provider. • For regular filesystems, a Path is interoperable with File. • For other providers (e.g., ZipFileSystemProvider) there is no analogy. • A Path instance also supports symbolic links and provides the method: readSymbolicLink(). 26 copyright 2009 Trainologic LTD
  • 28. What’s new in Java 7? Path Methods • Interesting methods: • getRoot(). • isAbsolute(). • startsWith(), endsWith(). • normalize() – removes ‘..’ and ‘.’. • copyTo() , moveTo(). • newByteChannel(), newOutputStream(). • And of-course, ‘watch’ methods. 26 copyright 2009 Trainologic LTD
  • 29. What’s new in Java 7? Watchable • Path implements the Watchable interface. • This allows for registering watchers that are interested in events on the Path. • Example for events: • OVERFLOW, ENTRY_CREATE, ENTRY_DELETE, ENTRY _MODIFY. • Let’s see an example for logging which files are deleted on a given directory… 26 copyright 2009 Trainologic LTD
  • 30. What’s new in Java 7? Example FileSystem fs = FileSystems.getDefault(); WatchService ws = fs.newWatchService(); Path path = fs.getPath("c:todeletewatch"); path.register(ws, StandardWatchEventKind.ENTRY_DELETE); while(true) { WatchKey e = ws.take(); List<WatchEvent<?>> events = e.pollEvents(); for (WatchEvent<?> watchEvent : events) { Path ctx = (Path) watchEvent.context(); System.out.println("deleted: " + path); } } 21 copyright 2011 Trainologic LTD
  • 31. What’s new in Java 7? Not Included • The following (promised) features were not included in Java 7: • Lambda and Closures. • Refied Generics. • Modularization. • Annotations on Java types. • Collections literals. 38 copyright 2011 Trainologic LTD
  • 32. What’s new in Java 7? Java 8? • So, what is intended for Java 8? • Well, JSR 337 (Java 8) promises the following: • Annotations on types. • Lambdas. • Parallel collections and support for lambdas in collections. • Date & time APIs. • Module system. 38 copyright 2011 Trainologic LTD
  • 33. What’s new in Java 7? Proposed Lambda Syntax • Following is the current state of JSR 335 (Lambda expressions for Java): Lambda for Runnable executor.submit( #{ System.out.println("Blah") } ); Collections.sort(people, #{ Person x, Person y -> x.getLastName().compareTo(y.getLastName() ) }); 38 copyright 2011 Trainologic LTD

Editor's Notes

  1. TODO
  2. TODO
  3. TODO
  4. TODO