瀏覽代碼

0915 整体回顾

Qing 8 月之前
父節點
當前提交
a466e2ddc9

+ 29 - 0
lesson/.gitignore

@@ -0,0 +1,29 @@
+### IntelliJ IDEA ###
+out/
+!**/src/main/**/out/
+!**/src/test/**/out/
+
+### Eclipse ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+bin/
+!**/src/main/**/bin/
+!**/src/test/**/bin/
+
+### NetBeans ###
+/nbproject/private/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/
+
+### VS Code ###
+.vscode/
+
+### Mac OS ###
+.DS_Store

+ 8 - 0
lesson/.idea/.gitignore

@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml

+ 6 - 0
lesson/.idea/google-java-format.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="GoogleJavaFormatSettings">
+    <option name="enabled" value="false" />
+  </component>
+</project>

+ 5 - 0
lesson/.idea/inspectionProfiles/Project_Default.xml

@@ -0,0 +1,5 @@
+<component name="InspectionProjectProfileManager">
+  <profile version="1.0">
+    <option name="myName" value="Project Default" />
+  </profile>
+</component>

+ 6 - 0
lesson/.idea/misc.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="corretto-17" project-jdk-type="JavaSDK">
+    <output url="file://$PROJECT_DIR$/out" />
+  </component>
+</project>

+ 8 - 0
lesson/.idea/modules.xml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ProjectModuleManager">
+    <modules>
+      <module fileurl="file://$PROJECT_DIR$/lesson.iml" filepath="$PROJECT_DIR$/lesson.iml" />
+    </modules>
+  </component>
+</project>

+ 124 - 0
lesson/.idea/uiDesigner.xml

@@ -0,0 +1,124 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="Palette2">
+    <group name="Swing">
+      <item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
+      </item>
+      <item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
+      </item>
+      <item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
+      </item>
+      <item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
+        <default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
+      </item>
+      <item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
+        <initial-values>
+          <property name="text" value="Button" />
+        </initial-values>
+      </item>
+      <item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
+        <initial-values>
+          <property name="text" value="RadioButton" />
+        </initial-values>
+      </item>
+      <item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
+        <initial-values>
+          <property name="text" value="CheckBox" />
+        </initial-values>
+      </item>
+      <item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
+        <initial-values>
+          <property name="text" value="Label" />
+        </initial-values>
+      </item>
+      <item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
+          <preferred-size width="150" height="-1" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
+          <preferred-size width="150" height="-1" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
+          <preferred-size width="150" height="-1" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
+          <preferred-size width="150" height="50" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
+          <preferred-size width="150" height="50" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
+          <preferred-size width="150" height="50" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
+      </item>
+      <item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
+          <preferred-size width="150" height="50" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
+          <preferred-size width="150" height="50" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
+          <preferred-size width="150" height="50" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
+          <preferred-size width="200" height="200" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
+          <preferred-size width="200" height="200" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
+      </item>
+      <item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
+      </item>
+      <item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
+      </item>
+      <item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
+      </item>
+      <item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
+          <preferred-size width="-1" height="20" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
+      </item>
+      <item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
+      </item>
+    </group>
+  </component>
+</project>

+ 6 - 0
lesson/.idea/vcs.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="VcsDirectoryMappings">
+    <mapping directory="$PROJECT_DIR$/.." vcs="Git" />
+  </component>
+</project>

+ 11 - 0
lesson/lesson.iml

@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="JAVA_MODULE" version="4">
+  <component name="NewModuleRootManager" inherit-compiler-output="true">
+    <exclude-output />
+    <content url="file://$MODULE_DIR$">
+      <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
+    </content>
+    <orderEntry type="inheritedJdk" />
+    <orderEntry type="sourceFolder" forTests="false" />
+  </component>
+</module>

+ 36 - 0
lesson/src/com/sf/Main10.java

