Understanding the Long Data Type in Java

Java long behaves differently when used with the letter L and without it.

Code snippet

public class JavaLong{   public static void main(String args[])   {      JavaLong javaLong = new JavaLong();      javaLong.proceed();   }   private void proceed()   {      long longWithL = 1000*60*60*24*365L;      long longWithoutL = 1000*60*60*24*365;      System.out.println("With L: " + longWithL);      System.out.println("Without L: " + longWithoutL);   }}/*Expected output:[[email protected]]# java JavaLongWith L: 31536000000Without L: 1471228928
Share the Post:
Share on facebook
Share on twitter
Share on linkedin


Recent Articles: