Home>Article>Java> What are the eight basic data types in java

What are the eight basic data types in java

hzc
hzc Original
2020-06-22 15:51:58 6469browse

What are the eight basic data types in java

#javaThere are only 8 basic data types, just remember them. Except these are all reference types.

javaFour categories and eight basic data types

The first category: integer typebyte short int long

Second Class: Floating point typefloat double

Category 3: Logical typeboolean(It has only two possible valuestrue false)

Category 4: Character typechar

The data that can directly allocate memory on the stack is a basic data type.

Reference data type: The reference to the data is on the stack, but its object is on the heap.

If you want to learn Java well, you must know where various data are stored in memory. Having a good understanding of memory can help you analyze programs.

Bytes:

booleanBoolean type 1/8

byteByte type 1

charCharacter type 2 One character can store one Chinese character

shortShort integer type 2

intInteger type 4

floatFloating point type (single precision) 4

longLong integer 8

double Double precision type (double precision ) 8

The default integer type in javais int type. If you want to define it asfloattype, you must add l or L after the value;

The default floating-point type is also a double-precision floating point. If you want to define it as afloattype, you must add f or F after the value.

One byte is equal to 8 bits, and one byte is equal to 256 numbers, which is -128 to 127, a total of 256.

kB means kBytes Bytes means "bytes"!

K means thousands, because the computer calculates through binary, 10 1's are exactly 1024

1111111111 (binary) = 1024 (decimal)

1Bytes (word Section) = 8bit (bit)

An English letter or an Arabic numeral is one character, occupying one byte

One Chinese character is two characters, occupying two bytes.

Generally, when talking about size, Bytes is used with a capital "B". When talking about network speed, bits are used. Note that it is a lowercase "b".

Example: A file has 8MBytes

Example: The rate at which I download files is 256KB/s, which is 2Mbit. This is usually the rate at which we use broadband Internet access.

Automatic conversion of basic data types

byte->short,char -> int -> long

float -> ; double

int -> float

long -> double

Remember: Xiao Ke If you turn large or small, you will lose accuracy! ! !

Recommended tutorial: "java tutorial"

The above is the detailed content of What are the eight basic data types in java. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn