Java2all.com  

Long





Share This Topic -

Long :

The Long class encapsulates a long value. It defines the constants MAX_VALUE and MIN_VALUE and provides the following constructors:

Long(long l)

Long(String str) 

EX :

 import java.util.*;

public class Long_Demo
{
	public static void main(String args[])
	{
		Long L1 = new Long(68764);
		Long L2 = new Long("686748");
		System.out.println("Object L1 = " + L1);
		System.out.println("Object L2 = " + L2);
		System.out.println("Minimum Value of Long = " + Long.MIN_VALUE);
		System.out.println("Maximum Value of Long = " + Long.MAX_VALUE);
		System.out.println("L1 * 2 = " + L1 * 2);
		System.out.println("L1.longValue() * 2 = " + L1.longValue() * 2);
		System.out.println("L1.compareTo(l2) = " + L1.compareTo(L2));
		System.out.println("L1==L2 ? = " + L1.equals(L2));
		Long L3 = Long.valueOf("10", 16);
		System.out.println("Object L3 = " + L3);
		System.out.println("Byte value of Long = " + L1.byteValue());
		System.out.println("int value of Long = " + L1.intValue());
		System.out.println("Double value of Long = " + L1.doubleValue());
		int i = 12;
		System.out.println("Binary equivalent of decimal " + i + "=" + Long.toBinaryString(i));
		System.out.println("Hexadecimal equivalent of decimal " + i + "=" + Long.toHexString(i));
		
	}
}

 
Output :
 
Object L1 = 68764
Object L2 = 686748
Minimum Value of Long = -9223372036854775808
Maximum Value of Long = 9223372036854775807
L1 * 2 = 137528
L1.longValue() * 2 = 137528
L1.compareTo(l2) = -1
L1==L2 ? = false
Object L3 = 16
Byte value of Long = -100
int value of Long = 68764
Double value of Long = 68764.0
Binary equivalent of decimal 12=1100
Hexadecimal equivalent of decimal 12=c