最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

15道非常經(jīng)典的Java面試題 附詳細(xì)答案

 更新時(shí)間:2016年10月22日 10:40:18   作者:楊尚川  
這篇文章主要為大家推薦了15道非常經(jīng)典的Java面試題,附詳細(xì)答案,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

試題如下:

參考答案:

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Created by ysc on 7/26/16.
 */
public class Interview {
 private static void one(){
 String str1 = "hello";
 String str2 = "he"+new String("llo");
 System.err.println(str1==str2);
 System.out.println("1. false");
 }
 private static void two(){
 int i = Integer.MAX_VALUE;
 System.err.println((i+1)<i);
 System.out.println("2. 存在一個(gè)i, 使得(i+1)<i");
 }
 private static void three(){
 System.err.println("gc is not a Java Thread, it is a native thread");
 Thread.getAllStackTraces().keySet().forEach(thread -> System.out.println(thread.getName()+"->"+thread.isDaemon()+" "+thread.getPriority()));
 System.out.println("3. gc線程是daemon線程");
 }
 private static volatile int count = 0;
 private static void four(){
 ExecutorService executorService = Executors.newCachedThreadPool();
 for(int j=0; j<10; j++){
  executorService.submit(()->{
  for(int i=0; i<1000000; i++){
   count++;
  }
  });
 }
 System.out.println("count should be: "+10000000+", actual be: "+count);
 System.out.println("4. volatile不能保證線程安全");
 }
 private static void five(){
 ArrayList<Integer> list = new ArrayList<>(20);
 list.add(1);
 System.out.println("debug code, not execute grow method");
 System.out.println("5. list grow 0 times");
 }
 private static void six() {
 System.out.println("BufferedReader's constructor only accepts a Reader instance");
 System.out.println("6. new BufferedReader(new FileInputStream(\"a.dat\")); is wrong");
 }
 private static void seven() {
 try{
  if(true){
  throw new IOException();
  }
 }catch (FileNotFoundException e){
  System.out.print("FileNotFoundException!");
 }catch (IOException e){
  System.out.print("IOException!");
 }catch (Exception e){
  System.out.print("Exception!");
 }
 System.out.println("\n7. IOException!");
 }
 private static void eight() {
 System.out.println("String s;System.out.println(s); error: variable s might not have been initialized\nRecompile with -Xlint:unchecked for details.");
 System.out.println("8. 由于String s沒(méi)有初始化, 代碼不能編譯通過(guò)");
 }
 private static void nine() {
 System.out.println("5"+2);
 System.out.println("9. 52");
 }
 private static void ten() {
 int i = 2;
 int result = 0;
 switch(i){
  case 1:
  result = result + i;
  case 2:
  result = result + i * 2;
  case 3:
  result = result + i * 3;
 }
 System.out.println("result="+result);
 System.out.println("10. 10");
 }
 private static class Null{
 public static void hello(){
  System.out.println("hello");
 }
 public static void main(String[] args) {
  ((Null)null).hello();
  Null _null = (Null)null;
  _null.hello();
 }
 }
 private static class StringExample1{
 String str = new String("good");
 char[] ch = {'a', 'b', 'c'};
 public void change(String str, char[] ch){
  str = "test ok";
  ch[0] = 'g';
 }

 public static void main(String[] args) {
  StringExample1 ex = new StringExample1();
  ex.change(ex.str, ex.ch);
  System.out.print(ex.str+" and ");
  System.out.print(ex.ch);
  System.out.println();
 }
 }
 private static class StringExample2{
 public static void change(String str){
  str = "welcome";
 }

 public static void main(String[] args) {
  String str = "1234";
  change(str);
  System.out.println(str);
 }
 }
 private static class ForLoop{
 static boolean foo(char c){
  System.out.print(c);
  return true;
 }

 public static void main(String[] args) {
  int i=0;
  for(foo('A');foo('B')&&(i<2);foo('C')){
  i++;
  foo('D');
  }
  System.out.println();
 }
 }
 private static class HelloA{
 public HelloA(){
  System.out.println("HelloA");
 }

 { System.out.println("I'm A class"); }

 static {
  System.out.println("static A");
 }
 }
 private static class HelloB extends HelloA{
 public HelloB(){
  System.out.println("HelloB");
 }

 { System.out.println("I'm B class"); }

