Thursday, 29 May 2014

JAVA SE 7 Features

JAVA SE 7 Features



  1. Switch Statement supports String Literal
  2. Diamond Operator
  3. ARM with Try-With-Resource block
  4. Multi-Catch Exception
  5. Suppressed Exceptions
  6. Number Formatting Enhancement
  7. Binary Literals
  8. Integer.compare()
  9. @SafeVarargs annotation
  10. ClassLoader Improvements
  11. Collection API Improvements: LinkedTransferQueue
  12. Concurrent Utils Improvements
  13. java.util.concurrent.ConcurrentLinkedDeque
  14. java.util.concurrent.ThreadLocalRandom
  15. Java 7 Concurrency API: Phaser
  16. Fork/Join Framework
  17. JDBC 4.1
  18. NIO 2.0

Now we'll discuss each topic in detail.


Integer.compare()


java.lang.Integer

public static int compare(int first,int second)

The value 0 if first == second
The value less than 0 if first < second
the value greater than 0 if first > second


Example:-

public class LengthComparator implements Comparator<String>
{
public int compare(String first, String second)
{
return Integer.compare(first.length(),second.length());
}
}


Arrays.sort(strArray,new LengthComparator());