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
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist