Java基本数据类型只有八种?第九种告诉你

一、前言

今天看了一下Oracle官网的JVM规范,发现基本数据不止有八种。

这个东西一直都是说着八种,官网把returnAddress放在八种基本数据类型一起说的,我们可以理解为第九种!

常说的八种用于存储常见的数值和字符数据,第九种是指向 Java 虚拟机指令的操作码的指针,属于内部使用的!

说的时候一般忽略returnAddress,小编这里把它作为第九种不知道合不合适,欢迎讨论哈!

结论咱们都说的差不多了,下面我们一起来看看定义和文档吧!

二、八种基本数据类型

借此来说一下常见面试题:Java中基本数据类型有几种,占几个字节?

类型占用字节
byte1 字节
short2 字节
int4 字节
long8 字节
float4 字节
double8 字节
char2 字节
boolean:不定,通常实现为 1 字节或更多字节,但不会按照字节来衡量。

八种数据类型用于存储常见的数值和字符数据,是 Java 语言的核心数据类型。

三、官网文档和定义

大家可以去文档里看看:

Oracle JVM规范1.8文档

2.3. Primitive Types and Values
The primitive data types supported by the Java Virtual Machine are the numeric types, the boolean type (§2.3.4), and the returnAddress type (§2.3.3).
The numeric types consist of the integral types (§2.3.1) and the floating-point types (§2.3.2).
The integral types are:
byte, whose values are 8-bit signed two’s-complement integers, and whose default value is zero
short, whose values are 16-bit signed two’s-complement integers, and whose default value is zero
int, whose values are 32-bit signed two’s-complement integers, and whose default value is zero
long, whose values are 64-bit signed two’s-complement integers, and whose default value is zero
char, whose values are 16-bit unsigned integers representing Unicode code points in the Basic Multilingual Plane, encoded with UTF-16, and whose default value is the null code point (‘\u0000’)
The floating-point types are:
float, whose values are elements of the float value set or, where supported, the float-extended-exponent value set, and whose default value is positive zero
double, whose values are elements of the double value set or, where supported, the double-extended-exponent value set, and whose default value is positive zero
The values of the boolean type encode the truth values true and false, and the default value is false.
The First Edition of The Java® Virtual Machine Specification did not consider boolean to be a Java Virtual Machine type. However, boolean values do have limited support in the Java Virtual Machine. The Second Edition of The Java® Virtual Machine Specification clarified the issue by treating boolean as a type.
The values of the returnAddress type are pointers to the opcodes of Java Virtual Machine instructions. Of the primitive types, only the returnAddress type is not directly associated with a Java programming language type.

翻一下给大家:

在这里插入图片描述
returnAddress详细的介绍,我们看一下官网:

2.3.3. 类型returnAddress和值

该returnAddress类型由 Java 虚拟机的jsr、ret和jsr_w指令(§ jsr、§ ret、 § jsr_w)使用。

该类型的值returnAddress 是指向 Java 虚拟机指令的操作码的指针

与数字基元类型不同,该returnAddress类型不对应于任何 Java 编程语言类型,并且不能由正在运行的程序修改。


看到这里了,还请动一下您的发财小手,关注一下公众号哈!!谢谢您的关注!!文章首发看!!!

建了一个IT交流群,欢迎大家加入,过期加我拉你们进哈!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

掉发的小王

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值