Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Practical Migration to Java 7    Small Code examples1                     Markus Eisele, Oracle ACE Director FMW & SOA   m...
http://blog.eisele.nethttp://twitter.com/myfearmarkus@eisele.net
Overview         1.    Introduction         2.    msg systems         3.    20 examples?         4.    sumary3
Questions4               Markus Eisele, Oracle ACE Director FMW & SOA   msg systems ag, 26/06/11
Introduction                                msg netzwerkservice     PREVO-System AG         finnova AG Bankware        m3 ...
Java 7 Release Contents                                  • Java Language                                     • Project Coi...
Coin – Underscores in Numeric Literals         •   private static final int default_kostenart = 215879;         •   privat...
Coin - String Switch Statement         […]         else if         (o1.getVehicleFeatureDO().getFeatureType().equals(     ...
Coin - String Switch Statement         String s = o1.getVehicleFeatureDO().getFeatureType();         switch (s) {         ...
Coin – Diamond Operator          final List<SelectItem> items = new ArrayList<SelectItem>();          Collection<KalkFLAuf...
Coin – Diamond Operator          final List<SelectItem> items = new ArrayList<>();          Collection<KalkFLAufwandsverla...
Coin – Automatic Resource Management          public DateiAnhangDO setDateiContent(DateiAnhangDO dateiAnhang, InputStream ...
Coin – Automatic Resource Management           public void setDateiContent(String dateiAnhang, InputStream dateiInhalt)   ...
Coin - Multi Catch           try {                    final Method method = cls.getMethod("getDefault", new Class[0]);    ...
Coin - Multi Catch           try {                    final Method method = cls.getMethod("getDefault", new Class[0]);    ...
NIO.2       public boolean createZIPFile(String workDir, String zipFileName, ZipOutputStream out,           String subdir)...
NIO.2 – (ZIP)FileSystem, ARM, FileCopy, WalkTree          public static void create(String zipFilename, String... filename...
Sumary         •    Nice, new features         •    Moving old stuff to new stuff isn’t an automatism         •    Most re...
SE 6 still not broadly adopted19                                    Markus Eisele, Oracle ACE Director FMW & SOA   msg sys...
Lesson in a tweet      “The best thing about a boolean is      even if you are wrong,      you are only off by a bit.”    ...
Disclaimer      The thoughts expressed here are      the personal opinions of the author      and no official statement   ...
Thank you for your attention     Markus Eisele     Principle IT Architect     Phone: +49 89 96101-0     markus.eisele@msg-...
Upcoming SlideShare
Loading in …5
×

Practical Migration to Java 7

3,880 views

Published on

Published in: Technology, News & Politics
  • DOWNLOAD FULL BOOKS, INTO AVAILABLE FORMAT ......................................................................................................................... ......................................................................................................................... ,DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... ,DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... ,DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... ,DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... ,DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... ,DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD FULL BOOKS, INTO AVAILABLE FORMAT ......................................................................................................................... ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Practical Migration to Java 7

  1. 1. Practical Migration to Java 7 Small Code examples1 Markus Eisele, Oracle ACE Director FMW & SOA msg systems ag, 2011
  2. 2. http://blog.eisele.nethttp://twitter.com/myfearmarkus@eisele.net
  3. 3. Overview 1. Introduction 2. msg systems 3. 20 examples? 4. sumary3
  4. 4. Questions4 Markus Eisele, Oracle ACE Director FMW & SOA msg systems ag, 26/06/11
  5. 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 Leasing5 Markus Eisele, Oracle ACE Director FMW & SOA msg systems ag, 2011
  6. 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 things6 Markus Eisele, Oracle ACE Director FMW & SOA msg systems ag, 2011
  7. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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  InvokeDynamik18 Markus Eisele, Oracle ACE Director FMW & SOA msg systems ag, 2011
  19. 19. SE 6 still not broadly adopted19 Markus Eisele, Oracle ACE Director FMW & SOA msg systems ag, 26/06/11
  20. 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. 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. 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.com22 Markus Eisele, Oracle ACE Director FMW & SOA msg systems ag, 2011

×