devxlogo

Understanding the Long Data Type in Java

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:[root@mypc]# java JavaLongWith L: 31536000000Without L: 1471228928

devx-admin

Share the Post: