Comprehensive Guide to Java Backend Interview Topics: Object Creation, Reflection, Serialization, GC, I/O Multiplexing, and Network Troubleshooting
This article provides an in-depth review of common Java backend interview questions, covering alternative object creation methods, practical reflection scenarios, serialization techniques, garbage‑collection algorithms, I/O multiplexing mechanisms, network port listening, and troubleshooting tips for server‑client communication issues.
With the autumn campus recruitment approaching, the author continues to share backend development interview material to help candidates review knowledge points efficiently.
Alternative Ways to Create Java Objects
Using reflection: Class clazz = MyClass.class; MyClass obj = (MyClass) clazz.newInstance();
Using deserialization: serialize an object to a file and read it back with ObjectOutputStream and ObjectInputStream .
Using cloning: implement Cloneable and override clone() to return super.clone() .
public class MyClass implements Serializable { }
public class Main {
public static void main(String[] args) throws Exception {
Class
clazz = MyClass.class;
MyClass obj = (MyClass) clazz.newInstance();
}
}Typical Reflection Scenarios
Loading database drivers dynamically (e.g., Class.forName("com.mysql.cj.jdbc.Driver") ).
Reading configuration files and instantiating beans via Spring IOC.
Parsing a properties file to obtain class and method names, then invoking the method with reflection.
Class
c = Class.forName(getName("className"));
Method method = c.getDeclaredMethod(getName("methodName"));
method.setAccessible(true);
TestInvoke ti = (TestInvoke) c.newInstance();
method.invoke(ti);Transferring an Object Between JVMs
Serialization & deserialization using ObjectOutputStream/ObjectInputStream .
Message‑queue mechanisms such as RabbitMQ or Kafka.
Remote Procedure Call frameworks like gRPC.
Shared databases or caches (MySQL, Redis) for state sharing.
Custom Serialization Considerations
Java's built‑in serialization has security, cross‑language, and performance drawbacks; alternatives such as FastJSON or Protobuf are recommended for production use.
Converting an Object to a Binary Byte Stream
Implement Serializable , then write the object with ObjectOutputStream and read it back with ObjectInputStream :
import java.io.*;
public class MyClass implements Serializable { }
MyClass obj = new MyClass();
try (FileOutputStream fos = new FileOutputStream("object.ser");
ObjectOutputStream out = new ObjectOutputStream(fos)) {
out.writeObject(obj);
}
try (FileInputStream fis = new FileInputStream("object.ser");
ObjectInputStream in = new ObjectInputStream(fis)) {
MyClass newObj = (MyClass) in.readObject();
}Garbage‑Collection Algorithms and STW Phases
Mark‑Sweep: marks reachable objects then sweeps; suffers from fragmentation.
Copying: moves live objects to a new region, eliminating fragmentation but using only half of the heap.
Mark‑Compact: moves live objects to one side and compacts memory.
Generational collection: separates young and old generations based on object age.
In G1, the Stop‑The‑World (STW) pauses occur during Initial Mark, Final Mark, Cleanup, and the Transfer phase of the copying algorithm.
Listening to a Spring Service Port
The server creates a socket, binds it to an IP and port, calls listen() , and then accepts client connections.
I/O Multiplexing Usage Scenarios
Single‑process handling of many network connections (e.g., Redis, Nginx).
Comparison of select , poll , and epoll : select uses a fixed‑size bitset, requires two copies and two traversals. poll uses a dynamic array, still O(n) traversal. epoll maintains a red‑black tree in kernel space and an event‑driven ready‑list, achieving O(log n) updates and O(1) event retrieval, solving the C10K problem.
Server‑Client Request Troubleshooting
Verify IP, port, firewall, and proxy settings.
Interpret HTTP status codes (400, 401, 403, 404, 500, 502/503/504) for targeted debugging.
Reasons for Excessive TIME_WAIT Connections
Short‑lived HTTP connections (no Keep‑Alive).
Keep‑Alive timeout on the server side.
Maximum request count per persistent connection exceeded (e.g., Nginx keepalive_requests ).
Increasing the keepalive_requests value or adjusting keepalive_timeout can mitigate the issue.
Ping vs. HTTP Accessibility
Ping uses ICMP, while HTTP uses TCP; firewalls may block ICMP while allowing TCP, causing ping failures but successful HTTP requests.
IT Services Circle
Delivering cutting-edge internet insights and practical learning resources. We're a passionate and principled IT media platform.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.