Posts

Java Architecture Explained: Coding, Compilation, and Execution

Java Architecture Java architecture explains how a Java program is written, compiled, and executed. The Java architecture is broadly classified into three main stages: Coding Compilation Execution 1. Coding Coding is the process of writing Java program instructions inside a Java class using the main method. Key points: A Java program is saved with the .java file extension. To write Java programs, programmers use editors or Integrated Development Environments (IDEs). Editor An editor is software that supports only writing code. It does not support compilation, execution, or debugging. Examples of Editors: Notepad Notepad++ IDE (Integrated Development Environment) An IDE provides complete support for: Writing code Compiling programs Executing programs Debugging errors Examples of IDEs: Eclipse NetBeans IntelliJ IDEA 2. Compilation Compilation is the process of converting a .java file into a .class file. Key points: The Java compiler used for compilation is called javac. The compiler conv...

Servlet in Java: Server-Side Programming and Role of servlet-api.jar Explained

What is a Servlet? A Servlet is a server-side Java program that runs inside a web server and is used to handle client requests and generate responses. Servlets can perform different types of logic, such as: Presentation Logic – Generating output (HTML, JSON, etc.) Business Logic – Processing application rules and conditions Persistence Logic – Interacting with databases Response Handling – Sending the response back to the client Servlets act as a bridge between the client (browser) and the server-side application logic. 🔹 Secure Web Application Development Using Servlets To develop a secure Java web application, a programmer must use the Servlet API. 🔸 servlet-api.jar servlet-api.jar is a library that provides all Servlet and HTTP-related classes and interfaces. This JAR file is present inside the Apache Tomcat server. 📂 Location in Tomcat Apache Tomcat → lib → servlet-api.jar 🔹 Role of servlet-api.jar       Acts as a runtime environment for servlet applications. ...

Servlets in Java: Web Server vs Application Server and URL Explained for Beginners

What are Servlets? Servlets are Java programs that run on a server and handle client requests, usually coming from a web browser. They are mainly used to build dynamic web applications. Servlets run inside a server environment, which can be classified into: Web Server Application Server 🔹 Web Server A Web Server is a server that contains: Web Server Engine Web Container 🔸 How a Web Server Works A client (browser) sends a request. The web server receives the request. The request is forwarded to the web container. The web container processes the request. A response is generated and sent back to the browser. 🔸 Role of Web Container       Provides a runtime environment for web applications.      Can run only web applications, such as: Servlet applications Spring applications Struts applications 🔸 Web Server Limitations Cannot run enterprise applications (EJB, distributed systems). 🔸 Examples of Web Servers Apache Tomcat GlassFish 🔹 Application Server An ...

HTML Tutorial for Beginners: Structure, Tags, Headings, Paragraphs, Links, Images, and Tables

What is HTML? HTML (HyperText Markup Language) is the standard language used to create and display content on web browsers. It was developed by the World Wide Web Consortium (W3C). HTML uses markup tags to define the structure and format of content. Each HTML element usually has a start tag and an end tag: <start-tag>Content</end-tag> 🔹 Basic Structure of an HTML Page <!DOCTYPE html> <html>   <head>     <title>Home Page</title>   </head>   <body>     <!-- Content goes here -->   </body> </html> Explanation : <!DOCTYPE html> → Informs the browser that this is an HTML5 document. <html> → Root element of an HTML page. <head> → Contains meta-information, title, and links to styles/scripts. <body> → Contains visible content like text, images, links, tables, etc. 🔹 Example 1: Displaying Text with Formatting <!DOCTYPE html> <html>   <hea...

JDBC Transaction in Java: Commit, Rollback, and Savepoint Explained with Flowchart

JDBC Transaction in Java A JDBC transaction is a set of SQL operations executed as a single atomic unit. All the SQL queries inside a transaction must either succeed together or fail together. If any query fails, the entire transaction is rolled back to maintain data consistency. 🔹 Key Concepts Transaction Success: All SQL queries in the transaction execute successfully → Commit the transaction . Transaction Failure: If any SQL query fails → Rollback the entire transaction. 3. Auto-Commit Mode: By default, JDBC connections run in auto-commit mode. In auto-commit mode, each SQL query is committed immediately after execution. 4. Manual Transaction Control: To manage transactions manually: connection.setAutoCommit(false); // Disable auto-commit true → Enable auto-commit false → Disable auto-commit 🔹 Commit & Rollback Methods             Method.                          Purpose.  ...

JDBC Batch Update in Java: Statement vs PreparedStatement with Advantages and Working

JDBC Batch Update in Java Batch Update in JDBC is a process where multiple SQL queries are grouped together and sent to the database server in a single request. Instead of executing SQL queries one by one, batch update improves performance and efficiency by reducing network traffic between the Java application and the database server . ✅ Why Use Batch Update? 🚀 Improves application performance 🌐 Reduces network calls to the database 📉 Minimizes database load 🧠 Efficient for bulk insert, update, and delete operations Real-Life Example: When inserting thousands of student records or updating employee salaries in bulk, batch update is the best approach. 🔹 Batch Update Using Statement Batch update can be performed using the Statement interface in the following way: Steps: Create a Statement object. Create a batch. Add SQL queries (similar or dissimilar) to the batch. Execute the batch. Important Methods: addBatch(String query) Adds an SQL query to the batch. This method is declared i...

JDBC Statement in Java: Creating Statements and Executing SQL Queries (Execute, ExecuteQuery, ExecuteUpdate)

JDBC Statement in Java In JDBC, a Statement is an interface present in the java.sql package. It is used to send SQL queries from a Java program to a database server. The implementation of the Statement interface is provided by the database vendor (such as MySQL, Oracle, PostgreSQL) inside the JDBC driver JAR file. Creating a JDBC Statement To create a JDBC Statement, a database connection is required. The Connection interface provides the createStatement() method. This method returns an object of a subclass of the Statement interface. Method Syntax: public Statement createStatement(); The returned Statement object is used to execute SQL queries on the database . Executing SQL Queries Using Statement The Statement interface provides different methods to execute SQL queries depending on the query type. 1️⃣ execute(String query) A generic method used to execute any type of SQL query. Can execute DDL, DML, and DQL queries. Examples : CREATE TABLE (DDL) INSERT, UPDATE, DELETE (DML) SELECT (...