Pin It

Java 7 new feature : Using Underscores in literals to improve code readability

Program to demonstrate Java 7 new feature : Using Underscores in literals to improve code readability

package com.hubberspot.java7;

public class UnderscoresInLiterals {

 public static void main(String[] args) {

  // Credit Card and Debit Card numbers 
  // not very clear to read.
  // Poor code readability
  long debitCard = 4657847382084234L;
  long creditCard = 7657382844234084L;

  System.out.println("Lets print out credit card and debit card numbers : ");
  System.out.println("Debit Card as String: " + Long.toString(debitCard));
  System.out.println("Credit Card as String: " + Long.toString(creditCard));

  System.out.println();

  // Credit Card and Debit Card numbers 
  // very clear to read.
  // Better code readability
  debitCard = 4657_8473_8208_4234L;
  creditCard = 7657_3828_4423_4084L;

  // Result is same as above.
  System.out.println("Lets print out credit card and debit card numbers : ");
  System.out.println("Debit Card as String: " + Long.toString(debitCard));
  System.out.println("Credit Card as String: " + Long.toString(creditCard));

 }

}



Output of the program : 

 
Please Give Us Your 1 Minute In Sharing This Post!
SOCIALIZE IT →
FOLLOW US →
SHARE IT →
Related Posts Plugin for WordPress, Blogger...

Post your related queries below ...

comments powered by Disqus
Powered by Blogger.
 
© 2012 Learn Java by Examples Template by Hubber Spot