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 ()); Converts a Size u=size.valueof ("SMALL") from a string; System.out.println (s==u); True //lists all its values for (Size value:Size.values ()) { System.out.println (value);} } } enum Size{small,medium,large};
Run will get results
This shows that the different constants defined by the enumeration type are not the same object and are no longer the original data type, and the results obtained are the same. However, different constants are defined.
Different data types in Java are stored differently and occupy different spaces
Short 2byte
int 4byte
Long 8byte
Char 1byte
Float 32byte
Double 64byte
It is common sense to lose precision when converting from a small byte to a large byte, but a double from int to float can also lose precision because the integer portion of int is 32 bits and the float integer part is only 16 bits, so it loses precision.
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));
}
}
There are some problems with double calculation, and the result is this
A conclusion is calculated using a numeric value of type double , the result is imprecise.
public class test1{
publicstatic void Main (String args[])
{
intx=100;
inty=200;
System.out.println ("x+y=" +x+y);
System.out.println (x+y+ "=x+y");
}
}
The result of the execution is this.
This is because the value of the plus sign at the time of the output is from left to right if there is a string on both sides of the plus sign, it will add the back to the back of the previous one, two numbers will be added,
Java Beginner Knowledge points