Tossing the Project Coin!   Marimuthu Rajagopal
Java Version History Language Enhancement Version Release Date Language Enhancement JDK 1.0 Jan 23, 1996 (Initial Release)Oak JDK 1.1 Feb 19,1997 Inner Class ,Reflection,JavaBeans,JDBC,RMI J2SE 1.2 Dec 8, 1998 Strictfp, Collection frame work J2SE 1.3 May 8,2000 Hotspot JVM,JNDI,JPDA J2SE 1.4 Feb 6,2002 Assert, Regular expression,exception chaining. J2SE 1.5 Sep 30,2004 Generics,annotation,auto  boxing,Enumeration,Var  args,for each,staticimport Java SE 6 Dec 11,2006 Scripting  Language Support,Performance Improvement Java SE 7 July 07,2011 String in Switch Binary literal & Underscore in literal Multi-Catch  and More precise rethrow. Try-with-Resources statement(ARM). Diamond Operator Improved compiler warnings and Errors (Simplified varargs method invocation)  Java SE 8 Lambda expression(Clousers)
Java 7 Language Enhancement(Project Coin) JSR 334 “ Project Coin is a suite of language and library Changes to make things programmers do every day easier”. Coin, n. A piece of small change Coin, v. To create new language Joseph D.Darcy’s –Lead (http://blogs.oracle.com/darcy )
Java 7 Language Enhancement(Project Coin) JSR 334 Readability & Consistency  String in Switch Binary literal & Underscore in literal Very short error & resource handling Multi-Catch and More precise rethrow. Try-with-Resources statement(ARM). Generics Diamond Operator Improved compiler warnings for Varargs
String in Switch String object in the expression of a switch statement Included in definition of the constant expression Using hashcode and equals NetBeans 7.0: Nested else if -> Switch Case. http://download.java.net/jdk7/docs/technotes/guides/language/strings-switch.html   http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#15.28  http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#5313
String in Switch Java 6 and Prior public static String getTypeOfDayWithSwitchStatement(String dayOfWeekArg) { String typeOfDay="";  if(dayOfWeekArg.equals("Monday")) typeOfDay="Start of Work week"; else if(dayOfWeekArg.equals("Tuesday")|| dayOfWeekArg.equals("Wednesday")|| dayOfWeekArg.equals("Thursday")) typeOfDay="Midweek"; else if(dayOfWeekArg.equals("Friday")) typeOfDay="End of work week"; else if(dayOfWeekArg.equals("Saturday")|| dayOfWeekArg.equals("Sunday")) typeOfDay="Week off"; else typeOfDay="Invalid day"; return typeOfDay; } http://download.java.net/jdk7/docs/technotes/guides/language/strings-switch.html
String in Switch Java 7 public static String getTypeOfDayWithSwitchStatement(String dayOfWeekArg) { String typeOfDay="";  switch (dayOfWeekArg) { case "Monday": typeOfDay="Start of Work week"; break; case "Tuesday": case "Wednesday": case "Thursday": typeOfDay="Midweek"; break; case "Friday": typeOfDay="End of work week"; break; case "Saturday": case "Sunday": typeOfDay="Week off"; break; default: typeOfDay="Invalid day"; break; } return typeOfDay;  } http://download.java.net/jdk7/docs/technotes/guides/language/strings-switch.html
Binary literal & Underscore in literal Improve readability Existing literals  (0-Oct,0x-Hex) ‏ New Literal : (0b/0B-Binary all primitive data type and Wrapper class Byte,Short,Integer,Long ) ‏ Underscore :  Long  UID=1234_1234_1234;        int rs=10_000; http://download.java.net/jdk7/docs/technotes/guides/language/binary-literals.html http://download.java.net/jdk7/docs/technotes/guides/language/underscores-literals.html
Binary literal & Underscore in literal Binary Literal Sample  int binary= 0b 10000; int oct= 0 20; int hex= 0x 10;  output: 16 Underscore in literal: UID=1234_1234_1234; place underscores only between digits. Invalid Place At the beginning or end of a number(int x1 = _52;int x3 = 52_;) ‏ Adjacent to a decimal point in a floating point literal(float pi1 = 3_.1415F;float pi2 = 3._1415F;) ‏ Prior to an F or L suffix(long socialSecurityNumber1 = 999_99_9999_L) ‏ In positions where a string of digits is expected(int x5 = 0_x52;) ‏ public class BinaryLiteral { public static void main(String arg[]) { int anInt2 = 0b10_1; System.out.println(anInt2); } }
Multi-Catch and More precise rethrow. Reduce code duplication Single catch block handle more than one Exception (|) ‏ Try{} catch(NullPointerException|ArrayIndexOutOfBoundsException  exception ) {} Catch parameter( exception)  become implicitly final. Generated Byte code size is less. http://download.java.net/jdk7/docs/technotes/guides/language/catch-multiple.html
Multi-Catch. Java 6 and Prior   try{ // Method method=Object.class.getMethod("toString"); final Class[] ARG_TYPE=new Class[]{String.class}; Method method=Integer.class.getMethod("parseInt",ARG_TYPE); Object result=method.invoke(null,new Object[]{new String("44")}); System.out.println("result:"+result.toString()); } catch(NoSuchMethodException e) { e.printStackTrace(); }catch(IllegalAccessException e) { e.printStackTrace(); } catch(InvocationTargetException e) { e.printStackTrace(); }
Multi-Catch. Java 7 try{ // Method method=Object.class.getMethod("toString"); final Class[] ARG_TYPE=new Class[]{String.class}; Method method=Integer.class.getMethod("parseInt",ARG_TYPE); Object result=method.invoke(null,new Object[]{new String("44")}); System.out.println("result:"+result.toString()); } catch( NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { e.printStackTrace(); }
More precise rethrow. Java 6 and Prior public static void precise() throws NoSuchMethodException, IllegalAccessException { try{ // Method method=Object.class.getMethod("toString"); final Class[] ARG_TYPE=new Class[]{String.class}; Method method=Integer.class.getMethod("parseInt",ARG_TYPE); Object result=method.invoke(null,new Object[]{new String("44")}); System.out.println("result:"+result.toString()); } catch(Exception e) { throw  new NoSuchMethodException(); } }
More precise rethrow. Java 7 public static void precise() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { try{ // Method method=Object.class.getMethod("toString"); final Class[] ARG_TYPE=new Class[]{String.class}; Method method=Integer.class.getMethod("parseInt",ARG_TYPE); Object result=method.invoke(null,new Object[]{new String("44")}); System.out.println("result:"+result.toString()); } catch(ReflectiveOperationException e) { throw e; } }
Try-with-Resources statement. Automatic Resource Management(ARM) ‏ Try statement declares one or more resources(object) ‏ Declared resource will be closed end of the statement. Any object implements AutoCloseable eligible for resource. Syntax:  try ResourceSpecification Block  Catchesopt   Finallyopt  http://download.java.net/jdk7/docs/technotes/guides/language/catch-multiple.html
Try-with-Resources statement. Java 6 and Prior static void jdk16writeFile(String path)  { BufferedWriter bw = null; try  { bw=new BufferedWriter(new FileWriter(path)); bw.write("JDK1.6 Need to close resource manualy."); }catch(IOException e) { e.printStackTrace(); } finally { try { bw.close(); } catch (IOException ex) { ex.printStackTrace(); } } }
Try-with-Resources statement. Java 7 static void jdk17writeFile(String path) { try (BufferedWriter bw = new BufferedWriter(new FileWriter(path))) { bw.write("Welcome to JDK1.7 Try with resource concept"); } catch(IOException ex) ‏ { System.out.println("ex"+ex); } }
Diamond Operator(Type Inference for Generic Instance Creation) ‏ Replace type Argument with empty set of Parameter(<>) ‏ Jdk1.6 List<String> userList=new ArrayList<String>(); Jdk1.7 List<String> userList=new ArrayList<>(); userList.addAll(new ArrayList<>());//Failed http://download.java.net/jdk7/docs/technotes/guides/language/catch-multiple.html
Diamond Operator(Type Inference for Generic Instance Creation) ‏ In Java 6 and Prior List<String> jvmLanguages=new ArrayList<String>(); In Java 7 List<String> jvmLanguages=new ArrayList<>(); jvmLanguages.add(&quot;Groovy&quot;); jvmLanguages.add(&quot;Scala&quot;); System.out.println(jvmLanguages); Type Inference List<?> typeinference=new ArrayList<> ();
Improved compiler warnings for Varargs Summary :no longer receive uninformative unchecked compiler warning from calling platform library methods. Uses: @SafeVarargs @SuppressWarning({“unchecked”,”varargs”); does not suppress warning generated from method call. -<T> List<T> Arrays.asList<T… a> -<T> boolean Collection.addAll(Collection<? Super T> c,T… elements)
Thank you Q&A    e-mail :muthu.svm@gmail.com  blog :http://microtechinfo.blogspot.com

Project Coin

  • 1.
      Tossing theProject Coin!   Marimuthu Rajagopal
  • 2.
    Java Version HistoryLanguage Enhancement Version Release Date Language Enhancement JDK 1.0 Jan 23, 1996 (Initial Release)Oak JDK 1.1 Feb 19,1997 Inner Class ,Reflection,JavaBeans,JDBC,RMI J2SE 1.2 Dec 8, 1998 Strictfp, Collection frame work J2SE 1.3 May 8,2000 Hotspot JVM,JNDI,JPDA J2SE 1.4 Feb 6,2002 Assert, Regular expression,exception chaining. J2SE 1.5 Sep 30,2004 Generics,annotation,auto boxing,Enumeration,Var args,for each,staticimport Java SE 6 Dec 11,2006 Scripting Language Support,Performance Improvement Java SE 7 July 07,2011 String in Switch Binary literal & Underscore in literal Multi-Catch and More precise rethrow. Try-with-Resources statement(ARM). Diamond Operator Improved compiler warnings and Errors (Simplified varargs method invocation) Java SE 8 Lambda expression(Clousers)
  • 3.
    Java 7 LanguageEnhancement(Project Coin) JSR 334 “ Project Coin is a suite of language and library Changes to make things programmers do every day easier”. Coin, n. A piece of small change Coin, v. To create new language Joseph D.Darcy’s –Lead (http://blogs.oracle.com/darcy )
  • 4.
    Java 7 LanguageEnhancement(Project Coin) JSR 334 Readability & Consistency String in Switch Binary literal & Underscore in literal Very short error & resource handling Multi-Catch and More precise rethrow. Try-with-Resources statement(ARM). Generics Diamond Operator Improved compiler warnings for Varargs
  • 5.
    String in SwitchString object in the expression of a switch statement Included in definition of the constant expression Using hashcode and equals NetBeans 7.0: Nested else if -> Switch Case. http://download.java.net/jdk7/docs/technotes/guides/language/strings-switch.html http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#15.28 http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#5313
  • 6.
    String in SwitchJava 6 and Prior public static String getTypeOfDayWithSwitchStatement(String dayOfWeekArg) { String typeOfDay=&quot;&quot;; if(dayOfWeekArg.equals(&quot;Monday&quot;)) typeOfDay=&quot;Start of Work week&quot;; else if(dayOfWeekArg.equals(&quot;Tuesday&quot;)|| dayOfWeekArg.equals(&quot;Wednesday&quot;)|| dayOfWeekArg.equals(&quot;Thursday&quot;)) typeOfDay=&quot;Midweek&quot;; else if(dayOfWeekArg.equals(&quot;Friday&quot;)) typeOfDay=&quot;End of work week&quot;; else if(dayOfWeekArg.equals(&quot;Saturday&quot;)|| dayOfWeekArg.equals(&quot;Sunday&quot;)) typeOfDay=&quot;Week off&quot;; else typeOfDay=&quot;Invalid day&quot;; return typeOfDay; } http://download.java.net/jdk7/docs/technotes/guides/language/strings-switch.html
  • 7.
    String in SwitchJava 7 public static String getTypeOfDayWithSwitchStatement(String dayOfWeekArg) { String typeOfDay=&quot;&quot;; switch (dayOfWeekArg) { case &quot;Monday&quot;: typeOfDay=&quot;Start of Work week&quot;; break; case &quot;Tuesday&quot;: case &quot;Wednesday&quot;: case &quot;Thursday&quot;: typeOfDay=&quot;Midweek&quot;; break; case &quot;Friday&quot;: typeOfDay=&quot;End of work week&quot;; break; case &quot;Saturday&quot;: case &quot;Sunday&quot;: typeOfDay=&quot;Week off&quot;; break; default: typeOfDay=&quot;Invalid day&quot;; break; } return typeOfDay; } http://download.java.net/jdk7/docs/technotes/guides/language/strings-switch.html
  • 8.
    Binary literal &Underscore in literal Improve readability Existing literals (0-Oct,0x-Hex) ‏ New Literal : (0b/0B-Binary all primitive data type and Wrapper class Byte,Short,Integer,Long ) ‏ Underscore : Long UID=1234_1234_1234;       int rs=10_000; http://download.java.net/jdk7/docs/technotes/guides/language/binary-literals.html http://download.java.net/jdk7/docs/technotes/guides/language/underscores-literals.html
  • 9.
    Binary literal &Underscore in literal Binary Literal Sample int binary= 0b 10000; int oct= 0 20; int hex= 0x 10; output: 16 Underscore in literal: UID=1234_1234_1234; place underscores only between digits. Invalid Place At the beginning or end of a number(int x1 = _52;int x3 = 52_;) ‏ Adjacent to a decimal point in a floating point literal(float pi1 = 3_.1415F;float pi2 = 3._1415F;) ‏ Prior to an F or L suffix(long socialSecurityNumber1 = 999_99_9999_L) ‏ In positions where a string of digits is expected(int x5 = 0_x52;) ‏ public class BinaryLiteral { public static void main(String arg[]) { int anInt2 = 0b10_1; System.out.println(anInt2); } }
  • 10.
    Multi-Catch and Moreprecise rethrow. Reduce code duplication Single catch block handle more than one Exception (|) ‏ Try{} catch(NullPointerException|ArrayIndexOutOfBoundsException exception ) {} Catch parameter( exception) become implicitly final. Generated Byte code size is less. http://download.java.net/jdk7/docs/technotes/guides/language/catch-multiple.html
  • 11.
    Multi-Catch. Java 6and Prior try{ // Method method=Object.class.getMethod(&quot;toString&quot;); final Class[] ARG_TYPE=new Class[]{String.class}; Method method=Integer.class.getMethod(&quot;parseInt&quot;,ARG_TYPE); Object result=method.invoke(null,new Object[]{new String(&quot;44&quot;)}); System.out.println(&quot;result:&quot;+result.toString()); } catch(NoSuchMethodException e) { e.printStackTrace(); }catch(IllegalAccessException e) { e.printStackTrace(); } catch(InvocationTargetException e) { e.printStackTrace(); }
  • 12.
    Multi-Catch. Java 7try{ // Method method=Object.class.getMethod(&quot;toString&quot;); final Class[] ARG_TYPE=new Class[]{String.class}; Method method=Integer.class.getMethod(&quot;parseInt&quot;,ARG_TYPE); Object result=method.invoke(null,new Object[]{new String(&quot;44&quot;)}); System.out.println(&quot;result:&quot;+result.toString()); } catch( NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { e.printStackTrace(); }
  • 13.
    More precise rethrow.Java 6 and Prior public static void precise() throws NoSuchMethodException, IllegalAccessException { try{ // Method method=Object.class.getMethod(&quot;toString&quot;); final Class[] ARG_TYPE=new Class[]{String.class}; Method method=Integer.class.getMethod(&quot;parseInt&quot;,ARG_TYPE); Object result=method.invoke(null,new Object[]{new String(&quot;44&quot;)}); System.out.println(&quot;result:&quot;+result.toString()); } catch(Exception e) { throw new NoSuchMethodException(); } }
  • 14.
    More precise rethrow.Java 7 public static void precise() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { try{ // Method method=Object.class.getMethod(&quot;toString&quot;); final Class[] ARG_TYPE=new Class[]{String.class}; Method method=Integer.class.getMethod(&quot;parseInt&quot;,ARG_TYPE); Object result=method.invoke(null,new Object[]{new String(&quot;44&quot;)}); System.out.println(&quot;result:&quot;+result.toString()); } catch(ReflectiveOperationException e) { throw e; } }
  • 15.
    Try-with-Resources statement. AutomaticResource Management(ARM) ‏ Try statement declares one or more resources(object) ‏ Declared resource will be closed end of the statement. Any object implements AutoCloseable eligible for resource. Syntax: try ResourceSpecification Block Catchesopt Finallyopt http://download.java.net/jdk7/docs/technotes/guides/language/catch-multiple.html
  • 16.
    Try-with-Resources statement. Java6 and Prior static void jdk16writeFile(String path) { BufferedWriter bw = null; try { bw=new BufferedWriter(new FileWriter(path)); bw.write(&quot;JDK1.6 Need to close resource manualy.&quot;); }catch(IOException e) { e.printStackTrace(); } finally { try { bw.close(); } catch (IOException ex) { ex.printStackTrace(); } } }
  • 17.
    Try-with-Resources statement. Java7 static void jdk17writeFile(String path) { try (BufferedWriter bw = new BufferedWriter(new FileWriter(path))) { bw.write(&quot;Welcome to JDK1.7 Try with resource concept&quot;); } catch(IOException ex) ‏ { System.out.println(&quot;ex&quot;+ex); } }
  • 18.
    Diamond Operator(Type Inferencefor Generic Instance Creation) ‏ Replace type Argument with empty set of Parameter(<>) ‏ Jdk1.6 List<String> userList=new ArrayList<String>(); Jdk1.7 List<String> userList=new ArrayList<>(); userList.addAll(new ArrayList<>());//Failed http://download.java.net/jdk7/docs/technotes/guides/language/catch-multiple.html
  • 19.
    Diamond Operator(Type Inferencefor Generic Instance Creation) ‏ In Java 6 and Prior List<String> jvmLanguages=new ArrayList<String>(); In Java 7 List<String> jvmLanguages=new ArrayList<>(); jvmLanguages.add(&quot;Groovy&quot;); jvmLanguages.add(&quot;Scala&quot;); System.out.println(jvmLanguages); Type Inference List<?> typeinference=new ArrayList<> ();
  • 20.
    Improved compiler warningsfor Varargs Summary :no longer receive uninformative unchecked compiler warning from calling platform library methods. Uses: @SafeVarargs @SuppressWarning({“unchecked”,”varargs”); does not suppress warning generated from method call. -<T> List<T> Arrays.asList<T… a> -<T> boolean Collection.addAll(Collection<? Super T> c,T… elements)
  • 21.
    Thank you Q&A   e-mail :muthu.svm@gmail.com blog :http://microtechinfo.blogspot.com