Home / Programs / long Datatype in Java
Programming Example

long Datatype in Java

👁 2,252 Views
💻 Practical Program
📘 Step by Step Learning
long Datatype in Java

Information & Algorithm

  • Long data type is a 64-bit signed two's complement integer
  • Minimum value is -9,223,372,036,854,775,808(-2^63)
  • Maximum value is 9,223,372,036,854,775,807 (inclusive)(2^63 -1)
  • This type is used when a wider range than int is needed
  • Default value is 0L
  • Example: long a = 100000L, long b = -200000L

Program Code

 public class LongDataType {

   public static void main(String []args) {
      // this is declaration and initialization of variable a
	  // datatype is long
	  long a = 100000L;
	  // this is declaration and initialization of variable b
	  // datatype is long
       long b = -200000L;
      System.out.println(a); // it will print a variable
      System.out.println(b); // it will print b variable
   }
}

 

Output

100000
-200000
Press any key to continue . . .

How to learn from this program

First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.