search
HomeJavaJavaBaseWhat are the commonly used data types in Java?

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!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software