Server-side programming can refer to another book, "Enterprise Java Programming" (Thinking in Enterprise Java).
1. Basic types
Basic type |
Size |
Minimum value |
Maximum Value |
Default value |
Boolean |
----- |
----- |
------ |
False |
Char |
16-bit |
Unicode 0 |
Unicode 2^16-1 |
\u0000 (NULL) |
Byte |
8-bit |
-128 |
+127 |
0 |
Short |
16-bit |
-2^15 |
+2^15-1 |
0 |
Int |
32-bit |
-2^31 |
+2^31-1 |
0 |
Long |
64-bit |
-2^63 |
+2^63-1 |
0L |
Float |
32-bit |
IEEE754 |
IEEE754 |
0.0f |
Double |
64-bit |
IEEE754 |
IEEE754 |
0.0d |
There are positive and negative points for numeric types.
The space occupied by the Boolean type is not explicitly formulated.
The value of 1.java is signed, do not forget to consider negative numbers
Judging if a number is odd,
if (i% 2 = = 1) {
...
}
If I is a negative number, the result of i%2 will be-1. Should be written as:
if (i%2! =0) {
...
}
2. If a decimal is used, the default will be double type, to use the float type, the type of the indicated decimal should be displayed
float F = 1.24f;
3. Decimals can be lost in precision, the use of float and double small number calculations may encounter such problems, if it is necessary to calculate accurately, you can consider using Bigdicemal, the integer corresponding to the BigInteger. It is important to note that the new Bigdicemal (String) is used instead of the new Bigdicemal (double), and the precision has been lost before the Bigdicemal is constructed.
System.out.println (2.0f-1.1f);
System.out.println (2.0D-1.1D);
2. Package Type
Package types include: Integer, Long, short, Byte, Character, Double, Float, Boolean, BigInteger, Bigdecmail
Among them, BigInteger and BigDecimal have no corresponding basic types, which are mainly applied to high precision operation, BigInteger support arbitrary precision Integer, bigdecimal support arbitrary precision operation with decimal point.
The use of BigInteger, BigDecimal will not produce the problem of loss of precision, but with a long,float When you need to consider the problem of loss of precision. Calculations that may not be of great value have the problem of loss of precision.
Why do I need a wrapper type for a basic type? Many times the parameter of a method is an object, not a primitive type, such as the ArrayList of an Add method.
3. Caching
Cache is a typical space switching time scheme, the database frequently read the need to consider the cache, the most basic idea is map.
Issues to consider when using the cache:
1. How long does the data need to be cached
2. Cache data is consistent with real data, when real data is updated or deleted
3. Cache concurrency control, additions and deletions to be considered in multi-threaded environment
The Java.lang package is imported into each Java file by default, so the classes under the Lang package can be used directly by default.
The Rt.jar package will also load automatically, and the jar package under Jre/lib will also be loaded automatically.
"Thinking in Java" learning Note (i)