Public classBasicdatatype { Public Static voidMain (string[] args) {/** Identifier: Used to name a variable, method, class, must begin with a letter, an underscore, a $ symbol. Combination of letters, underscores, numbers, $ symbols, and cannot be keywords * **/System.out.println ("--------------designator------------"); int$,_,a;//the correct naming intPeng = 12;//because of the Unicode encoding inside Java, it can be named with Chinese charactersSystem.out.println ("Value of variable named with Peng" +Peng); /** Java data type, Java is a strongly typed language, so variables must declare type. * * Numeric type (byte, short, int, long--------------float, double) * * * * * * BASIC data Type * Data type * character type (char) * * * * * * * Array * * Reference data type * * * class * * * Interface * * **/System.out.println ("-------------Numeric Type------------------"); //numeric type, the default type of the Java internal constant integer value is type int byteby = 100;//byte is 1 bytes and the number of tables is -128~127 ( -2^8~2^8-1) Shortsh = 30000;//Short is 2 bytes and the table number range is -2^16~2^16-1 (approximately 30,000) intin = 300000;//int is 4 bytes, table number range is -2^32~2^32-1 (approximately 2.1 billion) LongLo = 30000000L;////A Long is 8 bytes, the number of tables is -2^64~2^64-1 (about a lot), and the number is followed by L (l) to indicate that the value is a long typeSystem.out.println ("By:" +by+ "" + "sh:" +sh+ "in:" +in+ "" + "Lo:" +lo); //floating-point number, the default type of the Java internal decimal constant is double floatFL = 3.14f;//float accounts for 4 bytes, the table number range is -3403e38~3403e38 (e38=10^38), and the float type constant is followed by F, otherwise the system will consider it to be double, and report a syntax error DoubleDou = 3.14;//A Double is 8 bytes, representing a range of -1798e308-1798e308System.out.println ("FL:" +fl+ "" + "Dou:" +Dou); //floating-point numbers will have errors, so use them less as a comparison, as belowSystem.out.println ("3.14*100==314%100 Output:" + (3.14*100==314%100));//The output is false because there is an error in the floating-point value, such as 1.0 of the true value is only 0.999999999999999. //char character type, accounting for two bytes, with the ' number '. Charch = ' A '; //Common escape characters: \b-backspace, \ n-newline, \r-carriage return, \t-tab, \ "-double quotes, \ '-single quote, \\-backslash,//Boolean type BooleanBOOL =true;//The Boolean occupies 1 bits. is 1 bits is not 1 bytes, its value is not true or false /** Automatic conversion * General capacity of small type can be automatically converted into large capacity type * **/SH=by;//byte is converted to short without strong transferIn=sh;in=by;in=ch;//byte, short, char converted to int, no strong turn requiredLo=in;lo=sh;lo=by;//int, short, byte are converted to long without strong conversionFl=in;fl=lo;//int, long converted to float without strong turn, but with loss of precisionDou=fl;dou=in;dou=lo;//float, int, long convert to Double,int, long will have precision missing /** Forced type conversion*/CH=(Char) in;//forcing type conversions in front parentheses and strong-turn types /** Type Promotion*/ floatLo1 = 4.0f+in;//4.0f+in after type is automatically promoted to float /** JDK7 new features----binary and numeric separators **/System.out.println ("JDK7 new attributes----binary and numeric separators"); intin1 = 0b00000000000000000000000000000010;//JDK7 can write binary code directly after the beginning of 0b intin2 = 1_000_000;//JDK7 You can use underline to split the values, viewSystem.out.println ("Value of binary 00000000000000000000000000000010:" +in1); System.out.println ("1_000_000 Value:" +in2); }}
Operation Result:
Java 0 Basic Series 002--naming, variable type, type conversion, binary integer and numeric delimiters in JDK new features