Java Basic data types

Source: Internet
Author: User

650) this.width=650; "src=" https://s4.51cto.com/wyfs02/M02/97/0F/wKioL1koP2PzKUvPAACdZhrxcN8720.png "title=" QQ picture 20170526224319.png "alt=" wkiol1kop2pzkuvpaacdzhrxcn8720.png "/>

First Class: Logical Type Boolean

Boolean type data allows only true or false, not integers of 0 or 0 to replace true and false, which differs from C language

Type ii: Text Char

   char data is used to represent three representations of "character" (2-byte)
character constants in the usual sense:
   character constants are single quotes A single character enclosed in ('), covering all the characters of the written word in the WORLD. For example: char c1 = ' a ';   char c2 = ' Medium '; Char C3 =  ' 9 '; The escape character ' \ ' is also allowed in
   Java to convert subsequent characters to Special-character Constants. For example: char c3 = ' \ n '; //' \ n ' means the newline character
   uses Unicode values directly to represent the Char-type constant: ' \uxxxx '. where xxxx represents a hexadecimal integer. Such as: \u000a means \ N.
char type is available for Operation. Because it's all about the Unicode Code.

Type iii: integer (byte, short, int, Long)

java Each integer type has a fixed number of table range and field length, which is not affected by the specific operating system, to ensure the portability of Java Programs.

Three representations of the java-language integer constants:

A decimal integer, such as: 12,-314,0.

An octal integer that requires starting with 0, such as 012.

Hexadecimal number, requires 0x or 0X beginning, such as: 0x12.

Integer Constants in the Java language default to int, declaring a long constant must be followed by ' | ' or ' L '.

Type Occupy Storage space
Table Count Range

Byte

1 bytes =8bit

-128 ~ 127

Short

2 bytes

-215 ~215-1

Int

4 bytes

-231 ~ 231-1

Long

8 bytes

-263 ~ 263

Class Fourth: floating-point type (float, Double)

The Java floating-point constant defaults to type double, declaring a float constant, followed by ' F ' or ' F '.
There are two types of expressions for floating-point constants:
Decimal number form: 5.12 512.0f. 512 (must have decimal points)
Scientific notation form: for example: 5.12e2 512E2 100e-

1.798E30
Type Occupy Storage space Table Count Range

Single Precision Float

4 bytes

-3.403E38 ~ 3.403E38

Double-precision Doubles

8 bytes

-1.798E308 ~

Basic Data type Conversions

1. Automatic type Conversion: small capacity types are automatically converted to large-capacity data types. The data types are sorted by capacity size:
650) this.width=650; "src=" https://s1.51cto.com/wyfs02/M00/97/0F/wKioL1koR8DCK0AVAABWpagSZ1g417.png "title=" QQ picture 20170526232054.png "alt=" wkiol1kor8dck0avaabwpagsz1g417.png "/> 2. When there are several types of data blending operations, the system first automatically converts all data to the type of data with the largest capacity, And then the Calculation.
3.byte,short,char do not convert to each other, and the three of them are first converted to the int type when calculating.
When the value of any base type is concatenated with a string value (+), the value of the base type is automatically converted to the string type.

4. Real Constants (such as: 1.2) default to double, and integer constants (for example: 123) by default to int.

Forcing type conversions

1. The inverse process of automatic type conversion converts a large-capacity data type to a small-capacity data type. Use the cast character (()), but it may result in a decrease in accuracy or overflow, especially to be aware.
2. In general, strings cannot be converted directly to basic types, but wrapper classes that correspond to basic types can be implemented to convert strings to basic Types.
Such as: String a = "43"; int i = Integer.parseint (a);
The 3.boolean type cannot be converted to another data type.

This article is from the "ciyo technology sharing" blog, Please be sure to keep this source http://ciyorecord.blog.51cto.com/6010867/1930037

Java 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.