Java Features JDK 7
Features added in Java7.0 :
The codename of this version is Dolphin. This version was release in 2011,this version bring the following uupdates in the language:Strings in switch : In earlier versions the switch only accepts (int,short,byte,char,enum) and from this version onward String also included in the list.
Example:
class Test { public static void main(String[] ar) { String time = "morning"; switch(time){ case "morning": System.out.print("Good Morning"); break; case "noon": System.out.print("Good AfterNoon"); break; case "night": System.out.print("Good Night"); break; } } }
try with Resource : Automatic resource management in try-statement.Any object that implements java.lang.AutoCloseable , which includes all objects which implement java.io.Closeable , can be used as a resource.
import java.io.*; class Test { public static void main(String[] ar) { try(FileReader f=new FileReader("ab.txt")) { int i; while((i=f.read())!=-1) System.out.print((char)i); } catch(Exception e){ System.err.print(e.getMessage()); } } }
Improved type inference for generic instance creation, the diamond operator <>.
import java.util.*; class Test { public static void main(String[] ar) { ArrayList< String> al; al = new ArrayList<>(); //<> al.add("Albert"); al.add("Bob"); al.add("Peter"); System.out.print(al); } }
Simplified Varargs Method Invocation :
When a programmer tries to invoke a *varargs* (variable arity) method with a non-reifiable varargs type, the compiler currently generates an "unsafe operation" warning. JDK 7 moves the warning from the call site to the method declaration. This will enable API designers to use varargs due to the reduction of warnings reported.
Binary Integer Literal : Java code, due to its C heritage, has traditionally forced programmers to represent numbers in only decimal, octal, or hexadecimal.
As quite a few domains are bit orientated, this restriction can introduce errors. You can now create binary numbers using an 0b prefix.
class Test { public static void main(String[] ar) { int i = 0b101; //binary literal System.out.print(i); //5 } }
Allowing underscores in numeric literals : Long numbers are hard to read. You can now split them up using an underscore in ints and longs.
class Test { public static void main(String[] ar) { int i = 1_000_00; //underscore System.out.print(i); //100000 } }
Catch with Multiple Exception :
Catching multiple exception types and rethrowing exceptions with improved type checking.
class Test { public static void main(String[] ar) { try{ String s=null; s.toUpperCase(); int i = Integer.parseInt(s); } catch(NullPointerException|NumberFormatException e){ System.err.print(e.getMessage()); } } }
New file I/O librar (defined by JSR 203) adding support for multiple file systems, file metadata and symbolic links.
The new packages are java.nio.file, java.nio.file.attribute and java.nio.file.spi.
Enhanced library-level support for new network protocols, including SCTP and Sockets Direct Protocol.
Timsort is used to sort collections and arrays of objects instead of merge sort.
Next topic is java-features-jdk-8
Training For College Campus
We offers college campus training for all streams like CS, IT, ECE, Mechanical, Civil etc. on different technologies
like
C, C++, Data Structure, Core Java, Advance Java, Struts Framework, Hibernate, Python, Android, Big-Data, Ebedded & Robotics etc.
Please mail your requirement at info@prowessapps.in
Projects For Students
Students can contact us for their projects on different technologies Core Java, Advance Java, Android etc.
Students can mail requirement at info@prowessapps.in