SlideShare a Scribd company logo
1 of 22
Practical Migration to Java 7
    Small Code examples




1                     Markus Eisele, Oracle ACE Director FMW & SOA   msg systems ag, 2011
http://blog.eisele.net
http://twitter.com/myfear
markus@eisele.net
Overview




         1.    Introduction
         2.    msg systems
         3.    20 examples?
         4.    sumary




3
Questions




4               Markus Eisele, Oracle ACE Director FMW & SOA   msg systems ag, 26/06/11
Introduction



                                msg netzwerkservice     PREVO-System AG         finnova AG Bankware        m3 management consulting GmbH
                                GmbH



    1980      1990     1995   1996     1997           1998      2000       2006        2008        2009          2010

       Foundation of                        GILLARDON financial     Regional company        msg global                msg services ag
       msg systems                          software AG (now        in the USA              solutions ag
                                            msgGillardon AG)
                                                                                            COR AG
                                                                                            (now COR&FJA AG)

                                                                                            msg systems
                                                                                            Romania S.R.L.


      Industries:
      • Insurance
      • Financial Services
      • Automotive                                           Individual Solutions:
      • Communications                                       • Allianz | AUDI | BG-PHOENICS | BMW
      • Travel & Logistics                                       Financial Services | BMW Group | Daimler |
      • Utilities                                                DER Deutsches Reisebüro |
                                                                 Deutsche Bank | Deutsche Post | Sächsischer
      • Life Science & Healthcare
                                                                 Landtag | Versicherungskammer Bayern | VR
      • Government                                               Leasing



5                                       Markus Eisele, Oracle ACE Director FMW & SOA                                      msg systems ag, 2011
Java 7 Release Contents




                                  • Java Language
                                     • Project Coin (JSR-334)
                                  • Class Libraries
                                     • NIO2 (JSR-203)
                                     • Fork-Join framework,
                                        ParallelArray (JSR-166y)
                                  • Java Virtual Machine
                                     • The DaVinci Machine project
                                        (JSR-292)
                                     • InvokeDynamic bytecode
                                   • Miscellaneous things


6                             Markus Eisele, Oracle ACE Director FMW & SOA   msg systems ag, 2011
Coin – Underscores in Numeric Literals



         •   private static final int default_kostenart = 215879;
         •   private static final int ZZ_BUFFERSIZE = 16384;




7                                 Markus Eisele, Oracle ACE Director FMW & SOA   msg systems ag, 2011
Coin - String Switch Statement



         […]
         else if
         (o1.getVehicleFeatureDO().getFeatureType().equals(
         “PAINTWORK“)
         || o1.getVehicleFeatureDO().getFeatureType().equals(
         “UPHOLSTERY“)) {
         return -1;
         } else if
         (o1.getVehicleFeatureDO().getFeatureType().equals(
         “OPTION“)
         return 1;
         }
         …




8                                Markus Eisele, Oracle ACE Director FMW & SOA   msg systems ag, 2011
Coin - String Switch Statement



         String s = o1.getVehicleFeatureDO().getFeatureType();
         switch (s) {
             case "PAINTWORK": case "UPHOLSTERY"
             return -1;
             case "OPTION"
             return 1;
         }




9                                Markus Eisele, Oracle ACE Director FMW & SOA   msg systems ag, 2011
Coin – Diamond Operator



          final List<SelectItem> items = new ArrayList<SelectItem>();

          Collection<KalkFLAufwandsverlaufBE> saveVerlauf = new
          ArrayList<KalkFLAufwandsverlaufBE>();

          final List<ErrorRec> errorRecList = new ArrayList<ErrorRec>();

          List<ProjektDO> resultList = new ArrayList<ProjektDO>();

          Map<String, String> retVal = new HashMap<String, String>();




10                                 Markus Eisele, Oracle ACE Director FMW & SOA   msg systems ag, 2011
Coin – Diamond Operator




          final List<SelectItem> items = new ArrayList<>();

          Collection<KalkFLAufwandsverlaufBE> saveVerlauf = new ArrayList<>();

          final List<ErrorRec> errorRecList = new ArrayList<>();

          List<ProjektDO> resultList = new ArrayList<>();

          Map<String, String> retVal = new HashMap<>();




11                                 Markus Eisele, Oracle ACE Director FMW & SOA   msg systems ag, 2011
Coin – Automatic Resource Management

          public DateiAnhangDO setDateiContent(DateiAnhangDO dateiAnhang, InputStream dateiInhalt) throws
          ValidationException {
               OutputStream out = null;
               try {
                   File f = new File(dateiAnhang.getDateiNameSystem());
                   out = new FileOutputStream(f);
                   byte[] buf = new byte[1024];
                   int len;
                   while ((len = dateiInhalt.read(buf)) > 0) {
                       out.write(buf, 0, len);
                   }
               } catch (IOException e) {
                    // Error management skipped
                   throw AppExFactory.validation(CLAZZ, true, errorRecList);
               } finally {
                   try {
                       out.close();
                   } catch (IOException e) {
                   // Error management skipped
                       throw AppExFactory.validation(CLAZZ, true, errorRecList);
                   }
                   try {
                       dateiInhalt.close();
                   } catch (IOException e) {
                    // Error management skipped
                       throw AppExFactory.validation(CLAZZ, true, errorRecList);
                   }
               }
               return dateiAnhang;
            }




