1. Analysis Code
Package Example; public class Exam { public static void main (String [] args) { // the TODO Auto-Generated Method Stub Size = S Size.SMALL; Size t = Size.LARGE; // S and t refer to the same object? System.out.println (S == t); // // primitive data type? System.out.println (s.getClass () isPrimitive ().); // convert from a string Size Size.valueOf U = ( "the SMALL" ); System.out.println (S == U); // to true // list all of its value for(Size value:Size.values()){ System.out.println(value); } } } enum Size{SMALL,MEDIUM,LARGE};
operation result:
Enumerated type common usage:
https://blog.csdn.net/testcs_dn/article/details/78604547
2. The principle of the same name variables shield
In java, local variables can override the value of a global variable.
3.
byte: 1 byte -128 to 127
short: 2 bytes ~ 2 ^ 15 ^ -2 15-1
int: ~. 4 byte 31 is ^ 2 ^ -2 31-1
Long:. 8 ~ byte 63 is 2 ^ ^ -2 63-1
Boolean:. 1 byte true false (java can not be replaced by 0 or 0)
a float: 3.403E38. 4 ~ byte -3.403E38
Double: ~. 8 bytes -1.798E308 - 4.9E324
char: 2-byte '\ u0000' ~ '' \ uffff '(hexadecimal, i.e. recalculated from 0 to 65535)
(1 byte is equal to 8)
Note: low-accuracy conversion without losing the accuracy of precision, accuracy is lost from the low steering precision.
4.
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)); } }
Double inaccurate calculation, loses precision; String type can be accurately calculated.
5.
int X = 100;
int Y = 200;
System.out.println("X+Y=" + X + Y);
// string plus the latter plays the role of connection, i.e., "X + Y" after the plus sign is automatically converted to a string of 100 to X, so that X has become a string
// the same token, Y plus sign will later converted to a string of X 200, the final output is "X + Y =" 100200
System.out.println(X + Y + "=X+Y");
X // because no string in front, so that X and Y are first subjected to ordinary summation, the final output is 300 = X + Y