可以改变的数,称为变量。在JAVA语言中,所有 变量在使用前必须声明。一般通过“变量类型”变量名 =变量值 ,这三部分来描述一个变量。如:int a=3;变量的使用原则:就近原则,即尽量控制变量的使用范围到最小
1.2局部变量位置:定义在方法里或者方法的声明上
注意:必须手动初始化来分配内存,如:int i=5;或者int i;i=5;
生命周期:随着方法的调用而存在,方法运行完毕就释放了
1.4练习:变量的默认值测试 创建包:cn.tedu.basic 创建类:TestVariable1.Javapackage cn.tedu.design;
public class TestVariable1 {
static String name;
static byte b;//整数类型默认值都是0
static short c;
static int d;
static long e;
static float f;//小数类型的默认值是0.0
static double g;
static char j;//char类型的默认值是u0000
static boolean h;//boolean类型的默认值是falsepublic static void main(String[] args) {
System.out.println(name);//null,引用类型的默认值
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(j);
System.out.println(h);
}
}



