Home > Java > JavaBase > body text

What are the eight basic data types in java

hzc
Release: 2020-06-22 15:51:58
Original
6553 people have browsed it

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 type float 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:

boolean Boolean type 1/8

byte Byte type 1

char Character type 2 One character can store one Chinese character

short Short integer type 2

int Integer type 4

float Floating point type (single precision) 4

long Long integer 8

double Double precision type (double precision ) 8

The default integer type in java is int type. If you want to define it as 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 -&gt ; 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!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!