Language  New Features – Project Coin – JSR 334
<ul><li>Earlier </li></ul><ul><li>public String getPostalCode(Person person) { </li></ul><ul><li>if (person != null)  { </...
<ul><li>Earlier </li></ul><ul><li>public void process() { </li></ul><ul><li>try { </li></ul><ul><li>} catch (Exception one...
<ul><li>Earlier </li></ul><ul><li>public void writeContent(String fileName, String content)  throws YourException { </li><...
<ul><li>Now </li></ul><ul><li>public void writeContent(String fileName, String content)  throws YourException { </li></ul>...
<ul><li>Earlier </li></ul><ul><li>Map<String,Integer> map = new HashMap<String, Integer>(); </li></ul><ul><li>Now </li></u...
<ul><li>Collections can be used as Arrays e.g. </li></ul><ul><ul><li>List <String> itemList = [“item1”,”item2”]; </li></ul...
<ul><li>You can use switch case for Strings as well. Remember: It will use equals() method for comparison and not equalIgn...
<ul><li>Though not of much use for most of the developers, but still good to mention. 4 key rules to be used with Numeric ...
<ul><ul><li>Valid Examples </li></ul></ul><ul><ul><ul><li>double var1 = 1_23.456D; </li></ul></ul></ul><ul><ul><ul><li>flo...
<ul><li>vm </li></ul><ul><ul><li>Compressed 64-bit object pointers </li></ul></ul><ul><ul><li>Garbage-First GC (G1) </li><...
<ul><li>core </li></ul><ul><ul><li>Upgraded class-loaded architecture </li></ul></ul><ul><ul><li>Method to close a URLClas...
<ul><li>ionet </li></ul><ul><ul><li>JSR 203: More new I/O APIs for the Java platform (NIO.2)NIO.2 file system provider for...
<ul><li>client </li></ul><ul><ul><li>XRender pipeline for Java 2D </li></ul></ul><ul><ul><li>Create new platform APIs for ...
 
Upcoming SlideShare
Loading in …5
×

Java 7

654 views
591 views

Published on

New features introduced in Java 7

Published in: Technology, Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
654
On SlideShare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Java 7

  1. 1. Language New Features – Project Coin – JSR 334
  2. 2. <ul><li>Earlier </li></ul><ul><li>public String getPostalCode(Person person) { </li></ul><ul><li>if (person != null) { </li></ul><ul><li>Address address = person.getAddress(); </li></ul><ul><li>if (address != null) { </li></ul><ul><li>return address.getPostalCode(); </li></ul><ul><li>} </li></ul><ul><li>} </li></ul><ul><li>return null; </li></ul><ul><li>} </li></ul><ul><li>Now </li></ul><ul><li>public String getPostalCode(Person person) { </li></ul><ul><li>return person ? .getAddress() ? . getPostalCode() ; </li></ul><ul><li>} </li></ul><ul><li>Use Null-safe operator ‘?.’ in Java 7. </li></ul>
  3. 3. <ul><li>Earlier </li></ul><ul><li>public void process() { </li></ul><ul><li>try { </li></ul><ul><li>} catch (Exception one) { </li></ul><ul><li>// do something </li></ul><ul><li>} catch (Exception two) { </li></ul><ul><li>// do something else </li></ul><ul><li>} catch (Exception three) { </li></ul><ul><li>// do something </li></ul><ul><li>} </li></ul><ul><li>} </li></ul><ul><li>Now </li></ul><ul><li>public void process() { </li></ul><ul><li>try { </li></ul><ul><li>} catch ( Exception one | Exception three ) { </li></ul><ul><li>// do something </li></ul><ul><li>} catch (Exception two) { </li></ul><ul><li>// do something else </li></ul><ul><li>} </li></ul><ul><li>} </li></ul><ul><li>If in two exception blocks you’re doing same thing you can use ‘|’ operator to join them in java 7. </li></ul>
  4. 4. <ul><li>Earlier </li></ul><ul><li>public void writeContent(String fileName, String content) throws YourException { </li></ul><ul><li>FileOutputStream fileOutputStream = null; </li></ul><ul><li>DataOutputStream dataOutputStream = null; </li></ul><ul><li>try { </li></ul><ul><li>fileOutputStream = new FileOutputStream (fileName); </li></ul><ul><li>dataOutputStream = new DataOutputStream (fileOutputStream ); </li></ul><ul><li>dataOutputStream .writeUTF(content); </li></ul><ul><li>} catch (IOException ioException) { </li></ul><ul><li>throw new YourException(ioException.getMessage(), ioException); </li></ul><ul><li>} finally { </li></ul><ul><li>try { </li></ul><ul><li>if (fileOutputStream != null) { </li></ul><ul><li> fileOutputStream .close(); </li></ul><ul><li>} </li></ul><ul><li>if (dataOutputStream != null) { </li></ul><ul><li>dataOutputStream .close(); </li></ul><ul><li>} </li></ul><ul><li>} catch (IOException ioException) { </li></ul><ul><li>//Log the exception </li></ul><ul><li>} </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>
  5. 5. <ul><li>Now </li></ul><ul><li>public void writeContent(String fileName, String content) throws YourException { </li></ul><ul><li>FileOutputStream fileOutputStream = null; </li></ul><ul><li>DataOutputStream dataOutputStream = null; </li></ul><ul><li>try ( </li></ul><ul><li>fileOutputStream = new FileOutputStream (fileName); </li></ul><ul><li>dataOutputStream = new DataOutputStream (fileOutputStream ); </li></ul><ul><li>) { </li></ul><ul><li>dataOutputStream .writeUTF(content); </li></ul><ul><li>} catch (IOException ioException) { </li></ul><ul><li>throw new YourException(ioException.getMessage(), ioException); </li></ul><ul><li>} </li></ul><ul><li>} </li></ul><ul><li>Look at the content written in brackets after try. All of the open resources are automatically managed. So, no open connections, resultset, file issues  . </li></ul>
  6. 6. <ul><li>Earlier </li></ul><ul><li>Map<String,Integer> map = new HashMap<String, Integer>(); </li></ul><ul><li>Now </li></ul><ul><li>Map<String,Integer> map = new HashMap <> (); </li></ul><ul><li>No need to repeat <String, Integer> again. </li></ul>
  7. 7. <ul><li>Collections can be used as Arrays e.g. </li></ul><ul><ul><li>List <String> itemList = [“item1”,”item2”]; </li></ul></ul><ul><ul><li>String item = itemList[0]; </li></ul></ul><ul><ul><li>Map<String, Integer> map = [“item1”:1,”item2”:2] </li></ul></ul>
  8. 8. <ul><li>You can use switch case for Strings as well. Remember: It will use equals() method for comparison and not equalIgnoreCase() method. </li></ul>
  9. 9. <ul><li>Though not of much use for most of the developers, but still good to mention. 4 key rules to be used with Numeric literals for using underscore: </li></ul><ul><ul><li>Underscores can't go at the beginning or the end of a number. </li></ul></ul><ul><ul><li>You can't use an underscore on either side of a decimal.  </li></ul></ul><ul><ul><li>The underscore cannot go before an identifying suffix such as F, D or L </li></ul></ul><ul><ul><li>You can't put an underscore before or after the binary or hexadecimal identifiers b and x. </li></ul></ul>
  10. 10. <ul><ul><li>Valid Examples </li></ul></ul><ul><ul><ul><li>double var1 = 1_23.456D; </li></ul></ul></ul><ul><ul><ul><li>float var2 = 123.45_6F; </li></ul></ul></ul><ul><ul><ul><li>long var3 = 1010_0101_1010L; </li></ul></ul></ul><ul><ul><ul><li>int hexed = 0xBASE_01; </li></ul></ul></ul><ul><ul><li>Invalid Examples </li></ul></ul><ul><ul><ul><li>double var1 = 123_.456D; </li></ul></ul></ul><ul><ul><ul><li>float var2 = 123.456_F; </li></ul></ul></ul><ul><ul><ul><li>long var3 = 1010_0101_1010_L; </li></ul></ul></ul><ul><ul><ul><li>int hexed = 0_x_BASE_01; </li></ul></ul></ul>
  11. 11. <ul><li>vm </li></ul><ul><ul><li>Compressed 64-bit object pointers </li></ul></ul><ul><ul><li>Garbage-First GC (G1) </li></ul></ul><ul><ul><li>JSR 292: VM support for non-Java languages (InvokeDynamic) </li></ul></ul><ul><ul><li>Strict class file checking </li></ul></ul><ul><li>lang – Project Coin JSR 334 already covered </li></ul>
  12. 12. <ul><li>core </li></ul><ul><ul><li>Upgraded class-loaded architecture </li></ul></ul><ul><ul><li>Method to close a URLClassLoader </li></ul></ul><ul><ul><li>Concurrency and Collections updates </li></ul></ul><ul><li>i18n </li></ul><ul><ul><li>Unicode 6.0 </li></ul></ul><ul><ul><li>Locale enhancemements </li></ul></ul><ul><ul><li>Separate user locale and user-interface locale </li></ul></ul>
  13. 13. <ul><li>ionet </li></ul><ul><ul><li>JSR 203: More new I/O APIs for the Java platform (NIO.2)NIO.2 file system provider for zip/jar archives </li></ul></ul><ul><ul><li>Other platform oriented changes such as SCTP and SDP. </li></ul></ul><ul><li>Sec </li></ul><ul><ul><li>Elliptic-curve cryptography (ECC) </li></ul></ul><ul><li>Jdbc 4.1 </li></ul>
  14. 14. <ul><li>client </li></ul><ul><ul><li>XRender pipeline for Java 2D </li></ul></ul><ul><ul><li>Create new platform APIs for 6u10 graphics features </li></ul></ul><ul><ul><li>Nimbus look-and-feel for Swing </li></ul></ul><ul><ul><li>Swing JLayer component </li></ul></ul><ul><ul><li>Gervill sound synthesizer </li></ul></ul><ul><li>web </li></ul><ul><ul><li>Update the XML stack </li></ul></ul><ul><li>mgmt </li></ul><ul><ul><li>Enhanced Mbeans </li></ul></ul><ul><li>Refer to http://openjdk.java.net/projects/jdk7/features/ for details </li></ul>

×