Posts

Showing posts from October, 2025

Advance Java

SERVLETS Java Servlets are server-side Java programs that handle client requests and generate dynamic web content, typically in response to HTTP requests.  They act as a middle layer between a web browser (or other client) and a backend database or application. What Exactly Is a Servlet? A Servlet is a Java class that runs inside a Servlet container (like Apache Tomcat) and extends the capabilities of servers that host applications accessed via a request-response model.  It’s a core component of Java EE (now Jakarta EE) for building web applications. Key Features - Runs on the server-side : Handles HTTP requests and responses. - Dynamic content generation : Can generate HTML, JSON, XML, etc. - Efficient and scalable : Better performance than older CGI-based solutions. - Platform-independent : Written in Java, runs on any OS with a compatible JVM. - Session management : Supports cookies, URL rewriting, and HTTPS sessions. Servlet Lifecycle 1. Initialization (` init() `): Called...

Java 11 features

Java 11 features 1. New HTTP Client API (Standardized) Replaces `HttpURLConnection` with a modern, fluent API. ```java HttpClient client = HttpClient.newHttpClient(); HttpRequest request = HttpRequest.newBuilder()     .uri(URI.create("https://api.github.com"))     .build(); HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString()); System.out.println(response.body()); ``` 2. String API Enhancements ```java String str = "  Hello Java 11  "; System.out.println(str.isBlank());              // false System.out.println(str.strip());                // "Hello Java 11" System.out.println(str.stripLeading());         // "Hello Java 11  " System.out.println(str.stripTrailing());        // "  Hello Java 11" System.out.println("Java".repeat(3));           // "JavaJavaJava"...

JMS (Java Message Service)

JMS (Java Message Service) Java Message Service (JMS) is a Java API for sending and receiving messages between distributed systems, enabling loosely coupled, reliable, and asynchronous communication. What Is JMS? - JMS (Java Message Service) is a standard API provided by Java EE for messaging between software components in distributed applications. - It allows asynchronous communication, meaning the sender and receiver do not need to interact with the message at the same time. - JMS is designed to be loosely coupled, which improves scalability and flexibility in system architecture. Core Concepts - Message : The data being transmitted. JMS supports different message types like `TextMessage`, `ObjectMessage`, `BytesMessage`, etc. - Producer : The component that sends messages. - Consumer : The component that receives messages. - Destination : The target for messages, which can be a **Queue** (point-to-point) or a **Topic** (publish-subscribe). - ConnectionFactory : Used to create connec...

JPA

JPA Stored Procedure Q. Calling a Stored Procedure in JPA? In JPA (Java Persistence API), calling a stored procedure is typically done using the ` @NamedStoredProcedureQuery ` annotation or the ` EntityManager ` API .  Here's a breakdown of how it works, especially in the context of Spring Boot + JPA, which you're already fluent with: 1. Using `@NamedStoredProcedureQuery` (Annotation-Based) Step-by-step setup : a. Define the stored procedure in your entity : ```java @Entity @ NamedStoredProcedureQuery (     name = "User.getUserByEmail",     procedureName = "get_user_by_email",     parameters = {         @StoredProcedureParameter(mode = ParameterMode.IN, name = "email", type = String.class),         @StoredProcedureParameter(mode = ParameterMode.OUT, name = "user_id", type = Long.class)     } ) public class User {     @Id     private Long id;     private String email; ...