guyanqing 7 ヶ月 前
コミット
54eb5a132b

+ 124 - 0
.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>

+ 0 - 1
src/main/java/com/sf/day01/Te.java

@@ -48,6 +48,5 @@ public class Te {
           * println  换行
           * print不换行
           */
-
     }
 }

+ 82 - 0
src/main/java/com/sf/day01/day02/TE.java

@@ -0,0 +1,82 @@
+package com.sf.day01.day02;
+
+import org.junit.Test;
+
+public class TE {
+
+    public static final String IP_ADDRESS = "192.168.1.1";
+
+   @Test
+    public void test01(){
+       System.out.println("Hello");
+       int  num = 20;
+//       int  NUM = 20;
+    }
+
+
+    public String getUserInfo(){
+       return "h";
+    }
+
+    @Test
+    public void t2(){
+       int num = 10;  //  =  ==
+       num = 20;
+        System.out.println(num);
+        /**
+         * 变量 (按照数据类型进行分):
+         * 基本数据类型:
+         * 整型: byte   short   int(默认)   long
+         * 4?字节数不同 ->表数范围不同   1字节 = 8bit(计算机的最小单元)
+         * 字节数   1      2      4             8
+         * 1字节  == 8bit
+         * 0/1   0/1  0/1   0/1  0/1   0/1  0/1   0/1
+         * 2^8  = 256
+         *符号位     +  -   -->256种  包含正负
+         *  -128--------------------0--------------------------127>
+         * byte  表数范围  -128   +127
+         *  short    2字节   = 16bit
+         *  0/1   0/1  0/1   0/1  0/1   0/1  0/1   0/1  0/1   0/1  0/1   0/1  0/1   0/1  0/1   0/1
+         *2^16     ---  -2^15   +2^15-1
+         *
+         *
+         * 浮点型: float   double(默认)   12.3
+         *         4          8
+         *         float uu  = 12.3;
+         *
+         * 字符型: char   'a'    String字符串  "ANC"
+         *      字符和整型是可以进行运算的   ‘A’+1 = 'B'    int    66   A   65   a  97
+         * 布尔型: boolean    true 真     false   假
+         *
+         *
+         * 引用数据类型: 数组   类  接口
+         */
+
+        byte count = 0;
+        long  mm  = 19L;
+        long  nn  = 19l;
+        float uu  = 12.3F;
+        float yy  = 12.3f;
+        double ii = 12.3D;
+        String str = "abc";
+
+        float num1 = (float) 12.3;
+    }
+
+    /**
+     * i++   ++i 的区别
+     * i++  ++i
+     * 没有接收值:  一样的都是对变量i进行加一操作
+     * 有接收值:  i++  先赋值后运算    ++i先运算后赋值
+     */
+    @Test
+    public void t3(){
+       int num = 10;
+       int c =  num++;
+//      int c =  ++num;
+       System.out.println(num);
+       System.out.println(c);
+    }
+
+
+}

+ 46 - 0
src/main/java/com/sf/quanrizhi/Student.java

@@ -0,0 +1,46 @@
+package com.sf.quanrizhi;
+
+public class Student {
+    private Integer id;
+    private String name;
+
+    public Student() {
+    }
+
+    public Student(Integer id, String name) {
+        this.id = id;
+        this.name = name;
+    }
+
+    public Integer getId() {
+        return id;
+    }
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    @Override
+    public String toString() {
+        return "Student{" +
+                "id=" + id +
+                ", name='" + name + '\'' +
+                '}';
+    }
+
+    public static void printInfo(String name){
+        System.out.println("这是静态方法name ="+name);
+    }
+
+    public static void main(String[] args) {
+        printInfo("name");
+    }
+}

+ 235 - 0
src/main/java/com/sf/quanrizhi/T.java