@@ -0,0 +1,36 @@
+package com.sf;
+
+public class Main10 {
+
+    static void sayHello(Human human) {
+        System.out.println("sayHello Human");
+    }
+
+    static void sayHello(Man man) {
+        System.out.println("sayHello Man");
+    }
+
+    static void sayHello(Woman woman) {
+        System.out.println("sayHello Woman");
+    }
+
+    public static void main(String[] args) {
+        // 编译时类型  运行时类型
+        Human man = new Man();
+        Human woman = new Woman();
+        sayHello(man);
+        sayHello(woman);
+        // 对重载方法的选择 是根据编译时类型(静态类型)来确定的 而不是根据运行时类型
+        // A Human Human
+        // B Man Woman
+    }
+}
+
+class Human {
+}
+
+class Man extends Human {
+}
+
+class Woman extends Human {
+}

+ 41 - 0
lesson/src/com/sf/Main12.java

@@ -0,0 +1,41 @@
+package com.sf;
+
+import java.io.Serializable;
+
+public class Main12 {
+
+//    static void sayHello(char arg) {
+//        System.out.println("sayHello char 1");
+//    }
+
+//    static void sayHello(int arg) {
+//        System.out.println("sayHello int 2");
+//    }
+
+//    static void sayHello(long arg) {
+//        System.out.println("sayHello long 3");
+//    }
+
+//    static void sayHello(Character arg) {
+//        System.out.println("sayHello Character 4");
+//    }
+
+//    static void sayHello(Serializable arg) {
+//        System.out.println("sayHello Serializable 5");
+//    }
+
+//    static void sayHello(Object arg) {
+//        System.out.println("sayHello Object 6");
+//    }
+
+    static void sayHello(char... arg) {
+        System.out.println("sayHello char... 7");
+    }
+    public static void main(String[] args) {
+        // 如果找不到char 可以向上转型 调用int 如果int找不到 可以再向上转型
+        // 如果找不到基本数据类型 会找包装类
+        // 如果找不到包装类 会找实现的接口 如果找不到接口 会找Object
+        // 如果单个的参数类型没有匹配的 会找char...
+         sayHello('a');
+    }
+}

+ 43 - 0
lesson/src/com/sf/Main15.java

@@ -0,0 +1,43 @@
+package com.sf;
+
+public class Main15 {
+    // String创建了几个对象?
+    // 变量+对象可能存在的位置 栈 堆 常量池
+    public static void main(String[] args) {
+        String str = "hello";
+        // 1个 常量池
+
+        String str1 = "";
+        // 0个 在jvm启动时会创建
+
+        String str2 = "he" + "llo";
+        // 1个 此时会进行编译优化 此时相当于  str = "hello";
+
+        String str3 = new String("hello");
+        // 2个 堆和常量池
+
+        String str4 = "hello";
+        String str5 = str4 + " world";  // 变量和常量拼接
+        // 3个 常量池中是 "hello" " world"  堆中是 "hello world"
+        // 字符串拼接时
+//        new StringBuilder().append(str4).append(" world").toString();
+
+        String str6 = "hello";
+        String str7 = "hi " + str6 + " wor" + "ld"; // 常量+变量+多个常量
+        String str8 = "h" + "i " + str6 + " wor" + "ld"; // 常量+变量+多个常量
+        // 当变量和常量同时出现时 常量不能做编译优化
+        // 这里是以变量作为分界点 变量前面的常量可以优化 后面的不能优化
+        // 5个
+        // hi hello wor ld 常量池
+        // "hi hello world" 堆
+
+        // Integer中有一个静态内部类IntegerCache 存放了从-128到127范围内的对象
+//        Integer a1 = 1;
+//        Integer a2 = 1;
+//        System.out.println(a1 == a2);
+//
+//        Integer a3 = 1000;
+//        Integer a4 = 1000;
+//        System.out.println(a3 == a4);
+    }
+}

+ 29 - 0
lesson/src/com/sf/Main2.java

@@ -0,0 +1,29 @@
+package com.sf;
+
+public class Main2 {
+
+    // 浮点型有精度的丢失
+    public static void main(String[] args) {
+//        int
+//        Integer
+//        BigInteger
+
+        // 如果在对精度要求很高的场景 可以使用BigDecimal
+//        BigDecimal
+
+        double d1 = 0.01;
+        for (int i = 0; i < 100; i++) {
+            d1 += 0.01;
+        }
+        // 输出的结果是多少?
+        // 1.0100000000000007
+        System.out.println(d1);
+
+        float f1 = 0.01f;
+        for (int i = 0; i < 100; i++) {
+            f1 += 0.01;
+        }
+        // 1.0099994
+        System.out.println(f1);
+    }
+}

+ 21 - 0
lesson/src/com/sf/Main20.java

@@ -0,0 +1,21 @@
+package com.sf;
+
+import java.io.Serializable;
+
+public class Main20 {
+    public static void main(String[] args) {
+        Health health = new Health();
+        Person person = new Person();
+        person.health = health;
+        Person person1 = new Person();
+        person1.health = health;
+
+
+    }
+}
+
+class Person implements Serializable{
+    Health health;
+}
+class Health implements Serializable{
+}

+ 31 - 0
lesson/src/com/sf/Main3.java

@@ -0,0 +1,31 @@
+package com.sf;
+
+public class Main3 {
+
+    public static void main(String[] args) {
+        int a = 10;
+        int b = 20;
+
+        // _________
+        // 使用第三方变量
+//        int c = a;
+//        a = b;
+//        b = c;
+
+        // 使用加和
+        a = a + b; // 30
+        b = a - b; // 10
+        a = a - b; // 20
+
+        // 异或 ^
+        // 同一个数异或两次是自己
+        // 假定 a = 1  b = 2
+        a = a ^ b;  // 01 ^ 10 = 11 = 3
+        b = a ^ b;  // 11 ^ 10 = 01 = 1
+        a = a ^ b;  // 11 ^ 01 = 10 = 2
+
+        // 打印的效果是  20 和 10
+        System.out.println(a);
+        System.out.println(b);
+    }
+}

+ 31 - 0
lesson/src/com/sf/Main6.java

@@ -0,0 +1,31 @@
+package com.sf;
+
+import java.util.Arrays;
+
+public class Main6 {
+
+    // 快捷键 ctrl+alt+L  格式化
+    public static void main(String[] args) {
+        int[] arr = {1, 2, 3};
+        // 1 2 3 0 0
+        int[] newArr = Arrays.copyOf(arr, 5);
+        // 1 2
+        int[] newArr1 = Arrays.copyOf(arr, 2);
+        System.out.println(Arrays.toString(newArr));
+        System.out.println(Arrays.toString(newArr1));
+
+        // 另一种数组拷贝的方法
+        // 是 native 修饰的
+        // 代表这个方法是由 jvm中的c++实现的 处理性能更高
+        // 参数分别是 源对象 源的位置 目标对象 目标位置  拷贝的长度
+        // public static native void arraycopy(Object src,  int  srcPos,
+        //                                        Object dest, int destPos,
+        //                                        int length);
+        int[] copied = new int[10];
+        // [1, 2, 3, 0, 0, 0, 0, 0, 0, 0]
+        // [2, 3, 0, 0, 0, 0, 0, 0, 0, 0]
+        System.arraycopy(arr, 1, copied, 0, 2);
+        System.out.println(Arrays.toString(copied));
+        // 本质上 Arrays.copyOf 就调用了  System.arraycopy
+    }
+}

+ 43 - 0
lesson/src/com/sf/Main9.java

