An enumeration type
Source:
public class Enumtest {
public static void Main (string[] args) {
Size S=size.small;
Size T=size.large;
S and T refer to the same object?
System.out.println (s==t); //
is the original data type?
System.out.println (S.getclass (). isprimitive ());
Convert from String
Size u=size.valueof ("SMALL");
System.out.println (S==u); True
List all of its values
For (Size value:Size.values ()) {
System.out.println (value);
}
}
}
Enum Size{small,medium,large};
Summary: The enumeration type is a reference type.
An enumeration is not part of the original data type, and each of its specific values refers to a specific object. The same value refers to the same object.
You can use the "= =" and the Equals () methods to directly compare the values of the enumeration variables, in other words, the result of the "= =" and the Equals () methods are equivalent for variables of enum types.
Second, anti-code complement the original code
1. Original code
The original code is the absolute value of the symbolic bit plus the truth, that is, the first digit represents the symbol, and the remaining bits represent the values. For example, if it is a 8-bit binary:
[+1] original = 0000 0001
[-1] original = 1000 0001
The first bit is the sign bit. Because the first bit is the sign bit, the range of values for the 8-bit binary number is:
[1111 1111, 0111 1111]
That
[-127, 127]
The original code is the most easily understood and calculated representation of the human brain.
2. Anti-code
The inverse code is represented by:
The inverse of a positive number is its own
Negative number of the inverse code is on the basis of its original code, the sign bit is unchanged, the remaining bits are reversed.
[+1] = [00000001] original = [00000001] Reverse
[-1] = [10000001] original = [11111110] Reverse
It can be seen that if an inverse code represents a negative number, the human brain cannot visually see its value. It is usually converted to the original code and then calculated.
3. Complement
The complement is expressed in the following ways:
A positive complement is its own
The complement of a negative number is on the basis of its original code, the sign bit is unchanged, the rest of you take the counter, the last +1. (That is, on the basis of the anti-code +1)
[+1] = [00000001] original = [00000001] counter = [00000001] Complement
[-1] = [10000001] original = [11111110] counter = [11111111] Complement
For negative numbers, the complement representation is also the human brain can not intuitively see its value. It is also often necessary to convert the original code to calculate its value.
Three, the principle of the same name variable shielding
public class Testtong {
private static int value = 1;
public static void Main (string[] args) {
TODO auto-generated Method Stub
int value = 2;
System.out.println (value);
}
}
Four, hands-on experiment (Testdouble.java)
public class Testdouble {
public static void Main (String args[]) {
System.out.println ("0.05 + 0.01 =" + (0.05 + 0.01));
System.out.println ("1.0-0.42 =" + (1.0-0.42));
SYSTEM.OUT.PRINTLN ("4.015 * 100 =" + (4.015 * 100));
System.out.println ("123.3/100 =" + (123.3/100));
}
}
Summary: A numeric value of type Double is used to calculate the result is imprecise.
A value of type double takes 64bit, or 64 binary numbers, except that the highest bit represents the positive and negative sign, and the lowest bit is bound to have an error with the actual data (unless the actual data is exactly 2 of the n-th square).
Workaround, use the BigDecimal class. You should use a string instead of a double value when building a BigDecimal object, or it is still possible to raise the problem of computational precision.
V. To move the brain
public class Ex_xy {
public static void Main (string[] args) {
int x=100;
int y=200;
System.out.println ("x+y=" +x+y);
System.out.println (x+y+ "=x+y");
}
}
Java Grammar Basics Classroom Example Validation