Primitive Types:
1) byte:
size: 8-Bit = 1-Byte
range: -128~+127
usage:
1> The byte data type can be useful for saving memory in large arrays, where memory saving actually matters.
2> They can also be used in place of int where their limits help to clearify your code. The fact that a variable's range is limited can serve as a form of documentation.
2) short:
size: 16-Bit = 2-Byte
range: -32768~+32767
usage:
1> You can use short to save memory in large arrays, in situation memory where memory savings acutally matters.
3) int:
size: 32-Bit = 4-Byte
range: -(2^31)~+(2^31-1)
4) long:
size: 64-Bit = 8-Byte
range: -(2^63) ~ +(2^63-1)
5) float:
size: single-precision 32-Bit IEEE 754 floating point
range: Its range of value is beyond the scope of this discussion.
usage: Use a float if you need to save memory in large arrays of floating point numbers.
This data type should never be used for precise values, such as currency.
For that, you need to use the java.math.BigDecimal class instead.
6) double:
size: double-precision 64-Bit IEEE 754 floating point.
range: Its range of values is beyond the scope of this discussion.
usage: For decimal values, this data type is generally the default choice.
As mentioned above, this data type should never be used for precise values.
7) boolean:
size: represent one-bit of information, but its size isn't precisely defined.
range: true/false
usage: Use this data type for simple flags that track true/false conditions.
8) char:
size: 16-Bit = 2 Byte
range: '\u0000' or 0 inclusive ~ '\uffff' or 65535 inclusive
Default Values:
byte | 0 |
short | 0 |
int | 0 |
long | 0L |
float | 0.0f |
double | 0.0d |
char | '\u0000' |
String (or any object) | null |
boolean | false |
Reference Links:
1) http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html
相关推荐
Java How to Program (Late Objects), Tenth Edition is intended for use in the Java programming course. It also serves as a useful reference and...Appendix D: Primitive Types Appendix E: Using the Debugger
字节短整数长Java原始类型
Supports: primitive types, multiple inner JSONArrays. Download get it and install from plugin repository or simply find it in "Preferences" -> "Plugins" -> "Browse Repositories" -> "RoboPOJOGenerator...
Chapter 6 - The Primitive Types and Their Input/Output Chapter 7 - Declarations, Definitions, and Initializations Chapter 8 - Object Reference and Memory Allocation Chapter 9 - Functions and Methods ...
java编程基础,Java primitive data types and related subjects, such as variables, constants, data types, operators, and expressions. Control statements Array String
2.1.1Primitive Data Types 2.1.2Arithmetic and Relational Operators 2.1.3Arrays 2.1.4Strings 2.1.5Multi-Level Break 2.1.6Memory Management and Garbage Collection 2.1.7The Background ...
Item 61: Prefer primitive types to boxed primitives Item 62: Avoid strings where other types are more appropriate Item 63: Beware the performance of string concatenation Item 64: Refer to objects by ...
Chapter 6 - The Primitive Types and Their Input/Output Chapter 7 - Declarations, Definitions, and Initializations Chapter 8 - Object Reference and Memory Allocation Chapter 9 - Functions and Methods ...
基本数据类型(primitive types):由程序设计语言系统所定义的,不可再划分;内存大小固定,存放数据本身;与软硬件环境无关。 引用类型(reference types):在内存中存放的是指向该数据的地址,不是数据本身;...
實踐38:使用基本型別(primitive types)使代碼更快更小 130 實踐39:不要使用Enumeration或Iterator來遍歷Vector 135 實踐40:使用System.arraycopy()來複製arrays 136 實踐41:優先使用array,然後才考慮Vector和...
一种是基本类型(primitive types),共有 8 种,即 int, short, long, byte, float, double, boolean, char(注意,并没有 string 的基本类型)。这种类型的定义是通过诸如 int a = 3; long b= 255L; 的形式来定义...
Java语言中有多种数据类型,包括基本类型(primitive types)和引用类型(reference types)。例如,在给定的代码中,使用了long、int、double等基本类型,以及String和Scanner等引用类型。 五、输入输出(Input/...
Creating new data types: class ..................................... 46 Fields and methods ..................... 47 Methods, arguments, and return values ................. 48 The argument list ..........
Java数据类型(type)可以分为两大类:基本类型(primitive types)和引用类型(reference types)。下面是动力节点给大家整理java基本数据类型相关知识,感兴趣的朋友一起学习吧
Chapter 10Control Flowdescribes how control statements direct the order of statement execution. <br>Chapter 11Generic Typesdescribes generic types: how they are written and used, their power, and ...
Automatic mapping from Java to native functions, with simple mappings for all primitive data types Runs on most platforms which support Java Automatic conversion between C and Java strings, with ...
6.2 Primitive Data Types 253 6.3 Character String Types 256 History Note 258 6.4 User-Defined Ordinal Types 261 6.5 Array Types 266 History Note 267 History Note 269 6.6 Associative ...
the basic JavaScript foundations, such as primitive objects and types. Then, this book covers implementations and algorithms for fundamental data structures such as linked lists, stacks, trees, heaps,...
Creating new data types: class ..................................... 46 Fields and methods ..................... 47 Methods, arguments, and return values ................. 48 The argument list ..........
All C# types, including primitive types such as int and double, inherit from a single root object type. Thus, all types share a set of common operations, and values of any type can be stored, ...