Java Data types

Source: Internet
Author: User

1. JavaThe basic data type is only8Species arebyte, Short,int,Long,float,Double,Char,BooleanNoteStringNoJavaThe basic data type)

Data type Size/bit can represent a range of data
Byte (bytes) 8 -128~127
Short (shorter integer type) 16 -32768~32767
int (integral type) 32 -More than 2.1 billion ~ 2.1 billion
Long (integer) 64 -2^63~ (2^63)-1
Float (single precision) 32 -3.4e38~3.4e38
Double (dual precision) 64 -1.7e308~1.7e308
char (character) 16 0~65535
Boolean (Boolean) - True or False

(Attached: long and double are all 64 bits.) Why is a double representing so much scope? )

1.1. Data type Conversion

  1.1.1, automatic type conversion: Small type to large type

1.1.2, coercion type conversions: large types to small types

Strong turns are likely to overflow or loss of precision

1.1.3, data types from small to large in the order of: Byte + short (char) = int = Long = = Float = Double

1.2. Assignment and operation

1.2.1, integer direct value can be directly assigned to Byte,short,char, but not out of range

char c =; // Char type is a character, essentially a code int, which holds an integral type.  // based on Unicode character set encoding, each character has a corresponding code

1.2.2 and Byte,short,char data participate in the operation, the first is converted to int re-operation

 Short B1 = 5;  Short b2 = 6;  Short B3 = (short) (b1+B2); // the B1 and B2 operations here are automatically converted to int, so you must be strong to short to assign a value to B3

  

1.2.3, assign Value

The direct volume range is a compile error and the overrun is overflow when the operation is over

long a = 1000000000*2*10l//20 billion Llong b = 1000000000*3*10l/ / overflow long c = 1000000000l*3*10//30 billion L//  When using a long type for large numeric operations, it is best to write the L// after the first number to indicate that the number is long, avoiding the default integer operation
Note: The direct amount of the long integer, the number must be added L or l

1.2.4, common data unit conversions

1g=1024m ( MB )

1m=1024kb ( kbytes )

1kb=1024b ( bytes )

1b=8bit ( bit )

1.2.5, the base type "=" is the variable assignment, and the reference type "=" is the reference variable that points to an address value

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.