@@ -0,0 +1,43 @@
+package com.sf;
+
+public class Main9 {
+    public static void main(String[] args) {
+        Child.test2();
+        Parent.test2();
+    }
+}
+
+class Parent{
+    // final修饰的不能重写
+    final void test(){}
+    // private修饰的是自有的方法
+    private void test1(){}
+    // static修饰的方法是类的 而非对象的 也不能重写
+    static void test2(){
+        System.out.println("Parent test2");
+    }
+
+    // 两同两小一大
+    // 两同是 方法名相同 形参列表相同
+    // 两小是 方法的返回值类型可以相等或更小 方法抛出的异常类可以相等或更小
+    // 一大是 子类方法的访问权限可以比父类方法的权限相等或更大
+    protected Object test3() throws Exception{
+        return null;
+    }
+}
+class Child extends Parent{
+//    void test(){}
+//    @Override
+    void test1(){}
+
+//    @Override
+    static void test2(){
+        System.out.println("Child test2");
+    }
+
+    @Override
+    public Integer test3() throws RuntimeException {
+        return 1;
+    }
+
+}

+ 84 - 0
lesson/src/com/sf/leetcode/Solution_88.java

@@ -0,0 +1,84 @@
+package com.sf.leetcode;
+
+import java.util.Arrays;
+
+public class Solution_88 {
+
+    public void merge(int[] nums1, int m, int[] nums2, int n) {
+//        for (int i = m; i < nums1.length; i++) {
+//            nums1[i] = nums2[i - m];
+//        }
+        System.arraycopy(nums2, 0, nums1, m, n);
+        Arrays.sort(nums1);
+    }
+
+
+    // 是一种双指针的算法思想
+    // 时间复杂度 O(m+n)
+    // 空间复杂度 O(m+n)
+    public void merge1(int[] nums1, int m, int[] nums2, int n) {
+        // 同时遍历两个数组 然后将更小的值放入新的数组中 遍历完成新数组保持有序
+        // 声明两个索引 代表nums1和nums2的遍历位置
+        int pa = 0;
+        int pb = 0;
+        int[] sorted = new int[m + n];
+
+        // 声明一个值 来记录找到的当前最小元素
+        int cur;
+        while (pa < m || pb < n) {
+            // 假设某一个数组先遍历完
+            if (pa == m) {
+                cur = nums2[pb];
+                pb++;
+            } else if (pb == n) {
+                cur = nums1[pa];
+                pa++;
+            } else if (nums1[pa] <= nums2[pb]) {
+                // 找到更小的值 且让当前数组位置后移
+                cur = nums1[pa];
+                pa++;
+            } else {
+                cur = nums2[pb];
+                pb++;
+            }
+            // 放到数组中的索引是什么
+            // pa = 1 pb = 0
+            // pa = 1 pb = 1
+            sorted[pa + pb - 1] = cur;
+        }
+
+        // 将sorted中的元素 复制给nums1
+        System.arraycopy(sorted, 0, nums1, 0, m + n);
+    }
+
+
+    public void merge2(int[] nums1, int m, int[] nums2, int n) {
+        // 声明两个索引 代表nums1和nums2的遍历位置
+        int pa = m - 1, pb = n - 1;
+        // 记录nums1的存储位置
+        int tail = m + n - 1;
+        // 记录要取出的值 剩余元素中的最大值
+        int cur;
+        while (pa >= 0 || pb >= 0) {
+            if(pa == -1){
+                cur = nums2[pb--];
+            }else if(pb == -1){
+                cur = nums1[pa--];
+            }else if (nums1[pa] > nums2[pb]) {
+                cur = nums1[pa--];
+            } else {
+                cur = nums2[pb--];
+            }
+            nums1[tail--] = cur;
+        }
+    }
+
+
+    public static void main(String[] args) {
+        int[] nums1 = {1, 2, 3, 0, 0, 0};
+        int[] nums2 = {2, 5, 6};
+        Solution_88 solution_88 = new Solution_88();
+        solution_88.merge2(nums1, 3, nums2, 3);
+        System.out.println(Arrays.toString(nums1));
+    }
+}