Javase Review Diary: Eight types of basic data

Source: Internet
Author: User

/** Basic Data type * * 8 basic data types in Java: * byte- --1 byte = 8 bit; * Short---2 byte = n bit; * int---4 byte = n bit; * Long---8 byte = n bit; * Float---float, 32-bit space, data representation is decimal (e.g. 3.0) * Double---floating-point, 64-bit space, data representation is decimal * char---character type, char data occupies two BYTE 2 byte = 16bit; * Boolean---Boolean, data only true and false, no numbers (0 and 1, etc.), mainly used in logical operations and conditional control statements; *----------------------------------------------------------------------------------------------------- *//*Byte,short,int,long * * The first four assignment calls to data types, and data type conversions; * Here's a comment first. * 1 variable assignment and method call public Clas    s javase{public static void Main (string[] args) {javase.m_1 ();//Call m_1 method;        } public static void M_1 () {//static method m_1;        byte a = 10;//assignment a=10;        Assignment://data type variable name = value;        Short B = 11;        int c = 12;        Long d = 13;        System.out.println (a);//output A/B/C/D;        System.out.println (b);        System.out.println (c);    System.out.println (d); }}*//*2 Conversion of the base data type public class javase{public static void Main (string[] args) {m_2 ();        } public static void M_2 () {Short A = 10;        int B = 20;        Long C = A + b;//automatic type conversion: Low type to high type conversion; byte d = (Byte) ((short) b-a);//coercion type conversion: High type to high type conversion, need to strengthen the conversion character: (data type) value;//Here is a high type to low type of data type conversion, loss of precision//if the high type to low type conversion data more than the lower class        Type of memory space, there will be unpredictable results, this can be changed to the next number to try;        System.out.println (d);    System.out.println (c); }}*-----------------------------------------------------------------------------------------------------------*//*float and Double type * * variable assignment and data type conversion*//*Public class javase{public static void Main (string[] args) {m_3 ();//Call Method M_3;        } public static void M_3 () {Float A = 1;//here a=1.0, but cannot write directly float a = 1.0;        Double b = 3;        Double c = 4.0;        Double d = a + B;        float e = (float) 5.0;//here if you assign a value directly to write 5.0, then the default is double type, so you need to strengthen the type of conversion character;        float f = (float) b + A;        System.out.println (a);        System.out.println (b);        System.out.println (c);        System.out.println (d);        System.out.println (e);    System.out.println (f); }}*-----------------------------------------------------------------------------------------------------------*//*char * * Char type assignment and escape character * Here's the concept of the escape character: * What is an escape character? * The slash "\" means escaping in the computer, and the conversion of characters and ordinary characters with special meaning can be realized; * Specific We put in the example; *//*Public class javase{public static void Main (string[] args) {char c_1 = ' a ';//general assignment;        The assigned content needs to be added single quotation marks ";        System.out.println (c_1);        Char c_2 = ' Medium ';        System.out.println (c_2);   Char c_3 = ' \u4e2d ';//The default value of the character is: u0000;        U4e2d is ' middle ';        System.out.println (C_3);        char c_4 = ' \ n ';//here ' \ n ' is a career change character;        System.out.print (c_4);//This is the difference between print () and println (): the latter will default to the output after the addition of a shift character;        char c_5 = ' \ \ ';        System.out.println (C_5);        char c_6 = ' \ ';//output single quotation mark, same no switch, also useless println (), so will and double quotation mark continuous output;        System.out.print (C_6);        char c_7 = ' \ ';//output double quotation mark;    System.out.println (c_7); }}*///boolean-Type Boolean/** Here's one thing to note: * Boolean Boolean values cannot participate in data type conversions * There is also a Boolean Boolean default value of false;*///   Public classjavase{StaticBoolean F;//here, let's not assign a value and look at the default value of the Boolean Boolean value;     Public Static voidMain (string[] args) {m_1 (); System. out. println (f);//output default value;    }     Public Static voidM_1 () {Boolean B=true; if(b) {System. out. println ("correct");//if b=true, the output is correct;}Else{System. out. println ("Error");//if b=false, output error;        }    }}

Javase Review Diary: Eight types of basic data

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.