vlambda博客
学习文章列表

2022最新70道常见的Java面试题及答案,看看你会几道?

1

使使使.

使.使.使.

/.

..线线.

.使GC.


2Java

JVMJava.

线finalize..

System.gcRuntime.gcJVM.

HeapJava_OutOfMemoryError_**java.lang.OutOfMemoryError**

3Stringbuilder
StringBuilder.String.
4Stringbuilder使+

String.StringBuilder.

5StringbuilderStringbuffer

StringBufferStringBuilder线.线StringBuilder.

6Java

使.try访.finally.

.catch使.

..

Javadoc..

..

..

使API.使.

...


7JavaClassLoader

Java.class.ClassLoaderJava.

ClassLoader.使Java Runtime Environment.

JavaClassLoader

  1. Bootstrap


8使

线.线.-..-.JVM.. 

9

-..... 

..

10Java 8Optional

Optionalnull.isPresenttrueget.orElseifPresent.

11Java使doublefloat

doublefloatJava..

.151667.

.使1使11使52float使1使8使23.

12Java使线

线

使 volatile  synchronized

使使 wait()  notify() 线 BlockingQueueCountDownLatch  Semeaphore

使

.

.

使StringInteger..

Java线线.

使使.

使使BlockingQueue..

CyclicBarrierCountDownLatchSemaphore使.

13Java使Collections

使.

使Java Collections FrameworkArraysCollections

.

使isEmptysize.使.

null..

Java 8.使Stream API.

使for使.for.

14Javavolatile

使volatile使线.线使.

使volatile

  1. volatile线..

  2. 访.

volatile

class Shared
{
  static volatile int value = 15;
}

线使volatile线.

15volatile  synchronized

volatile synchronized
使null
访volatile 退.
访 Java 5.
Java 5.
16线线

Java线线.线JVM.线JVM退.线线线.

17线

CPU便线.线.

18

...

19线

线..

20runstart

线线.

21线

使ThreadsleepThread.线线线线.

22线

CPU线.线Thread Scheduler.

CPU线.线线CPU线CPU.线Java线.

23线

线线.waitnotifynotifyAll线.

24Java线

Java线synchronization, atomic concurrent classes, implementing concurrent Lock interface使volatile使Thread.

25Java线

线setDaemontrueJava线.startIllegalThreadStateException.

26ThreadLocal

Java ThreadLocal线.线线使使ThreadLocal.

线ThreadLocal使getsetThread.ThreadLocal线.

27Java Thread DumpJava Thread Dump

Thread DumpJVM线Thread Dump.使Dump Thread 使ProfilerKill -3jstack.使jstack Dump Thread使JDK.Dump Thread.

28线Java线

线线使.

线线线线.

java.util.concurrent.Executorsjava.util.concurrent.ExecutorJava线.线Java使线.ScheduledThreadPoolExecutor.

29 constructoroverride?


30 OverloadOverride?

访


31abstractstatic,nativesynchronized?

Csynchronized

32Java final

(1)(2)(3)

 33Error Exception ?

Error Exception 


34Java throwsthrowtrycatchfinally使

Java Java Throwable 便Java 5 trycatchthrowthrowsfinallytrythrowcatchfinallytrycatch trythrow throwsfinally trytrytry trytrytry 

 35final, finally, finalize ?

finalfinalabstractfinal使final final 使finallytrycatchJVMfinallyfinalizeObjectJava使finalize() finalize() 

36TreeMap

TreeMap 

TreeMap使

TreeMap线

37Java

JavaUnicodeUnicode使

38Java 线

 wait()notify()  wait()线 notify()线

waitnotify  synchronized  waitnotify  wait 线 wait 线

39线

SynchronizedLock

40使

IOCSpringnew~

DI ~

41ArrayList  LinkedList 

ArrayList  LinkedList 

访ArrayList  LinkedList 访 LinkedList 线

LinkedList  ArrayList  ArrayList 

LinkedList  ArrayList  LinkedList 

线ArrayList  LinkedList 线

使 ArrayList使 LinkedList

LinkedList 便访

42ArrayArrayList

ArrayArrayListArrayList使arrayListArrayListArray

43ConcurrentHashMap  Hashtable 

