Java starts from scratch four (data type)

Source: Internet
Author: User

One, Java data Type Division

ii. Basic data Types

No. Data type size / bit Range of data that can be represented
1 Long (length integer) 64 -9223372036854775808 ~ 9223372036854775807
2 Int (integer) 32 -2147483648 ~ 2147483647
3 Short (shorter integer) 16 -32768~32767
4 BYTE (bit) 8 -128 ~ 127
5 char (character) 2 0 ~ 255
6 Float (single precision) 32 -3.4E38 ( -3.4´1038) ~ 3.4E38 (3.4´1038)
7 Double (dual precision) 64 -1.7E308 ( -1.7´10308) ~ 1.7E308 (1.7´10308)

Default value

No. Data type Default value
1 Byte (byte) 0
2 Short (short) 0
3 Int 0
4 Long 0L
5 Float 0.0f
6 Double 0.0d
7 Char \u0000 (Empty, ")
8 Boolean False
2.1. Integral typewhen the data does not have decimals or fractions, it can be declared as an integer variablesuch as: 3,-147the integral type can be divided into long,int,short and byte4 species .
         byte b=8;          short s=100;         int i=2;         long v=1000;    
2.2. Character Typethe character type occupies 2 bytes in memory and can be used to hold characters such as English letters, which are enclosed in a pair of single quotation marks (") .
         Char ch1= ' a ';         Char ch2=97;        System.out.println ("ch1=" +ch1);        System.out.println ("ch2=" +CH2);
results: Ch1=a,ch2=aA character type is also considered an integer type. commonly used escape characters:
No. Escape character Describe No. Escape character Describe
1 \f Page change 2 \\ Reverse Slash
3 \b One step backwards. 4 \‘ Single quotation marks
5 \ r Return to position 6 \" Double quotes
7 \ t TAB tab 8 \ n Line break

        char ch1= ' \ ';         char ch2= ' \ \ ';        System.out.println ("ch1=" +ch1);        System.out.println ("ch2=" +CH2);        System.out.println ("\" Hello world\ "");

Results:

Ch1= "
ch2= \
"Hello World"

2.3.Floating-point type (float,double) in mathematics, these numbers with decimal points are called real numbers, and in Java, the data type is called the floating-point type, which defaults to the double type in Java.
        double num1=3.14;         float num2=7.3f;        System.out.println ("num1=" +num1);        System.out.println ("num2=" +num2);
2.4, Boolean Type (Boolean) Boolean (Boolean) type of variable, only true (true) and False (false) two. That is, when a variable is defined as a Boolean type, its value can only be true or false, except that no other value can be assigned to the variable
         booleantrue;        SYSTEM.OUT.PRINTLN ("flag =" +flag);

Results: Flag =true;

Java starts from scratch four (data type)

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.