1.类的主方法——Main方法
1.主方法是静态的,如果在主方法中调用其他方法,则该方法必须也是静态的。
2.主方法没有返回值。
2.eclipse中设置程序参数
略
3.对象的特性
1.对象的创建:使用new操作符调用构造方法就可以创建一个对象
2.对象的引用:
public class DuiXiangTest {
int i = 365;
public int getname() {
return i;
}
public static void main(String[] args) {
DuiXiangTest a = new DuiXiangTest();//a是对象的一个引用
System.out.println(a.getname());//可以用引用来调用
System.out.println(new DuiXiangTest().getname());//也可以直接来调用
}
}
3.对象的使用
public class YinYong {
String a = "刘情利";//成员变量
public void call(){
System.out.println("调用了call方法");
System.out.println(a);
}
public static void main(String[] args) {
YinYong a = new YinYong();
a.call();//调用成员方法
System.out.println(a.a);//输出成员变量
}
}
4.对象的销毁
略
4.整数类型包装类——Integer类
用于封装int 类型数据,基本操作如下
public class IntegerTest {
public static void main(String[] args) {
System.out.println("int类型的最小值"+Integer.MIN_VALUE);
System.out.println("int类型的最大值"+Integer.MAX_VALUE);
System.out.println("int类型所占用的长度"+Integer.SIZE);
System.out.println("int类型的类型"+Integer.TYPE);
Integer inte1 = new Integer(123);
System.out.println(inte1);
Integer inte2 = new Integer("321");//两种构造方法
System.out.println(inte2);
Integer inte3 = Integer.valueOf(123456);//一种赋值方法
System.out.println(inte3);
int a = Integer.parseInt("1234");//转换成int类型
System.out.println(a+1);
int b = inte2.intValue();//转换成int类型
System.out.println(b-1);
String er = Integer.toBinaryString(12);//转换成2进制数
System.out.println("11的二进制表示为"+er);
String liu = Integer.toHexString(14);
System.out.println("14的十六进制表示为"+liu);
String ba = Integer.toOctalString(9);
System.out.println("9的十六进制表示为"+ba);
String renyi = Integer.toString(15,16);//15的16进制表示
System.out.println(renyi);
}
}