Java Data types

Source: Internet
Author: User

Constant

Constants: Fixed amount of constant in program

Categories of constants:

Literal constants: Integer constants, Decimal constants, Boolean constants

Variables defined with the final modifier

Variable

Declaring variables: data type variable name;

Initialize variable: variable name = value;

Initializing a variable will occupy a memory space in memory

Variables can be declared and initialized at the same time: data type variable name = value;

Variables that cannot define the same variable name

Integer type (byte, short, int, long)

Four representations of integer constants:

1. Binary integer: 0B or 0b beginning, int a = 0B12;

2. Eight binary integers: starting with 0, int a = 012;

3. Decimal integer: int a = 12;

4.16 binary integers: Starting with 0 x or 0x, int a = 0x12;

The numbers can be underlined

Integer constants for the Java language are type int by default, declaring a long variable to be followed by L or L

Decimal type (float, double)

A decimal type is also known as a floating-point type, where float represents a single-precision type, and double represents a doubles type, but neither can represent exact decimals to represent exact decimals, with the Bigecimal type

The decimal constant is the double type by default, and if you want to represent the float type, add F or F after

Scientific notation: 3.14e2-phase equals 3.14 * 10^2

Character type (char): characters, letters, and symbols

One character in Java takes two bytes

ASCII code that can correspond to characters in decimal digits

ASCII code that can correspond to characters in hexadecimal digits char a = "\u0041"; # four-bit

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