Home > Java > JavaBase > body text

What are the commonly used data types in Java?

Release: 2019-12-04 10:32:26
Original
3610 people have browsed it

What are the commonly used data types in Java?

There are only 8 basic data types in Java, just remember them. Except these are all reference types.

Introduction to commonly used data types in java: (Recommended: java video tutorial)

Four categories and eight basic data types in java

The first category: integer type byte short int long

The second category: floating point type float double

The third category: logical type boolean (it has only two values ​​​​that can be true or false)

Category 4: Character type char

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.

Byte:

boolean Boolean type: 1/8

byte Byte type: 1

char Character type: 2 One character can store one Chinese characters

short short integer type: 2

int integer type: 4

float floating point type (single precision): 4

long long integer type :8

double Double precision type (double precision) 8

The default integer type in Java is the int type. If you want to define it as a float type, 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 a float type, 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: small can be converted to large, but accuracy will be lost if large is converted to small! ! !

For more java knowledge, please pay attention to the

java basic tutorial column.

The above is the detailed content of What are the commonly used data types in Java?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template