12                                          Markus Eisele, Oracle ACE Director FMW & SOA                    msg systems ag, 2011
Coin – Automatic Resource Management

           public void setDateiContent(String dateiAnhang, InputStream dateiInhalt)
          throws ValidationException {
               try (InputStream in = dateiInhalt; OutputStream out = new
          FileOutputStream(new File(dateiAnhang))) {
                  byte[] buf = new byte[1024];
                  int len;
                  while ((len = in.read(buf)) > 0) {
                     out.write(buf, 0, len);
                  }
               } catch (IOException e) {
                  // Error management details skipped
                  throw AppExFactory.validation(CLAZZ, true, errorRecList);
               }
               return dateiAnhang;
             }




13                                 Markus Eisele, Oracle ACE Director FMW & SOA       msg systems ag, 2011
Coin - Multi Catch



           try {
                    final Method method = cls.getMethod("getDefault", new Class[0]);
                    final Object obj = method.invoke(cls, new Object[0]);
                    return (Enum) obj;
                 } catch (NoSuchMethodException nsmex) {
                    throw new EmergencyException(Enum.class, Level.SEVERE,
          "getDefault method not found", nsmex);
                 } catch (IllegalAccessException iae) {
                    throw new EmergencyException(Enum.class, Level.SEVERE,
          "getDefault method not accessible", iae);
                 } catch (InvocationTargetException ite) {
                    throw new EmergencyException(Enum.class, Level.SEVERE,
          "getDefault method invocation exception", ite);
                 }




14                                 Markus Eisele, Oracle ACE Director FMW & SOA        msg systems ag, 2011
Coin - Multi Catch



           try {
                    final Method method = cls.getMethod("getDefault", new Class[0]);
                      final Object obj = method.invoke(cls, new Object[0]);
                      return (Enum) obj;
                  } catch (NoSuchMethodException | IllegalAccessException |
          IllegalArgumentException| InvocationTargetException nsmex) {
                      throw new EmergencyException(Enum.class, Level.SEVERE,
          "getDefault method not found", nsmex);
                  }




15                                 Markus Eisele, Oracle ACE Director FMW & SOA        msg systems ag, 2011
NIO.2

       public boolean createZIPFile(String workDir, String zipFileName, ZipOutputStream out,
           String subdir) {
         boolean zipOk = false;
         String outFilename = zipFileName;
         FileInputStream in = null;
         boolean closeZip = true;
         String nfilen = "";
         try {
           if (out == null) {
             out = new ZipOutputStream(new FileOutputStream(outFilename));
           } else {
             closeZip = false;
           }
           if (subdir != null) {
             workDir = workDir + "/" + subdir;
           }

                // Compress the files
                File srcDir = new File(workDir);
                File[] files = srcDir.listFiles();
                byte[] buf = new byte[1024];
                for (int i = 0; i < files.length; i++) {
                  if (zipFileName.equals(files[i].getName())) {
                    continue;
                  }
                  if (files[i].isDirectory()) {
                    createZIPFile(workDir, zipFileName, out, files[i].getName());                  Recursive ZIP File Handling
                    continue;
                  }
                  in = new FileInputStream(files[i]);                                              - ZipOutputStream
                    // Add ZIP entry to output stream.
                    nfilen = files[i].getName();                                                   - ZipEntry
                    if (subdir != null) {
                      nfilen = subdir + "/" + nfilen;
                    }
                    out.putNextEntry(new ZipEntry(nfilen));

                    // Transfer bytes from the file to the ZIP file
                    int len;
                    while ((len = in.read(buf)) > 0) {
                      out.write(buf, 0, len);
                    }

                    // Complete the entry
                    out.closeEntry();
                    in.close();
                    zipOk = true;
                }

            // Complete the ZIP file
          } catch (FileNotFoundException e) {
       //skipped

          } catch (IOException e) {
       //skipped

          } finally {
            try {
              if (in != null) {
                in.close();
              }
            } catch (IOException e) {

                                                                                                   Error Handling (condensed )
       //skipped
            }

            try {
              if (closeZip && out != null) {
                out.close();
              }
            } catch (IOException e) {
       //skipped
            }

            }

            return (zipOk);
        }




