Java Learning Diary--Basic data types

Source: Internet
Author: User

Basic data type:

Byte 1 bytes positive or negative can represent 2 of the 8-1 square -128~127 (including 0)

Short 2 bytes 2 of 16-1 times
Integer type (default is int type)
int 4 bytes 2 of 32-1 Times Square

Long 8 byte 2 of the 64-1-time long type is defined with the number of L or L after the digit: Long is a = 2344534656348204L;

Character type Char2 bytes

Basic data types
Float 4 bytes
Floating-point type (default is double type)
Double 8 bytes

BOOL Type Boolean


Integral type


The number of positive and negative numbers represented by integers--one byte = 8 bit so the number that can be represented is 2 8, which is the first sign that becomes positive or negative, when the first is 0, the number is an integer and 1 is negative.
Wide conversion accuracy of small conversion to high precision, without loss of precision
Narrow conversion precision large conversion to precision know, will lose precision, will error

Character type

Character types are typically used to denote that a single character type must be enclosed in single quotation marks (').
Generally there are three ways to express:
1, directly specify a single character as a character value
char Achar = ' a ';
2, using the escape character as a character value commonly used transfer characters have \b backspace \ n line break \ r return character \ ", \", \ \ Double cited, single-lead, backslash
char Enterchar = ' \ r ';
3. Use Unicode encoded values to specify character values where 9999 represents a hexadecimal integer
char ch = ' \ u 9999 ';

Floating point Type


There are two ways to represent Java floating-point numbers: The decimal number form (the float must contain a decimal point), the scientific notation form


Float represents a single-precision floating-point number for 4 bytes 32-bit single precision immediately after the float type value F or f
Double stands for 8 bytes of 64 bits for dual-precision floating-point numbers
Only the positive float is divided by 0 to get the positive infinity, the negative float divided by 0 can be negative infinity
If an integer value is divided by 0, an exception is thrown arithmeticexcrption:/by Zero (divided by 0 exception)

Boolean type

The numeric value of Boolean can only be true or false, and cannot be substituted with 0 or not 0. Values for other data types cannot be converted to a Boolean type
A Boolean variable requires only one bit, but most of the time it actually occupies 8 bits (1 bytes)
Boolean values are automatically converted to strings when using the Boolean type of paper and word A for connection operations.
For example: String str = true + ""; The output will be output true

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