本周主要学习了markdown,git,docker等工具的使用。在本周的学习中,初步了解了markdown,git,docker的使用。本周的静态博客部署中,对于怎么显示一个博客内容,有两种,一是把public/下的内容放入nginx,然后配置Nginx配置文件,二是在Dockerfile配置hugo服务器,我刚开始把hugo-linux下到本地,传入github,但是太大了,整个项目有30m,于是在dockerfile中下载hugo,但可能网速有些慢。
记得idea开启断言调试
RUN -> Edit Configurations -> Configuration -> VM options : 输入-ea,点击确定。
编译通不过,methodB()不能是一个void函数,必须有返回值,如int,String等。或者methodB()可以换成有返回值的东西,如i=1,i++等。
assert用法
assert 如果为true,则程序继续执行。 如果为false,则程序抛出AssertionError,并终止执行。
assert : 如果为true,则程序继续执行。 如果为false,则程序抛出java.lang.AssertionError,并输入。
首先,需要明白类的加载顺序:
父类静态对象和静态代码块(并且静态代码块和静态变量的执行顺序只跟代码中出现的顺序有关.)静态变量最好定义在静态代码块的前面子类静态对象和静态代码块父类非静态对象和非静态代码块父类构造函数子类非静态对象和非静态代码块子类构造函数接下来是变量的作用范围(作用域(scope))
在C、C++和Java中,作用去由花括号的位置决定
代码块中的局部变量与作用域
public static void main(String args[]) { int x = 100; { int x = 30; } System.out.println(x); }报错重复定义
public static void main(String args[]) { { int x = 30; } int x = 100; System.out.println(x); }代码块中的局部变量已经销毁,能定义
生存周期与作用域的区别:
生存周期: 变量从定义到销毁的时间范围。
作用域: 变量的可见代码域(块作用域,函数作用域,类作用域,程序全局作用域)。
静态变量,全局或局部声明的static变量都存放于程序的全局变量区域,,静态变量的生命周期都是整个源程序。它的作用域决定于它被定义的位置。所以静态变量的作用域<=生存周期。
static函数在内存中只有一份,普通函数在每个被调用中维持一份拷贝
class文件:java字节码文件
static int x; static { x = 5; }x结果为5
static { x = 5; } static int x;x结果为5
static { x = 5; } static int x = 1;x结果为1
static int x = 1; static { x = 5; }x结果为5
static int x = 1; static { int x = 5; }x结果为1(static块为局部变量)
static { int x = 5; } static int x = 1;x结果为1(static块为局部变量)
static String s; public static void main(String args[]) { //String s = ""; 1 if (s instanceof String) { System.out.println("I am true String"); } else { System.out.println("I am false String"); } }运行结果为 "I am false String"如果改成1处则为true
instanceof 运算符是用来在运行时指出对象是否是特定类的一个实例
输出9.0,根据运算符的精确度类型进行自动类型转换
char x='x'; int i =10; System.out.println(false ? i : x); System.out.println(false ? 10 : x);输出120,x.
java规范中提到,当后两个表达式有一个是常量表达式(10),另外一个类型是T(char)时,而常量表达式可以被T表示时,输出结果是T类型。
Boolean b = new Boolean("dfas"); #能编译,返回false int c = 0x1234; #能编译通过打印
MyThread: start() MyRunnable: run() 在MyThread中start方法加上super.start(); 打印 MyThread: start() MyThread: run() MyRunnable: run()A正确,MyThread重写了start方法,实际上只是一个普通方法调用,thread.start()不会调用MyRunnable中的start方法.
线程启动
注意throwMethod() throws IllegalAccessException
**初始化:先成员变量再构造方法,先父类再子类
多态表现:有同名方法执行子类的**
class Parent { private void method1() { System.out.println("Parent's method1()"); } public void method2() { System.out.println("Parent's method2()"); method1(); } } class Child extends Parent { public void method1() { System.out.println("Child's method1()"); } public static void main(String args[]) { Parent p = new Child(); p.method2(); } }注意Parent的method1是私有的,所以会调用父类方法
Parent's method2() Parent's method1() String str = "Java"; StringBuffer buffer = new StringBuffer(str); if(str.equals(buffer)) { System.out.println("Both are equal"); } else { System.out.println("Both are not equal"); }返回false,都不是同一个对象,可以看一下equals的源码
public boolean equals(Object anObject) { if (this == anObject) { return true; } if (anObject instanceof String) { ... } return false; }转载于:https://www.cnblogs.com/sufferingStriver/p/9332287.html
相关资源:你必须知道的495个C语言问题