Rules for Java data types
Rules of data types
Select the appropriate data type to store, for example, if it is used to store age, its value cannot exceed 200, so use short storage, which wastes 2 bytes, which is very economical. If the value is never greater than 100, then we will use byte to store it. If the value is not greater than 100, we have to use long to store it, which is a bit wasteful.
However, it is no different now than 10 years ago. In the past, programming was all done on microcomputers. The resources for programming on a microcomputer are very small, and each memory is very small. Therefore, at that time, you must care about the use of its resources and cannot waste the resources inside, otherwise the resources will become smaller and smaller.
Nowadays, any memory can exceed GB, and servers have hundreds of GB or more. So now you don’t need to worry about the use of data types. In Java, it is said that if your integer value is less than a few billion, then only use int. Int is a universal integer type, which is not a waste at all for today’s machines. On the contrary, it will be much simpler and less troublesome. If you use short to store age, byte to store 100 values, and int to store the price of a house, it will be troublesome, and it will overflow during transformation. As shown in Figure 3.5:
If you have to turn it upside down again, it will overflow again, which is quite messy. So Java says that the default for integers is int. If it is a decimal, the default is double. Even if you don't use int, it's still int, and if you don't use double, it's still double.
The data type is the space size selected for data storage. Everyone’s storage size is different, so we have to choose. However, in Java, he recommends us to use int for integers and double for decimals. If you have to replace it, it is the same. OK.
For more articles related to the rules of Java data types, please pay attention to the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Troubleshooting and solutions to the company's security software that causes some applications to not function properly. Many companies will deploy security software in order to ensure internal network security. ...

Solutions to convert names to numbers to implement sorting In many application scenarios, users may need to sort in groups, especially in one...

Field mapping processing in system docking often encounters a difficult problem when performing system docking: how to effectively map the interface fields of system A...

Start Spring using IntelliJIDEAUltimate version...

When using MyBatis-Plus or other ORM frameworks for database operations, it is often necessary to construct query conditions based on the attribute name of the entity class. If you manually every time...

Conversion of Java Objects and Arrays: In-depth discussion of the risks and correct methods of cast type conversion Many Java beginners will encounter the conversion of an object into an array...

How does the Redis caching solution realize the requirements of product ranking list? During the development process, we often need to deal with the requirements of rankings, such as displaying a...

Detailed explanation of the design of SKU and SPU tables on e-commerce platforms This article will discuss the database design issues of SKU and SPU in e-commerce platforms, especially how to deal with user-defined sales...
