JAVA中八种基本数据类型介绍:
package Test;
/*
* 一、基本数据字符类型(八种)
* 1.整形数据类型:byte、short、int、long
* 2.字符数据类型:char
* 3.浮点数据类型:float、double
* 4.布尔数据类型:boolean
* 字符串不是基本数据类型,其为引用数据类型
*/
public class Test {
public static void main(String[] args){
//1byte = 8 bit(位)
byte a = 2; //占1个字节
short b = 57; //占2个字节
int c = 67098; //占4个字节
long d = 4567890; //占8个字节
char e = 'a'; //占2个字节
//因为浮点数类型默认是用double,定义float类型时需要加f来区别
float f = 145.6f; //占4个字节
double g = 4532.54; //占8个字节
//布尔类型只有两种数据:false/true,其所占内存大小没有明确说法
boolean h = true;
System.out.println(a);
System.out.println(b);
System.out.println(c);
System.out.println(d);
System.out.println(e);
System.out.println(f);
System.out.println(g);
System.out.println(h);
System.out.println(Byte.SIZE/8);//byte所占字节数
System.out.println(Short.SIZE/8);//short所占字节数
System.out.println(Integer.SIZE/8);//int所占字节数
System.out.println(Long.SIZE/8);//long所占字节数
System.out.println(Character.SIZE/8);//char所占字节数
System.out.println(Float.SIZE/8);//float所占字节数
System.out.println(Double.SIZE/8);//double所占字节数
}
}