@@ -0,0 +1,235 @@
+package com.sf.quanrizhi;
+
+import org.junit.Test;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.annotation.ElementType;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Arrays;
+import java.util.Properties;
+
+public class T {
+    @Test
+    public void t1() throws ClassNotFoundException {
+        //  1
+        Class<User> userClass = User.class;
+
+        //2
+        User user = new User();
+        Class<? extends User> aClass = user.getClass();
+        //3
+        Class<?> aClass1 = Class.forName("com.sf.quanrizhi.User");
+
+        //4
+        ClassLoader classLoader = this.getClass().getClassLoader();
+        Class<?> aClass2 = classLoader.loadClass("com.sf.quanrizhi.User");
+    }
+
+    @Test
+    public void t2() throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException {
+        Class<?> clazz = Class.forName("com.sf.quanrizhi.Student");
+        Object o = clazz.newInstance();
+        Student student = null;
+        if(o instanceof Student){
+             student = (Student) o;
+        }
+        System.out.println(student);
+        String str = "com.sf.reflectiontest.Student";
+//        Class<?> clazz = Class.forName(str);
+//        Object o = clazz.newInstance();
+        System.out.println((Student)o);
+        String name = clazz.getName();
+        System.out.println(name);
+        System.out.println(clazz.getSuperclass());
+        System.out.println(Arrays.toString(clazz.getInterfaces()));
+        ClassLoader classLoader = clazz.getClassLoader();
+        System.out.println(classLoader);
+        System.out.println(Arrays.toString(clazz.getConstructors()));
+        System.out.println(Arrays.toString(clazz.getDeclaredMethods()));
+        System.out.println(Arrays.toString(clazz.getMethods()));
+        System.out.println(clazz.getMethod("setId",Integer.class));
+    }
+
+    @Test
+    public void t3(){
+        Class c1 = Object.class;
+        Class c2 = Comparable.class;
+        Class c3 = String[].class;
+        Class c4 = int[][].class;
+        Class c5 = ElementType.class;
+        Class c6 = Override.class;
+        Class c7 = int.class;
+        Class c8 = void.class;
+        Class c9 = Class.class;
+
+        int[] a = new int[10];
+        int[] b = new int[100];
+        Class c10 = a.getClass();
+        Class c11 = b.getClass();
+// 只要元素类型与维度一样,就是同一个Class
+        System.out.println(c10 == c11);
+    }
+
+    //总结:
+    /**
+     * getField("pName");   获取属性  包含父类 (public)
+     * getFields():获得某个类的所有的公共(public)的字段,包括父类中的字段。
+     * getDeclaredFields():获得当前类的所有声明的字段,不包含父类  即包括public、private和proteced,
+     *
+     * getConstructors()   获取当前类的构造器(public)
+     * getDeclaredConstructors()   获取当前类的构造器(所有声明的)
+     *
+     * getMethods是获取类中所有公共方法,包括继承自父类的
+     * getDeclaredMethods是获取类中自己声明的方法,即自己声明的任何权限的方法,包括私有方法  不包含父类方法
+     */
+
+    @Test
+    public void test01(){
+        ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
+        System.out.println("systemClassLoader = " + systemClassLoader);
+    }
+
+    @Test
+    public void test02()throws Exception{
+        ClassLoader c1 = String.class.getClassLoader();
+        System.out.println("加载String类的类加载器:" + c1);
+
+        ClassLoader c2 = T.class.getClassLoader();
+        System.out.println("加载当前类的类加载器:" + c2);
+    }
+
+    @Test
+    public void test03(){
+        ClassLoader c1 = T.class.getClassLoader();
+        System.out.println("加载当前类的类加载器c1=" + c1);
+
+        ClassLoader c2 = c1.getParent();
+        System.out.println("c1.parent = " + c2);
+
+        ClassLoader c3 = c2.getParent();
+        System.out.println("c2.parent = " + c3);
+
+    }
+
+    /**
+     * 使用ClassLoader获取流
+     */
+    @Test
+    public void test04() throws IOException {
+        InputStream resourceAsStream = this.getClass().getClassLoader().getResourceAsStream("jdbc.properties");
+        Properties properties = new Properties();
+        properties.load(resourceAsStream);
+        String name = properties.getProperty("name");
+        String password = properties.getProperty("password");
+        System.out.println(name);
+        System.out.println(password);
+    }
+
+    @Test
+    public void test1() throws Exception{
+//        LcClass obj = new lLClass();//编译期间无法创建
+
+        Class<?> clazz = Class.forName("com.lc.demo.LcClass");
+        //clazz代表com.lc.demo.LcClass类型
+        //clazz.newInstance()创建的就是LcClass的对象
+        Object obj = clazz.newInstance();
+        System.out.println(obj);
+    }
+
+    @Test
+    public void test2()throws Exception{
+        Class<?> clazz = Class.forName("com.lc.demo.LcDemo");
+        //java.lang.InstantiationException: com.lc.demo.LcDemo
+        //Caused by: java.lang.NoSuchMethodException: com.lc.demo.LcDemo.<init>()
+        //即说明lcDemo没有无参构造,就没有无参实例初始化方法<init>
+        Object o = clazz.newInstance();
+        System.out.println(o);
+    }
+
+    @Test
+    public void test3()throws Exception{
+        //(1)获取Class对象
+        Class<?> clazz = Class.forName("com.lc.demo.LcDemo");
+        /*
+         * 获取lcDemo类型中的有参构造
+         * 如果构造器有多个,我们通常是根据形参【类型】列表来获取指定的一个构造器的
+         * 例如:public LcDemo(String title, int num)
+         */
+        //(2)获取构造器对象
+        Constructor<?> constructor = clazz.getDeclaredConstructor(String.class,int.class);
+
+        //(3)创建实例对象
+        // T newInstance(Object... initargs)  这个Object...是在创建对象时,给有参构造的实参列表
+        Object obj = constructor.newInstance("爱扣钉",2022);
+        System.out.println(obj);
+    }
+
+
+    /**
+     * 通过反射的形式对当前Student类进行赋值
+     */
+    @Test
+    public void t5() throws ClassNotFoundException, NoSuchFieldException, InstantiationException, IllegalAccessException {
+        // 获取student对象的class对象
+        Class<?> clazz = Class.forName("com.sf.quanrizhi.Student");
+        //获取对象属性
+        Field idFiled = clazz.getDeclaredField("id");
+        //取消java语言访问权限
+        idFiled.setAccessible(true);
+        //创建student的实例对象
+        Object stu = clazz.newInstance();
+        //获取属性值
+        Object o = idFiled.get(stu);
+        System.out.println(o);
+
+        //操作当前属性值
+        idFiled.set(stu,120);
+
+        System.out.println(idFiled.get(stu));
+    }
+
+
+    /**
+     * 通过反射的形式去操作方法
+     */
+    @Test
+    public void t7() throws ClassNotFoundException, NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException {
+        Class<?> clazz = Class.forName("com.sf.quanrizhi.Student");
+        Method setNameMethod = clazz.getDeclaredMethod("setName", String.class);
+        //实例化对象
+        Object obj = clazz.newInstance();
+
+        Object objectMethod = setNameMethod.invoke(obj, "zhangsan");
+        System.out.println(objectMethod);  //null
+        //掉用方法获取设置值   获取getName方法
+        Method getName = clazz.getDeclaredMethod("getName");
+        Object invoke = getName.invoke(obj);
+        System.out.println(invoke);
+    }
+
+    @Test
+    public void t8() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
+//        Student.printInfo();
+        Class<?> clazz = Class.forName("com.sf.quanrizhi.Student");
+        Method printInfo = clazz.getMethod("printInfo",String.class);
+        printInfo.invoke(null,"zs");
+    }
+
+    @Test
+    public void t9() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
+        InputStream resourceAsStream = ClassLoader.getSystemClassLoader().getResourceAsStream("user.properties");
+        Properties properties = new Properties();
+        properties.load(resourceAsStream);
+        String className = properties.getProperty("className");
+        String methodName = properties.getProperty("methodName");
+        Class<?> clazz = Class.forName(className);
+        Object o = clazz.newInstance();
+        Method method = clazz.getMethod(methodName);
+        Object invoke = method.invoke(o);
+        System.out.println(invoke);
+    }
+}

