一、java基礎(chǔ)
1、JDK 和 JRE 有什么區(qū)別?
JDK(Java Development Kit),Java開發(fā)工具包
JRE(Java Runtime Environment),Java運行環(huán)境
JDK中包含JRE,JDK中有一個名為jre的目錄,里面包含兩個文件夾bin和lib,bin就是JVM,lib
就是JVM工作所需要的類庫。
2、== 和 equals 的區(qū)別是什么?
對于基本類型,== 比較的是值;
對于引用類型,==比較的是地址;
equals不能用于基本類型的比較;
如果沒有重寫equals,equals就相當(dāng)于 ==;
如果重寫了equals方法,equals比較的是對象的內(nèi)容;
3、final 在 java 中有什么作用?
(1)用來修飾一個引用
如果引用為基本數(shù)據(jù)類型,則該引用為常量,該值無法修改;
如果引用為引用數(shù)據(jù)類型,比如對象、數(shù)組,則該對象、數(shù)組本身可以修改,但指向該對象或數(shù)組的地址的引用不能修改。
如果引用時類的成員變量,則必須當(dāng)場賦值,否則編譯會報錯。
(2)用來修飾一個方法
當(dāng)使用final修飾方法時,這個方法將成為最終方法,無法被子類重寫。但是,該方法仍然可以被繼承。
(3)用來修飾類
當(dāng)用final修改類時,該類成為最終類,無法被繼承。
比如常用的String類就是最終類。
4、java 中的 Math.round(-1.5) 等于多少?
Math提供了三個與取整有關(guān)的方法: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 屬于基礎(chǔ)的數(shù)據(jù)類型嗎?
不屬于。
八種基本數(shù)據(jù)類型:byte、short、char、int、long、double、float、boolean。
6、String str="i"與 String str=new String(“i”)一樣嗎?
String str="i"會將起分配到常量池中,常量池中沒有重復(fù)的元素,如果常量池中存中i,就將i的地址賦給變量,如果沒有就創(chuàng)建一個再賦給變量。
String str=new String(“i”)會將對象分配到堆中,即使內(nèi)存一樣,還是會重新創(chuàng)建一個新的對象。
7、如何將字符串反轉(zhuǎn)?
將對象封裝到stringBuilder中,調(diào)用reverse方法反轉(zhuǎn)。
8、String 類的常用方法都有那些?
(1)常見String類的獲取功能
length:獲取字符串長度;
charAt(int index):獲取指定索引位置的字符;
indexOf(int ch):返回指定字符在此字符串中第一次出現(xiàn)處的索引;
substring(int start):從指定位置開始截取字符串,默認(rèn)到末尾;
substring(int start,int end):從指定位置開始到指定位置結(jié)束截取字符串;
(2)常見String類的判斷功能
equals(Object obj): 比較字符串的內(nèi)容是否相同,區(qū)分大小寫;
contains(String str): 判斷字符串中是否包含傳遞進(jìn)來的字符串;
startsWith(String str): 判斷字符串是否以傳遞進(jìn)來的字符串開頭;
endsWith(String str): 判斷字符串是否以傳遞進(jìn)來的字符串結(jié)尾;
isEmpty(): 判斷字符串的內(nèi)容是否為空串"";
(3)常見String類的轉(zhuǎn)換功能
byte[] getBytes(): 把字符串轉(zhuǎn)換為字節(jié)數(shù)組;
char[] toCharArray(): 把字符串轉(zhuǎn)換為字符數(shù)組;
String valueOf(char[] chs): 把字符數(shù)組轉(zhuǎn)成字符串。valueOf可以將任意類型轉(zhuǎn)為字符串;
toLowerCase(): 把字符串轉(zhuǎn)成小寫;
toUpperCase(): 把字符串轉(zhuǎn)成大寫;
concat(String str): 把字符串拼接;
(4)常見String類的其他常用功能
replace(char old,char new) 將指定字符進(jìn)行互換
replace(String old,String new) 將指定字符串進(jìn)行互換
trim() 去除兩端空格
int compareTo(String str) 會對照ASCII 碼表 從第一個字母進(jìn)行減法運算 返回的就是這個減法的結(jié)果,如果前面幾個字母一樣會根據(jù)兩個字符串的長度進(jìn)行減法運算返回的就是這個減法的結(jié)果,如果連個字符串一摸一樣 返回的就是0。
9、new String(“a”) + new String(“b”) 會創(chuàng)建幾個對象?
對象1:new StringBuilder()
對象2:new String(“a”)
對象3:常量池中的"a"
對象4:new String(“b”)
對象5:常量池中的"b"
深入剖析:StringBuilder中的toString():
對象6:new String(“ab”)
強(qiáng)調(diào)一下,toString()的調(diào)用,在字符串常量池中,沒有生成"ab"
附加題
String s1 = new String(“1”) + new String(“1”);//s1變量記錄的地址為:new String
s1.intern();//在字符串常量池中生成"11"。如何理解:jdk6:創(chuàng)建了一個新的對象"11",也就有新的地址;jdk7:此時常量池中并沒有創(chuàng)建"11",而是創(chuàng)建了一個指向堆空間中new
String(“11”)的地址; String s2 = “11”; System.out.println(s1 ==
s2);//jdk6:false;jdk7:true
10、如何將字符串反轉(zhuǎn)?
添加到StringBuilder中,然后調(diào)用reverse()。
更多Java基礎(chǔ)知識面試題 https://writer.blog.csdn.net/article/details/129093071
二、java集合
Java集合面試題 https://writer.blog.csdn.net/article/details/129758782
三、多線程
Java并發(fā)編程面試題 https://writer.blog.csdn.net/article/details/129860582
四、JVM
Java虛擬機(jī)(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
七、設(shè)計模式面試題
設(shè)計模式面試題 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
二十五、互聯(lián)網(wǎng)相關(guān)面試題
互聯(lián)網(wǎng)相關(guān)面試題 https://writer.blog.csdn.net/article/details/129953268文章來源:http://www.zghlxwxcb.cn/news/detail-405393.html
二十六、互聯(lián)網(wǎng)安全面試題
互聯(lián)網(wǎng)安全面試題 https://writer.blog.csdn.net/article/details/129953758文章來源地址http://www.zghlxwxcb.cn/news/detail-405393.html
到了這里,關(guān)于【面試】Java高頻面試題(2023最新整理)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!