"Long is a class." Long is a primitive. That means long can is null, where long can ' t. Long can go anywhere that takes an Object, long can ' t (since it isn ' t a CLA SS it doesn ' t derive from Object).
Java would usually translate a long to a long automatically (and vice versa), but won ' t for nulls (since a long can ' t being A long), and you need to use the long version if you need to pass a class (such as in a generic declaration).
”
There are two types of data in Java:
1. Basic type: Long,int,byte,float,double,char
2. Object type (Class): long,integer,byte,float,double,char,string, everything else provided by Java, or a class you create yourself.
Where long is also called Long of the wrapper class. Byte and float are similar, and the first name of the generic wrapper class is the beginning of the capitalization of the numeric name.
What is the packing class?
In Java, sometimes the operation must be between two classes of objects, do not allow the operation between the object and the number. So there needs to be an object that wraps the numbers so that the object can be operated on with another object.
For example, we can also define a class:
1classLong {
2inti=0;
3 PublicLong (inti) {
4 This. i=i;
5}
6}
So this long is a wrapper class, he wraps an integer value, and can then write some operator overloading in it to support some operations. You can assign a value at this time:
Long It=new long (10);
Now variable it is an object, not a number.
Long is an integer, in how long itself is also integral type, 12.10 of the shaping part is 12, of course, the result is 12,
BYTE: A eight-bit integer -128--127 that can be used to save memory.
Short:16 bit integer -32768--32,767, also compared to save memory.
Int:32 bit integer -2,147,483,648--2,147,483,647, in general, integers are sufficient.
long:64 bit integer -9,223,372,036,854,775,808--9,223,372,036,854,775,807, generally not required
Float:32 bit floating point, if floating point needs to save memory with this.
double:64 bit floating point, generally non-integer floating point can be used this.
But remember that float and double are not accurate, and if you want to store money, you have to be precise, with java.math.BigDecimal.
What is the difference between long and Long in Java (reprint)