SlideShare uma empresa Scribd logo
1 de 33
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

Mais conteúdo relacionado

Mais procurados

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 8Simon Ritter
 
모던자바의 역습
모던자바의 역습모던자바의 역습
모던자바의 역습DoHyun Jung
 
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 InterfacesRaffi Khatchadourian
 
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 ApplicationsNikita 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 & EncodingsAnton Keks
 
Java tutorials
Java tutorialsJava tutorials
Java tutorialssaryu2011
 
Modern Java Workshop
Modern Java WorkshopModern Java Workshop
Modern Java WorkshopSimon Ritter
 
Java Course 4: Exceptions & Collections
Java Course 4: Exceptions & CollectionsJava Course 4: Exceptions & Collections
Java Course 4: Exceptions & CollectionsAnton Keks
 
Java - OOPS and Java Basics
Java - OOPS and Java BasicsJava - OOPS and Java Basics
Java - OOPS and Java BasicsVicter Paul
 
Java Course 3: OOP
Java Course 3: OOPJava Course 3: OOP
Java Course 3: OOPAnton Keks
 
Benefits of OSGi in Practise
Benefits of OSGi in PractiseBenefits of OSGi in Practise
Benefits of OSGi in PractiseDavid Bosschaert
 

Mais procurados (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
 

Destaque

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 scalazKobib9
 
черонобыльская аэс
черонобыльская аэсчеронобыльская аэс
черонобыльская аэсWINDOSILL
 
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 2013Thor Jusnes
 

Destaque (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
 

Semelhante a 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 OredevMattias Karlsson
 
New Features Of JDK 7
New Features Of JDK 7New Features Of JDK 7
New Features Of JDK 7Deniz Oguz
 
What to expect from Java 9
What to expect from Java 9What to expect from Java 9
What to expect from Java 9Ivan 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 StreamsEmiel Paasschens
 
Features java9
Features java9Features java9
Features java9srmohan06
 
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 featuresshrinath97
 
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
 
Inside IBM Java 7
Inside IBM Java 7Inside IBM Java 7
Inside IBM Java 7Tim Ellison
 
Java7 - Top 10 Features
Java7 - Top 10 FeaturesJava7 - Top 10 Features
Java7 - Top 10 FeaturesAndreas Enbohm
 
What’s expected in Java 9
What’s expected in Java 9What’s expected in Java 9
What’s expected in Java 9Gal Marder
 
Java/Servlet/JSP/JDBC
Java/Servlet/JSP/JDBCJava/Servlet/JSP/JDBC
Java/Servlet/JSP/JDBCFAKHRUN 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 MINAtrustinlee
 
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 referenceGiacomo 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, HibernateAnton Keks
 

Semelhante a 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
 

Último

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
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
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
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
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
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
 
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
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
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
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
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
 
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
 
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
 
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
 

Último (20)

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
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...
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
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 ...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
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
 
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
 
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
 
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
 

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

Notas do Editor

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