编程语言
首页 > 编程语言> > Java面试手册V2.0+突击V3.0知识点整理(四)

Java面试手册V2.0+突击V3.0知识点整理(四)

作者:互联网

在这里插入图片描述


1. Java泛型和类型擦除


2. 如何将字符串反转?

package otherDemo;

public class StrReverse {
    public static void main(String[] args) {
        // StringBuffer reverse
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append("abcdefg");
        System.out.println(stringBuffer.reverse());
        // StringBuilder reverse
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("abcdefg");
        System.out.println(stringBuilder.reverse());
    }
}

运行结果
在这里插入图片描述


3. String类的常用方法有哪些?


4. 抽象类必须要有抽象方法吗?

abstract class Dog{
	public static void say(){
		System.out.println("汪~");
	}
}

5. 抽象类和普通类有什么区别?


6. 接口和抽象类有什么区别?


7. 以下代码中,s5==s2返回什么?

	String s1 = "ab";
	String s2 = "a"+"b";
	String s3 = "a";
	String s4 = "b";
	String s5 = s3 + s4;

8. String中的intern()

	String s1 = "aa";
	String s2 = s1.intern();
	System.out.println(s1==s2); // true

9. 什么是编译器常量?使用它有什么风险?


10. Object常用方法总结

Object是一个特殊的类,是所有类的父类。它主要提供了以下11个方法:
1. public final native Class<?> getClass() // native方法,用于返回当前运行时对象的Class对象,使用了final关键字修饰,故不允许子类重写
2. public native int hashCode() // native方法,用于返回对象的哈希码,主要使用在哈希表中,如JDK的HashMap
3. // 用于比较两个对象的内存地址是否相等,String类对该方法进行了重写用户比较字符串的值是否相等
	public boolean equals(Object obj)

4. // native方法,用于创建并返回当前对象的一份拷贝。一般情况下,任何对象x, 表达式x.clone()!=x 为true,
// x.clone.getClass() == x.getClass()为true。Object本身没有实现Cloneable接口,所以不重写clone方法
// 并且进行调用的话会发生CloneNotSupportedException异常
    public boolean Clone() throws CloneNotSupportedException 
5. // 返回类的名字@实例的哈希码的16进制的字符串,建议Object所有的子类都重写这个方法
	public String toString() 
6. // native方法,并且不能重写。唤醒一个在此对象监视器上等待的线程(监视器相当于锁的概念)。如果有多个线程在等待只会任意唤醒一个
	public final native void notify()
7. // native方法,并且不能重写。和notify一样,唯一的区别就是会唤醒在此对象监视器上等待的所有线程,而不是一个线程
	public final native void notifyAll()
8. // native方法,并且不能重写。暂停线程的执行。注意:sleep方法没有释放锁,而wait方法释放了锁。timeout是等待时间
	public final native void wait(long timeout) throws InterruptedException
9. // 多了nanos参数,这个参数表示额外时间(以毫微秒为单位,范围是0-999999).所以超时的时间还需要加上nanos毫秒
	public final void wait(long timeout, int nanos) throws InterruptedException
10. // 跟之前的2个wait方法一样,只不过该方法一直等待,没有超时时间这个概念
	public final void wait() throws InterruptedException
11. 实例被垃圾回收器回收的时候触发的操作
	protected void finalize() throws Throwable{} 


上一篇: Java面试手册V2.0+突击V3.0知识点整理(三)

标签:知识点,V3.0,Java,String,字符串,抽象类,方法,public,native
来源: https://blog.csdn.net/weixin_51062176/article/details/120753337