这篇文章,我们讨论一些java的最基本的东西,这些东西我们一般刚刚学java的时候就学过,但是不一定真正明白。正好,我在做一个读取内存的值,涉及到bit位的值的读取和写。那就可以讨论一个java的基本数据类型的值在机器的详细情况:
Java基本数据类型共有八种三类:字符类型char,布尔类型boolean以及数值类型byte、short、int、long、float、double。数值类型又可以分为整数类型byte、short、int、long和浮点数类型float、double。
Java决定了每种简单类型的大小。这些大小并不随着机器结构的变化而变化。这种大小的不可更改正是Java程序具有很强移植能力的原因之一。
下面,我们就是要分析java基本数据类型的取值范围和占多少字节多少bit(1字节 = 8 bit)。
public class BaseDataInfo{
public static void main(String[] args) {
System.out.println("Boolean.FALSE:"+Boolean.FALSE);
System.out.println("Boolean.TRUE:"+Boolean.TRUE);
int maxByte = Byte.MAX_VALUE;
int minByte = Byte.MIN_VALUE;
int sizeByte = Byte.SIZE;
System.out.println("Byte.MAX_VALUE:"+maxByte);
System.out.println("Byte.MIN_VALUE:"+minByte);
System.out.println("Byte.SIZE:"+sizeByte);
int maxChar = Character.MAX_VALUE;
int minChar = Character.MIN_VALUE;
int sizeChar = Character.SIZE;
System.out.println("Character.MAX_VALUE:"+maxChar);
System.out.println("Character.MIN_VALUE:"+minChar);
System.out.println("Character.SIZE:"+sizeChar);
int maxShort = Short.MAX_VALUE;
int minShort = Short.MIN_VALUE;
int sizeShort = Short.SIZE;
System.out.println("Short.MAX_VALUE:"+maxShort);
System.out.println("Short.MIN_VALUE:"+minShort);
System.out.println("Short.SIZE:"+sizeShort);
int maxInt = Integer.MAX_VALUE;
int minInt = Integer.MIN_VALUE;
int sizeInt = Integer.SIZE;
int bitCount = Integer.bitCount(10);
System.out.println("Integer.MAX_VALUE:"+maxInt);
System.out.println("Integer.MIN_VALUE:"+minInt);
System.out.println("Integer.SIZE:"+sizeInt);
System.out.println("Integer.bitCount(1):"+bitCount);
long maxLong = Long.MAX_VALUE;
long minLong = Long.MIN_VALUE;
int sizeLong = Long.SIZE;
System.out.println("Long.MAX_VALUE:"+maxLong);
System.out.println("Long.MIN_VALUE:"+minLong);
System.out.println("Long.SIZE:"+sizeLong);
float maxFloat = Float.MAX_VALUE;
float minFloat = Float.MIN_VALUE;
int sizeFloat = Float.SIZE;
System.out.println("Float.MAX_VALUE:"+maxFloat);
System.out.println("Float.MIN_VALUE:"+minFloat);
System.out.println("Float.SIZE:"+sizeFloat);
Double maxDouble = Double.MAX_VALUE;
Double minDouble = Double.MIN_VALUE;
int sizeDouble = Double.SIZE;
System.out.println("Double.MAX_VALUE:"+maxDouble);
System.out.println("Double.MIN_VALUE:"+minDouble);
System.out.println("Double.SIZE:"+sizeDouble);
}
}
Boolean.FALSE:false
Boolean.TRUE:true
Byte.MAX_VALUE:127
Byte.MIN_VALUE:-128
Byte.SIZE:8
Character.MAX_VALUE:65535
Character.MIN_VALUE:0
Character.SIZE:16
Short.MAX_VALUE:32767
Short.MIN_VALUE:-32768
Short.SIZE:16
Integer.MAX_VALUE:2147483647
Integer.MIN_VALUE:-2147483648
Integer.SIZE:32
Integer.bitCount(1):2
Long.MAX_VALUE:9223372036854775807
Long.MIN_VALUE:-9223372036854775808
Long.SIZE:64
Float.MAX_VALUE:3.4028235E38
Float.MIN_VALUE:1.4E-45
Float.SIZE:32
Double.MAX_VALUE:1.7976931348623157E308
Double.MIN_VALUE:4.9E-324
Double.SIZE:64
Java基本数据类型总结
http://www.cnblogs.com/doit8791/archive/2012/05/25/2517448.html
内容来源于网络,如有侵权,请联系作者删除!