16                                                                                             Markus Eisele, Oracle ACE Director FMW & SOA   msg systems ag, 2011
NIO.2 – (ZIP)FileSystem, ARM, FileCopy, WalkTree
          public static void create(String zipFilename, String... filenames)
              throws IOException {

              try (FileSystem zipFileSystem = createZipFileSystem(zipFilename, true)) {
                final Path root = zipFileSystem.getPath("/");

                  //iterate over the files we need to add
                  for (String filename : filenames) {
                    final Path src = Paths.get(filename);

                      //add a file to the zip file system
                      if(!Files.isDirectory(src)){
                                                                                                private static FileSystem createZipFileSystem(String
                        final Path dest = zipFileSystem.getPath(root.toString(),                zipFilename, boolean create)   throws IOException {
                                                                src.toString());                  // convert the filename to a URI
                        final Path parent = dest.getParent();
                        if(Files.notExists(parent)){
                                                                                                  final Path path = Paths.get(zipFilename);
                          System.out.printf("Creating directory %sn", parent);                   final URI uri = URI.create("jar:file:" +
                          Files.createDirectories(parent);                                      path.toUri().getPath());
                        }
                        Files.copy(src, dest, StandardCopyOption.REPLACE_EXISTING);
                      }                                                                             final Map<String, String> env = new HashMap<>();
                      else{                                                                         if (create) {
                        //for directories, walk the file tree                                         env.put("create", "true");
                        Files.walkFileTree(src, new SimpleFileVisitor<Path>(){
                          @Override                                                                 }
                          public FileVisitResult visitFile(Path file,                               return FileSystems.newFileSystem(uri, env);
                              BasicFileAttributes attrs) throws IOException {                   }
                            final Path dest = zipFileSystem.getPath(root.toString(),
                                                                    file.toString());
                            Files.copy(file, dest, StandardCopyOption.REPLACE_EXISTING);
                            return FileVisitResult.CONTINUE;
                          }

                            @Override
                            public FileVisitResult preVisitDirectory(Path dir,
                                BasicFileAttributes attrs) throws IOException {
                              final Path dirToCreate = zipFileSystem.getPath(root.toString(),
                                                                             dir.toString());
                              if(Files.notExists(dirToCreate)){
                                System.out.printf("Creating directory %sn", dirToCreate);
                                Files.createDirectories(dirToCreate);
                              }
                              return FileVisitResult.CONTINUE;
                            }
                          });
                      }
                  }
              }
          }
17                                                            Markus Eisele, Oracle ACE Director FMW & SOA                              msg systems ag, 2011
Sumary



         •    Nice, new features
         •    Moving old stuff to new stuff isn’t an automatism

         •    Most relevant ones:
                  Multi-Catch probably the most used one
                  Diamond Operator


         •    Maybe relevant:
                  NIO.2
                  Fork/Join


         •    Not a bit relevant:
                  Better integer literals
                  String in switch case
                  Varargs Warnings
                  InvokeDynamik




18                                       Markus Eisele, Oracle ACE Director FMW & SOA   msg systems ag, 2011
SE 6 still not broadly adopted




19                                    Markus Eisele, Oracle ACE Director FMW & SOA   msg systems ag, 26/06/11
Lesson in a tweet




      “The best thing about a boolean is
      even if you are wrong,
      you are only off by a bit.”
      (Anonymous)




      http://www.devtopics.com/101-great-computer-programming-quotes/


20                                             Markus Eisele, Oracle ACE Director FMW & SOA   msg systems ag, 2011
Disclaimer




      The thoughts expressed here are
      the personal opinions of the author
      and no official statement
      of the msg systems ag.




21                   Markus Eisele, Oracle ACE Director FMW & SOA   msg systems ag, 2011
Thank you for your attention




     Markus Eisele

     Principle IT Architect

     Phone: +49 89 96101-0
     markus.eisele@msg-systems.com


     www.msg-systems.com




                                   www.msg-systems.com




22                            Markus Eisele, Oracle ACE Director FMW & SOA   msg systems ag, 2011

More Related Content

Similar to Practical Java 7 Code Migration Examples

[Strukelj] Why will Java 7.0 be so cool
[Strukelj] Why will Java 7.0 be so cool[Strukelj] Why will Java 7.0 be so cool
[Strukelj] Why will Java 7.0 be so cooljavablend
 
Getting started with ES6 : Future of javascript
Getting started with ES6 : Future of javascriptGetting started with ES6 : Future of javascript
Getting started with ES6 : Future of javascriptMohd Saeed
 
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
 
JavaScript Editions ES7, ES8 and ES9 vs V8
JavaScript Editions ES7, ES8 and ES9 vs V8JavaScript Editions ES7, ES8 and ES9 vs V8
JavaScript Editions ES7, ES8 and ES9 vs V8Rafael Casuso Romate
 
Erlang
ErlangErlang
ErlangESUG
 
Integration&SOA_v0.2
Integration&SOA_v0.2Integration&SOA_v0.2
Integration&SOA_v0.2Sergey Popov
 
Javaforum 20110915
Javaforum 20110915Javaforum 20110915
Javaforum 20110915Squeed
 
Yury's CV as of 2013.03.31
Yury's CV as of 2013.03.31Yury's CV as of 2013.03.31
Yury's CV as of 2013.03.31Yury Velikanov
 
