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.

Java se7 features

2,498 views

Published on

This presentation provides overview of Java SE 7 new features, mainly concentrates on Project Coin, NIO.2 updates

Published in: Technology, Education
  • Visit Here to Read eBook === http://ebookdfsrewsa.justdied.com/ ebookdfsrewsa.justdied.com 2755618868-le-bouquin-du-petit-coin-tome-7-wc-zen-07.html
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Java se7 features

  1. 1. JAVA SE 7 Features Kumaraswamy Gowda May 2012
  2. 2. JDK 7 Release – Session agenda Project Coin NIO.2 Concurrency and collections updates Performance JDK 7 release More features from JDK 7 release A glimpse of Java SE 8 Q&A1
  3. 3. Project Coin The Six Coin Features and How They Help Easier to use generics Diamond Varargs warnings More concise error handling Multi-catch try-with-resources (aka ARM or TWR) Consistency and clarity Strings in switch Literal improvements Binary literals Underscores in literals2
  4. 4. Diamond syntax  Type Inference for Generic Instance Creation3
  5. 5. Multi Catch and Final Re-throw Handling More Than One Type of Exception in a single catch blockNote: If a catch block handles more than one exception type, then the catchparameter is implicitly final. In this example, the catch parameter ex is final andtherefore you cannot assign any value to it within the catch block.4
  6. 6. Multi Catch and Final Re-throwContd.  Rethrowing Exceptions with More Inclusive Type Checking5
  7. 7. try-with-resources Prior JDK 7  code in finally block, to ensure that a resource is closed regardless of whether the try statement completes normally or abruptly. The code is a bit messy!6
  8. 8. try-with-resources Cont. JDK 7 introduces a try-with-resources statement, which ensures that each of the resources in try(resourses) is closed at the end of the statement. This results in cleaner code. Note: A try-with-resources statement can have catch and finally blocks just like an ordinary try statement. In a try-with-resources statement, any catch or finally block is run after the resources declared have been closed. Suppressed Exceptions Throwable.getSuppressed Classes That Implement the AutoCloseable or Closeable Interface7
  9. 9. Strings in switch  Nothing much to explain here, the title says it all.  Previous versions of Java, the argument of switch had to be only of the following primitive data types: byte, short, char, int, or enum  Starting from JDK 7, you can use arguments of type String in the expression of a switch statement.  How about LONG in switch?8
  10. 10. Binary Literals  Integral types (byte, short, int, and long) can also be expressed using the binary number system  Add the prefix 0b or 0B to the number9
  11. 11. Underscores in Numeric Literals How much is 10000000000? And now 10_000_000_000? You can place underscores only between digits; you cannot place underscores in the following places: At the beginning or end of a number Adjacent to a decimal point in a floating point literal Prior to an F or L suffix In positions where a string of digits is expected10
  12. 12. Simplified vararg methods invocation Heap Pollution  Non-reifiable types  parameterized types, such as ArrayList<Number> and List<String>  Occurs when a variable of a parameterized type refers to an object that is not of that parameterized type  During type erasure, the types ArrayList<Number> and List<String> become ArrayList and List, respectively. In JDK 1.7  @SafeVarargs has been introduced to suppress such exception.11
  13. 13. vararg methods invocation Contd.12
  14. 14. Project Coin – Design complexity vs Implementation Effort13
  15. 15. Project Coin support in IDEs  Pick an IDE, any IDE IntelliJ IDEA 10.5 and later http://blogs.jetbrains.com/idea/2011/02/announcin g-intellij-idea-105-with-full-java-7-support/ Eclipse 3.7.1 and later http://www.eclipse.org/jdt/ui/r3_8/Java7news/what s-new-java-7.html NetBeans 7.0 and later http://netbeans.org/kb/docs/java/javase-jdk7.html14
  16. 16. NIO.2 Navigation Helpers  Two key navigation Helper Types: Class java.nio.file.Paths Exclusively static methods to return a Path by converting a string or Uniform Resource Identifier (URI) Interface java.nio.file.Path Used for objects that represent the location of a file in a file system, typically system dependent. Typical use case: Use Paths to get a Path. Use Files to do stuff.15
  17. 17. NIO.2 Features –Files Helper Class  Class java.nio.file.Files  Exclusively static methods to operate on files, directories and other types of files Files helper class is feature rich: Copy Create Directories Create Files Create Links Use of system “temp” directory Delete Attributes –Modified/Owner/Permissions/Size, etc. Read/Write  Files.move(src, dst);  Files.copy(src, dst,StandardCopyOption.COPY_ATTRIBUTES, StandardCopyOption.REPLACE_EXISTING);16
  18. 18. NIO.2 Directories  Directory support in NIO.2 using DirectoryStream  Uses less resources  Smooth out response time for remote file systems  Implements Iterable and Closeable for productivity17
  19. 19. NIO.2 Symbolic Links  Path and Files are “link aware”.  One could create symbolic link or hard link from one path to another.18
  20. 20. NIO.2 Walking A File TreeA FileVisitor interface makes walking a file tree for search, or performing actions. SimpleFileVisitor implements preVisitDirectory(T dir, BasicFileAttributes attrs); visitFile(T dir, BasicFileAttributes attrs); visitFileFailed(T dir, IOException exc); postVisitDirectory(T dir, IOException exc);19
  21. 21. NIO.2 Watching A Directory  Create a WatchService “watcher” for the filesystem Register a directory with the watcher “Watcher” can be polled or waited on for eventsEvents raised in the form of Keys Retrieve the Key from the Watcher Key has filename and events within it for create/delete/modify Ability to detect event overflows20
  22. 22. NIO.2 many more… Custom FileSystems Provider registration method may depend on JSR-277 Provider is a factory for FileSystem, FileRef and FileChannel objects Need not be tied to a “real” filesystem Zip file, CD-ROM image, ram disk, flash rom, etc Multiple/alternate views of same underlying files Hide sensitive files, read-only views, path munging, etc Filesystem provider for zip/jar archives Asynchronous I/O Buffers, Sockets and File I/O Mostly small additions for completeness Multicast is the big new feature21
  23. 23. Concurrency and Collections updates platform-independent parallel speed-ups of computation-intensive operations not a full substitute for the kinds of arbitrary processing supported by Executors or Threads provide significantly greater performance on multiprocessor platforms22
  24. 24. Concurrency: Recursive Taskexample23
  25. 25. Concurrency: Recursive Task example Cont.24
  26. 26. Performance - JDK 7 The JDK 7 delivers quite a speed boost over JDK 6 array accesses25
  27. 27. More features of Java SE 7 Support for dynamically-typed languages (InvokeDynamic) Concurrency and collections updates SCTP (Stream Control Transmission Protocol) SDP (Sockets Direct Protocol) JDBC 4.1 Enhanced Mbeans Update the XML stack client XRender pipeline for Java 2D Create new platform APIs for 6u10 graphics features Nimbus look-and-feel for Swing Swing JLayer component Gervill sound synthesizer  and few more… JavaDoc Improvements CSS for JavaDoc -stylesheet.css26
  28. 28. Java SE 8  Due to land Spring / Summer 2013 Main Features Lambdas (aka Closures) New Date and Time APIs Jigsaw (modularisation) Also: Type Annotations Coin Part 2 Ongoing work to merge VMs Getting rid of PermGen27
  29. 29. Java SE 8 Cont. Creating collections like Arrays and Index based access Advanced Example Creating immutable collection28
  30. 30. References for resources  JDK 7 features:  http://openjdk.java.net/projects/jdk7/features/  http://www.oracle.com/technetwork/java/javase/jdk7-relnotes- 418459.html  Project coin:  http://docs.oracle.com/javase/7/docs/technotes/guides/language/ enhancements.html#javase7  Support for Dynamically Typed Languages in the Java Virtual Machine  http://java.sun.com/developer/technicalArticles/DynTypeLang/  NIO.2  http://docs.oracle.com/javase/7/docs/technotes/guides/io/enhanc ements.html#729
  31. 31. References for JDK8  Project Lambda http://openjdk.java.net/projects/lambda/  Project Lambda: Straw-Man Proposal http://cr.openjdk.java.net/~mr/lambda/straw-man/30
  32. 32. Java 7 New Features Questions?31

×