Baidu's first 200 pages of "Java Interview Questions" selected first chapters
Multi-threaded
Basic concepts
What are the advantages of threaded multithreading
Several implementation methods of multi-threading
1. Use Runnable or Thread
What is thread safety
What is a busy loop in multithreading? How to create a thread. How many ways to write a multithreaded program? What are thread local variables? What is the difference between thread and process? How to communicate between processes, how to communicate between threads, what is false sharing in a multi-threaded environment?
What are the similarities and differences between synchronization and asynchronous, and under what circumstances do they use separately? Give an example
Current
The difference between ConcurrentHashMap and Hashtable
ArrayBlockingQueue, CountDownLatch usage
What is the concurrency of ConcurrentHashMap
What is the difference between CyclicBarrier and CountDownLatch? What are their internal principles and usages
How to use Semaphore
Thread
Should I start a thread call the run() or start() method? What is the difference between start() and run() methods? When calling start() method, the run() method will be executed. Why can't the run() method be called directly?
The wait() method of the sleep() method and the object's wait() method can make the thread pause execution. What is the difference between them
What is the function of the yield method? What is the difference between sleep() method and yield() method
How to stop a thread in Java
Why are stop() and suspend() methods not recommended to use How to share data between two threads How to force a thread to start? How to make a running thread pause for a period of time What is a thread group and why is it not recommended to use in Java How do you call wait(method)? Using if block or loop? Why
life cycle
What are the different thread life cycle thread states? What is the difference between BLOCKED and WAITING? Draw a thread life cycle state diagram?
What is the purpose, the principle, and what should you pay attention to when using it
ThreadPool
What is a thread pool? Why use it How to create a Java thread pool
ThreadPool usage and advantages What happens when a thread pool queue is full when a task is submitted
What is the difference between newCache and newFixed? Briefly describe the principle. What is the meaning of each parameter of the constructor? For example, coreSize, maxsize and other thread pool implementation strategy, there are several ways to close the thread pool. What is the difference between submit() and execute() methods in the thread pool?
Thread Scheduling
What is the thread scheduling algorithm used in Java? What is the context switching in multithreads? What is your understanding of thread priority? What is the thread scheduler and time slicing?
Thread synchronization
Please tell me what you know about thread synchronization methods
What is the principle of synchronized
What are the differences between synchronized and ReentrantLock? In what scenarios can you use volatile to replace synchronized
There are three threads T1, T2 and T3. How to make sure they are executed in order? How to ensure that T2 is executed after T1 is executed, and T3 executes the thread in the synchronization block after T2 is executed. What happens when a thread enters the synchronized method A of an object? After another thread enters the synchronized method B of this object?
What is the difference between using synchronized to modify static methods and non-static methods How to create a synchronized collection from a given collection
Lock
What is the Lock interface in the Java Concurrency API? What are the advantages of synchronizing it
What is the difference between Lock and Synchronized? What are the advantages of the Lock interface over the synchronized block?
What is ReadWriteLock?
What is the use of locking mechanism and what is optimistic locking? How to achieve optimistic locks? How to avoid ABA problems explain the following nouns: reordering, spin lock, biased lock, lightweight lock, reentrant lock, fair lock, non-fair lock, optimistic lock, pessimistic lock, when should the reentrant lock be used briefly describe the level method of lock, object lock, class lock
What is the difference between a live lock and a dead lock in Java?
What is a deadlock? What causes thread deadlock? How to ensure that N threads can access N resources without causing the difference between deadlock and live lock, the difference between deadlock and hunger How to detect whether a thread has a lock How to implement what lock-free data structures does a distributed lock have? What are the principles of their implementation
What application scenarios can read and write locks be used for?
abnormal
Basic concepts
What is the difference between Error and Exception
1.What is UnsupportedOperationException
2. What are the similarities between NullPointerException and ArrayIndexOutOfBoundException
What is the checked exception, what is the runtime exception and the general exception? Briefly describe the runtime exception you most commonly see.
Finally
How to use finally keywords in exception handling
1. If the method returns the result before executing the finally code block, or the JVM exits, will the code in the finally block be executed?
2. There is a return in the try, is it finally executed? So will the code in finally {} immediately following this try be executed, when will it be executed, before or after return
3. Under what circumstances will finally statement not be executed
What is the difference between throw and throws?
OOM What situations have you encountered? How did you do it?
SOF What situations have you encountered?
Since we can use RuntimeException to handle errors, why do you think there are still checked exceptions in Java? When you create an exception class, you should pay attention to what causes null pointer exceptions. Exception handling handle or declare principle should be understood. How to use JUnit to test exceptions in a method?
Don't write code in the catch block. Are there any problems? Have you ever implemented exceptions in customization? How to write what is an exception chain can throw exceptions in a try block?
JDBC
What are the ways to connect to a database through JDBC to explain the basic steps of JDBC operating a database
How to do transactions in JDBC What is JdbcTemplate
What is the performance of reading data when a DAO module uses JDBC to operate a database? How to Improve Performance of Updated Data List 5 JDBC Best Practices Should Follow
IO
File
What method is defined in File type to create a first-level directory
What method is defined in the File type to determine whether a file exists
flow
In order to improve read and write performance, what streams can be used
There are several types of streams in Java
JDK provides some abstract classes for inheritance for each type of stream, which classes use what I/O stream to read and write various basic data types and String types, and what streams can be used to specify the character-encoded I/O stream types.
Serialization
What is serialization? How to implement Java serialization and precautions
The difference between Serializable and Externalizable
Socket
What does socket option TCP NO DELAY mean
Which layer does Socket work on the TCP/IP protocol stack?
The difference between TCP and UDP and Java implementation methods
What are the best practices for IO? What is the difference between direct buffers and non-direct buffers?
How to read and write ByteBuffer? What is the endianness in ByteBuffer? When using System.in.read(buffer) to enter a line of n characters from the keyboard, what is the number of bytes stored in the buffer buffer? How to use the Scanner Class tokenization
Object-Oriented Programming (OOP)
Explain polymorphism, encapsulation, cohesion and coupling
The implementation principle of polymorphism. What are the encapsulation, inheritance and polymorphism? What are the principles of object encapsulation?
kind
What are the differences between overloading and overriding a class object? Can overloaded methods be distinguished based on the return type?
Tell out some best practices for method overloading in Java
Abstract Class
The difference between abstract class and interface. Is there a static main method in an abstract class? Is the abstract class implementing? Is the interface abstract class inheritable?
Anonymous Inner Class
Can anonymous inner classes inherit other classes? Is the interface possible?
Internal class
Inner classes are divided into several types of inner classes. Can it refer to its members that contain classes (external classes). Please tell me why internal classes are introduced in Java? There are also anonymous internal classes
inherit
Where is the difference between inheritance and aggregation? What is the difference between inheritance and composition? Why can classes be inherited by only single inheritance? Interfaces can inherit two more classes. B inherits A and C inherits B. Can B be converted to C? If C = (C) B
If class a inherits class b and implements interface c, and class b and interface c define variables of the same name, what problems will occur?
interface
What interface is an interface? Is it inheritable? Why should we use an interface instead of using concrete classes directly? What are the advantages of interfaces
Generics
What problems does generics exist to solve? Common features of generics
Can List be converted to List
Tools
calendar
How to get examples of calendar class in Java Explain some important methods in calendar classes
What is the GregorianCalendar class
What is the SimpleTimeZone class
What is the Locale class How to format a date object How to add hours to a date object
How to convert string YYYYMMDD to date
Math
What is the function of Math.round()? What does Math.round(11.5) equal? What is Math.round(-11.5) equal?
XML
How many forms are there in XML document definition? What is the essential difference between them? What are the ways to parse XML documents? What is the difference between DOM and SAX parsers?
How to solve Chinese problems when parsing XML using jdom when parsing XML? How to parse what aspects of XML technology you used in your project? How to implement it
Dynamic Agent
Describe several implementation methods of dynamic proxy and explain the corresponding advantages and disadvantages respectively
The above is all the content of this article. I hope it will be helpful to everyone's learning and I hope everyone will support Wulin.com more.