Let Spark Fly: Advantages and Use Cases for Spark on Hadoop
 Let Spark Fly: Advantages and Use Cases for Spark on Hadoop Let Spark Fly: Advantages and Use Cases for Spark on Hadoop
Let Spark Fly: Advantages and Use Cases for Spark on HadoopMapR Technologies
 
Choose'10: Ralf Laemmel - Dealing Confortably with the Confusion of Tongues
Choose'10: Ralf Laemmel - Dealing Confortably with the Confusion of TonguesChoose'10: Ralf Laemmel - Dealing Confortably with the Confusion of Tongues
Choose'10: Ralf Laemmel - Dealing Confortably with the Confusion of TonguesCHOOSE
 
Making Exceptions on Exception Handling (WEH 2012 Keynote Speech)
Making Exceptions on  Exception Handling (WEH 2012 Keynote Speech)Making Exceptions on  Exception Handling (WEH 2012 Keynote Speech)
Making Exceptions on Exception Handling (WEH 2012 Keynote Speech)Tao Xie
 
Overhauling a database engine in 2 months
Overhauling a database engine in 2 monthsOverhauling a database engine in 2 months
Overhauling a database engine in 2 monthsMax Neunhöffer
 
Introduction To Erlang Final
Introduction To Erlang   FinalIntroduction To Erlang   Final
Introduction To Erlang FinalSinarShebl
 
Finding Bugs, Fixing Bugs, Preventing Bugs - Exploiting Automated Tests to In...
Finding Bugs, Fixing Bugs, Preventing Bugs - Exploiting Automated Tests to In...Finding Bugs, Fixing Bugs, Preventing Bugs - Exploiting Automated Tests to In...
Finding Bugs, Fixing Bugs, Preventing Bugs - Exploiting Automated Tests to In...University of Antwerp
 

Similar to Practical Java 7 Code Migration Examples (20)

[Strukelj] Why will Java 7.0 be so cool
[Strukelj] Why will Java 7.0 be so cool[Strukelj] Why will Java 7.0 be so cool
[Strukelj] Why will Java 7.0 be so cool
 
The State of JavaScript
The State of JavaScriptThe State of JavaScript
The State of JavaScript
 
Hybrid Applications
Hybrid ApplicationsHybrid Applications
Hybrid Applications
 
Getting started with ES6 : Future of javascript
Getting started with ES6 : Future of javascriptGetting started with ES6 : Future of javascript
Getting started with ES6 : Future of javascript
 
ES6 - JavaCro 2016
ES6 - JavaCro 2016ES6 - JavaCro 2016
ES6 - JavaCro 2016
 
Javantura v3 - ES6 – Future Is Now – Nenad Pečanac
Javantura v3 - ES6 – Future Is Now – Nenad PečanacJavantura v3 - ES6 – Future Is Now – Nenad Pečanac
Javantura v3 - ES6 – Future Is Now – Nenad Pečanac
 
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
 
Modern Java Development
Modern Java DevelopmentModern Java Development
Modern Java Development
 
JavaScript Editions ES7, ES8 and ES9 vs V8
JavaScript Editions ES7, ES8 and ES9 vs V8JavaScript Editions ES7, ES8 and ES9 vs V8
JavaScript Editions ES7, ES8 and ES9 vs V8
 
Erlang
ErlangErlang
Erlang
 
Integration&SOA_v0.2
Integration&SOA_v0.2Integration&SOA_v0.2
Integration&SOA_v0.2
 
Javaforum 20110915
Javaforum 20110915Javaforum 20110915
Javaforum 20110915
 
Yury's CV as of 2013.03.31
Yury's CV as of 2013.03.31Yury's CV as of 2013.03.31
Yury's CV as of 2013.03.31
 
Let Spark Fly: Advantages and Use Cases for Spark on Hadoop
 Let Spark Fly: Advantages and Use Cases for Spark on Hadoop Let Spark Fly: Advantages and Use Cases for Spark on Hadoop
Let Spark Fly: Advantages and Use Cases for Spark on Hadoop
 
Devoxx
DevoxxDevoxx
Devoxx
 
Choose'10: Ralf Laemmel - Dealing Confortably with the Confusion of Tongues
Choose'10: Ralf Laemmel - Dealing Confortably with the Confusion of TonguesChoose'10: Ralf Laemmel - Dealing Confortably with the Confusion of Tongues
Choose'10: Ralf Laemmel - Dealing Confortably with the Confusion of Tongues
 
Making Exceptions on Exception Handling (WEH 2012 Keynote Speech)
Making Exceptions on  Exception Handling (WEH 2012 Keynote Speech)Making Exceptions on  Exception Handling (WEH 2012 Keynote Speech)
Making Exceptions on Exception Handling (WEH 2012 Keynote Speech)
 
Overhauling a database engine in 2 months
Overhauling a database engine in 2 monthsOverhauling a database engine in 2 months
Overhauling a database engine in 2 months
 
Introduction To Erlang Final
Introduction To Erlang   FinalIntroduction To Erlang   Final
Introduction To Erlang Final
 
