java中8中基本数据类型

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/xiao_xiao_b/article/details/96364658
java中八种基本数据类型
序号 数据类型 大小/位 大小/字节 封装类 默认值 可表示数据范围
1 byte(位) 8 1 Byte 0 -128~127
2 short(短整数) 16 2 Short 0 - 2^15 ~ 2^15-1
3 int(整数) 32 4 Integer 0 - 2^31 ~ 2^31-1
3 long(长整数) 64 8 Long 0 - 2^63 ~ 2^63-1
5 float(单精度) 32 4 Float 0.0 1.4E-45~3.4028235E38
6 double(双精度) 64 8 Double 0.0 4.9E-324~1.7976931348623157E308
7 char(字符) 16 2 Character '\u0000' 0~2^16-1
8 boolean布尔) 8 1 Boolean flase true或false
验证代码
package 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);     
        
  
    }  
  
}  
输出结果
byte的大小: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  

原文:https://blog.csdn.net/fysuccess/article/details/40656761#

猜你喜欢

转载自blog.csdn.net/xiao_xiao_b/article/details/96364658