java中8种数据类型和默认值所占字节数

通过一段代码来测试一下 8种基本数据类型的默认值

复制代码
 1 package dierge;
 2 
 3 public class Ceshi {
 4     int a;
 5     double b;
 6     boolean c;
 7     char d;
 8     float f;
 9     byte e;
10     long h;
11     short j;
12     public static void main(String args[]){
13         Ceshi a=new Ceshi();
14         System.out.println("整型的默认值是:"+a.a);
15         System.out.println("双精度浮点型的默认值是:"+a.b);
16         System.out.println("布尔型的默认值是:"+a.c);
17         System.out.println("字符型的默认值是:"+a.d);
18         System.out.println("byte的默认值是:"+a.e);
19         System.out.println("单精度浮点型的默认值是:"+a.f);
20         System.out.println("短整型的默认值是:"+a.j);
21         System.out.println("长整型的默认值是:"+a.h);
22 
23         
24         
25     }
26 
27 }
运行结果如下:

整型的默认值是:0
双精度浮点型的默认值是:0.0
布尔型的默认值是:false
字符型的默认值是:

得出如下结论:

基本类型默认值
byte 0
short 0
int 0
long 0L
float 0.0f
double 0.0d
char ‘u0000’
boolean false
 
   
复制代码

 java中8种数据类型所占字节数如下:

boolean 这个试编译环境而定
byte 1个字节
short 2个字节
char 2个字节
int 4个字节
long 8个字节
float 4个字节
double 8个字节
原文地址:https://www.cnblogs.com/wangzhuxing/p/6527927.html