Skip to Content

Java long Example

  1. /*
  2.         Java long Example
  3.         This Java Example shows how to declare and use Java primitive long variable
  4.         inside a java class.
  5. */
  6.  
  7. import java.util.*;
  8.  
  9. public class JavaLongExample {
  10.  
  11.         public static void main(String[] args) {
  12.                
  13.                 /*
  14.                  * long is 64 bit signed type and used when int is not large
  15.                  * enough to hold the value.
  16.                  *
  17.                  * Declare long varibale as below
  18.                  *
  19.                  * long <variable name> = <default value>;
  20.                  *
  21.                  * here assigning default value is optional.
  22.                  */
  23.  
  24.                 long timeInMilliseconds = new Date().getTime();
  25.                 System.out.println("Time in milliseconds is : " + timeInMilliseconds);           
  26.         }
  27. }
  28.  
  29. /*
  30. Output would be
  31. Time in milliseconds is : 1226836372234
  32. */