Finding Bugs, Fixing Bugs, Preventing Bugs - Exploiting Automated Tests to In...
Finding Bugs, Fixing Bugs, Preventing Bugs - Exploiting Automated Tests to In...Finding Bugs, Fixing Bugs, Preventing Bugs - Exploiting Automated Tests to In...
Finding Bugs, Fixing Bugs, Preventing Bugs - Exploiting Automated Tests to In...
 

More from Markus Eisele

Sustainable Software Architecture - Open Tour DACH '22
Sustainable Software Architecture - Open Tour DACH '22Sustainable Software Architecture - Open Tour DACH '22
Sustainable Software Architecture - Open Tour DACH '22Markus Eisele
 
Going from java message service (jms) to eda
Going from java message service (jms) to eda Going from java message service (jms) to eda
Going from java message service (jms) to eda Markus Eisele
 
Let's be real. Quarkus in the wild.
Let's be real. Quarkus in the wild.Let's be real. Quarkus in the wild.
Let's be real. Quarkus in the wild.Markus Eisele
 
What happens when unicorns drink coffee
What happens when unicorns drink coffeeWhat happens when unicorns drink coffee
What happens when unicorns drink coffeeMarkus Eisele
 
Stateful on Stateless - The Future of Applications in the Cloud
Stateful on Stateless - The Future of Applications in the CloudStateful on Stateless - The Future of Applications in the Cloud
Stateful on Stateless - The Future of Applications in the CloudMarkus Eisele
 
Java in the age of containers - JUG Frankfurt/M
Java in the age of containers - JUG Frankfurt/MJava in the age of containers - JUG Frankfurt/M
Java in the age of containers - JUG Frankfurt/MMarkus Eisele
 
Java in the Age of Containers and Serverless
Java in the Age of Containers and ServerlessJava in the Age of Containers and Serverless
Java in the Age of Containers and ServerlessMarkus Eisele
 
Migrating from Java EE to cloud-native Reactive systems
Migrating from Java EE to cloud-native Reactive systemsMigrating from Java EE to cloud-native Reactive systems
Migrating from Java EE to cloud-native Reactive systemsMarkus Eisele
 
Streaming to a new Jakarta EE / JOTB19
Streaming to a new Jakarta EE / JOTB19Streaming to a new Jakarta EE / JOTB19
Streaming to a new Jakarta EE / JOTB19Markus Eisele
 
Cloud wars - A LavaOne discussion in seven slides
Cloud wars - A LavaOne discussion in seven slidesCloud wars - A LavaOne discussion in seven slides
Cloud wars - A LavaOne discussion in seven slidesMarkus Eisele
 
Streaming to a new Jakarta EE
Streaming to a new Jakarta EEStreaming to a new Jakarta EE
Streaming to a new Jakarta EEMarkus Eisele
 
Reactive Integrations - Caveats and bumps in the road explained
Reactive Integrations - Caveats and bumps in the road explained  Reactive Integrations - Caveats and bumps in the road explained
Reactive Integrations - Caveats and bumps in the road explained Markus Eisele
 
Stay productive while slicing up the monolith
Stay productive while slicing up the monolithStay productive while slicing up the monolith
Stay productive while slicing up the monolithMarkus Eisele
 
Stay productive while slicing up the monolith
Stay productive while slicing up the monolithStay productive while slicing up the monolith
Stay productive while slicing up the monolithMarkus Eisele
 
Stay productive_while_slicing_up_the_monolith
Stay productive_while_slicing_up_the_monolithStay productive_while_slicing_up_the_monolith
Stay productive_while_slicing_up_the_monolithMarkus Eisele
 
Architecting for failure - Why are distributed systems hard?
Architecting for failure - Why are distributed systems hard?Architecting for failure - Why are distributed systems hard?
Architecting for failure - Why are distributed systems hard?Markus Eisele
 
Stay productive while slicing up the monolith
Stay productive while slicing up the monolith Stay productive while slicing up the monolith
Stay productive while slicing up the monolith Markus Eisele
 
Nine Neins - where Java EE will never take you
Nine Neins - where Java EE will never take youNine Neins - where Java EE will never take you
Nine Neins - where Java EE will never take youMarkus Eisele
 
How lagom helps to build real world microservice systems
How lagom helps to build real world microservice systemsHow lagom helps to build real world microservice systems
How lagom helps to build real world microservice systemsMarkus Eisele
 
CQRS and Event Sourcing for Java Developers
CQRS and Event Sourcing for Java DevelopersCQRS and Event Sourcing for Java Developers
CQRS and Event Sourcing for Java DevelopersMarkus Eisele
 

More from Markus Eisele (20)

Sustainable Software Architecture - Open Tour DACH '22
Sustainable Software Architecture - Open Tour DACH '22Sustainable Software Architecture - Open Tour DACH '22
Sustainable Software Architecture - Open Tour DACH '22
 
