欠下的
字符流没认真学,案例也都没看,异常处理 P312~P323重要!!TCP练习没有练,四种引用讲的不行,自己以后看博客吧,反射学的也粗糙
1.IO流
1.1File
1.1.1File类概述和构造方法
1.1.2File类创建功能
1.1.3File类判断和获取删除功能
1.1.4遍历目录
public class FileDemo02 {
public static void main(String[] args) {
File srcFile = new File("D:\\project\\IdeaProjects");
getAllFilePath(srcFile);
}
public static void getAllFilePath(File srcFile){
File[] fileArray = srcFile.listFiles();
if(fileArray != null){
for(File file: fileArray){
if(file.isDirectory()){
getAllFilePath(file);
}
else{
System.out.println(file.getAbsolutePath());
}
}
}
}
}
1.2字节流
1.2.1IO流概述和分类
1.2.2字节流写数据
String类下方法:
bytes[] getBytes (String s);
1.2.3字节流写数据异常处理
1.2.4字节流读数据
一次读一个字节
一次读一个字节数组
1.2.5案例:复制图片
1.2.6字节缓冲流
public class BufferedStreamDemo {
public static void main(String[] args) throws IOException {
FileOutputStream fos = new FileOutputStream("D:\\project\\IdeaProjects\\FirstProject\\fos.txt");
BufferedOutputStream bos = new BufferedOutputStream(fos);
//写数据
bos.write("hello\r\n".getBytes());
bos.write("world\r\n".getBytes());
//释放资源
bos.close();
fos.close();
BufferedInputStream bis = new BufferedInputStream(new FileInputStream("D:\\project\\IdeaProjects\\FirstProject\\fos.txt"));
int by;
while((by = bis.read()) != -1){
System.out.print((char)by);
}
//释放资源
bis.close();
}
}
1.3字符流
1.3.1为什么有字符流
1.3.2字符流的编码解码问题
***用什么方式编码,就用什么方式解码,否则会出现乱码
下面是使用字符流的两个抽象基类进行编码解码读写
1.3.3字符流写数据
1.3.4字符流读数据
1.3.5字符缓冲流
1.3.6字符缓冲流特有功能
1.4异常处理
2.多线程
2.1实现多线程
2.1.1多线程实现方式
2.1.2线程调度
2.1.3
康熙和四阿哥八阿哥
刘关张守护线程
2.1.4多线程实现方式
Runnable接口较继承Thread的好处
2.2线程同步
2.2.1同步代码块
2.2.2同步方法
2.2.3线程安全的类
StringBuffer
Vector
HashTable
2.3生产者消费者
3.网络编程
3.1网络编程
3.2UDP
3.2.1UDP发送数据
public class SendDemo {
public static void main(String[] args) throws IOException {
DatagramSocket dgs = new DatagramSocket();
byte[] bys = "Hello, udp. 我来啦".getBytes();
int length = bys.length;
InetAddress address = InetAddress.getByName("192.168.1.2");
int port = 10086;
DatagramPacket dp = new DatagramPacket(bys,length,address,port);
dgs.send(dp);
dgs.close();
}
}
3.2.2UDP接收数据
public class SendDemo {
public static void main(String[] args) throws IOException {
DatagramSocket dgs = new DatagramSocket();
byte[] bys = "Hello, udp. 我来啦".getBytes();
int length = bys.length;
InetAddress address = InetAddress.getByName("192.168.1.2");
int port = 10086;
DatagramPacket dp = new DatagramPacket(bys,length,address,port);
dgs.send(dp);
dgs.close();
}
}
3.3TCP
3.3.1TCP发送数据
3.3.1TCP接收数据
4.Lambda表达式
4.1Lambda初体验
4.2Lambda练习
4.2.1练习一 无参无返回值
public class EatableDemo {
public static void main(String[] args) {
//第一种
Eatable e = new EatableImpl();
useEatable(e);
//第二种,匿名内部类
useEatable(new Eatable() {
@Override
public void eat() {
System.out.println("一天一苹果,医生远离我");
}
});
//第三种,Lambda表达式
useEatable(() -> {
System.out.println("一天一苹果,医生远离我");
});
}
public static void useEatable(Eatable e){
e.eat();
}
}
4.2.2练习三 带参带返回值
public class AddableDemo {
public static void main(String[] args) {
useAddable(new Addable() {
@Override
public int add(int x, int y) {
return x + y;
}
});
useAddable((int x,int y) -> {
return x + y;
});
}
public static void useAddable(Addable a){
int sum = a.add(3,4);
System.out.println("sum = " + sum);
}
}
public interface Addable {
int add(int x, int y);
}
4.2.3Lambda省略模式
4.2.4Lambda与匿名内部类的区别
4.3接口方法
4.3.1接口中默认方法
4.3.2接口中静态方法
4.3.3接口中私有方法(需要JDK9
5.方法引用
5.1方法引用符
5.2四种引用
6.函数式接口
6.1概述
6.2函数式接口作为方法参数
6.3函数式接口作为方法返回值
(有点懵
6.4常用函数式接口
6.4.1Supplier
6.4.2Consumer接口
6.4.3Predicate接口
6.4.4Function接口
7.Stream流
7.1概述
7.2流的使用
7.3流的生成
7.4流的中间操作
精彩操作
7.5终结操作
7.6流的收集操作
8.类加载器和反射
8.1类加载
8.2反射
9.模块化
image.png