 static {
  System.out.println("static B");
 }

 public static void main(String[] args) {
  System.out.println("main start");
  new HelloB();
  new HelloB();
  System.out.println("main end");
 }
 }
 public static void main(String[] args) {
 one();
 two();
 three();
 four();
 five();
 six();
 seven();
 eight();
 nine();
 ten();
 Null.main(null);
 StringExample1.main(null);
 StringExample2.main(null);
 ForLoop.main(null);
 HelloB.main(null);
 }
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Java這個(gè)名字的來(lái)歷與優(yōu)勢(shì)

    Java這個(gè)名字的來(lái)歷與優(yōu)勢(shì)

    Java是Sun公司開(kāi)發(fā)的一種編程語(yǔ)言,Sun公司最初的方向是讓Java來(lái)開(kāi)發(fā)一些電器裝置程序,Java名字的由來(lái),實(shí)際上是一個(gè)有趣的故事。
    2014-10-10
  • springcloud gateway網(wǎng)關(guān)服務(wù)啟動(dòng)報(bào)錯(cuò)的解決

    springcloud gateway網(wǎng)關(guān)服務(wù)啟動(dòng)報(bào)錯(cuò)的解決

    這篇文章主要介紹了springcloud gateway網(wǎng)關(guān)服務(wù)啟動(dòng)報(bào)錯(cuò)的解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-03-03
  • 使用springMVC通過(guò)Filter實(shí)現(xiàn)防止xss注入

    使用springMVC通過(guò)Filter實(shí)現(xiàn)防止xss注入

    這篇文章主要介紹了使用springMVC通過(guò)Filter實(shí)現(xiàn)防止xss注入的操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-07-07
  • Mybatis操作多數(shù)據(jù)源的實(shí)現(xiàn)

    Mybatis操作多數(shù)據(jù)源的實(shí)現(xiàn)

    本文主要介紹了Mybatis操作多數(shù)據(jù)源,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2023-05-05
  • java外部類與內(nèi)部類簡(jiǎn)介

    java外部類與內(nèi)部類簡(jiǎn)介

    這篇文章簡(jiǎn)單介紹了java外部類與內(nèi)部類,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2021-12-12
  • spring項(xiàng)目如何配置多數(shù)據(jù)源(已上生產(chǎn),親測(cè)有效)

    spring項(xiàng)目如何配置多數(shù)據(jù)源(已上生產(chǎn),親測(cè)有效)

    這篇文章主要介紹了spring項(xiàng)目如何配置多數(shù)據(jù)源(已上生產(chǎn),親測(cè)有效),具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-12-12
  • Spring Security 和Apache Shiro你需要具備哪些條件

    Spring Security 和Apache Shiro你需要具備哪些條件

    這篇文章主要介紹了Spring Security 和Apache Shiro你需要具備哪些條件,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-07-07
  • Java中Integer兩種轉(zhuǎn)int方法比較

    Java中Integer兩種轉(zhuǎn)int方法比較

    本文主要介紹了Java Integer兩種轉(zhuǎn)int方法比較。具有很好的參考價(jià)值,下面跟著小編一起來(lái)看下吧
    2017-02-02
  • 詳談Springfox與swagger的整合使用

    詳談Springfox與swagger的整合使用

    下面小編就為大家?guī)?lái)一篇詳談Springfox與swagger的整合使用。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-08-08
  • 利用SpringMVC和Ajax實(shí)現(xiàn)文件上傳功能

    利用SpringMVC和Ajax實(shí)現(xiàn)文件上傳功能

    這篇文章主要為大家詳細(xì)介紹了利用SpringMVC和Ajax實(shí)現(xiàn)文件上傳功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-08-08

最新評(píng)論

贵州省| 婺源县| 宝应县| 天峻县| 安达市| 桃江县| 枣阳市| 临朐县| 富顺县| 泰来县| 静海县| 北海市| 衡阳县| 隆尧县| 灵川县| 镇安县| 嵩明县| 杭州市| 元朗区| 德清县| 安宁市| 宽甸| 永州市| 普兰店市| 德格县| 曲靖市| 白水县| 和林格尔县| 水城县| 大渡口区| 肃南| 香港| 白山市| 宝清县| 逊克县| 文成县| 阿图什市| 海伦市| 麦盖提县| 芦山县| 抚顺市|