Posts

Showing posts from November, 2013

Java Versions, Features and History

Image
A popular interview question in java is “what is new in Java version X?”. Is that an intelligent question is debatable. I have summarized below important new features added in each major java release till now. I target to highlight important features added in respective release. Apart from below list of features, every release has enhancements and lots of bug fixes. Java Version SE 7 Code named Dolphin and released on July 28, 2011. New features in Java SE 7 Strings in switch Statement Type Inference for Generic Instance Creation Multiple Exception Handling Support for Dynamic Languages Try with Resources Java nio Package Binary Literals, underscore in literals Diamond Syntax Automatic null Handling Java Version SE 6 Code named Mustang and released on December 11, 2006. New features in Java SE 6 Scripting Language Support JDBC 4.0 API Java Compiler API Pluggable Annotations Native PKI, Java ...

Some amazing java features

 Goto initialization; // code goes here   getmeout :{      for ( int i = 0 ; i < N ; ++ i ) {          for ( int j = i ; j < N ; ++ j ) {              for ( int k = j ; k < N ; ++ k ) {                  //do something here                  break getmeout ;              }          }      } } Null Check :  Haven't seen anyone mention instanceof being implemented in such a way that checking for null is not necessary. Instead of: if ( null != aObject && aObject instanceof String ) {      ... } just use: if ( aObject instanceof S...

Double Brace Initialization

Java doesn't have a convenient literal syntax for collections (lists, maps, sets, etc.). This makes creating constant collections or passing collections to functions quite laborious. Every time you have to 1.      Declare a variable for a temporary collection 2.      Create a new empty collection and store a reference to it in the variable 3.      Put things into the collection 4.      Pass the collection to the method E.g. To pass a set to a method:    Set<String> validCodes = new HashSet<String>(); validCodes.add("XZ13s"); validCodes.add("AB21/X"); validCodes.add("YYLEX"); validCodes.add("AR2D"); removeProductsWithCodeIn(validCodes);   Or to initialize a set of constants:   private static final Set<String> VALID_CODES = new HashSet<String>(); static {             ...