Going from java message service (jms) to eda
Going from java message service (jms) to eda Going from java message service (jms) to eda
Going from java message service (jms) to eda
 
Let's be real. Quarkus in the wild.
Let's be real. Quarkus in the wild.Let's be real. Quarkus in the wild.
Let's be real. Quarkus in the wild.
 
What happens when unicorns drink coffee
What happens when unicorns drink coffeeWhat happens when unicorns drink coffee
What happens when unicorns drink coffee
 
Stateful on Stateless - The Future of Applications in the Cloud
Stateful on Stateless - The Future of Applications in the CloudStateful on Stateless - The Future of Applications in the Cloud
Stateful on Stateless - The Future of Applications in the Cloud
 
Java in the age of containers - JUG Frankfurt/M
Java in the age of containers - JUG Frankfurt/MJava in the age of containers - JUG Frankfurt/M
Java in the age of containers - JUG Frankfurt/M
 
Java in the Age of Containers and Serverless
Java in the Age of Containers and ServerlessJava in the Age of Containers and Serverless
Java in the Age of Containers and Serverless
 
Migrating from Java EE to cloud-native Reactive systems
Migrating from Java EE to cloud-native Reactive systemsMigrating from Java EE to cloud-native Reactive systems
Migrating from Java EE to cloud-native Reactive systems
 
Streaming to a new Jakarta EE / JOTB19
Streaming to a new Jakarta EE / JOTB19Streaming to a new Jakarta EE / JOTB19
Streaming to a new Jakarta EE / JOTB19
 
Cloud wars - A LavaOne discussion in seven slides
Cloud wars - A LavaOne discussion in seven slidesCloud wars - A LavaOne discussion in seven slides
Cloud wars - A LavaOne discussion in seven slides
 
Streaming to a new Jakarta EE
Streaming to a new Jakarta EEStreaming to a new Jakarta EE
Streaming to a new Jakarta EE
 
Reactive Integrations - Caveats and bumps in the road explained
Reactive Integrations - Caveats and bumps in the road explained  Reactive Integrations - Caveats and bumps in the road explained
Reactive Integrations - Caveats and bumps in the road explained
 
Stay productive while slicing up the monolith
Stay productive while slicing up the monolithStay productive while slicing up the monolith
Stay productive while slicing up the monolith
 
Stay productive while slicing up the monolith
Stay productive while slicing up the monolithStay productive while slicing up the monolith
Stay productive while slicing up the monolith
 
Stay productive_while_slicing_up_the_monolith
Stay productive_while_slicing_up_the_monolithStay productive_while_slicing_up_the_monolith
Stay productive_while_slicing_up_the_monolith
 
Architecting for failure - Why are distributed systems hard?
Architecting for failure - Why are distributed systems hard?Architecting for failure - Why are distributed systems hard?
Architecting for failure - Why are distributed systems hard?
 
Stay productive while slicing up the monolith
Stay productive while slicing up the monolith Stay productive while slicing up the monolith
Stay productive while slicing up the monolith
 
Nine Neins - where Java EE will never take you
Nine Neins - where Java EE will never take youNine Neins - where Java EE will never take you
Nine Neins - where Java EE will never take you
 
How lagom helps to build real world microservice systems
How lagom helps to build real world microservice systemsHow lagom helps to build real world microservice systems
How lagom helps to build real world microservice systems
 
CQRS and Event Sourcing for Java Developers
CQRS and Event Sourcing for Java DevelopersCQRS and Event Sourcing for Java Developers
CQRS and Event Sourcing for Java Developers
 

Recently uploaded

Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 

Recently uploaded (20)

Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 

