【面试】Java高频面试题(2023最新整理)

一、java基础

1、JDK 和 JRE 有什么区别?

JDK(Java Development Kit),Java开发工具包
JRE(Java Runtime Environment),Java运行环境
JDK中包含JRE,JDK中有一个名为jre的目录,里面包含两个文件夹bin和lib,bin就是JVM,lib
就是JVM工作所需要的类库。

2、== 和 equals 的区别是什么?

对于基本类型,== 比较的是值;
对于引用类型,==比较的是地址;
equals不能用于基本类型的比较;
如果没有重写equals,equals就相当于 ==;
如果重写了equals方法,equals比较的是对象的内容;

3、final 在 java 中有什么作用?

(1)用来修饰一个引用
如果引用为基本数据类型,则该引用为常量,该值无法修改;
如果引用为引用数据类型,比如对象、数组,则该对象、数组本身可以修改,但指向该对象或数组的地址的引用不能修改。
如果引用时类的成员变量,则必须当场赋值,否则编译会报错。
(2)用来修饰一个方法
当使用final修饰方法时,这个方法将成为最终方法,无法被子类重写。但是,该方法仍然可以被继承。
(3)用来修饰类
当用final修改类时,该类成为最终类,无法被继承。
比如常用的String类就是最终类。

4、java 中的 Math.round(-1.5) 等于多少?

Math提供了三个与取整有关的方法:ceil、floor、round
(1)ceil:向上取整;
Math.ceil(11.3) = 12;
Math.ceil(-11.3) = 11;
(2)floor:向下取整;
Math.floor(11.3) = 11;
Math.floor(-11.3) = -12;
(3)round:四舍五入;
加0.5然后向下取整。
Math.round(11.3) = 11;
Math.round(11.8) = 12;
Math.round(-11.3) = -11;
Math.round(-11.8) = -12;

5、String 属于基础的数据类型吗?

不属于。
八种基本数据类型:byte、short、char、int、long、double、float、boolean。

6、String str="i"与 String str=new String(“i”)一样吗?

String str="i"会将起分配到常量池中,常量池中没有重复的元素,如果常量池中存中i,就将i的地址赋给变量,如果没有就创建一个再赋给变量。
String str=new String(“i”)会将对象分配到堆中,即使内存一样,还是会重新创建一个新的对象。

7、如何将字符串反转?

将对象封装到stringBuilder中,调用reverse方法反转。
在这里插入图片描述

8、String 类的常用方法都有那些?

(1)常见String类的获取功能
length:获取字符串长度;
charAt(int index):获取指定索引位置的字符;
indexOf(int ch):返回指定字符在此字符串中第一次出现处的索引;
substring(int start):从指定位置开始截取字符串,默认到末尾;
substring(int start,int end):从指定位置开始到指定位置结束截取字符串;

(2)常见String类的判断功能
equals(Object obj): 比较字符串的内容是否相同,区分大小写;
contains(String str): 判断字符串中是否包含传递进来的字符串;
startsWith(String str): 判断字符串是否以传递进来的字符串开头;
endsWith(String str): 判断字符串是否以传递进来的字符串结尾;
isEmpty(): 判断字符串的内容是否为空串"";

(3)常见String类的转换功能
byte[] getBytes(): 把字符串转换为字节数组;
char[] toCharArray(): 把字符串转换为字符数组;
String valueOf(char[] chs): 把字符数组转成字符串。valueOf可以将任意类型转为字符串;
toLowerCase(): 把字符串转成小写;
toUpperCase(): 把字符串转成大写;
concat(String str): 把字符串拼接;

(4)常见String类的其他常用功能
replace(char old,char new) 将指定字符进行互换
replace(String old,String new) 将指定字符串进行互换
trim() 去除两端空格
int compareTo(String str) 会对照ASCII 码表 从第一个字母进行减法运算 返回的就是这个减法的结果,如果前面几个字母一样会根据两个字符串的长度进行减法运算返回的就是这个减法的结果,如果连个字符串一摸一样 返回的就是0。

