2020-05-04基礎(chǔ)知識復(fù)習3——java基礎(chǔ)2

欠下的

字符流沒認真學(xué),案例也都沒看,異常處理 P312~P323重要!!TCP練習沒有練,四種引用講的不行,自己以后看博客吧,反射學(xué)的也粗糙

1.IO流

1.1File

1.1.1File類概述和構(gòu)造方法

1.1.2File類創(chuàng)建功能

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字節(jié)流

1.2.1IO流概述和分類

1.2.2字節(jié)流寫數(shù)據(jù)

String類下方法:
bytes[] getBytes (String s);




1.2.3字節(jié)流寫數(shù)據(jù)異常處理

1.2.4字節(jié)流讀數(shù)據(jù)

一次讀一個字節(jié)



一次讀一個字節(jié)數(shù)組


1.2.5案例:復(fù)制圖片

1.2.6字節(jié)緩沖流

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);

        //寫數(shù)據(jù)
        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字符流的編碼解碼問題

***用什么方式編碼,就用什么方式解碼,否則會出現(xiàn)亂碼
下面是使用字符流的兩個抽象基類進行編碼解碼讀寫


1.3.3字符流寫數(shù)據(jù)

1.3.4字符流讀數(shù)據(jù)

1.3.5字符緩沖流

1.3.6字符緩沖流特有功能



1.4異常處理

2.多線程

2.1實現(xiàn)多線程

2.1.1多線程實現(xiàn)方式
2.1.2線程調(diào)度
2.1.3
康熙和四阿哥八阿哥

劉關(guān)張守護線程
2.1.4多線程實現(xiàn)方式

Runnable接口較繼承Thread的好處

2.2線程同步

2.2.1同步代碼塊
2.2.2同步方法
2.2.3線程安全的類

StringBuffer
Vector
HashTable


2.3生產(chǎn)者消費者

3.網(wǎng)絡(luò)編程

3.1網(wǎng)絡(luò)編程

3.2UDP

3.2.1UDP發(fā)送數(shù)據(jù)

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接收數(shù)據(jù)

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發(fā)送數(shù)據(jù)


3.3.1TCP接收數(shù)據(jù)


4.Lambda表達式

4.1Lambda初體驗



4.2Lambda練習

4.2.1練習一 無參無返回值

public class EatableDemo {
    public static void main(String[] args) {
        //第一種
        Eatable e = new EatableImpl();
        useEatable(e);

        //第二種,匿名內(nèi)部類
        useEatable(new Eatable() {
            @Override
            public void eat() {
                System.out.println("一天一蘋果,醫(yī)生遠離我");
            }
        });

        //第三種,Lambda表達式
        useEatable(() -> {
            System.out.println("一天一蘋果,醫(yī)生遠離我");
        });
    }

    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與匿名內(nèi)部類的區(qū)別

4.3接口方法

4.3.1接口中默認方法

4.3.2接口中靜態(tài)方法

4.3.3接口中私有方法(需要JDK9

5.方法引用

5.1方法引用符

5.2四種引用

6.函數(shù)式接口

6.1概述

6.2函數(shù)式接口作為方法參數(shù)

6.3函數(shù)式接口作為方法返回值

(有點懵

6.4常用函數(shù)式接口

6.4.1Supplier


6.4.2Consumer接口


6.4.3Predicate接口

6.4.4Function接口

7.Stream流

7.1概述

7.2流的使用


7.3流的生成

7.4流的中間操作


精彩操作



7.5終結(jié)操作

7.6流的收集操作





8.類加載器和反射

8.1類加載


8.2反射

9.模塊化

image.png
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容