ConcurrentHashMap  Hashtable 线

JDK1.7 ConcurrentHashMap  JDK1.8 HashMap1.8+/Hashtable  JDK1.8  HashMap   HashMap 

JDK1.7ConcurrentHashMap(Segment)线访访16SegmentHashtable16 线 HashMapJDK1.8 Segment 

使 synchronized 线线访线访使 put 线使 put 使 get

HashTable

 JDK1.7ConcurrentHashMap

JDK1.8ConcurrentHashMapTreeBin:  Node: 

ConcurrentHashMap  HashMap  HashTable HashMap HashTable 使synchronized  HashTable ConcurrentHashMap 

44Java  LinkedHashMap  PriorityQueue 

PriorityQueue  LinkedHashMap  PriorityQueue  LinkedHashMap 

45

public,private,static访staticfinal

finalstatic

46JVM 

FromTo,15(JVMMaxTenuringThreshold,15),,

EdenoldoldmajorGCedenminorgcGC

minor gcsurvivor

 survivor 

4732  JVM  64  JVM 

 32  JVM  2^32 4GB Windows  1.5 GBSolaris  3GB64  JVM 2^64 100GB JVM Azul 1000G 

48 hashcode

 hashcode  hashmap  hashcode hashcode 

49synchronized  Lock 

synchronizedJavaJVMLockJava

synchronized  lock 

synchronized 使 lock 使 unLock()

 Lock  synchronized 

50Vector

VectorArrayList线线Vector线访访ArrayList

ArrayListList访ArrayListArrayList

51ReentrantLock

public class UnReentrant{
Lock lock = new Lock();
public void outer(){
lock.lock();
inner();
lock.unlock();
}
public void inner(){
lock.lock();
//do something
lock.unlock();
}
}

outerinnerouterlockinnerlockouter线lockinner 线

synchronizedReentrantLock

52 OOM 

 -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/tmp/heapdump.hprof OOM  dump 

 jstat  JVM  GC 

使 MAT  dump  HashMap 

53线

线

线使线

线线使线

线

54String 

String  8 bytebooleancharshortintfloatlongdouble String 

55线 sleep() yield()

sleep()线线线yield()线

线 sleep()blocked yield()ready


sleep() InterruptedException yield()

sleep() yield() CPU 使yield()线

56线 submit()  execute() 

线

execute() Runnable submit() Runnable  Callable 

submit() Future execute()

submit()便Exception

57

58

1 JNDI 线 Thread.setContextClassLoader  SPI 线 JNDI 线

2 Tomcat class

3 OSGi

4 JDK 9Extension ClassLoader  Platform ClassLoader 

59?

1 线线 CPU  CPU 线使线CPU 线线线使

2  CPU 便

3  CPU 

4 Linux  Unix 

60Xmljava

Domxml使dom

Sax

xmldom4jjdom

61JVM 

JVM 

  java.lang.Class   Class  ZIP  jar  war  JSP  Class 

 Class 

使

 v  0  8080  v  8080  put static  

public static final int v = 8080;

 v  ConstantValue  ConstantValue  v 8080

 class 

public static int v = 8080;

 v  0  8080  v  8080  put static  

 v  ConstantValue  ConstantValue  v 8080


  Java  Class 

 JVM  Java 

 ()

1 

2 

3 

4  Class 

5  Class.forName  initialize  false 

6  ClassLoader  loadClass 

62hystrix 

线

  1. 线

线 

-+1-1

线线


63ribbonhystrix

hystrix

64

  • Memcached Memcached  add  key  add线

  • Redis Memcached  Redis  setnx  key  set 

  • Zookeeper Zookeeper Zookeeper 

  • ChubbyGoogle  Paxos 

  • Redission

65线

线 = 线线 CPU  + 1* CPU

66线

67ThreadLocal 

ThreadLocalJDKjava.langThreadLocal访线线线线线线线线线线线ThreadLocal线ThreadLocal线

ThreadLocal 线线线

1线2

68线

    

69线

ExecutorService 

  • void shutdown(); 线

  • List<Runnable> shutdownNow(); 线

70线

java3线

使退使线退run线

使stopstopsuspendresume

使interrupt线