9、new String(“a”) + new String(“b”) 会创建几个对象?

对象1:new StringBuilder()
对象2:new String(“a”)
对象3:常量池中的"a"
对象4:new String(“b”)
对象5:常量池中的"b"
深入剖析:StringBuilder中的toString():
对象6:new String(“ab”)
强调一下,toString()的调用,在字符串常量池中,没有生成"ab"
附加题

String s1 = new String(“1”) + new String(“1”);//s1变量记录的地址为:new String
s1.intern();//在字符串常量池中生成"11"。如何理解:jdk6:创建了一个新的对象"11",也就有新的地址;jdk7:此时常量池中并没有创建"11",而是创建了一个指向堆空间中new
String(“11”)的地址; String s2 = “11”; System.out.println(s1 ==
s2);//jdk6:false;jdk7:true

10、如何将字符串反转?

添加到StringBuilder中,然后调用reverse()。

更多Java基础知识面试题 https://writer.blog.csdn.net/article/details/129093071

二、java集合

Java集合面试题 https://writer.blog.csdn.net/article/details/129758782

三、多线程

Java并发编程面试题 https://writer.blog.csdn.net/article/details/129860582

四、JVM

Java虚拟机(JVM)面试题 https://writer.blog.csdn.net/article/details/129881700

五、JavaIO、BIO、NIO、AIO、Netty面试题

JavaIO、BIO、NIO、AIO、Netty面试题 https://writer.blog.csdn.net/article/details/129354121

六、Java异常面试题

Java异常面试题 https://writer.blog.csdn.net/article/details/129878263

七、设计模式面试题

设计模式面试题 https://writer.blog.csdn.net/article/details/127910080

八、Spring面试题

Spring面试题 https://writer.blog.csdn.net/article/details/129887594

九、 Spring MVC面试题

Spring MVC面试题 https://writer.blog.csdn.net/article/details/129892819

十、Spring Boot面试题

Spring Boot面试题 https://writer.blog.csdn.net/article/details/129431019

十一、Spring Cloud面试题

Spring Cloud面试题 https://writer.blog.csdn.net/article/details/129430572

十二、Redis面试题

Redis面试题 https://writer.blog.csdn.net/article/details/129895331

十三、MyBatis面试题

MyBatis面试题 https://writer.blog.csdn.net/article/details/129906686

十四、MySQL面试题

MySQL面试题https://writer.blog.csdn.net/article/details/129907409

十五、TCP、UDP、Socket、HTTP面试题

TCP、UDP、Socket、HTTP面试题 https://writer.blog.csdn.net/article/details/129913146

十六、Nginx面试题

Nginx面试题 https://writer.blog.csdn.net/article/details/129918147

十七、ElasticSearch面试题

ElasticSearch面试题 https://writer.blog.csdn.net/article/details/129941424

十八、kafka面试题

kafka面试题 https://writer.blog.csdn.net/article/details/129944044

十九、RabbitMQ面试题

RabbitMQ面试题 https://writer.blog.csdn.net/article/details/129918812

二十、Dubbo面试题

Dubbo面试题 https://writer.blog.csdn.net/article/details/129921254

二十一、ZooKeeper面试题

ZooKeeper面试题 https://writer.blog.csdn.net/article/details/129922008

二十二、Netty面试题

Netty面试题 https://writer.blog.csdn.net/article/details/129938744

二十三、Tomcat面试题

Tomcat面试题 https://writer.blog.csdn.net/article/details/129928438

二十四、Linux面试题

Linux面试题 https://writer.blog.csdn.net/article/details/129931699

二十五、互联网相关面试题

互联网相关面试题 https://writer.blog.csdn.net/article/details/129953268

二十六、互联网安全面试题

互联网安全面试题 https://writer.blog.csdn.net/article/details/129953758

猜你喜欢

转载自blog.csdn.net/u011397981/article/details/129970612