Java基本数据类型
八种基本类型
- 字节型byte 8位
- 短整型short 16位
- 整型int 32位
- 长整型long 64位
- 单精度float 32位
- 双精度double 64位
- 布尔型:boolean 8位,可存储"True"和"false"
Integer是int的封装,跟int的表示范围一样
引用数据类型
包括:类、接口、数组
Java中各种数据的默认值
8种基本类型的初始值:
- byte:0
- short:0
- int:0
- long:0
- float:0.0
- double:0.0
- char: (一个空格)
- boolean:false
- 引用数据类型:
- String:null
- a[0]:0
- cha[0]: (一个空格)
附代码
//////TestMain.java::::
package com.main;
import com.bean.Test;
public class TestMain {
public static void main(String[] args) {
Test stu1=new Test();
System.out.println("8种基本类型的初始值:");
System.out.println("byte:"+stu1.getBytes());
System.out.println("short:"+stu1.getShorts());
System.out.println("int:"+stu1.getInts());
System.out.println("long:"+stu1.getLongs());
System.out.println("float:"+stu1.getFloats());
System.out.println("double:"+stu1.getDoubles());
System.out.println("char:"+stu1.getChars());
System.out.println("boolean:"+stu1.isBooleans());
System.out.println("引用数据类型:");
System.out.println("String:"+stu1.getStr());
int[] aa=stu1.getA();
System.out.println("a[0]:"+aa[0]);
char[] cha=stu1.getCha();
System.out.println("cha[0]:"+cha[0]);
}
}
//////Test.java:::::
package com.bean;
public class Test {
//8种基本数据类型
private byte bytes;
private short shorts;
private int ints;
private long longs;
private float floats;
private double doubles;
private char chars;
private boolean booleans;
public byte getBytes() {
return bytes;
}
public void setBytes(byte bytes) {
this.bytes = bytes;
}
public short getShorts() {
return shorts;
}
public void setShorts(short shorts) {
this.shorts = shorts;
}
public int getInts() {
return ints;
}
public void setInts(int ints) {
this.ints = ints;
}
public long getLongs() {
return longs;
}
public void setLongs(long longs) {
this.longs = longs;
}
public float getFloats() {
return floats;
}
public void setFloats(float floats) {
this.floats = floats;
}
public double getDoubles() {
return doubles;
}
public void setDoubles(double doubles) {
this.doubles = doubles;
}
public char getChars() {
return chars;
}
public void setChars(char chars) {
this.chars = chars;
}
public boolean isBooleans() {
return booleans;
}
public void setBooleans(boolean booleans) {
this.booleans = booleans;
}
//引用数据类型
private String str;
private int[] a=new int[4];
private char[] cha=new char[4];
public char[] getCha() {
return cha;
}
public void setCha(char[] cha) {
this.cha = cha;
}
public int[] getA() {
return a;
}
public void setA(int[] a) {
this.a = a;
}
public String getStr() {
return str;
}
public void setStr(String str) {
this.str = str;
}
}