Top 200 pages of Baidu Java interview questions (middle)
Baidu's first 200 pages of "Java interview questions"
Multithreading
Basic concepts
What are the advantages of multithreading
Several implementations of multithreading 1 Runnable or thread
What is thread safety
What is the busy loop in multithreading? How to create a thread? There are several ways to write multithreaded programs. What is the thread local variable? What is the difference between thread and process? How to communicate between processes, how to communicate between threads, what is false sharing in multithreaded environment, what are the similarities and differences between synchronization and asynchrony, and under what circumstances are they used respectively? Examples are given
Current
What is the difference between concurrent HashMap and hashtable? What is the concurrency of concurrent HashMap
What is the difference between cyclicbarrier and countdownlatch? What are their internal principles and usage? Semaphore thread
Does starting a thread call the run () or start () method? What's the difference between the start () and run () methods? When calling the start () method, the run () method will be executed. Why can't you directly call the run () method? Both the sleep () method and the wait () method of the object can make the thread pause execution. What's the difference between them? What's the role of the yield method? What is the difference between the sleep () method and the yield () method? How to stop a thread in Java? Why are the stop () and suspend () methods not recommended? How to share data between two threads? How to force a thread to start? How to suspend a running thread for a period of time? What is a thread group, Why is it not recommended in Java? How do you call wait (method), if block or loop? Why
life cycle
What are the different thread life cycles and thread states? What are the differences between blocked and waiting? Draw a thread life cycle state diagram
What is the purpose and principle of ThreadLocal? What should be paid attention to when using ThreadPool
What is a thread pool? Why use it? How to create a java thread pool? What is the difference between ThreadPool usage and advantage? What happens when the thread pool queue is full when submitting a task? What is the difference between newcache and newfixed? Briefly describe the principle. What are the meanings of the parameters of the constructor, such as the implementation strategies of coresize, maxsize and other thread pools? There are several ways to close the thread pool. What are the differences between the submit() and execute() methods in the thread pool?
Thread scheduling
What is the thread scheduling algorithm used in Java? What is context switching in multithreading? What is your understanding of thread priority? What are thread scheduler and time slicing
Thread synchronization
What is the principle of thread synchronization? What are the differences between synchronized and reentrantlock? In what scenario, volatile can be used to replace synchronized. There are three threads: T1, T2 and T3. How to ensure that they are executed in order? How to ensure that T2 is executed after T1 is executed, and what happens when the thread in the synchronization block throws an exception after T3 is executed after T2. When a thread enters the synchronized method a of an object, Can other threads enter the synchronized method B of this object? What is the difference between static methods and non static methods using synchronized? 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 lock versus synchronized? What are the advantages of the lock interface over synchronized blocks? What is readwritelock? What is the use of lock mechanism? What is optimistic lock (optimal locking)? How to implement optimistic locks? How to avoid ABA problems? Explain the following terms: reordering, spin lock, bias lock, lightweight lock, reentrant lock, fair lock, unfair lock, optimistic lock and pessimistic lock. When should reentrant locks be used? Briefly describe the level method of locks, object locks and class locks. What is the difference between live locks and deadlocks in Java? What is death Deadlock? What causes thread deadlock? How to ensure that n threads can access n resources without causing deadlock? The difference between deadlock and livelock, the difference between deadlock and starvation, how to detect whether a thread has a lock, how to implement distributed locks, what are the unlocked data structures, and what is the principle of their implementation
What application scenarios can read-write locks be used for
abnormal
Basic concepts
What is the difference between error and exception 1 What is unsupported operationexception 2 What are the similarities between NullPointerException and arrayindexoutofboundexception
What are the checked exceptions? What are the runtime exceptions? What are the similarities and differences between runtime exceptions and general exceptions? Briefly describe one of the most common runtime exceptions you see
finally
How to use finally keyword in exception handling 1 If the method returns a result before executing the finally code block, or if the JVM exits, will the code in the finally code block still be executed? 2 There is a return in try. Is finally executed? So will the code in finally {} immediately after this try be executed and when, before or after return Under what circumstances will a finally statement not execute
What's the difference between throw and throws? Oom what situations have you encountered? How did you handle it? Sof what situations have you encountered? Since we can handle errors with runtimeException, So why do you think there are checking exceptions in Java? When you create an exception class, you should pay attention to what causes null pointer exceptions. How should the exception handling handle or declare principle understand how to use JUnit to test the exception of a method? Don't write code in the catch block. What's the problem? Have you ever customized the implementation of exceptions? What is the exception chain? Can exceptions be thrown in the try block
JDBC
What are the ways to connect to the database through JDBC? This paper expounds the basic steps of JDBC operating the database, how to carry out transaction processing in JDBC, what is jdbctemplate, what is Dao module, and how to improve the performance of reading data when using JDBC to operate the database? How to improve the performance of updating data? List 5 JDBC best practices that should be followed
IO
File
What method is defined in the file type to create a primary directory? What method is defined in the file type to judge whether a file exists
flow
In order to improve the reading and writing performance, what streams can be used? There are several types of streams in Java. The JDK provides some abstract classes for each type of stream to inherit, including which classes operate on text files, what I / O streams are used to read and write various basic data types and string types, and what streams can be used to specify the type of character coded I / O streams
serialize
What is serialization? How to implement Java serialization and precautions the difference between serializable and externalizable
Socket
The socket option TCP no delay refers to what socket works in the TCP / IP protocol stack, which layer is the difference between TCP and UDP and the Java implementation method
What is the difference between direct buffers and indirect buffers? How to read and write ByteBuffer? What is the byte order in ByteBuffer when using system in. Read (buffer) after inputting a line of n characters from the keyboard, how many bytes are stored in the buffer? How to tokenize using the scanner class
Object oriented programming (OOP)
Explain the implementation principles of polymorphism, encapsulation, cohesion and coupling polymorphism. What are encapsulation, inheritance and polymorphism, and what are the principles of object encapsulation?
class
What are the differences between overloading and overriding the class objects of a class? Can overloaded methods be distinguished according to the return type? Name several best practices of method overloading in Java
abstract class
The difference between abstract classes and interfaces whether there can be static main methods in abstract classes whether abstract classes can implement interfaces whether abstract classes can inherit concrete classes
Anonymous inner class
Can anonymous inner classes inherit from other classes? Can the interface be implemented
Inner class
The internal class is divided into several types. Can the internal class refer to the members of its containing class (external class)? Please tell us why the internal class is introduced in Java? There are also anonymous internal classes
inherit
What is the difference between inheritance and aggregation? What are the differences between inheritance and composition? Why can classes only inherit single, and interfaces can inherit multiple? There are two classes, B inherits a and C inherits B. can b be converted to C? For example, C = (c) B if class a inherits class B and implements interface C, and variables with the same name are defined in class B and interface C, What will happen
Interface
What is an interface? Is an interface inheritable? Why use an interface instead of a concrete class? What are the advantages of interfaces
generic paradigm
The existence of generics is used to solve what problems. The common feature of generics is whether list can be converted to list
Tool class
calendar
Purpose of calendar class how to get an instance of calendar class in Java explain some important methods in calendar classes what is gregoriancalendar class what is simpletimezone class what is locale class how to format date objects how to add hours to a date object how to convert string yyyymmdd to date
Math
Math. What does round () do? Math. What is round (11.5) equal to? Math. What is round (- 11.5) equal to?
XML
How many forms do XML document definitions take? 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 the Chinese problem when parsing XML files with JDOM? How to parse what aspects of XML technology you use in your project? How
Dynamic agent
Describe several implementation methods of dynamic agent, and say the corresponding advantages and disadvantages respectively
The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.