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中的数据类型分为两大类:基本数据类型(Primitive Data Types)和引用数据类型(Reference Data Types)。基本数据类型包括整型(如int)、浮点型(如float、double)、字符型(char)和布尔型(boolean...
java编程基础,Java primitive data types and related subjects, such as variables, constants, data types, operators, and expressions. Control statements Array String
Java 中有两种基本数据类型:primitive types 和 reference types。primitive types 包括整数、浮点数、字符、布尔值等,而 reference types 则包括类和接口。primitive types 的值是存储在栈中的,而 reference ...
在Java编程语言中,原生类型(Primitive Types)是其语法结构的基础,它们不依赖于类或接口。本文将深入探讨Java中的四个整数类型:字节(Byte)、短整数(Short)、整数(Integer)和长整数(Long)。理解这些类型...
在类型、值和变量(Types, Values, and Variables)章节中,文档详细解释了Java类型系统的基础,包括各种类型和值的种类,其中既有基本类型(Primitive Types)也有引用类型(Reference Types),以及变量的定义和...
Java中共有八种原始类型(Primitive Types),它们包括: 1. 整数类型:byte(1字节)、short(2字节)、int(4字节)和long(8字节)。 2. 浮点类型:float(4字节)和double(8字节)。 3. 字符类型:char(2字节...
Java有两大类数据类型:**原始数据类型(Primitive Data Types)**和**引用数据类型(Reference Data Types)**。原始数据类型包括: 1. **整型**(Integers):如`byte`, `short`, `int`, `long`,分别表示8位、16...
基本类型(primitive types) Java中的基本类型可以分为八种:boolean、char、byte、short、int、long、float、double、void。每种基本类型都有其对应的默认值和所占空间大小。 基本类型的特殊处理 在Java中,...
- **原始类型(Primitive Types)**:包括整数类型(byte, short, int, long)、浮点类型(float, double)和字符类型(char)以及布尔类型(boolean)。 - **引用类型(Reference Types)**:类、接口和数组,...
1. Java 变量和数据类型:在 Java 中,变量可以是基本类型(primitive types)或引用类型(reference types)。基本类型包括整数、浮点数、字符、布尔值等,而引用类型包括数组、类、接口等。Java 中的变量可以使用 ...
*JAVA 中的变量可以是基本数据类型(primitive types)或引用类型(reference types) *基本数据类型包括整数(int)、浮点数(float)、字符(char)等 *引用类型包括数组、字符串、对象等 二、运算符 *JAVA 中的...
Java中的数据类型分为两大类:原始类型(Primitive Types)和引用类型(Reference Types)。 ##### 2.1 原始类型 (Primitive Types) 原始类型直接存储值,它们包括: - `byte` - `short` - `int` - `long` - `float` -...
Java 中有两种基本数据类型:基本数据类型(primitive types)和引用数据类型(reference types)。 基本数据类型 基本数据类型包括: 1. 数值型(numeric type): byte, short, int, long, float, double 2. ...
1. **原始类型**(Primitive Types):包括布尔型(`boolean`)、整型(如`int`、`byte`等)、字符型(`char`)以及浮点型(如`float`、`double`)。 - **整型**:包括`byte`、`short`、`int`、`long`,分别占用8...
在Java中,数据类型可以分为两大类:基本类型(Primitive Types)和引用类型(Reference Types)。下面将详细阐述这两类类型以及它们在实际编程中的应用。 1. 基本类型(Primitive Types) - 整型:Java提供了四种...
This chapter delves into the data types available in Java, including primitive types (such as `int`, `float`, and `char`) and reference types (such as `String` and `Object`). It also covers operators ...
Java分为两种主要的数据类型:基本类型(Primitive Types)和引用类型(Reference Types)。在"JAVA-type.rar_java Type"压缩包中,重点讲解的是Java的基本数据类型转换,这包括了数值类型之间的转换以及基本类型与...