About Ilias Tsagklis

Ilias Tsagklis
Ilias is a software developer turned online entrepreneur. He is co-founder and Executive Editor at Java Code Geeks.

long

With this example we are going to demonstrate how to use a long type in Java. The long data type is a 64-bit signed two’s complement integer. It has a minimum value of -9,223,372,036,854,775,808 and a maximum value of 9,223,372,036,854,775,807 (inclusive). Use this data type when you need a range of values wider than those provided by int.

    In short, to create a variable of long type you should type the long keyword in your variable. In the example the System.currentTimeMillis() returns a long number that is the current time in milliseconds.

Let’s take a look at the code snippet that follows:  
 

package com.javacodegeeks.snippets.basics;

public class LongExample {
	
	public static void main(String[] args) {
		
		long l1 = System.currentTimeMillis();
		long l2 = 1000*1000;
		
		System.out.println("Value of long l1 is: " + l1);
		System.out.println("Value of long l2 is: " + l2);
		
	}

}

Output:

Value of long l1 is: 1318967029108
Value of long l2 is: 1000000

  
This was an example of how to use a long type in Java.

(No Ratings Yet)
Start the discussion Views Tweet it!

Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you our best selling eBooks for FREE!

 

1. JPA Mini Book

2. JVM Troubleshooting Guide

3. JUnit Tutorial for Unit Testing

4. Java Annotations Tutorial

5. Java Interview Questions

6. Spring Interview Questions

7. Android UI Design

 

and many more ....

 

Receive Java & Developer job alerts in your Area

 

Leave a Reply

avatar
  Subscribe  
Notify of