+ 34 - 0
src/main/java/com/sf/quanrizhi/User.java

@@ -0,0 +1,34 @@
+package com.sf.quanrizhi;
+
+public class User {
+    private Integer id;
+    private String name;
+
+    public Integer getId() {
+        return id;
+    }
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    @Override
+    public String toString() {
+        return "User{" +
+                "id=" + id +
+                ", name='" + name + '\'' +
+                '}';
+    }
+
+    public void show(){
+        System.out.println("show!!!");
+    }
+}

+ 2 - 0
src/main/resources/jdbc.properties

@@ -0,0 +1,2 @@
+name=zs
+password=123456

+ 2 - 0
src/main/resources/user.properties

@@ -0,0 +1,2 @@
+className:com.sf.quanrizhi.User
+methodName:show

BIN
target/classes/com/sf/day01/Te.class


BIN
target/classes/com/sf/day01/day02/TE.class


BIN
target/classes/com/sf/quanrizhi/Student.class


BIN
target/classes/com/sf/quanrizhi/T.class


BIN
target/classes/com/sf/quanrizhi/User.class


+ 2 - 0
target/classes/jdbc.properties

@@ -0,0 +1,2 @@
+name=zs
+password=123456

+ 2 - 0
target/classes/user.properties

@@ -0,0 +1,2 @@
+className:com.sf.quanrizhi.User
+methodName:show