- Java 9 Programming By Example
- Peter Verhas
- 280字
- 2021-07-02 23:37:33
Types
Each variable has one type. In Java, there are two major groups of type: primitive and reference types. The primitive types are predefined, and you cannot define or create a new primitive type. There are eight primitive types: byte, short, int, long, float, double, boolean, and char.
The first four types, byte, short, int, and long, are signed numeric integer types, capable of storing positive and negative numbers on 8, 16, 32, and 64 bits.
The float and double types store floating point numbers on 32 and 64 bits in the IEEE 754 floating-point format.
The boolean type is a primitive type that can only be true or false.
The char type is a character data type that stores a single 16-bit Unicode character.
For each primitive type, there is a class that can store the same type of value. When a primitive type has to be converted to the matching class type it is done automatically. It is called auto boxing. These types are Byte, Short, Integer, Long, Float, Double, Boolean, and Character. Take, for example, the following variable declaration:
Integer a = 113;
This converts the value 113, which is an int number, to an Integer object.
These types are part of the runtime, and also part of the language. Although there is no primitive counterpart of it, there is a very important and ubiquitous class that we have already used: String. A string contains characters.
The major differences between primitive types and objects are that primitive types cannot be used to invoke methods, but they consume less memory. The difference between the memory consumption and its consequences for speed is important in the case of arrays.
- ClickHouse性能之巔:從架構(gòu)設(shè)計(jì)解讀性能之謎
- Android開發(fā)精要
- 高效微控制器C語言編程
- Visual C++串口通信技術(shù)詳解(第2版)
- JavaScript動態(tài)網(wǎng)頁開發(fā)詳解
- JavaScript動態(tài)網(wǎng)頁編程
- Vue.js應(yīng)用測試
- SQL Server 2008中文版項(xiàng)目教程(第3版)
- SwiftUI極簡開發(fā)
- 深度實(shí)踐KVM:核心技術(shù)、管理運(yùn)維、性能優(yōu)化與項(xiàng)目實(shí)施
- scikit-learn Cookbook(Second Edition)
- SEO教程:搜索引擎優(yōu)化入門與進(jìn)階(第3版)
- Raspberry Pi Blueprints
- Scratch編程從入門到精通
- Elastix Unified Communications Server Cookbook