Welcome!

Talk is Cheap. Show me the Code!

Sumith Kumar Puri

Subscribe to Sumith Kumar Puri: eMailAlertsEmail Alerts
Get Sumith Kumar Puri via: homepageHomepage mobileMobile rssRSS facebookFacebook twitterTwitter linkedinLinkedIn


Related Topics: Java EE Journal, JavaBlackBelt, Innovations Software Technology, Java Developer Magazine, Java in the Cloud

Blog Post

Revisiting Java SE 7 Features | @CloudExpo #Java #Cloud #OpenSource

A tutorial series on Java as we all eagerly await the official release of Java SE 9

Diamond Syntax (Type Inference for Generics)
Sometimes when we are using generics in an application, we may end up with a long line of code, which may be very confusing or have poor readability. This is because there may be multiple generic types that are used in the same line. To improve upon this, JDK7 introduces the concept of the diamond operator or diamond syntax, where the type of the generic variable is inferred.

public class jdk7_DiamondSyntax {
public static void main(String[] args) {
Map<String, Map<String, List<String>>> list = new HashMap<>();
List<String> aList = new ArrayList<String>();
aList.add("09.10");
aList.add("09.20");
aList.add("09.22");
Map<String,List<String>> iMap = new HashMap<>();
iMap.put("radiac", aList);
list.put("radia", iMap);
}
}<

Binary Literals, Underscore in Literals
Continuing on the aspects of readability for numeric literals, the concept of the underscore is provided to separate numeric literals - like at the thousands place, millions place, hundreds place, etc. Also, Binary Literals are allowed in JDK7, starting with 0b. All types of numeric literals will allow the use of '_'. You have to make sure that '_' is not used as the (before) first or (after) last digit of the numeric literal AND '_' is not used adjacent to the decimal point AND '_' is used before the F or the L suffix.

public class jdk7_Literals {
int million = 100_000_000;
byte b = (byte) 0b0001111111;
short s = (short) 0b111100000000;
int i = 0b11111111111111111111;
public static void main(String[] args) {
jdk7_Literals l = new jdk7_Literals();
System.out.println(l.million); System.out.println(l.b + ":" + l.s + ":" + l.i);
}
}

Happy times with JDK 7!

More Stories By Sumith Kumar Puri

Sumith Kumar Puri, an author (Java/JEE) at Packt Publishing, has close to 14 years of experience in entrepreneurship, conceptualization, architecture, design and development of software products and solutions. He also holds multiple certifications in Core Java, JEE, C, C++, Algorithms and Data Structures. He is an open source contributor and likes competitive programming and hackathons. He has 11 publications to his name in international and national conferences, journals and magazines. He is an active member of the IEEE/Computer Society, ACM and CSI.

He holds a Bachelor of Engineering [Information Science and Engineering] from Sri Revana Siddeshwara Institute of Technology, Bangalore, India. He has also completed the Executive Programme [Data Mining and Analytics] from the Indian Institute of Technology, Roorkee, India and the Executive Certificate Programme [Entrepreneurship] from the Indian Institute of Management, Kashipur, India. His current interests are in data mining, machine learning, Big Data and artificial intelligence. He is based out of Bangalore, India.