Java advanced
Class loading process
Load (Create class object) -> Connect (Validate – prepare – parse) -> initialize class
Class loader class
Root class loader: Loads the Java core classes
Extended class loader: loads jar packages in the JRE directory
System class loader: Loads user-defined classes and JAR packages in the classpath
What is Java reflection based on
Reflection allows us to manipulate classes or objects directly, such as getting the class definition of an object, getting the properties and methods declared by the class, calling methods or constructing objects, and even modifying the class definition at run time
What are dynamic proxies based on
A mechanism for dynamically building proxies and handling proxy method calls at run time
The difference between dynamic and static proxies
Static proxy: The agent class is written in advance. The disadvantage is that each business class has to correspond to a proxy class, which is not flexible
Dynamic proxy: Proxy objects are generated automatically at runtime, with the disadvantage of the extra time required to produce proxy objects and invoke proxy methods
What byte streams are there?
InputStream, FileInputStream, BufferedInputStream
OutputStream, FileOutputStream, BufferedOutputStream
A DataInputStream and DataOutputStream
ByteArrayInputStream, ByteArrayOutputStream
ObjectInputstream, ObjectOutputStream
PrintStream, SequenceInputStream
What character streams are there?
Reader, InputStreamReader, FileReader, BufferedReader
Writer, OutputStreamWriter, FileWriter, BufferedWriter
CharArrayReader, CharArrayWriter, PrintWriter
What other IO streams are there?
StringReader, StringWriter, RandomAccessFile, Properties
Common network minor problems
The problem | The answer |
What is a TCP client socket? | Socket |
What is a TCP server socket? | ServerSocket |
What is the socket used for UDP? | DatagramSocket |
What are UDP packets sent and received datagrams? | DatagramPacket |
GC main algorithm
The main objects of GC are heap and method area. In the heap, short-lived objects are classified as new generation and long-lived objects are classified as old age
- Root search algorithm
- Mark-clear algorithm
- Replication algorithm (New generation GC)
- Mark-collation algorithm (old GC)
- Generation collection algorithm (Cenozoic + Old GC)
Conditions that trigger the main Garbage Collector
GC is called when the application is idle, that is, when there are no application threads running
GC is called when the Java heap is out of memory. When the application thread is running and creating new objects in the process, the JVM forces the GC thread to be called to reclaim memory for new allocations if there is insufficient memory.
Cause of memory leak
- Database connections, network connections, and IOD connections will not be GC if close is not called
- Singleton pattern, holding references to external objects, objects with long life cycles
- Vector, into which objects are put
- Collection, object into the collection, object is modified after the property of remove object failed