Introduction
Not everything in Java is an object. There is a special group of data types (also known as primitive types) that will be used quite often in your programming. For performance reasons, the designers of the Java language decided to include these primitive types.
Creating an object using new isn't very efficient because new will place objects on the heap. This approach would be very costly for small and simple variables. Instead of create variables usingnew, Java can use primitive types to create automatic variables that are not references. The variables hold the value, and it's place on the stack so its much more efficient.
Java determines the size of each primitive type. These sizes do not change from one machine architecture to another (as do in most other languages). This is one of the key features of the language that makes Java so portable.
Take note that all numeric types are signed. (No unsigned types).
Finally, notice that each primitive data type also has a "wrapper" class defined for it. This means that you can create a "nonprimitive object" (using the wrapper class) on the heap (just like any other object) to represent the particular primitive type.
For example:
int i = 5;
Integer I = new Integer(i);
OR
Integer I = new Integer(5);
Data Types and Data Structures
Primitive Type |
Size |
Minimum Value |
Maximum Value |
Wrapper Type |
char |
16-bit |
Unicode 0 |
Unicode 216-1 |
Character |
byte |
8-bit |
-128 |
+127 |
Byte |
short |
16-bit |
-215 (-32,768)
|
+215-1 (32,767)
|
Short |
int |
32-bit |
-231 (-2,147,483,648)
|
+231-1 (2,147,483,647)
|
Integer |
long |
64-bit |
-263 (-9,223,372,036,854,775,808)
|
+263-1 (9,223,372,036,854,775,807)
|
Long |
float |
32-bit |
32-bit IEEE 754 floating-point numbers |
Float |
double |
64-bit |
64-bit IEEE 754 floating-point numbers |
Double |
boolean |
1-bit |
true or false
|
Boolean |
void |
----- |
----- |
----- |
Void |
分享到:
相关推荐
java编程基础,Java primitive data types and related subjects, such as variables, constants, data types, operators, and expressions. Control statements Array String
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 ...
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 ...
字节短整数长Java原始类型
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):在内存中存放的是指向该数据的地址,不是数据本身;...
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数据类型(type)可以分为两大类:基本类型(primitive types)和引用类型(reference types)。下面是动力节点给大家整理java基本数据类型相关知识,感兴趣的朋友一起学习吧
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 ...
實踐38:使用基本型別(primitive types)使代碼更快更小 130 實踐39:不要使用Enumeration或Iterator來遍歷Vector 135 實踐40:使用System.arraycopy()來複製arrays 136 實踐41:優先使用array,然後才考慮Vector和...
Chapter 8Primitives as Typesexplores the relationship between the primitive types and objects of their corresponding wrapper classes, and how boxing and unboxing can transparently convert between ...
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 ...
Special case: primitive types ....... 43 Arrays in Java .............................. 44 You never need to destroy an object .................. 45 Scoping ........................................ 45 ...
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,...
DefaultTableCellRenderer recognizes a few primitive types, rendering them as strings, and can even display Boolean types as checkboxes. But it defaults to displaying the value returned by toString() ...
Supports: primitive types, multiple inner JSONArrays. Download get it and install from plugin repository or simply find it in "Preferences" -> "Plugins" -> "Browse Repositories" -> "RoboPOJOGenerator...
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, ...
2. Primitive Types (int, boolean) 3. Conditionals (if, else if, else) 任务 Create three seperate if, else if, and else Conditionals with each having a different System.out.println Statement in them...
Special case: primitive types ....... 43 Arrays in Java .............................. 44 You never need to destroy an object .................. 45 Scoping ........................................ 45 ...
15.6.4 Specialization for Primitive Types 225 15.7 Annotations for Errors and Warnings 226 Exercises 227 16 XML PROCESSING A2 229 16.1 XML Literals 230 16.2 XML Nodes 230 16.3 Element Attributes 232 ...