Java4android Development Tutorial (v) Basic data type characteristics of Java _android

Source: Internet
Author: User

Java data types are divided into basic data types and reference data types.

Basic data types are of numeric, character (char), Boolean (Boolean)

Numeric type variable

1. Integer type

Type

Occupy Storage space

Representation Range

Byte

1 byte byte

-128~127

Short

2 bytes

-2~2-1

Int

4 bytes

-2~2-1

Long

8 bytes

-2~2-1

Three representations of the integral type constants of Java:

-decimal integers, such as 12,-31

-Eight binary integers, starting with 0, such as 012

-16 in number, beginning with 0x or 0X, such as 0x12

The Java integer constant defaults to the int type, declares the long type constant, plus l,

eg

Long a=10l;

2, floating point type

Type

Occupy Storage space

Representation Range

Float

4 bytes

-3.403e38~3.403e38

Double

8 bytes

-1.798e308~1.798e308

Character type variable

Used to represent and store a character, Java uses the Unicode character set.

A character is a single character that is included in single quotes

eg

Char c= ' B ';
What is a Unicode character set? Speaking from the ASCII character set ...

1, in the computer all the data in binary notation, but similar to a, B and other letters can not be directly expressed in binary.

2, standard ASCII code for common symbols, numbers and uppercase and lowercase letters, such as using a 7-bit binary number http://baike.baidu.com/view/15482.htm

But there are only English characters in the ASCII character set, in order to facilitate computer processing of characters in other languages, Unicode sets a uniform, unique binary code for each character of each language, satisfies the need for cross-language text conversion and processing, and uses numeric 0-0x10ffff to represent characters, Up to 1,114,112 characters are allowed.

The generation of garbled characters

When writing data to a file, a character set is used to convert the binary data to the computer, and the B character set is used when the data is read from the computer, and garbled characters are generated.

Because Java uses the Unicode character set, Unicode encoding consumes two bytes, so variables of type char are also two bytes, so a char variable in Java can store a Chinese character.


Boolean variable

Applies to logical operations and program flow control, in Java only true and false two values

eg

Boolean a=true;

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.