栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

X32专项练习部分09

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

X32专项练习部分09

X32专项练习部分09
  • 双向链表的搜索速度方差
  • 适合存放数据元素的结构
  • 有无符号位运算
  • 类变量和局部变量
  • (important)依赖注入和控制反转
  • Integer自动装箱
  • 构造方法赋值
  • 代码块执行顺序
  • 总目录

双向链表的搜索速度方差
	
适合存放数据元素的结构
	
有无符号位运算
		public static void main(String[] args) {
            
            System.out.println(20 >>> 2); // 5
            System.out.println(-20 >> 2); // -5
            System.out.println(-20 >>> 2); // 1073741819
        }
类变量和局部变量
class Test {
    public static int a = 1;
    public static void main(String[] args) {
        int a = 10;
        a++; // 类变量+1
        Test.a++; // 局部变量+1
        Test t=new Test();
        System.out.println("a=" + a + " t.a=" + t.a);
        // a = 11 t.a = 2
        
    }
}
(important)依赖注入和控制反转
		
// 解耦前
class Main {
    public static void main(String[] args) {
        
        Chinese chinese = new Chinese();
        chinese.sayHelloWorld("张三");

        American american = new American();
        american.sayHelloWorld("Jack");
    }
}

interface Human {
    public void sayHelloWorld(String name);
}


class Chinese implements Human {
    public void sayHelloWorld(String name) {
        String helloWorld = "你好," + name;
        System.out.println(helloWorld);
    }
}

class American implements Human {
    public void sayHelloWorld(String name) {
        String helloWorld = "Hello," + name;
        System.out.println(helloWorld);
    }
}

// 解耦后
class Main {
    public static void main(String[] args) {
        
        HumanFactory humanFactory = new HumanFactory();
        Human human1 = humanFactory.getHuman("chinese");
        human1.sayHelloWorld("张三");

        Human human2 = humanFactory.getHuman("american");
        human2.sayHelloWorld("Jack");
    }
}

interface Human {
    public void sayHelloWorld(String name);
}

class HumanFactory {
    public Human getHuman(String type) {
        if ("chinese".equals(type)) {
            return new Chinese();
        } else {
            return new American();
        }
    }
}

class Chinese implements Human {
    public void sayHelloWorld(String name) {
        String helloWorld = "你好," + name;
        System.out.println(helloWorld);
    }
}

class American implements Human {
    public void sayHelloWorld(String name) {
        String helloWorld = "Hello," + name;
        System.out.println(helloWorld);
    }
}
Integer自动装箱
		
        Integer a1 = 1;
        Integer b1 = 1;
        Integer c1 = 500;
        Integer d1 = 500;
        System.out.print(a1 == b1); // true
        System.out.print(c1 == d1); // false
        
构造方法赋值
class TestDemo{
    private int count;
    public static void main(String[] args) {
        TestDemo test=new TestDemo(88);
        System.out.println(test.count); // 88
    }
    TestDemo(int a) {
        
        count=a;
    }
}
代码块执行顺序
class HelloA {
    public HelloA() {
        System.out.println("A的构造函数");
    }
    {
        System.out.println("A的构造代码块");
    }
    static {
        System.out.println("A的静态代码块");
    }
    public static void main(String[] args) {
        HelloA a = new HelloA();
    }
}

总目录
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/327891.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号