Employee.java package com.google.eshop.javase;public class Employee {//不要把main方法写入一个类,main方法不是类必须//TestEyployee 单元测试 压力测试//类中的两部分1.属性 2.方法(1.构造方法 2.普通方法
package com.google.eshop.javase; public class Employee { //不要把main方法写入一个类,main方法不是类必须 //TestEyployee 单元测试 压力测试 //类中的两部分1.属性 2.方法(1.构造方法 2.普通方法) //Integer eid; private Integer eid; private String ename; //String gender; private String genter; //Boolean married; private Boolean married; //方法重载只能通过参数列表的不同来区分,不能通过是否有返回值来区分 //只要参数列表不同就可以了 可以交换参数之间的次序 尽量不要通过参数的次序来区别不同的方法 //这样的做法会让编译器的压力比较大 public Employee(){ } public Employee(int id,String name) { eid=id; ename=name; } public Employee(int id,String name,Boolean isMarried) { eid=id; ename=name; married=isMarried; } /*public void setEid(Integer eid) { this.eid = eid; } public void setEname(String ename) { this.ename = ename; } public void setGenter(String genter) { this.genter = genter; } public void setMarried(Boolean married) { this.married = married; }*/ public Integer getEid() { return eid; } public String getEname() { return ename; } public String getGenter() { return genter; } public Boolean getMarried() { return married; } public void working(int eid,String name) { System.out.println("工号:"+eid+"名字:"+name+"在工作"); } /*public void working(String ename,int eid) { System.out.println("NO:"+eid+"isMarried:"+ename+"在工作"); }*/ public String eat(int eid,String name,Boolean married) { return "工号"+eid+"姓名:"+name+"婚否"+married; } }TestEmployee.java
package com.google.eshop.javase; import java.util.Stack; public class TestEmployee { //Employee emp是引用 在堆栈中(Stack) new后面的是对象(地址空间)(heap)堆 public static void main(String[] args) { //System.out.println(i); 没有赋值 //局部变量必须赋值 Employee emp=new Employee(); emp=new Employee(); emp.working(22,""); emp.working(45, ""); /*if(null!=emp) { emp.eid=12; emp.ename="john"; emp.working(emp.eid, emp.ename); }*/ //泛型 generic type 1.5新特性 //限制在一个对象内,只能放置一种类型 StackTestInterface.javastack=new Stack (); //stack.push("abc"); //报错,只能是int型 stack.push(12); //进栈 stack.push(34); stack.push(56); stack.push(67); int top=stack.peek(); //顶元素 System.out.println(top); int element=stack.pop(); System.out.println(element); element=stack.pop(); //出栈 System.out.println(element); String str="def"; str.indexOf("a"); int result=Integer.parseInt("126358"); System.out.println(result); } }
package com.google.eshop.javase; //堆栈,堆,常量存储,非RAM存储 public class TestInterface { public static void main(String[] args) { //如果对象只使用一次可以使用匿名对象,如果要多次使用,需要用引用指向他 //new Employee().eid=34; new Employee().getEid(); new Employee().working(12, "abc"); new Employee().working(23, "gates"); Employee emp=new Employee(); emp=new Employee(); emp.working(34, "def"); emp.working(56, "ios"); //emp.eid=456; //字符串少做拼接操作 String str="abc"; String a="abc"; System.out.println(a+str); str=new String("def"); System.out.println(a+str); } }TestOverLoading.java
package com.google.eshop.javase; public class TestOverLoading { public static void main(String[] args) { Employee employee=new Employee();//无变量 System.out.println(employee.getEname()); employee=new Employee(23,"bush");//两个变量 System.out.println(employee.getEname()); employee=new Employee(45,"gates",false);//三个变量 System.out.println(employee.getEname()); } }WrapClass.java
package com.google.eshop.javase; import java.math.BigDecimal; import java.math.BigInteger; //import java.lang.*; 默认已导入,不需再导 //默认导入的是java.lang.* //import javax.xml.crypto.Data; //javax 扩展包 public class WrapClass { @SuppressWarnings("deprecation") public static void main(String[] args) { Employee emp=new Employee(); System.out.println(emp); Integer a=45+56; a=new Integer(56);//autoBoxing a=new Integer(5555);//autoBoxing System.out.println(a.intValue()); System.out.println(a);//unBoxing String str=new String("andiod"); //String str=new String(); System.out.println(str); //int Integer //double Double //char Character //有两个数据类型是没有对应基本数据类型的 没有自动拆装箱的功能 BigInteger bi=new BigInteger("555555"); BigInteger ab=bi.add(new BigInteger("7777777")); //bi.subtract(ab); //bi.multiply(ab); //bi.divide(ab); System.out.println(ab); BigDecimal bd=new BigDecimal("678.9999999"); bd=BigDecimal.valueOf(56.789); System.out.println(bd.divide(new BigDecimal("0.1"))); //Data data; //int c=5; Integer c=new Integer(555); c=555;//将一个基本类型赋值给一个引用类型 autoBoxing System.out.println(c.intValue()); System.out.println(c);//将一个引用类型的值直接取出来 不用方法 unBoxing Employee emp1=new Employee(); System.out.println(emp1); } }