导航

Java基础知识点总结(持续更新)

Posted on 2020-02-25 00:18  诺伊尔712  阅读(268)  评论(0)    收藏  举报

持续更新,可以用Ctrl+F来搜索内容!

给自己加深记忆!

 

一、Object类里面的方法有哪些?

1.

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

本地方法,用于返回当前对象所在的类对应的Class对象,不能重写。

 

2.

@HotSpotIntrinsicCandidate
public native int hashCode();

本地方法,返回当前对象的哈希值。

 

3.

public boolean equals(Object obj);

和其他对象比较是否相等。

 

4.

@HotSpotIntrinsicCandidate
protected native Object clone() throws CloneNotSupportedException;

返回一个克隆的当前对象。

 

5.

public String toString();

将当前对象转换为字符串,默认实现是 getClass().getName() + "@" + Integer.toHexString(hashCode()); 经常需要重写。

 

6.

@HotSpotIntrinsicCandidate
public final native void notify();

本地方法,唤醒任意一个在此对象监视器上等待的线程,但是调用该方法不会立即释放锁。

 

7.

@HotSpotIntrinsicCandidate
public final native void notifyAll();

本地方法,唤醒所有在此对象监视器上等待的线程,但是调用该方法不会立即释放锁。

 

8.

public final void wait() throws InterruptedException;

暂停当前线程的执行,并释放锁,wait结束时会尝试重写获得锁。

 

9.

public final native void wait(long timeoutMillis) throws InterruptedException;

暂停当前线程的执行,并释放锁,持续timeoutMillis毫秒的时间,wait结束时会尝试重写获得锁。

 

10.

public final void wait(long timeoutMillis, int nanos) throws InterruptedException

和上一个方法类似,但是增加了一个微秒的数值,范围是[0,999999]

 

11.

@Deprecated(since="9")
protected void finalize() throws Throwable();

是对象被垃圾回收前调用的方法,默认是空的可以重写,但是已经不建议使用了。

 

二、Java对象的生命周期

1. 创建阶段(Created)

2. 应用阶段(In Use)

3. 不可见阶段(Invisible)

4. 不可达阶段(Unreachable)

5. 收集阶段(Collected)

6. 终结阶段(Finalized)

7. 对象空间重分配阶段(De-allocated)

 

三、Spring IOC

@Resource 是javax中注解,在Spring中注入对象时默认按Bean的名称。

@Autowired是Springframework中的注解,注入对象时默认按照接口类型。如果在该接口有多个实现类,需要指定哪一个对象时,用 @Qualifier("nameOfTheBean")