3.3 Basic data types

Source: Internet
Author: User

3.3 Basic data types

Overview: In Java, there are 8 types of data, 6 of which are numeric types, the other two are character types and Boolean types, 4 of 6 numeric types are integer types, and two are floating-point types.

Basic data types

3.3.1. Numerical type

{

1, Integer type {byte;short;int;long}

2, floating-point type {float,double}

}

3.3.2. Character type

3.3.3 Boolean type

3.3.1 Numerical type

3.3.1.1 integer type

1. Byte

Memory Space: 8 bits 1 bytes (8 bits equals one byte), value range -128~127.

< problem >byte X=48,y=08,z; Defines the byte-type variable x, Y, Z, and assigns it to X, Y.

2.short: Short-integer

Memory space: 16 bits 2 bytes; value range -32768~32767

3.int: Shaping

The memory space is 32 bits and 4 bytes, and the value range is the most widely used in general.

In Java, the system default shaping is int.

< problem >int X=450,y=-463,z; define int type variable x, Y, Z, with initial value to X, y

4.long: Long Plastic

Memory space 64 bits 8 bytes;

A long variable must have an L or L at the end of the assignment, or the system will not recognize it. L is recommended because L and 1 are easy to confuse.

< problem >long X=123489861684265865965l;y=7896545236842659864l;z; Define a long variable x, y, z, and attach an initial value to X, y

Practice

3.3.1.2 floating-point types

Floating-point types represent numbers with fractional parts, in Java, and are divided into {1. single-precision floating-point decimals (float)

2. Double-precision floating point decimal (double). }

1. Single-precision floating point fractional float:

Memory Space: 32 bits 4 bytes; You must use F or f at the end of the assignment to declare the assignment as a single-precision floating-point decimal. Otherwise the system thinks of the double type variable.

< >:float z=12.125f;y=-5.132f,z;//defines the float type variable x, Y, Z, with an initial value of X, y

2. Double-precision floating-point decimal double:

Memory Space: 64 bits 8 bytes;

In Java, the system default floating-point double,

When you assign a double value, you can use the suffix D or D, or no, no hard rules.

< questions >:d ouble x=1.3201d,y= 61.8526d,z9.3214,q; ;//define float type variable x,y,z,q, and attach the initial value to X, Y, Z

3.3.2 character types

Char is a character type that is declared using the Insert keyword to store a single character, and the system allocates two bytes of memory space. When defining a character variable, enclose it in single quotation marks, for example, ' s ' denotes a character, and only one character in a single quotation mark, more than a character type, or a string. The string is to be declared with double quotation marks "".

<;://Declare char type variable

Char x= ' a ';

Since the sort position of character A in the Unicode table is 97, the above statement is allowed to be written as:

Char x=97;

int z= ' a ';

System.out.print (z);//Output 97

System.out.print (x);//Output A

As seen above, there is a certain connection between char and Int. can be converted!!!!

Escape character

\DDD the characters represented by the octal data, such as \456

\dxxx the characters represented by the 4-bit hexadecimal, such as \0052

\ \ backslash Character focus

\ t Vertical tab focus

\ r Enter key

\ nthe line of focus

\b Backspace key

\f Page Change

3.3.3 Boolean type

Boolean will only feedback true and false, that is, to determine the authenticity.

< example >boolean b1=true,b2=false,b3; Defines the Boolean variable b1,b2,b3 and assigns the initial value to the B1,B2


3.3 Basic data types

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.