Java基本数据类型只有八种?第九种告诉你
  duJ5DByAvvc0 2023年11月02日 40 0


一、前言

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

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

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

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

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

二、八种基本数据类型

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

类型

占用字节

byte

1 字节

short

2 字节

int

4 字节

long

8 字节

float

4 字节

double

8 字节

char

2 字节

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.

翻一下给大家:

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


returnAddress详细的介绍,我们看一下官网:

2.3.3. 类型returnAddress和值

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

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

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


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

【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
  xaeiTka4h8LY   2024年05月17日   38   0   0 数据库JavaSQL
  2iBE5Ikkruz5   2023年12月12日   80   0   0 JavaJavaredisredis
duJ5DByAvvc0