Your SlideShare is downloading. ×
0
Java7 - Top 10 Features
Java7 - Top 10 Features
Java7 - Top 10 Features
Java7 - Top 10 Features
Java7 - Top 10 Features
Java7 - Top 10 Features
Java7 - Top 10 Features
Java7 - Top 10 Features
Java7 - Top 10 Features
Java7 - Top 10 Features
Java7 - Top 10 Features
Java7 - Top 10 Features
Java7 - Top 10 Features
Java7 - Top 10 Features
Java7 - Top 10 Features
Java7 - Top 10 Features
Java7 - Top 10 Features
Java7 - Top 10 Features
Java7 - Top 10 Features
Java7 - Top 10 Features
Java7 - Top 10 Features
Java7 - Top 10 Features
Java7 - Top 10 Features
Java7 - Top 10 Features
Java7 - Top 10 Features
Java7 - Top 10 Features
Java7 - Top 10 Features
Java7 - Top 10 Features
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Java7 - Top 10 Features

9,126

Published on

My top 10 features in Java SE 7

My top 10 features in Java SE 7

Published in: Technology, News & Politics
2 Comments
11 Likes
Statistics
Notes
  • what is the procedure to download the slides......i can't download it
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Thanks for the Java 7 features and you can solved examples here - www.javadiscover.blogspot.com/search/label/Java%207
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total Views
9,126
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
220
Comments
2
Likes
11
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Java SE 7 {finally} <br />2011-08-18<br />Andreas Enbohm<br />
  • 2. 19 augusti 2011<br />Sida 2<br />Java SE 7<br />A evolutionaryevolement of Java<br />6 yearssince last update<br />Somethingsleftout, will briefly discuss this at the end<br />Oracle reallypushing Java forward- a lotpolitical problems with Sun made Java 7 postphonedseveraltimes<br />Java still growing (1.42%), #1 mostusedlanguageaccording to TIOBE with 19.4% (Aug 2011)<br />My top 10 new features (not ordered in anyway)<br />
  • 3. Java SE 7 – Language Changes<br />Number 1:Try-with-resources Statement (or ARM-blocks)<br />Before :<br />19 augusti 2011<br />Sida 3<br />static String readFirstLineFromFileWithFinallyBlock(String path) throwsIOException {<br />BufferedReaderbr = new BufferedReader(new FileReader(path));<br /> try {<br />returnbr.readLine();<br /> } finally {<br />if (br != null) {<br /> try {<br />br.close();<br /> } catch (IOExceptionignore){ <br /> //donothing<br /> }<br /> }<br /> }<br />}<br />
  • 4. Java SE 7 – Language Changes<br />Number 1:Try-with-resources Statement (or ARM-blocks)<br />With Java 7:<br />19 augusti 2011<br />Sida 4<br />static String readFirstLineFromFile(String path) throws IOException { <br /> try (BufferedReaderbr = new BufferedReader(new FileReader(path))) { <br /> return br.readLine(); <br /> } <br />} <br />
  • 5. Java SE 7 – Language Changes<br />Number 1 - NOTE:<br />The try-with-resources statement is a try statement that declares one or more resources. A resource is as an object that must be closed after the program is finished with it. <br />The try-with-resources statement ensures that each resource is closed at the end of the statement. <br />Any object that implements java.lang.AutoCloseable, which includes all objects which implement java.io.Closeable, can be used as a resource.<br />19 augusti 2011<br />Sida 5<br />
  • 6. Java SE 7 – Language Changes<br />Number 2: Strings in switch Statements<br />19 augusti 2011<br />Sida 6<br />public String getTypeOfDayWithSwitchStatement(String dayOfWeekArg) {<br /> String typeOfDay;<br /> switch (dayOfWeekArg) {<br /> case "Monday":<br />typeOfDay = "Start of work week";<br /> break;<br /> case "Tuesday":<br /> case "Wednesday":<br /> case "Thursday":<br />typeOfDay = "Midweek";<br /> break;<br /> case "Friday":<br />typeOfDay = "End of work week";<br /> break;<br /> case "Saturday":<br /> case "Sunday":<br />typeOfDay = "Weekend";<br /> break;<br /> default:<br /> throw new IllegalArgumentException("Invalid day of the week: " + dayOfWeekArg);<br /> }<br /> return typeOfDay;<br />}<br />
  • 7. Java SE 7 – Language Changes<br />Number 2 - NOTE:<br />The Java compiler generates generally more efficient bytecode from switch statements that use String objects than from chained if-then-else statements.<br />19 augusti 2011<br />Sida 7<br />
  • 8. Java SE 7 – Language Changes<br />Number 3:Catching Multiple ExceptionTypes<br />Before : <br />Difficult to eliminatecodeduplicationdue to different exceptions!<br />19 augusti 2011<br />Sida 8<br />try {<br /> …<br />} catch (IOException ex) { <br />logger.log(ex); <br />throw ex; <br />} catch (SQLException ex) { <br />logger.log(ex); <br />throw ex; <br />}<br />
  • 9. Java SE 7 – Language Changes<br />Number 3:Catching Multiple ExceptionTypes<br />With Java 7 :<br />19 augusti 2011<br />Sida 9<br />try {<br /> …<br />} catch (IOException|SQLException ex) { <br />logger.log(ex); <br />throw ex; <br />}<br />
  • 10. Java SE 7 – Language Changes<br />Number 3 - NOTE:Catching Multiple ExceptionTypes<br />Bytecode generated by compiling a catch block that handles multiple exception types will be smaller (and thus superior) than compiling many catch blocks that handle only one exception type each. <br />19 augusti 2011<br />Sida 10<br />
  • 11. Java SE 7 – Language Changes<br />Number 4:TypeInference for GenericInstance Creation<br />Before: <br />Howmanytimeshave you swornabout this duplicatedcode? <br />19 augusti 2011<br />Sida 11<br />Map<String, List<String>> myMap = new HashMap<String, List<String>>();<br />
  • 12. Java SE 7 – Language Changes<br />Number 4:TypeInference for GenericInstance Creation<br />With Java 7: <br />19 augusti 2011<br />Sida 12<br />Map<String, List<String>> myMap = new HashMap<>();<br />
  • 13. Java SE 7 – Language Changes<br />Number 4 - NOTE:TypeInference for GenericInstance Creation<br />Writing new HashMap() (withoutdiamond operator) will still use the rawtype of HashMap (compilerwarning)<br />19 augusti 2011<br />Sida 13<br />
  • 14. Java SE 7 – Language Changes<br />Number 5:Underscores in NumericLiterals<br />19 augusti 2011<br />Sida 14<br />longcreditCardNumber = 1234_5678_9012_3456L; <br />longsocialSecurityNumber = 1977_05_18_3312L; <br />float pi = 3.14_15F; <br />longhexBytes = 0xFF_EC_DE_5E; <br />longhexWords = 0xCAFE_BABE; <br />longmaxLong = 0x7fff_ffff_ffff_ffffL; <br />long bytes = 0b11010010_01101001_10010100_10010010;<br />
  • 15. Java SE 7 – Language Changes<br />Number 5 - NOTE:Underscores in NumericLiterals<br />You can place underscores only between digits; you cannot place underscores in the following places:<br />At the beginning or end of a number<br />Adjacent to a decimal point in a floating point literal<br />Prior to an F or L suffix <br />In positions where a string of digits is expected<br />19 augusti 2011<br />Sida 15<br />
  • 16. Java SE 7 – ConcurrentUtilities<br />Number 6:Fork/JoinFramework (JSR 166)<br />” a lightweightfork/joinframework with flexible and reusablesynchronizationbarriers, transfer queues, concurrent linked double-endedqueues, and thread-localpseudo-random-number generators.”<br />19 augusti 2011<br />Sida 16<br />
  • 17. Java SE 7 – ConcurrentUtilities<br />Number 6:Fork/JoinFramework (JSR 166)<br />19 augusti 2011<br />Sida 17<br />if (my portion of the work is small enough)<br /> do the work directly <br />else <br /> split my work into two pieces invoke the two pieces and wait for the results<br />
  • 18. Java SE 7 – ConcurrentUtilities<br />Number 6:Fork/JoinFramework (JSR 166)<br />19 augusti 2011<br />Sida 18<br />
  • 19. Java SE 7 – ConcurrentUtilities<br />Number 6:Fork/JoinFramework (JSR 166)<br />New Classes<br /><ul><li>ForkJoinTask
  • 20. RecursiveTask
  • 21. RecursiveAction
  • 22. ThreadLocalRandom
  • 23. ForkJoinPool</li></ul>19 augusti 2011<br />Sida 19<br />
  • 24. Java SE 7 – Filesystem API<br />Number 7: NIO 2 Filesystem API (Non-Blocking I/O)<br />Bettersupports for accessingfile systems such and support for customfile systems (e.g. cloudfile systems)<br />Access to metadata such as file permissions<br />Moreeffecient support whencopy/movingfiles<br />EnchancedExceptionswhenworking on files, i.e. file.delete() nowthrowsIOException (not just Exception)<br />19 augusti 2011<br />Sida 20<br />
  • 25. Java SE 7 – JVM Enhancement<br />Number 8:InvokeDynamic (JSR292)<br />Support for dynamiclanguages so theirperformance levels is near to that of the Java language itself<br />At byte code level this means a new operand (instruction) called invokedynamic<br />Make is possible to do efficient method invocation for dynamic languages (such as JRuby) instead of statically (like Java) .<br />Huge performance gain <br />19 augusti 2011<br />Sida 21<br />
  • 26. Java SE 7 – JVM Enhancement<br />Number 9: G1 and JVM optimization<br />G1 morepredictable and uses multiple coresbetterthan CMS<br />Tiered Compilation –Bothclient and server JIT compilers are usedduringstarup<br />NUMA optimization - Parallel Scavenger garbage collector has been extended to take advantage of machines with NUMA (~35% performance gain)<br />EscapeAnalysis - analyze the scope of a new object's and decide whether to allocate it on the Java heap<br />19 augusti 2011<br />Sida 22<br />
  • 27. Java SE 7 – JVM Enhancement<br />Number 9:EscapeAnalysis<br />19 augusti 2011<br />Sida 23<br />public class Person { <br /> private String name; private int age; <br /> public Person(String personName, intpersonAge) { <br />name = personName; age = personAge; } <br /> public Person(Person p) { <br /> this(p.getName(), p.getAge()); <br /> }<br />} <br />public classEmployee { <br /> private Person person; // makes a defensive copy to protectagainstmodifications by caller<br /> public Person getPerson() { <br />return new Person(person) <br /> }; <br />public voidprintEmployeeDetail(Employeeemp) { <br /> Person person = emp.getPerson(); // this callerdoes not modify the object, so defensive copywasunnecessary<br />System.out.println ("Employee'sname: " + person.getName() + "; age: " + person.getAge()); } <br />}<br />
  • 28. Java SE 7 - Networking<br />Number 10: Support for SDP <br />SocketDirectProtocol (SDP) enablesJVMs to use Remote Direct Memory Access (RDMA). RDMA enables moving data directly from the memory of one computer to another computer, bypassing the operating system of both computers and resulting in significant performance gains. <br />The result is High throughput and Low latency (minimal delay between processing input and providing output) such as you would expect in a real-time application. <br />19 augusti 2011<br />Sida 24<br />
  • 29. Java SE 7 - Networking<br />Number 10 - NOTE: Support for SDP<br />The Sockets Direct Protocol (SDP) is a networking protocol developed to support stream connections over InfiniBand fabric. <br />Solaris 10 5/08 has support for InfiniBand fabric (which enables RDMA). On Linux, the InfiniBand package is called OFED (OpenFabrics Enterprise Distribution). <br />19 augusti 2011<br />Sida 25<br />
  • 30. Java SE 7<br />A complete list of all new features can be seen on http://www.oracle.com/technetwork/java/javase/jdk7-relnotes-418459.html<br />19 augusti 2011<br />Sida 26<br />
  • 31. Java SE 8<br />Some features whereleftout in Java 7; mostimportant are Project Lambda (closures) and Project Jigsaw (modules) targeted for Java 8 (late 2012)<br />Lambdas (and extension methods) willprobably be the biggestsinglechangeevermade on the JVM. Will introduce a powerfulprogrammingmodel, however it comes with a great deal of complexity as well. <br />Moduleswillmade it easier to version modules (no moreJAR-hell) and introducea new way of definingclasspaths<br />19 augusti 2011<br />Sida 27<br />
  • 32. Java SE 7 & 8<br />Questions?<br />19 augusti 2011<br />Sida 28<br />

×