Byte: eight-digit integer-128--127, which can be used to save memory usage.
Short: 16-bit integer-32768--32, 767, also saves memory.
Int: 32-bit integer-2,147,483,648 -- 2,147,483,647. Generally, integers are enough.
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. This is used if the floating point needs to save memory.
Double: 64-bit floating point. This parameter is generally applicable to non-integer floating points.
Use java data type short
- Public class MainClass {
- Public static void main (String [] args ){
- Short numA = 5;
- Short numB = 10;
- Short numC = 0;
- NumC = (short) (numA + numB );
- System. out. println (numC );
- }
- }
- The code is above. Let's see what you should pay attention. Pay attention to the 7th rows and see (short ). Here we will explain it as follows: (DataType) means forced type conversion. in Java, the calculation results of short are converted to integer, therefore, when assigning values to the short type variable numC, it must be forcibly converted to the corresponding short type. Otherwise, the Java compiler reports an error.
Use java data float
- Public class MainClass {
- Public static void main (String [] arg ){
- Float f1 = 9E-28F;
- System. out. println (f1 );
- }
- }
- The above code can be explained in a few ways. The only note here is that the Float type should be followed by F or f. Otherwise, the compiler will report an error.