您的位置:首页 > 编程语言 > Java开发

Java中8种基本数据类型及其默认值

2018-03-12 11:23 405 查看
Java中8种基本数据类型总结
序号
数据类型
大小/位
封装类
默认值
可表示数据范围
1
byte(位)
8
Byte
0
-128~127
2
short(短整数)
16
Short
0
-32768~32767
3
int(整数)
32
Integer
0
-2147483648~2147483647
4
long(长整数)
64
Long
0
-9223372036854775808~9223372036854775807
5
float(单精度)
32
Float
0.0
1.4E-45~3.4028235E38
6
double(双精度)
64
Double
0.0
4.9E-324~1.7976931348623157E308
7
char(字符)
16
Character

0~65535
8
boolean
8
Boolean
flase
true或false
在Myeclipse中Java验证代码如下:[java] view plain copypackage com.test;  
  
abstract class Other {  
      
    static byte a;  
    static short b;  
    static int c;  
    static long d;  
    static float e;  
    static double f;  
    static char g;  
    static boolean h;  
      
    //String不是基本类型  
    static String str1 = "";//生成一个String类型的引用,而且分配内存空间来存放"";  
    static String str2; //只生成一个string类型的引用;不分配内存空间,默认为null  
  
    public static void main(String[] args) {  
        
      System.out.println("byte的大小:"+Byte.SIZE+" byte的默认值:"+a+" byte的数据范围:"+Byte.MIN_VALUE+"~"+Byte.MAX_VALUE);     
      System.out.println("short的大小:"+Short.SIZE+" short的默认值:"+b+" short的数据范围:"+Short.MIN_VALUE+"~"+Short.MAX_VALUE);     
      System.out.println("int的大小:"+Integer.SIZE+" int的默认值:"+c+" int的数据范围:"+Integer.MIN_VALUE+"~"+Integer.MAX_VALUE);     
      System.out.println("long的大小:"+Long.SIZE+" long的默认值:"+d+" long的数据范围:"+Long.MIN_VALUE+"~"+Long.MAX_VALUE);     
      System.out.println("float的大小:"+Float.SIZE+" float的默认值:"+e+" float的数据范围:"+Float.MIN_VALUE+"~"+Float.MAX_VALUE);     
      System.out.println("double的大小:"+Double.SIZE+" double的默认值:"+f+" double的数据范围:"+Double.MIN_VALUE+"~"+Double.MAX_VALUE);     
      System.out.println("char的大小:"+Character.SIZE+" char的默认值:"+g+" char的数据范围:"+Character.MIN_VALUE+"~"+Character.MAX_VALUE);     
      System.out.println("boolean的大小:"+Byte.SIZE+" boolean的默认值:"+h+" boolean的数据范围:"+Byte.MIN_VALUE+"~"+Byte.MAX_VALUE);     
        
      System.out.println("String字符串的默认值:"+str1+"str的默认长度:"+str1.length());     
      System.out.println("String字符串的默认值:"+str2);     
        
  
    }  
  
}  

输出结果如下:[java] view plain copybyte的大小:8 byte的默认值:0 byte的数据范围:-128~127  
short的大小:16 short的默认值:0 short的数据范围:-32768~32767  
int的大小:32 int的默认值:0 int的数据范围:-2147483648~2147483647  
long的大小:64 long的默认值:0 long的数据范围:-9223372036854775808~9223372036854775807  
float的大小:32 float的默认值:0.0 float的数据范围:1.4E-45~3.4028235E38  
double的大小:64 double的默认值:0.0 double的数据范围:4.9E-324~1.7976931348623157E308  
char的大小:16 char的默认值:  
boolean的大小:8 boolean的默认值:false boolean的数据范围:-128~127  
String字符串的默认值:str的默认长度:0  
String字符串的默认值:null  
Java中8种基本数据类型总结
序号
数据类型
大小/位
封装类
默认值
可表示数据范围
1
byte(位)
8
Byte
0
-128~127
2
short(短整数)
16
Short
0
-32768~32767
3
int(整数)
32
Integer
0
-2147483648~2147483647
4
long(长整数)
64
Long
0
-9223372036854775808~9223372036854775807
5
float(单精度)
32
Float
0.0
1.4E-45~3.4028235E38
6
double(双精度)
64
Double
0.0
4.9E-324~1.7976931348623157E308
7
char(字符)
16
Character

0~65535
8
boolean
8
Boolean
flase
true或false
在Myeclipse中Java验证代码如下:[java] view plain copypackage com.test;  
  
abstract class Other {  
      
    static byte a;  
    static short b;  
    static int c;  
    static long d;  
    static float e;  
    static double f;  
    static char g;  
    static boolean h;  
      
    //String不是基本类型  
    static String str1 = "";//生成一个String类型的引用,而且分配内存空间来存放"";  
    static String str2; //只生成一个string类型的引用;不分配内存空间,默认为null  
  
    public static void main(String[] args) {  
        
      System.out.println("byte的大小:"+Byte.SIZE+" byte的默认值:"+a+" byte的数据范围:"+Byte.MIN_VALUE+"~"+Byte.MAX_VALUE);     
      System.out.println("short的大小:"+Short.SIZE+" short的默认值:"+b+" short的数据范围:"+Short.MIN_VALUE+"~"+Short.MAX_VALUE);     
      System.out.println("int的大小:"+Integer.SIZE+" int的默认值:"+c+" int的数据范围:"+Integer.MIN_VALUE+"~"+Integer.MAX_VALUE);     
      System.out.println("long的大小:"+Long.SIZE+" long的默认值:"+d+" long的数据范围:"+Long.MIN_VALUE+"~"+Long.MAX_VALUE);     
      System.out.println("float的大小:"+Float.SIZE+" float的默认值:"+e+" float的数据范围:"+Float.MIN_VALUE+"~"+Float.MAX_VALUE);     
      System.out.println("double的大小:"+Double.SIZE+" double的默认值:"+f+" double的数据范围:"+Double.MIN_VALUE+"~"+Double.MAX_VALUE);     
      System.out.println("char的大小:"+Character.SIZE+" char的默认值:"+g+" char的数据范围:"+Character.MIN_VALUE+"~"+Character.MAX_VALUE);     
      System.out.println("boolean的大小:"+Byte.SIZE+" boolean的默认值:"+h+" boolean的数据范围:"+Byte.MIN_VALUE+"~"+Byte.MAX_VALUE);     
        
      System.out.println("String字符串的默认值:"+str1+"str的默认长度:"+str1.length());     
      System.out.println("String字符串的默认值:"+str2);     
        
  
    }  
  
}  

输出结果如下:[java] view plain copybyte的大小:8 byte的默认值:0 byte的数据范围:-128~127  
short的大小:16 short的默认值:0 short的数据范围:-32768~32767  
int的大小:32 int的默认值:0 int的数据范围:-2147483648~2147483647  
long的大小:64 long的默认值:0 long的数据范围:-9223372036854775808~9223372036854775807  
float的大小:32 float的默认值:0.0 float的数据范围:1.4E-45~3.4028235E38  
double的大小:64 double的默认值:0.0 double的数据范围:4.9E-324~1.7976931348623157E308  
char的大小:16 char的默认值:  
boolean的大小:8 boolean的默认值:false boolean的数据范围:-128~127  
String字符串的默认值:str的默认长度:0  
String字符串的默认值:null  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: