1、计算机软件主要分为系统软件和应用软件两大类,系统软件主要包括操作系统、语言处理系统、数据库管理系统和系统辅助处理系统。应用软件主要包括办公软件和多媒体处理软件。
2、Object类的方法:
- getClass()
- hasCode()
- equals()
- clone()
- toString()
- notify() ------- notifyAll()
- wait()
- finalize()
3、java代码使用的字符码集是 Unicode
4、数组是一个对象;数组不是原生类,我们定义数组的基本类型;数组定义后,大小不可以随意改变;在java中,数组存储在堆的连续内存空间中
5、
package com;
public class Main {
public static void main(String [] args){
System.out.println(new B().getValue()); // 17
}
static class A{
protected int value; // 10 11 22 16 17 34
public A(int v) {
setValue(v);
}
public void setValue(int value){
this.value = value;
}
public int getValue(){
try{
value++;
return value;
} catch(Exception e){
System.out.println(e.toString());
} finally {
this.setValue(value);
System.out.println(value); // 22 34
}
return value;
}
}
static class B extends A{
public B() {
super(5);
setValue(getValue() - 3); // 参数:8
}
public void setValue(int value){
super.setValue(2 * value);
}
}
}
最后输出:22 34 17
- 构造方法中的动态绑定,A(int v) 中调用的 setValue() 和 finally 语句中调用的 setValue() 都是调用其子类 B 中重写 setValue(int value)
- 不管有没有报错,都要执行 finally 中语句,先执行完 finally 中的语句,外层方法才拿到 try 中的 return语句 返回的结果;否则就是 22 17 34 了
6、
package com;
public class Main {
static int cnt = 6;
static {
cnt += 9;
}
public static void main(String[] args) {
System.out.println("cnt =" + cnt);
}
static {
cnt /= 3;
}
}
输出 cnt=5
main方法未启动之前,在类加载时,就获取到静态变量及运行静态代码块
7、
- 所有类的实例和数组都是在堆上分配内存的(所有 new 出来对象,都要在堆上分配内存)
- 对象的堆内存由自动内存管理系统回收
- 堆内存是由存活对象和死亡对象以及空闲碎片区组成的
8、接口仅包含方法定义和常量值
9、
class Child{
public void func(){
System.out.println("普通方法");
}
public static void print(){
System.out.println("静态方法");
}
}
public class TestClass {
public static void main(String[] args) {
((Child)null).print(); // 静态方法
((Child)null).func(); // NullPointerException
}
}
- 静态成员变量及静态方法属于 Child 类本身,无论 new 多少个实例,静态成员变量和静态方法都只有一份;所有 Child 类型的实例都可以调用静态成员变量和方法
- 我的理解是,null 类型强转成 Child,调用静态方法 print() 时,不经过实例,所以不会有 NullPointerException
10、
int i=0;
Integer j = new Integer(0);
System.out.println(i==j);
System.out.println(j.equals(i));
- i == j 比较的是 i 的值和 j 的值,并不是比较的地址;Integer 是 int 的包装类,比较时,Integer 类型的 j 自动拆箱,变成 int 类型
- Integer.equals()
public boolean equals(Object obj) {
if (obj instanceof Integer) {
return value == ((Integer)obj).intValue(); // intValue() 返回 Integer 的值
}
return false;
}
11、
public void getCustomerInfo() {
try {
// do something that may cause an Exception
} catch (java.io.FileNotFoundException ex) {
System.out.print("FileNotFoundException!");
} catch (java.io.IOException ex) {
System.out.print("IOException!");
} catch (java.lang.Exception ex) {
System.out.print("Exception!");
}
}
三个catch,只能有一个捕捉到 try{} 中的异常,要么是 FileNotFoundException,要么是IOException,要么是 Exception,不可能打印多个
山水人文地,世界风筝都
山东潍坊
本文含有隐藏内容,请 开通VIP 后查看