Practical Java 7 Code Migration Examples

  • 1. Practical Migration to Java 7 Small Code examples 1 Markus Eisele, Oracle ACE Director FMW & SOA msg systems ag, 2011
  • 3. Overview 1. Introduction 2. msg systems 3. 20 examples? 4. sumary 3
  • 4. Questions 4 Markus Eisele, Oracle ACE Director FMW & SOA msg systems ag, 26/06/11
  • 5. Introduction msg netzwerkservice PREVO-System AG finnova AG Bankware m3 management consulting GmbH GmbH 1980 1990 1995 1996 1997 1998 2000 2006 2008 2009 2010 Foundation of GILLARDON financial Regional company msg global msg services ag msg systems software AG (now in the USA solutions ag msgGillardon AG) COR AG (now COR&FJA AG) msg systems Romania S.R.L. Industries: • Insurance • Financial Services • Automotive Individual Solutions: • Communications • Allianz | AUDI | BG-PHOENICS | BMW • Travel & Logistics Financial Services | BMW Group | Daimler | • Utilities DER Deutsches Reisebüro | Deutsche Bank | Deutsche Post | Sächsischer • Life Science & Healthcare Landtag | Versicherungskammer Bayern | VR • Government Leasing 5 Markus Eisele, Oracle ACE Director FMW & SOA msg systems ag, 2011
  • 6. Java 7 Release Contents • Java Language • Project Coin (JSR-334) • Class Libraries • NIO2 (JSR-203) • Fork-Join framework, ParallelArray (JSR-166y) • Java Virtual Machine • The DaVinci Machine project (JSR-292) • InvokeDynamic bytecode • Miscellaneous things 6 Markus Eisele, Oracle ACE Director FMW & SOA msg systems ag, 2011
  • 7. Coin – Underscores in Numeric Literals • private static final int default_kostenart = 215879; • private static final int ZZ_BUFFERSIZE = 16384; 7 Markus Eisele, Oracle ACE Director FMW & SOA msg systems ag, 2011
  • 8. Coin - String Switch Statement […] else if (o1.getVehicleFeatureDO().getFeatureType().equals( “PAINTWORK“) || o1.getVehicleFeatureDO().getFeatureType().equals( “UPHOLSTERY“)) { return -1; } else if (o1.getVehicleFeatureDO().getFeatureType().equals( “OPTION“) return 1; } … 8 Markus Eisele, Oracle ACE Director FMW & SOA msg systems ag, 2011
  • 9. Coin - String Switch Statement String s = o1.getVehicleFeatureDO().getFeatureType(); switch (s) { case "PAINTWORK": case "UPHOLSTERY" return -1; case "OPTION" return 1; } 9 Markus Eisele, Oracle ACE Director FMW & SOA msg systems ag, 2011
  • 10. Coin – Diamond Operator final List<SelectItem> items = new ArrayList<SelectItem>(); Collection<KalkFLAufwandsverlaufBE> saveVerlauf = new ArrayList<KalkFLAufwandsverlaufBE>(); final List<ErrorRec> errorRecList = new ArrayList<ErrorRec>(); List<ProjektDO> resultList = new ArrayList<ProjektDO>(); Map<String, String> retVal = new HashMap<String, String>(); 10 Markus Eisele, Oracle ACE Director FMW & SOA msg systems ag, 2011
  • 11. Coin – Diamond Operator final List<SelectItem> items = new ArrayList<>(); Collection<KalkFLAufwandsverlaufBE> saveVerlauf = new ArrayList<>(); final List<ErrorRec> errorRecList = new ArrayList<>(); List<ProjektDO> resultList = new ArrayList<>(); Map<String, String> retVal = new HashMap<>(); 11 Markus Eisele, Oracle ACE Director FMW & SOA msg systems ag, 2011
  • 12. Coin – Automatic Resource Management public DateiAnhangDO setDateiContent(DateiAnhangDO dateiAnhang, InputStream dateiInhalt) throws ValidationException { OutputStream out = null; try { File f = new File(dateiAnhang.getDateiNameSystem()); out = new FileOutputStream(f); byte[] buf = new byte[1024]; int len; while ((len = dateiInhalt.read(buf)) > 0) { out.write(buf, 0, len); } } catch (IOException e) { // Error management skipped throw AppExFactory.validation(CLAZZ, true, errorRecList); } finally { try { out.close(); } catch (IOException e) { // Error management skipped throw AppExFactory.validation(CLAZZ, true, errorRecList); } try { dateiInhalt.close(); } catch (IOException e) { // Error management skipped throw AppExFactory.validation(CLAZZ, true, errorRecList); } } return dateiAnhang; } 12 Markus Eisele, Oracle ACE Director FMW & SOA msg systems ag, 2011
  • 13. Coin – Automatic Resource Management public void setDateiContent(String dateiAnhang, InputStream dateiInhalt) throws ValidationException { try (InputStream in = dateiInhalt; OutputStream out = new FileOutputStream(new File(dateiAnhang))) { byte[] buf = new byte[1024]; int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } } catch (IOException e) { // Error management details skipped throw AppExFactory.validation(CLAZZ, true, errorRecList); } return dateiAnhang; } 13 Markus Eisele, Oracle ACE Director FMW & SOA msg systems ag, 2011
  • 14. Coin - Multi Catch try { final Method method = cls.getMethod("getDefault", new Class[0]); final Object obj = method.invoke(cls, new Object[0]); return (Enum) obj; } catch (NoSuchMethodException nsmex) { throw new EmergencyException(Enum.class, Level.SEVERE, "getDefault method not found", nsmex); } catch (IllegalAccessException iae) { throw new EmergencyException(Enum.class, Level.SEVERE, "getDefault method not accessible", iae); } catch (InvocationTargetException ite) { throw new EmergencyException(Enum.class, Level.SEVERE, "getDefault method invocation exception", ite); } 14 Markus Eisele, Oracle ACE Director FMW & SOA msg systems ag, 2011
  • 15. Coin - Multi Catch try { final Method method = cls.getMethod("getDefault", new Class[0]); final Object obj = method.invoke(cls, new Object[0]); return (Enum) obj; } catch (NoSuchMethodException | IllegalAccessException | IllegalArgumentException| InvocationTargetException nsmex) { throw new EmergencyException(Enum.class, Level.SEVERE, "getDefault method not found", nsmex); } 15 Markus Eisele, Oracle ACE Director FMW & SOA msg systems ag, 2011
  • 16. NIO.2 public boolean createZIPFile(String workDir, String zipFileName, ZipOutputStream out, String subdir) { boolean zipOk = false; String outFilename = zipFileName; FileInputStream in = null; boolean closeZip = true; String nfilen = ""; try { if (out == null) { out = new ZipOutputStream(new FileOutputStream(outFilename)); } else { closeZip = false; } if (subdir != null) { workDir = workDir + "/" + subdir; } // Compress the files File srcDir = new File(workDir); File[] files = srcDir.listFiles(); byte[] buf = new byte[1024]; for (int i = 0; i < files.length; i++) { if (zipFileName.equals(files[i].getName())) { continue; } if (files[i].isDirectory()) { createZIPFile(workDir, zipFileName, out, files[i].getName()); Recursive ZIP File Handling continue; } in = new FileInputStream(files[i]); - ZipOutputStream // Add ZIP entry to output stream. nfilen = files[i].getName(); - ZipEntry if (subdir != null) { nfilen = subdir + "/" + nfilen; } out.putNextEntry(new ZipEntry(nfilen)); // Transfer bytes from the file to the ZIP file int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } // Complete the entry out.closeEntry(); in.close(); zipOk = true; } // Complete the ZIP file } catch (FileNotFoundException e) { //skipped } catch (IOException e) { //skipped } finally { try { if (in != null) { in.close(); } } catch (IOException e) { Error Handling (condensed ) //skipped } try { if (closeZip && out != null) { out.close(); } } catch (IOException e) { //skipped } } return (zipOk); } 16 Markus Eisele, Oracle ACE Director FMW & SOA msg systems ag, 2011
  • 17. NIO.2 – (ZIP)FileSystem, ARM, FileCopy, WalkTree public static void create(String zipFilename, String... filenames) throws IOException { try (FileSystem zipFileSystem = createZipFileSystem(zipFilename, true)) { final Path root = zipFileSystem.getPath("/"); //iterate over the files we need to add for (String filename : filenames) { final Path src = Paths.get(filename); //add a file to the zip file system if(!Files.isDirectory(src)){ private static FileSystem createZipFileSystem(String final Path dest = zipFileSystem.getPath(root.toString(), zipFilename, boolean create) throws IOException { src.toString()); // convert the filename to a URI final Path parent = dest.getParent(); if(Files.notExists(parent)){ final Path path = Paths.get(zipFilename); System.out.printf("Creating directory %sn", parent); final URI uri = URI.create("jar:file:" + Files.createDirectories(parent); path.toUri().getPath()); } Files.copy(src, dest, StandardCopyOption.REPLACE_EXISTING); } final Map<String, String> env = new HashMap<>(); else{ if (create) { //for directories, walk the file tree env.put("create", "true"); Files.walkFileTree(src, new SimpleFileVisitor<Path>(){ @Override } public FileVisitResult visitFile(Path file, return FileSystems.newFileSystem(uri, env); BasicFileAttributes attrs) throws IOException { } final Path dest = zipFileSystem.getPath(root.toString(), file.toString()); Files.copy(file, dest, StandardCopyOption.REPLACE_EXISTING); return FileVisitResult.CONTINUE; } @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { final Path dirToCreate = zipFileSystem.getPath(root.toString(), dir.toString()); if(Files.notExists(dirToCreate)){ System.out.printf("Creating directory %sn", dirToCreate); Files.createDirectories(dirToCreate); } return FileVisitResult.CONTINUE; } }); } } } } 17 Markus Eisele, Oracle ACE Director FMW & SOA msg systems ag, 2011
  • 18. Sumary • Nice, new features • Moving old stuff to new stuff isn’t an automatism • Most relevant ones:  Multi-Catch probably the most used one  Diamond Operator • Maybe relevant:  NIO.2  Fork/Join • Not a bit relevant:  Better integer literals  String in switch case  Varargs Warnings  InvokeDynamik 18 Markus Eisele, Oracle ACE Director FMW & SOA msg systems ag, 2011
  • 19. SE 6 still not broadly adopted 19 Markus Eisele, Oracle ACE Director FMW & SOA msg systems ag, 26/06/11
  • 20. Lesson in a tweet “The best thing about a boolean is even if you are wrong, you are only off by a bit.” (Anonymous) http://www.devtopics.com/101-great-computer-programming-quotes/ 20 Markus Eisele, Oracle ACE Director FMW & SOA msg systems ag, 2011
  • 21. Disclaimer The thoughts expressed here are the personal opinions of the author and no official statement of the msg systems ag. 21 Markus Eisele, Oracle ACE Director FMW & SOA msg systems ag, 2011
  • 22. Thank you for your attention Markus Eisele Principle IT Architect Phone: +49 89 96101-0 markus.eisele@msg-systems.com www.msg-systems.com www.msg-systems.com 22 Markus Eisele, Oracle ACE Director FMW & SOA msg systems ag, 2011