Master Java Reflection and Core Networking: From Basics to TCP/IP
An in‑depth guide covering Java reflection fundamentals, three methods to obtain Class objects, and practical code examples, followed by a comprehensive overview of computer networking layers, protocols, TCP/IP versus OSI models, transport protocols, HTTP/HTTPS differences, status codes, GET/POST, cookies, sessions, tokens, and servlet lifecycle.
Java Reflection Overview
Reflection allows a program to inspect and manipulate classes, fields, and methods at runtime. It enables dynamic type determination, class loading, and method invocation.
Static vs Dynamic Compilation
Static compilation: type binding at compile time.
Dynamic compilation: type binding at runtime.
Advantages and Disadvantages
Advantages: runtime type checking, dynamic class loading, increased flexibility.
Disadvantages: performance overhead due to interpreted operations.
Typical Use Cases
Framework design (e.g., Spring, Hibernate), modular development, dynamic proxies, JDBC driver loading via Class.forName(), XML‑based bean configuration.
Three Ways to Obtain a Class Object
public class Student {
private int id;
String name;
protected boolean sex;
public float score;
}
public class Get {
// three ways to get Class object
public static void main(String[] args) throws ClassNotFoundException {
// way 1: via instance
Student stu = new Student();
Class classobj1 = stu.getClass();
System.out.println(classobj1.getName());
// way 2: via fully‑qualified name
Class classobj2 = Class.forName("fanshe.Student");
System.out.println(classobj2.getName());
// way 3: via .class literal
Class classobj3 = Student.class;
System.out.println(classobj3.getName());
}
}Computer Network Fundamentals
Network architecture is layered; protocols define rules for data exchange. Layering simplifies design, improves flexibility, and aids standardization.
Why Layer Protocols?
Simplify complexity
Enable independent evolution of layers
Facilitate implementation and maintenance
Promote standardization
Drawbacks include potential redundancy and overhead.
OSI and TCP/IP Models
OSI defines seven layers; TCP/IP uses a four‑layer model (application, transport, internet, link). In practice a five‑layer model combining both is often taught.
Transport Layer Protocols
TCP provides reliable, connection‑oriented byte‑stream service; UDP offers connectionless, best‑effort delivery.
UDP: connectionless, unreliable, supports 1‑to‑1, 1‑to‑many, many‑to‑many, message‑oriented, header 8 bytes, suited for real‑time apps.
TCP: connection‑oriented, reliable (flow & congestion control), only 1‑to‑1, byte‑stream, header 20‑60 bytes, suited for file transfer and reliable apps.
Common Application‑Layer Protocols over TCP
HTTP / HTTPS
FTP
POP3
SMTP
TELNET
SSH
Application‑Layer Protocols over UDP
BOOTP
NTP
DHCP
DNS (also works over TCP)
TCP Connection Establishment and Termination
Three‑way handshake (SYN, SYN‑ACK, ACK) ensures both sides are ready; four‑step termination (FIN, ACK, FIN, ACK) cleanly closes the connection, with a 2 MSL wait on the client side.
HTTP vs HTTPS
Protocol: HTTP runs directly on TCP; HTTPS runs over SSL/TLS on TCP.
Port: 80 for HTTP, 443 for HTTPS.
Security: HTTP is plaintext; HTTPS provides encryption and authentication.
Resource consumption: HTTPS incurs extra CPU/memory for encryption.
Certificates: HTTPS requires a certificate, HTTP does not.
HTTP Status Codes Overview
1xx informational, 2xx success, 3xx redirection, 4xx client error, 5xx server error. Common codes: 200 OK, 204 No Content, 301 Moved Permanently, 302 Found, 304 Not Modified, 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 500 Internal Server Error.
GET vs POST
GET appends parameters to the URL, is cacheable, limited size (~2048 bytes), and less secure. POST sends data in the request body, has no size limit, and is not cached.
Cookies, Sessions, and Tokens
Cookies store key‑value data on the client; sessions keep state on the server and are identified by a session ID usually passed via a cookie. Tokens are server‑generated strings used for stateless authentication, reducing server load and enabling front‑end/back‑end separation.
Servlet Thread Safety and Lifecycle
Servlets are not thread‑safe by default; shared instance fields can cause race conditions. Use local variables or synchronize carefully. The servlet lifecycle includes init(), service(), and destroy() methods.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Intelligent Backend & Architecture
We share personal insights on intelligent, automated backend technologies, along with practical AI knowledge, algorithms, and architecture design, grounded in real business scenarios.
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.
