第一本书(类、对象、接口)
第一章结束后:
Console的商场(类之间的关系):EXcel代替数据库)
1.1、方法参数的传递
- 按值传递(传递的是值的拷贝)
public class MethodDemo {
public static void main(String[] args) {
int a=3;
m1(a);
System.out.println("AAAAAA: "+a);
}
/*
局部变量
*/
public static void m1(int a){
a=5;
System.out.println("CCCCCC: "+a);
}
}
- 按引用传递
public class MethodDemo01 {
public static void main(String[] args) {
int a[]={1,2,3};
m1(a);
for(int i=0;i<a.length;i++){
System.out.println(a[i]);
}
}
public static void m1(int b[]){
b[2]=88;
}
断点调试 debug
左键插入断点
开始Debug
让代码开始一步一步执行
计算机中的程序错误,为什么叫bug?
1.2、字符串String
教育的本质:见多识广
编程的本质:调用方法
字符串的常用方法
charAt(int index)
concat(String str)
contains(CharSequence s)
endsWith(String suffix)
equals(Object anObject)
getBytes(String charsetName)
indexOf(String str)
lastIndexOf(String str)
length()
matches(String regex)
replace(char oldChar, char newChar)
split(String regex)
startsWith(String prefix)
substring(int beginIndex)
toString()
toLowerCase()
toUpperCase()
trim()
valueOf(float f)
字符串的特点
不可变
public static void main(String[] args) {
String str="hechi";
String newStr=str.replace('h','H');
System.out.println("替换后的结果:"+newStr);
System.out.println("原本的字符串" + str);
}
结果

1.3、StringBuffer和StringBuilder
区别:synchronize
StringBuffer是线程安全
StringBuilder是非线程安全
N个火车票代售网点,相当于N线程
张三在宜州网点买G566车次的第8车厢的F座
李四在金城江区网点买G566次的第8车厢的F座
如果能买到就是非线程安全
1.4、类和对象
最重要的是会进行类的抽取
学生选课系统
学生:类,小明:对象
教师:类,李老师:对象
教务处秘书:类 , 小红秘书:对象
课程:类,课程名、课程号:对象
- 封装
1.所有属性private修饰
2.给所有的属性增加public的setter和getter的方法
- 继承(代码复用)
构造方法、this、super
this:类的当前对象,并不是特指哪个对象
JVM会给类提供一个默认的构造方法
给类的属性赋值方式
通过SETTER 快捷键:Ctrl+Insert 菜单中选择SETTER
通过构造方法 快捷键:Ctrl+Insert 菜单中选择constructor
supper表示的是父类的对象
需求:如何让Student和Teacher的对象都拥有默认的123456的密码?
第一步:
//新建一个Users父类,写一个构造方法设置密码password
public Users(String password) {
this.password = password;
}
第二步:
//在Student类中,创建构造方法,通过使用super关键字来设置密码为123456
public Student(String password) {
super("123456");
}
//在Student类中,创建构造方法,通过使用super关键字来设置密码为123456
public Teacher(String password) {
super("123456");
}
第三步:
public class Test {
public static void main(String[] args) {
Student stu = new Student();
Student stu1=new Student();
System.out.println(stu.getPassword());
System.out.println(stu1.getPassword());
}
}
输出结果为:123456
123456
重写:Override(先有继承,才能重写)
什么情况下才需要重写?当父类的方法满足不来子类的需求的时候,就要重写父类的方法
String类重写了父类的toString方法
学生类:
public class Student extends Users {
private String major;
private String phone;
public Student(String major, String phone) {
super("123456");
this.major = major;
this.phone = phone;
}
public String getMajor() {
return major;
}
public String getPhone() {
return phone;
}
@Override
public String toString() {
return "Student{" +
"major='" + major + '\'' +
", phone='" + phone + '\'' +
'}';
}
}
主类:
public class Test {
public static void main(String[] args) {
Student stu = new Student("计算机科学与技术","18377940962");
Student stu1=new Student("网络工程","1887415615");
System.out.println(stu.getMajor());
System.out.println(stu.getPhone());
System.out.println(stu1.getMajor());
System.out.println(stu1.getPhone());
System.out.println(stu.getPassword());
System.out.println(stu); //方法的重写
System.out.println(stu1); //方法的重写
}
}
多态
接口
抽象类
1.5、github的开发模式
项目组的成员从master创建分支(branch),每天下班的时候,先提交push到自己的分支,如果代码无误,则申请和master合并
每个组的成员fork一份master的代码,每天下班的时候,先提交push到自己的仓库,如果代码无误,则给组长发宋体pr(pull request)
1.6、git的使用
和idea集成使用
独立使用
SSH密钥
第二本书(异常、集合、I/O、多线程、Socket)
局域网内部的聊天程序(I/O、多线程、Socket)、传文件(单独传、群发),redis充当数据库
交push到自己的分支,如果代码无误,则申请和master合并
- 每个组的成员fork一份master的代码,每天下班的时候,先提交push到自己的仓库,如果代码无误,则给组长发宋体pr(pull request)
1.6、git的使用
和idea集成使用
独立使用
SSH密钥
第二本书(异常、集合、I/O、多线程、Socket)
局域网内部的聊天程序(I/O、多线程、Socket)、传文件(单独传、群发),redis充当数据库