Java 0 Basic Series 002--naming, variable type, type conversion, binary integer and numeric delimiters in JDK new features

Source: Internet
Author: User

 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.