1. java有哪些基本数据类型
网络上有很多。基本类型有八种,都有对应的封装类。类型基本上可以分为三类:char、boolean和byte、short、int、long、float和double。类型可以分为整数类型(如字节、短整型、整型、长整型)和浮点类型(如浮点型和双精度型)。JAVA中没有无符号值类型,它们的值域是固定的,不会随着机器硬件环境或操作系统的变化而变化。
字符类型,-128到127之间的字节8位有符号整数,-32768到32767之间的短16位无符号整数,-231到231-1之间的Int 32位有符号整数,-263到263-1之间的Long 64位有符号整数,根据IEEE754-1985标准的Float 32位单精度浮点数,根据IEEE754-1985标准的Double 64位双精度浮点数1布尔类型在前一章的逻辑运算符中,我们已经看到了值为true和false的变量,它们被称为布尔变量。
2. 在java中如何实现将Boolean类型的数据转换成byte类型呢
您好。
java不支持这样的转换的。
java
boolean类型的数据只能是true和false两个值
只能这样
byte
a
=
5;
if(a
==
5){
}
3. 在java中boolean具体怎么使用
boolean是java中的布尔型(逻辑型)数据类型,在java中boolean值只能是true和false,而不能用0和1代替,并且一定要小写。
布尔值 true 代表“真”,false 代表“假”。一般关系运算符会返回布尔值的结果。另外,数值的 0、-0、特殊值的 null、NaN、undefined 以及空字符("")都会被解释为 false ,其他值则会被解释为 true 。
(3)javaboolean字节扩展阅读
java中创建boolean对象的方法:
1、使用关键词 new 来定义 Boolean 对象。下面的代码定义了一个名为 myBoolean 的逻辑对象:
var myBoolean = new Boolean()
var myBoolean = new Boolean()
注释:如果逻辑对象无初始值或者其值为 0、-0、null、""、false、undefined 或者 NaN,那么对象的值为 false。否则,其值为 true(即使当自变量为字符串 "false" 时)!
2、下面的所有的代码行均会创建初始值为 false 的 Boolean 对象。
var myBoolean = new Boolean();
var myBoolean = new Boolean(0);
var myBoolean = new Boolean(null);
var myBoolean = new Boolean("");
var myBoolean = new Boolean(NaN);
3、下面的所有的代码行均会创初始值为 true 的 Boolean 对象:
var myBoolean = new Boolean(1);
var myBoolean = new Boolean(true);
var myBoolean = new Boolean("true");
var myBoolean = new Boolean("false");
var myBoolean = new Boolean("Bill Gates");
4. Java基本数据类型boolean占内存多少
boolean占1个bit,1/8个字节,而Boolean是引用类型,在栈内存中存放着它的引用,在堆内存中存放着它的对象(Integer可以看成是对象),没法计算它占对少内存
5. 在java中boolean代表多少字节
java的基本数据类型中,boolean占一个字节,默认值为false.取值范围是{true,false},具体的解释如下:
单个的boolean
类型变量在编译的时候是使用的int
类型。而对于boolean
类型的数组时,在编译的时候是作为byte
array来编译的所以boolean
数组里面的每一个元件占一个字节,
6. 在java中boolean只能取true,false,它占的空间多大是16位,两个字节吗
建议查看java API官方文档,里面有详细说明:
1)boolean a=true;//这个a在JVM中占4个字节即:32位。
2)boolean[] b = new boolean[10];//数组时,每一个boolean在JVM中占一个字节。
理由:
1)JAVA规范中没有定义boolean类型的大小。
2)但是:在JVM规范第2版中讲得十分清楚。我上边的结论就是从它当中取出来的。
根据:(JVM规范第2版 3.3.4节)
Instead, expressions in the Java programming language that operate on boolean values are compiled to use values of the Java virtual machine int data type.
Where Java programming language boolean values are mapped by compilers to values of Java virtual machine type int, the compilers must use the same encoding. 而:Java virtual machine type int, whose values are 32-bit signed two's-complement integers。
Arrays of type boolean are accessed and modified using the byte array instructions
In Sun's JDK releases 1.0 and 1.1, and the Java 2 SDK, Standard Edition, v1.2, boolean arrays in the Java programming language are encoded as Java virtual machine byte arrays, using 8 bits per boolean element.
PS(请注意最后几句):
sun's Data Types introction:
byte: The byte data type is an 8-bit signed two's complement integer
short: The short data type is a 16-bit signed two's complement integer
int: The int data type is a 32-bit signed two's complement integer
long: The long data type is a 64-bit signed two's complement integer
float: The float data type is a single-precision 32-bit IEEE 754 floating point
double: The double data type is a double-precision 64-bit IEEE 754 floating point.
char: The char data type is a single 16-bit Unicode character
boolean: The boolean data type has only two possible values: true and false.
Use this data type for simple flags that track true/false conditions. This data type represents one bit of information,
but its "size" isn't something that's precisely defined.
7. 大家谁知道在java中boolean类型占多少个字节
java的基本数据类型中,boolean占一个字节,默认值为false.取值范围是{true,false},具体的解释如下:
单个的boolean 类型变量在编译的时候是使用的int 类型。而对于boolean 类型的数组时,在编译的时候是作为byte array来编译的所以boolean 数组里面的每一个元件占一个字节,
8. java有几种数据类型
基本数据类型
整数类型:
byte:字节占用 1字节 8位,用来表达最小的数据单位,储存数据长度为 正负 127;
short:字节占用 2字节 16位,储存数值长度为 -32768-32767
int:字节占用 4字节 32位,最为常用的整数类型,储存长度为,-2^31-1~2^31 (21 亿)
long:字节占用 8字节 64位,当到达int数值极限时使用,储存长度为 看图片:
9. Java中boolean类型占用多少个字节
《Java虚拟机规范》给出了4个字节,和boolean数组1个字节的定义,具体还要看虚拟机实现是否按照规范来,所以1个字节、4个字节都是有可能的。