<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Tarun Joshi on Medium]]></title>
        <description><![CDATA[Stories by Tarun Joshi on Medium]]></description>
        <link>https://medium.com/@tarunjoshiji1?source=rss-09e7b7ede5f8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*mxIOyKc3QTCAYZky</url>
            <title>Stories by Tarun Joshi on Medium</title>
            <link>https://medium.com/@tarunjoshiji1?source=rss-09e7b7ede5f8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 10:39:08 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tarunjoshiji1/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Getting Started with IoC Containers and Dependency Injection in Java: A Beginner’s Guide]]></title>
            <link>https://medium.com/@tarunjoshiji1/getting-started-with-ioc-containers-and-dependency-injection-in-java-a-beginners-guide-7bdbf5a8577d?source=rss-09e7b7ede5f8------2</link>
            <guid isPermaLink="false">https://medium.com/p/7bdbf5a8577d</guid>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[ioc-container]]></category>
            <category><![CDATA[dependency-injection]]></category>
            <dc:creator><![CDATA[Tarun Joshi]]></dc:creator>
            <pubDate>Wed, 29 Nov 2023 04:37:05 GMT</pubDate>
            <atom:updated>2023-11-29T04:38:55.554Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>Introduce the concepts of Inversion of Control (IoC) and Dependency Injection (DI), highlighting their importance in building robust and maintainable Java applications. Briefly explain that the post is aimed at beginners who want to understand these fundamental concepts.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/851/0*GjUbUDZNhCF0LXiI.jpg" /></figure><h3>Understanding IoC and DI</h3><p>In the ever-evolving landscape of Java development, two fundamental concepts play a pivotal role in shaping the architecture of modern applications: Inversion of Control (IoC) and Dependency Injection (DI). For beginners venturing into the world of software engineering, these terms might sound intimidating, but fear not — this guide is designed to demystify them and provide a solid foundation for your journey into Java development.</p><h3>IoC Containers in Depth</h3><p>IoC Containers play a central role in implementing the Inversion of Control (IoC) principle. These containers are essentially frameworks that manage the lifecycle and configuration of application components. Instead of classes being responsible for creating instances of their dependencies, IoC containers take charge of the instantiation process. They act as centralized factories, managing the creation and wiring of objects based on configuration. Popular IoC containers in the Java ecosystem, such as Spring IoC container and Google Guice, provide a rich set of features. These include support for various configuration styles (XML, annotation-based, or Java-based), flexible dependency injection mechanisms, and the ability to define the scope and lifecycle of beans. Understanding IoC containers is pivotal for harnessing the power of IoC and creating modular, maintainable, and scalable Java applications.</p><pre>import org.springframework.context.annotation.Bean;<br>import org.springframework.context.annotation.Configuration;<br><br>@Configuration<br>public class AppConfig {<br><br>    @Bean<br>    public UserService userService() {<br>        return new UserService(userRepository());<br>    }<br><br>    @Bean<br>    public UserRepository userRepository() {<br>        return new UserRepository();<br>    }<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/910/0*qSEF0eP0k0rYBd-P.png" /></figure><h3>Dependency Injection Patterns</h3><p>Dependency Injection (DI) patterns are strategies for providing dependencies to classes, enhancing the flexibility and modularity of code. One prevalent pattern is Constructor Injection, where dependencies are injected through the class constructor. This pattern promotes the creation of immutable objects and ensures that a class is instantiated with all required dependencies. Another approach is Setter Injection, where dependencies are set through setter methods, allowing for more flexibility as dependencies can be changed after object creation. Method Injection is yet another pattern, involving passing dependencies as parameters to methods, offering a fine-grained control over when and where dependencies are utilized. Each DI pattern caters to specific scenarios, and choosing the appropriate one depends on the requirements of the application and the desired level of flexibility in managing dependencies.</p><pre>import org.springframework.beans.factory.annotation.Autowired;<br>import org.springframework.context.annotation.Bean;<br>import org.springframework.context.annotation.Configuration;<br><br>@Configuration<br>public class AppConfig {<br><br>    // Define UserRepository bean<br>    @Bean<br>    public UserRepository userRepository() {<br>        return new UserRepository();<br>    }<br><br>    // Define UserService bean with UserRepository dependency, and use @Autowired<br>    @Bean<br>    @Autowired<br>    public UserService userService(UserRepository userRepository) {<br>        return new UserService(userRepository);<br>    }<br>}</pre><h3>Configuration in IoC Containers</h3><ol><li>Configuration Styles: IoC containers support XML, annotation-based, and Java-based configurations.</li><li>Bean Definitions: Specify details like class, dependencies, and additional configurations for each bean.</li><li>Dependency Injection: Containers manage injecting dependencies into beans via constructor, setter, or method injection.</li><li>Bean Scopes: Define scopes like singleton or prototype to control the lifecycle of beans.</li><li>Lifecycle Callbacks: Use hooks like @PostConstruct and @PreDestroy for bean initialization and destruction.</li><li>Externalized Configuration: Separate configuration details from code for easier maintenance and flexibility.</li><li>Configuration Inheritance: Allow beans to inherit configurations from parent beans for reuse.</li><li>Conditional Configuration: Configure beans based on conditions, enhancing flexibility in different scenarios.</li></ol><h3>Code snipt:</h3><pre>import org.springframework.context.annotation.Bean;<br>import org.springframework.context.annotation.Configuration;<br><br>@Configuration<br>public class AppConfig {<br><br>    @Bean<br>    public UserService userService() {<br>        return new UserService(userRepository());<br>    }<br><br>    @Bean<br>    public UserRepository userRepository() {<br>        return new UserRepository();<br>    }<br>}</pre><h3>Scopes and Lifecycles</h3><h4><strong>Scopes:</strong></h4><p>1. Singleton Scope:</p><ul><li>One instance shared across the entire application.</li><li>Declared with @Scope(&quot;singleton&quot;).</li></ul><p>2. Prototype Scope:</p><ul><li>A new instance for each request.</li><li>Declared with @Scope(&quot;prototype&quot;).</li></ul><p>3. Request Scope (Web Applications):</p><ul><li>A new instance for each HTTP request.</li><li>Declared with @Scope(&quot;request&quot;).</li></ul><h4><strong>Lifecycles:</strong></h4><p>1. Initialization and Destruction Callbacks:</p><ul><li>Use @PostConstruct for initialization logic.</li><li>Use @PreDestroy for cleanup or destruction logic.</li></ul><p>2. Implementing InitializingBean and DisposableBean:</p><ul><li>Implement InitializingBean interface for initialization logic.</li><li>Implement DisposableBean interface for cleanup logic.</li></ul><p>3. Custom Lifecycle Methods:</p><ul><li>Define custom methods for initialization and destruction.</li><li>Specify methods with @Bean(initMethod = &quot;customInit&quot;, destroyMethod = &quot;customDestroy&quot;).</li></ul><h3>Autowiring Dependencies</h3><p><a href="https://www.baeldung.com/spring-annotations-resource-inject-autowire">Wiring</a> allows the Spring container to automatically resolve dependencies between collaborating beans by inspecting the beans that have been defined.</p><p>There are four modes of autowiring a bean using an XML configuration:</p><ul><li><strong><em>no</em>:</strong> the default value — this means no autowiring is used for the bean and we have to explicitly name the dependencies.</li><li><strong><em>byName</em>:</strong> autowiring is done based on the name of the property, therefore Spring will look for a bean with the same name as the property that needs to be set.</li><li><strong><em>byType</em>:</strong> similar to the <em>byName</em> autowiring, only based on the type of the property. This means Spring will look for a bean with the same type of the property to set. If there’s more than one bean of that type, the framework throws an exception.</li><li><strong><em>constructor</em>:</strong> autowiring is done based on constructor arguments, meaning Spring will look for beans with the same type as the constructor arguments.</li></ul><p>Suppose we have a PaymentGateway and a PaymentProcessor class. We want to inject PaymentGateway into PaymentProcessor by type using annotations:</p><pre>public interface PaymentGateway {<br>    void processPayment(double amount);<br>    // Other methods related to payment gateway<br>}</pre><pre>@Component<br>public class PayPalGateway implements PaymentGateway {<br>    // PayPalGateway implementation<br>    // ...<br>}</pre><pre>@Component<br>public class PaymentProcessor {<br>    private final PaymentGateway paymentGateway;</pre><pre>    @Autowired<br>    public PaymentProcessor(PaymentGateway paymentGateway) {<br>        this.paymentGateway = paymentGateway;<br>    }</pre><pre>    // Methods for payment processing using payment gateway<br>    // ...<br>}</pre><p>In this example:</p><ul><li>PaymentGateway is an interface defining payment-related methods.</li><li>PayPalGateway is an implementation of PaymentGateway.</li><li>PaymentProcessor is a class responsible for processing payments and has a dependency on PaymentGateway.</li><li>By using @Autowired on the constructor of PaymentProcessor, Spring will perform autowiring by type, injecting the PaymentGateway implementation (PayPalGateway in this case) into the PaymentProcessor automatically.</li></ul><p>This demonstrates how Spring, based on the @Autowired annotation, resolves and injects dependencies by type without explicitly defining the dependency in the configuration.</p><h3>Benefits of Dependency Injection [DI]:</h3><p>Dependency Injection (DI) provides numerous advantages in software development:</p><ol><li>Decoupling: DI reduces tight coupling between different components of an application. By injecting dependencies externally, classes aren’t tightly bound to specific implementations, promoting flexibility and easier maintenance.</li></ol><p>2. Testing: DI enables easier testing by allowing the substitution of real dependencies with mock objects or stubs. This facilitates unit testing where individual components can be tested in isolation, ensuring robustness and reliability.</p><p>3. Reusability: Components designed with DI are often more reusable. They can be easily integrated into various contexts without significant modifications, enhancing their versatility across different parts of an application.</p><p>4. Single Responsibility: Emphasizing the Single Responsibility Principle, DI encourages classes to focus on their primary purpose. With clearly defined dependencies injected, classes are more focused and have a clearer role in the application.</p><p>5. Configurability: DI allows the configuration of dependencies at runtime. This flexibility permits changes in component behaviors without modifying the code, making the application more adaptable to changing requirements.</p><h3>Conclusion</h3><p>In conclusion, embracing Inversion of Control (IoC) and Dependency Injection (DI) in Java is key to crafting modular, testable, and scalable applications. IoC containers, exemplified by Spring and Guice, streamline object lifecycles and configurations, while Dependency Injection patterns offer flexibility in wiring classes. Configuration styles, ranging from XML to annotation-based, provide customization, and understanding bean scopes and lifecycles adds control to the application’s architecture. Mastering these concepts empowers developers to create adaptable and maintainable systems. Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7bdbf5a8577d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Servlet and JSP: A Step-by-Step Guide]]></title>
            <link>https://medium.com/@tarunjoshiji1/servlet-and-jsp-a-step-by-step-guide-479728057d16?source=rss-09e7b7ede5f8------2</link>
            <guid isPermaLink="false">https://medium.com/p/479728057d16</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[dynamic-web-development]]></category>
            <category><![CDATA[jsp]]></category>
            <category><![CDATA[servlet]]></category>
            <category><![CDATA[api]]></category>
            <dc:creator><![CDATA[Tarun Joshi]]></dc:creator>
            <pubDate>Sun, 12 Nov 2023 10:49:21 GMT</pubDate>
            <atom:updated>2023-11-12T10:54:49.198Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Introduction:</strong></h3><p>In the dynamic world of web development, JavaServer Pages (JSP) and Servlets play a crucial role in creating robust and interactive web applications. This blog post will guide you through the fundamentals of JSP and Servlets, providing hands-on examples to illustrate key concepts.</p><h3>Understanding Servlets: A Brief Overview</h3><p>Servlets, at their core, are Java classes that extend the capabilities of servers to enhance the functionality of web applications. They provide a server-side component model that is both platform-independent and scalable. Servlets operate on the server side, responding to client requests and generating dynamic content.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*PDfustlMs6891NXX.jpg" /></figure><h3>Setting Up Your Servlet Environment</h3><p>Before delving into Servlet code, it’s essential to set up a development environment. Ensure you have Java Development Kit (JDK) and an integrated development environment (IDE) like Eclipse or IntelliJ IDEA.</p><h3>Creating Your First Servlet</h3><p>Let’s start with a simple “Hello, Servlets!” example.</p><pre>import java.io.IOException;<br>import javax.servlet.ServletException;<br>import javax.servlet.annotation.WebServlet;<br>import javax.servlet.http.HttpServlet;<br>import javax.servlet.http.HttpServletRequest;<br>import javax.servlet.http.HttpServletResponse;<br><br>@WebServlet(&quot;/HelloServlet&quot;)<br>public class HelloServlet extends HttpServlet {<br>    protected void doGet(HttpServletRequest request, HttpServletResponse response)<br>            throws ServletException, IOException {<br>        response.getWriter().println(&quot;Hello, Servlets!&quot;);<br>    }<br>}</pre><p>In this example, we create a class HelloServlet that extends HttpServlet. The doGet method handles HTTP GET requests, and it simply writes &quot;Hello, Servlets!&quot; to the response.</p><h3>Mapping Servlets in the Deployment Descriptor (web.xml)</h3><p>For Servlets to be accessible, they need to be mapped in the web.xml deployment descriptor.</p><pre>&lt;servlet&gt;<br>    &lt;servlet-name&gt;HelloServlet&lt;/servlet-name&gt;<br>    &lt;servlet-class&gt;com.example.HelloServlet&lt;/servlet-class&gt;<br>&lt;/servlet&gt;<br>&lt;servlet-mapping&gt;<br>    &lt;servlet-name&gt;HelloServlet&lt;/servlet-name&gt;<br>    &lt;url-pattern&gt;/HelloServlet&lt;/url-pattern&gt;<br>&lt;/servlet-mapping&gt;</pre><p>This XML configuration informs the servlet container about the servlet’s name, class, and URL pattern.</p><h3>The Servlet Lifecycle: Initialization to Destruction</h3><p>Servlets undergo a lifecycle that includes initialization, service, and destruction phases. The init method is called during initialization, service method handles requests, and destroy method is called before the servlet is taken out of service.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/0*KR9oi9NcZWJyWIYl.jpg" /></figure><pre>@Override<br>public void init() throws ServletException {<br>    // Initialization logic<br>}<br><br>@Override<br>protected void service(HttpServletRequest request, HttpServletResponse response)<br>        throws ServletException, IOException {<br>    // Request handling logic<br>}<br><br>@Override<br>public void destroy() {<br>    // Cleanup logic<br>}</pre><h3>Servlets and Form Handling</h3><p>Servlets play a pivotal role in processing HTML forms. Let’s create a simple form-handling servlet.</p><pre>&lt;!-- index.html --&gt;<br>&lt;form action=&quot;/FormServlet&quot; method=&quot;post&quot;&gt;<br>    &lt;label for=&quot;name&quot;&gt;Name:&lt;/label&gt;<br>    &lt;input type=&quot;text&quot; id=&quot;name&quot; name=&quot;name&quot; required&gt;<br>    &lt;br&gt;<br>    &lt;input type=&quot;submit&quot; value=&quot;Submit&quot;&gt;<br>&lt;/form&gt;</pre><pre>@WebServlet(&quot;/FormServlet&quot;)<br>public class FormServlet extends HttpServlet {<br>    protected void doPost(HttpServletRequest request, HttpServletResponse response)<br>            throws ServletException, IOException {<br>        String name = request.getParameter(&quot;name&quot;);<br>        response.getWriter().printf(&quot;Hello, %s!&quot;, name);<br>    }<br>}</pre><h3>Understanding RESTful API</h3><p>REST (Representational State Transfer) is an architectural style that uses a stateless, client-server communication model. A RESTful API is an interface that allows systems to communicate over HTTP, following REST principles. Key aspects of RESTful APIs include statelessness, resource-based URLs, and support for standard HTTP methods (GET, POST, PUT, DELETE).</p><h3>Why Servlets for RESTful APIs?</h3><p>Servlets, a fundamental part of Java EE (Enterprise Edition), are the perfect building blocks for creating RESTful APIs. They offer the following advantages:</p><ol><li><strong>Mature Ecosystem:</strong> Servlets have been a part of Java EE for a long time, making them a mature and well-supported technology.</li><li><strong>HTTP Handling:</strong> Servlets are specifically designed to handle HTTP requests and responses, aligning perfectly with the nature of RESTful communication.</li><li><strong>Flexibility:</strong> Servlets provide the flexibility to handle various aspects of the API, including request parsing, data processing, and response generation.</li></ol><h3>Building a Simple RESTful API with Servlets</h3><p>Let’s create a basic example of a RESTful API using Servlets. Assume we are building an API for managing a collection of books.</p><h3>1. doGet Method:</h3><ul><li>Description: Handles HTTP GET requests.</li><li>Use Case: Ideal for retrieving information from the server. Parameters are appended to the URL.</li></ul><pre>@WebServlet(&quot;/example&quot;)<br>public class MyServlet extends HttpServlet {<br>protected void doGet(HttpServletRequest request, HttpServletResponse response)<br>throws ServletException, IOException {<br>        // Handling GET requests<br>        PrintWriter out = response.getWriter();<br>        out.println(&quot;Hello, this is a GET request response!&quot;);<br>    }<br>}</pre><h3>2. doPost Method:</h3><ul><li>Description: Handles HTTP POST requests.</li><li>Use Case: Used for submitting data to be processed to a specified resource. Commonly used for form submissions.</li></ul><pre>@WebServlet(&quot;/example&quot;)<br>public class MyServlet extends HttpServlet {<br>protected void doPost(HttpServletRequest request, HttpServletResponse response)<br>throws ServletException, IOException {<br>        // Handling POST requests<br>        String data = request.getParameter(&quot;data&quot;); // Retrieve data from the request<br>        // Process the data<br>        PrintWriter out = response.getWriter();<br>        out.println(&quot;Received data: &quot; + data);<br>    }<br>}</pre><h3>3. doPut Method:</h3><ul><li>Description: Handles HTTP PUT requests.</li><li>Use Case: Typically used for updating a resource on the server. The entire representation of the resource is sent in the request.</li></ul><pre>@WebServlet(&quot;/example&quot;)<br>public class MyServlet extends HttpServlet {<br>protected void doPut(HttpServletRequest request, HttpServletResponse response)<br>throws ServletException, IOException {<br>        // Handling PUT requests<br>        // Extract data from the request and update a resource<br>        PrintWriter out = response.getWriter();<br>        out.println(&quot;Resource updated successfully!&quot;);<br>    }<br>}</pre><h3>4. doDelete Method:</h3><ul><li>Description: Handles HTTP DELETE requests.</li><li>Use Case: Used to request that a resource be removed. Can delete a specified resource on the server.</li></ul><pre>@WebServlet(&quot;/example&quot;)<br>public class MyServlet extends HttpServlet {<br>protected void doDelete(HttpServletRequest request, HttpServletResponse response)<br>throws ServletException, IOException {<br>        // Handling DELETE requests<br>        // Delete a resource based on the request<br>        PrintWriter out = response.getWriter();<br>        out.println(&quot;Resource deleted successfully!&quot;);<br>    }<br>}</pre><ul><li><strong>GET:</strong> Retrieve all books or a specific book: GET http://example.com/your-app/api/books or GET <a href="http://example.com/your-app/api/books/%7Bid%7D">http://example.com/your-app/api/books/{id}</a></li><li><strong>POST: </strong>Create a new book: POST <a href="http://example.com/your-app/api/books">http://example.com/your-app/api/books</a></li><li><strong>PUT:</strong> Update an existing book: PUT <a href="http://example.com/your-app/api/books/%7Bid%7D">http://example.com/your-app/api/books/{id}</a></li><li><strong>DELETE:</strong> Delete a book: DELETE <a href="http://example.com/your-app/api/books/%7Bid%7D">http://example.com/your-app/api/books/{id}</a></li></ul><h3>Understanding JavaServer Pages (JSP)</h3><p>JavaServer Pages, commonly known as JSP, provide a simplified way to create dynamic content for web applications. They are an integral part of the Java EE (Enterprise Edition) technology, enabling developers to embed Java code within HTML pages. JSP pages are ultimately translated into servlets by the web container during runtime.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/892/0*Vj0KIXYbvqlLVbWl.jpg" /></figure><h3>Setting Up Your JSP Environment</h3><p>Before diving into JSP development, ensure you have the Java Development Kit (JDK) installed on your system. Additionally, set up a web container like Apache Tomcat to deploy and run your JSP applications.</p><h3>The Anatomy of a JSP Page</h3><p>A JSP page combines HTML and Java code to create dynamic content. The Java code in JSP is enclosed within &lt;% %&gt; tags. Let&#39;s take a simple example:</p><pre>&lt;%@ page language=&quot;java&quot; contentType=&quot;text/html; charset=UTF-8&quot; pageEncoding=&quot;UTF-8&quot;%&gt;<br>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>&lt;head&gt;<br>    &lt;meta charset=&quot;UTF-8&quot;&gt;<br>    &lt;title&gt;My First JSP Page&lt;/title&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>    &lt;h1&gt;Welcome to JSP!&lt;/h1&gt;<br>    &lt;% <br>        String name = &quot;Guest&quot;;<br>        out.println(&quot;Hello, &quot; + name);<br>    %&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>In this example, we declare the page’s language as Java, set the character encoding, and then use Java code to dynamically generate content within the HTML structure.</p><h3>JSP Directives: Enhancing Control</h3><p>JSP directives provide additional information to the container during the translation phase. The &lt;%@ page %&gt; directive, seen in the previous example, is commonly used. Another useful directive is &lt;%@ include %&gt;, which allows including external files in the JSP page.</p><h3>JSP Actions: Encapsulating Dynamic Behavior</h3><p>JSP actions are special tags that encapsulate dynamic behavior, enhancing code modularity. For instance, the &lt;jsp:useBean&gt; action simplifies JavaBean integration into JSP pages.</p><pre>&lt;jsp:useBean id=&quot;user&quot; class=&quot;com.example.User&quot; scope=&quot;session&quot; /&gt;</pre><p>This action creates a session-scoped JavaBean named “user.”</p><h3>Expression Language (EL): Streamlining Data Access</h3><p>Expression Language, or EL, simplifies the retrieval of data from Java objects. It provides an elegant way to access object properties without using scriptlets.</p><pre>&lt;p&gt;Welcome, ${user.name}!&lt;/p&gt;</pre><p>Here, EL fetches the “name” property from the “user” JavaBean.</p><h3>JSP and MVC Architecture</h3><p>JSP plays a crucial role in the Model-View-Controller (MVC) architecture. It is often employed as the view component, responsible for presenting data to users. Combined with servlets (controller) and JavaBeans (model), JSP facilitates the creation of scalable and maintainable web applications.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/793/0*9HZojghjwzgezCzT.png" /></figure><h3>Integrating Servlets and JSP: A Powerful Duo</h3><p>Now, let’s explore how Servlets and JSP can be seamlessly integrated to harness the strengths of both technologies.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Fgn74I_3LPyfA2jp.jpeg" /></figure><h4>1. Servlet Dispatching to JSP</h4><p>Servlets can dispatch requests to JSP pages, allowing for the separation of concerns in web application development.</p><pre>@WebServlet(&quot;/DispatchServlet&quot;)<br>public class DispatchServlet extends HttpServlet {<br>    protected void doGet(HttpServletRequest request, HttpServletResponse response) <br>            throws ServletException, IOException {<br>        // Perform business logic or retrieve data<br>        String data = &quot;Greetings from Servlet!&quot;;<br>        <br>        // Set data as an attribute in the request<br>        request.setAttribute(&quot;message&quot;, data);<br>        <br>        // Dispatch the request to the JSP page<br>        RequestDispatcher dispatcher = request.getRequestDispatcher(&quot;result.jsp&quot;);<br>        dispatcher.forward(request, response);<br>    }<br>}</pre><h4>2. JSP Accessing Servlet Attributes</h4><p>In the JSP page, we can access the attributes set by the servlet and dynamically render content based on the provided data.</p><pre>&lt;%@ page language=&quot;java&quot; contentType=&quot;text/html; charset=UTF-8&quot; pageEncoding=&quot;UTF-8&quot;%&gt;<br>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>&lt;head&gt;<br>    &lt;meta charset=&quot;UTF-8&quot;&gt;<br>    &lt;title&gt;Servlet-JSP Integration&lt;/title&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>    &lt;h2&gt;Dynamic Content from Servlet&lt;/h2&gt;<br>    &lt;p&gt;<br>        &lt;% <br>            // Access attribute set by the servlet<br>            String message = (String) request.getAttribute(&quot;message&quot;);<br>            out.println(message);<br>        %&gt;<br>    &lt;/p&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><h3>Advantages of Using Servlets and JSP Together</h3><ol><li><strong>Clear Separation of Concerns:</strong> Servlets handle business logic and data processing, while JSP focuses on presenting the data to users. This separation enhances maintainability.</li><li><strong>Reusability:</strong> Servlets can be reused for different views, and JSP pages can be shared among multiple servlets.</li><li><strong>Simplified Development:</strong> JSP simplifies the integration of Java code with HTML, providing a more natural way to create dynamic content.</li><li><strong>Scalability:</strong> The MVC architecture facilitated by Servlets and JSP allows for scalable and modular web application development.</li></ol><h3>Conclusion: Crafting Dynamic and Scalable Web Applications</h3><p>The integration of Servlets and JSP brings a powerful combination to web development. Servlets handle the back-end logic and data processing, while JSP pages provide a flexible and dynamic way to present information to users. By mastering the collaboration of these technologies, developers can create web applications that are not only robust and scalable but also maintainable and efficient. Embrace the synergy of Servlets and JSP to unlock the full potential of Java in web development. Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=479728057d16" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Beginner’s Guide to HTML and CSS for Web Development]]></title>
            <link>https://medium.com/@tarunjoshiji1/a-beginners-guide-to-html-and-css-for-web-development-8a96b15265b4?source=rss-09e7b7ede5f8------2</link>
            <guid isPermaLink="false">https://medium.com/p/8a96b15265b4</guid>
            <category><![CDATA[html]]></category>
            <category><![CDATA[css]]></category>
            <dc:creator><![CDATA[Tarun Joshi]]></dc:creator>
            <pubDate>Sat, 04 Nov 2023 09:22:14 GMT</pubDate>
            <atom:updated>2023-11-04T09:22:14.606Z</atom:updated>
            <content:encoded><![CDATA[<h3>What Is HTML?</h3><p>HTML is the standard language used to create web pages. It’s a markup language that defines the structure and content of a web page using a set of elements, tags, and attributes. Each element tells the browser how to display a specific part of the content.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/630/0*k6Smi_A1ACr40-yi" /></figure><h3>Building Your First Web Page</h3><p>Let’s start by creating a simple HTML document. Here’s a basic template:</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>&lt;head&gt;<br>    &lt;title&gt;My First Web Page&lt;/title&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>    &lt;h1&gt;Hello, World!&lt;/h1&gt;<br>    &lt;p&gt;Welcome to my website.&lt;/p&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>In this code:</p><ul><li>&lt;!DOCTYPE html&gt; specifies the document type.</li><li>&lt;html&gt; wraps the entire web page.</li><li>&lt;head&gt; contains meta-information about the page, such as the title.</li><li>&lt;title&gt; sets the title displayed in the browser&#39;s tab.</li><li>&lt;body&gt; contains the visible content of the page.</li><li>&lt;h1&gt; is a top-level heading.</li><li>&lt;p&gt; is a paragraph of text.</li></ul><p>You can save this code in a .html file and open it in a web browser to see the result.</p><h3>HTML Elements</h3><p>HTML provides a wide range of elements to structure and format your web content. Here are some commonly used elements:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/580/0*YyCqOE-w0aVrgUTY" /></figure><h4>&lt;! — … → — Defines a Comment</h4><p>One of the most straightforward yet invaluable tags in HTML is &lt;!--...--&gt;. This tag allows you to include comments within your HTML code. Comments are essential for adding explanations, notes, and reminders directly into your code.</p><pre>&lt;!-- This is an example HTML comment --&gt;</pre><h4>&lt;!DOCTYPE&gt; — Defines the Document Type</h4><p>The &lt;!DOCTYPE&gt; declaration specifies the type and version of HTML you are using. It helps browsers understand how to interpret your HTML code correctly.</p><pre>htmlCopy code</pre><pre>&lt;!DOCTYPE html&gt;</pre><h4>&lt;a&gt; — Defines a Hyperlink</h4><p>The &lt;a&gt; tag is the foundation of web navigation. It defines hyperlinks, allowing you to link to other web pages or resources. It&#39;s a key element in creating interconnected websites.</p><pre>&lt;a href=&quot;https://www.example.com&quot;&gt;Visit Example.com&lt;/a&gt;</pre><h4>&lt;audio&gt; — Defines Embedded Sound Content</h4><p>Want to add audio to your web page? The &lt;audio&gt; tag is your go-to. It allows you to embed sound content, making it easy to incorporate music, podcasts, or other audio elements.</p><pre>&lt;audio controls&gt;<br>  &lt;source src=&quot;music.mp3&quot; type=&quot;audio/mpeg&quot;&gt;<br>  Your browser does not support the audio element.<br>&lt;/audio&gt;</pre><h4>&lt;body&gt; — Defines the Document’s Body</h4><p>The &lt;body&gt; tag defines the main content of your web page. It encapsulates everything that you want users to see and interact with, from text and images to forms and multimedia.</p><pre>&lt;body&gt;<br>  &lt;h1&gt;Welcome to My Website&lt;/h1&gt;<br>  &lt;p&gt;This is the main content of the web page.&lt;/p&gt;<br>  &lt;!-- More content goes here --&gt;<br>&lt;/body&gt;</pre><h4>&lt;br&gt; — Defines a Single Line Break</h4><p>The &lt;br&gt; tag is used for creating line breaks within your text. It&#39;s handy when you want to move content to a new line without starting a new paragraph.</p><pre>&lt;p&gt;This is some text.&lt;br&gt;Here&#39;s a new line of text.&lt;/p&gt;</pre><h4>&lt;button&gt; — Defines a Clickable Button</h4><p>Buttons are essential for user interactions. The &lt;button&gt; tag defines clickable buttons, often used for submitting forms or triggering JavaScript functions.</p><pre>&lt;button type=&quot;button&quot;&gt;Click Me&lt;/button&gt;</pre><h4>&lt;footer&gt; — Defines a Footer for a Document or Section</h4><p>The &lt;footer&gt; tag is used to create footers at the bottom of web pages or sections. Footers typically contain copyright information, links to privacy policies, and other related content.</p><pre>&lt;footer&gt;<br>  &amp;copy; 2023 Your Website Name<br>&lt;/footer&gt;</pre><h4>&lt;form&gt; — Defines an HTML Form for User Input</h4><p>Forms are essential for user input. The &lt;form&gt; tag is used to create interactive forms where users can enter data or make selections.</p><pre>&lt;form action=&quot;submit.php&quot; method=&quot;post&quot;&gt;<br>  &lt;label for=&quot;name&quot;&gt;Name:&lt;/label&gt;<br>  &lt;input type=&quot;text&quot; id=&quot;name&quot; name=&quot;name&quot;&gt;<br>  &lt;!-- More form elements go here --&gt;<br>&lt;/form&gt;</pre><h4>&lt;h1&gt; to &lt;h6&gt; — Defines HTML Headings</h4><p>HTML provides six heading tags, from &lt;h1&gt; to &lt;h6&gt;. These tags define different levels of headings, with &lt;h1&gt; being the most important and &lt;h6&gt; the least.</p><pre>&lt;h1&gt;Main Heading&lt;/h1&gt;<br>&lt;h2&gt;Subheading&lt;/h2&gt;<br>&lt;!-- More headings here --&gt;</pre><h4>&lt;head&gt; — Contains Metadata/Information for the Document</h4><p>The &lt;head&gt; tag is where you provide essential metadata and information about your web page. This section includes details like the document’s title, character encoding, and links to external resources.</p><pre>&lt;head&gt;<br>  &lt;title&gt;My Web Page&lt;/title&gt;<br>  &lt;meta charset=&quot;UTF-8&quot;&gt;<br>  &lt;!-- More metadata here --&gt;<br>&lt;/head&gt;</pre><h4>&lt;header&gt; — Defines a Header for a Document or Section</h4><p>The &lt;header&gt; tag is used to define a header section for your web document or a specific section within it. Headers often contain elements like logos, navigation menus, and introductory content.</p><pre>&lt;header&gt;<br>  &lt;h1&gt;Welcome to My Website&lt;/h1&gt;<br>  &lt;nav&gt;<br>    &lt;a href=&quot;/&quot;&gt;Home&lt;/a&gt;<br>    &lt;a href=&quot;/about&quot;&gt;About&lt;/a&gt;<br>    &lt;!-- More navigation links --&gt;<br>  &lt;/nav&gt;<br>&lt;/header&gt;</pre><h4>&lt;hr&gt; — Defines a Thematic Change in the Content</h4><p>Sometimes, you may want to create a visual separation or thematic change within your content. The &lt;hr&gt; tag is perfect for this. It draws a horizontal line to indicate a shift in content.</p><pre>&lt;p&gt;This is the first part of the content.&lt;/p&gt;<br>&lt;hr&gt;<br>&lt;p&gt;This is the second part of the content.&lt;/p&gt;</pre><h4>&lt;html&gt; — Defines the Root of an HTML Document</h4><p>The &lt;html&gt; tag defines the root of an HTML document. It encapsulates all the content and structure on your web page. This tag is the starting point for every web document.</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>  &lt;head&gt;<br>    &lt;!-- Metadata and information go here --&gt;<br>  &lt;/head&gt;<br>  &lt;body&gt;<br>    &lt;!-- Your web page content --&gt;<br>  &lt;/body&gt;<br>&lt;/html&gt;</pre><h4>&lt;i&gt; — Defines a Part of Text in an Alternate Voice or Mood</h4><p>The &lt;i&gt; tag is used to define a part of text that should be presented in an alternate voice or mood, often rendered as italicized text.</p><pre>&lt;p&gt;This is a &lt;i&gt;special&lt;/i&gt; part of the text.&lt;/p&gt;</pre><h4>&lt;iframe&gt; — Defines an Inline Frame</h4><p>An inline frame, defined using the &lt;iframe&gt; tag, allows you to embed another HTML document within your current document. It’s commonly used for embedding maps, videos, or external content.</p><pre>&lt;iframe src=&quot;https://www.example.com&quot;&gt;&lt;/iframe&gt;</pre><h4>&lt;img&gt; — Defines an Image</h4><p>Images are crucial for visual content on your web pages. The &lt;img&gt; tag is used to insert images into your documents. You provide the image source (src) within the tag.</p><pre>&lt;img src=&quot;image.jpg&quot; alt=&quot;A beautiful image&quot;&gt;</pre><h4>&lt;label&gt; — Defines a Label for an &lt;input&gt; Element</h4><p>When you have input elements like text fields or checkboxes, the &lt;label&gt; tag defines a label for them. It’s crucial for accessibility and user experience.</p><pre>&lt;label for=&quot;username&quot;&gt;Username:&lt;/label&gt;<br>&lt;input type=&quot;text&quot; id=&quot;username&quot; name=&quot;username&quot;&gt;</pre><h4>&lt;li&gt; — Defines a List Item</h4><p>Lists are prevalent in web content. The &lt;li&gt; tag is used within &lt;ul&gt; (unordered lists) and &lt;ol&gt; (ordered lists) to define individual list items.</p><pre>&lt;ul&gt;<br>  &lt;li&gt;Item 1&lt;/li&gt;<br>  &lt;li&gt;Item 2&lt;/li&gt;<br>  &lt;!-- More list items --&gt;<br>&lt;/ul&gt;</pre><h4>&lt;link&gt; — Defines the Relationship Between a Document and an External Resource</h4><p>The &lt;link&gt; tag is often used to link your HTML documents to external resources, such as stylesheets. It specifies the relationship between the current document and the linked resource.</p><pre>&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;styles.css&quot;&gt;</pre><h4>&lt;nav&gt; — Defines Navigation Links</h4><p>Navigation is a fundamental aspect of web design. The &lt;nav&gt; tag is used to define a section of your web page that contains navigation links. These links help users explore your website easily.</p><pre>&lt;nav&gt;<br>  &lt;a href=&quot;/&quot;&gt;Home&lt;/a&gt;<br>  &lt;a href=&quot;/about&quot;&gt;About&lt;/a&gt;<br>  &lt;a href=&quot;/services&quot;&gt;Services&lt;/a&gt;<br>&lt;/nav&gt;</pre><h4>&lt;ol&gt; — Defines an Ordered List</h4><p>Lists are an effective way to present information in a structured manner. The &lt;ol&gt; tag is used to create ordered lists, where each item is numbered.</p><pre>&lt;ol&gt;<br>  &lt;li&gt;Step 1: Register for an account.&lt;/li&gt;<br>  &lt;li&gt;Step 2: Log in to your profile.&lt;/li&gt;<br>  &lt;li&gt;Step 3: Start using our services.&lt;/li&gt;<br>&lt;/ol&gt;</pre><h4>&lt;p&gt; — Defines a Paragraph</h4><p>The humble &lt;p&gt; tag is used to define paragraphs on your web page. It’s crucial for separating and organizing textual content.</p><pre>&lt;p&gt;This is a paragraph of text. It provides valuable information to the reader.&lt;/p&gt;</pre><h4>&lt;script&gt; — Defines a Client-Side Script</h4><p>The &lt;script&gt; tag is a powerful tool for adding client-side scripts to your web page. JavaScript, for example, can be embedded within this tag to create dynamic and interactive content.</p><pre>&lt;script&gt;<br>  function greetUser() {<br>    alert(&#39;Hello, user!&#39;);<br>  }<br>&lt;/script&gt;</pre><h4>&lt;section&gt; — Defines a Section in a Document</h4><p>The &lt;section&gt; tag helps structure your web content. It defines a section within your document, making it easier to organize and style your content.</p><pre>&lt;section&gt;<br>  &lt;h2&gt;About Our Company&lt;/h2&gt;<br>  &lt;p&gt;We are a leading provider of innovative solutions...&lt;/p&gt;<br>&lt;/section&gt;</pre><h4>&lt;select&gt; — Defines a Drop-Down List</h4><p>When you want to present a list of options, such as a list of countries or categories, the &lt;select&gt; tag is your go-to choice.</p><pre>&lt;select name=&quot;category&quot;&gt;<br>  &lt;option value=&quot;sports&quot;&gt;Sports&lt;/option&gt;<br>  &lt;option value=&quot;technology&quot;&gt;Technology&lt;/option&gt;<br>  &lt;!-- More options here --&gt;<br>&lt;/select&gt;</pre><h4>&lt;span&gt; — Defines a Section in a Document</h4><p>The &lt;span&gt; tag is a versatile inline element used to apply styles or scripting to specific parts of your text content. It’s often used in combination with CSS and JavaScript.</p><pre>&lt;p&gt;This is a &lt;span style=&quot;color: red;&quot;&gt;highlighted&lt;/span&gt; word.&lt;/p&gt;</pre><h4>&lt;style&gt; — Defines Style Information for a Document</h4><p>Styling is a vital part of web design. The &lt;style&gt; tag lets you include CSS (Cascading Style Sheets) directly within your HTML document to control the appearance of your web page.</p><pre>&lt;style&gt;<br>  body {<br>    font-family: Arial, sans-serif;<br>    background-color: #f0f0f0;<br>  }<br>&lt;/style&gt;</pre><h4>&lt;svg&gt; — Defines a Container for SVG Graphics</h4><p>Scalable Vector Graphics (SVG) is a powerful way to include vector images on your web page. The &lt;svg&gt; tag acts as a container for SVG graphics, allowing you to create interactive and scalable visual content.</p><pre>&lt;svg width=&quot;100&quot; height=&quot;100&quot;&gt;<br>  &lt;circle cx=&quot;50&quot; cy=&quot;50&quot; r=&quot;40&quot; stroke=&quot;black&quot; stroke-width=&quot;3&quot; fill=&quot;red&quot; /&gt;<br>&lt;/svg&gt;</pre><h4>&lt;table&gt; — Defines a Table</h4><p>Tables are a fundamental component for presenting structured data. The &lt;table&gt; tag helps create tables on your web page, making it easy to organize and display information.</p><pre>&lt;table&gt;<br>  &lt;tr&gt;<br>    &lt;th&gt;Product&lt;/th&gt;<br>    &lt;th&gt;Price&lt;/th&gt;<br>  &lt;/tr&gt;<br>  &lt;tr&gt;<br>    &lt;td&gt;Laptop&lt;/td&gt;<br>    &lt;td&gt;$999&lt;/td&gt;<br>  &lt;/tr&gt;<br>  &lt;!-- More rows here --&gt;<br>&lt;/table&gt;</pre><h4>&lt;tbody&gt; — Groups the Body Content in a Table</h4><p>The &lt;tbody&gt; tag is used to group the body content within a table. It’s a best practice to include this tag to improve the structure and readability of your tables.</p><pre>&lt;table&gt;<br>  &lt;thead&gt;<br>    &lt;!-- Table header --&gt;<br>  &lt;/thead&gt;<br>  &lt;tbody&gt;<br>    &lt;!-- Table body --&gt;<br>  &lt;/tbody&gt;<br>&lt;/table&gt;</pre><h4>&lt;td&gt; — Defines a Cell in a Table</h4><p>Each cell within a table is defined using the &lt;td&gt; tag. It’s where you place the actual data to be displayed in the table.</p><pre>&lt;tr&gt;<br>  &lt;td&gt;John Doe&lt;/td&gt;<br>  &lt;td&gt;35 years old&lt;/td&gt;<br>&lt;/tr&gt;</pre><h4>&lt;th&gt; — Defines a Header Cell in a Table</h4><p>For table headers, use the &lt;th&gt; tag. It indicates that the cell contains a header for a column or row.</p><pre>&lt;tr&gt;<br>  &lt;th&gt;Product Name&lt;/th&gt;<br>  &lt;th&gt;Price&lt;/th&gt;<br>&lt;/tr&gt;</pre><h4>&lt;title&gt; — Defines a Title for the Document</h4><p>The &lt;title&gt; tag appears within the &lt;head&gt; section of your HTML document. It defines the title that appears in the browser’s title bar or tab.</p><pre>&lt;head&gt;<br>  &lt;title&gt;My Amazing Website&lt;/title&gt;<br>&lt;/head&gt;</pre><h4>&lt;tr&gt; — Defines a Row in a Table</h4><p>The &lt;tr&gt; tag is used to define rows in a table. Each row contains a series of cells (usually &lt;td&gt; or &lt;th&gt; elements).</p><pre>&lt;table&gt;<br>  &lt;tr&gt;<br>    &lt;td&gt;Cell 1&lt;/td&gt;<br>    &lt;td&gt;Cell 2&lt;/td&gt;<br>  &lt;/tr&gt;<br>  &lt;!-- More rows here --&gt;<br>&lt;/table&gt;</pre><h4>&lt;ul&gt; — Defines an Unordered List</h4><p>Unordered lists are a handy way to present items without any specific order. The &lt;ul&gt; tag creates these lists.</p><pre>&lt;ul&gt;<br>  &lt;li&gt;Item 1&lt;/li&gt;<br>  &lt;li&gt;Item 2&lt;/li&gt;<br>  &lt;!-- More items here --&gt;<br>&lt;/ul&gt;</pre><h4>&lt;video&gt; — Defines Embedded Video Content</h4><p>Incorporating video into your web page is made possible with the &lt;video&gt; tag. You can embed video files and control playback with HTML5.</p><pre>&lt;video width=&quot;320&quot; height=&quot;240&quot; controls&gt;<br>  &lt;source src=&quot;movie.mp4&quot; type=&quot;video/mp4&quot;&gt;<br>  Your browser does not support the video tag.<br>&lt;/video&gt;</pre><h3>The Art of CSS: Crafting Beautiful Web Designs</h3><p>When it comes to web development, CSS (Cascading Style Sheets) stands out as the unsung hero behind the aesthetics and visual appeal of websites. CSS is what turns plain HTML documents into beautifully designed, user-friendly web pages. In this blog post, we’ll delve into the world of CSS and explore its importance, fundamental concepts, and best practices.</p><h3>Understanding CSS</h3><p>CSS is a stylesheet language used to describe the presentation of a web page written in HTML. It controls how elements are displayed, determining everything from layout and positioning to colors and fonts. Here are some key aspects of CSS:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vG0q3_LXzO-tFuYl.png" /></figure><h4>Background</h4><p>The background property is used to set the background of an element. You can control background color, image, and more.</p><pre>div {<br>  background-color: #f2f2f2;<br>  background-image: url(https://medium.com/&#39;background.jpg&#39;);<br>}</pre><h4>Border</h4><p>Borders can enhance the appearance of HTML elements. Use border to define border properties like style, width, and color.</p><pre>button {<br>  border: 2px solid #007bff;<br>  border-radius: 5px;<br>}</pre><h4>Color</h4><p>Setting text and background colors is crucial. The color property manages the text color, and background-color handles the background color.</p><pre>p {<br>  color: #333;<br>  background-color: #fff;<br>}</pre><h4>Margin and Padding</h4><p>Margins and padding create space around and inside elements. Adjust spacing using margin and padding properties.</p><pre>div {<br>  margin: 10px;<br>  padding: 20px;<br>}</pre><h4>Background Properties</h4><p>Control the size, repeat behavior, and position of background images with background-size, background-repeat, and background-position.</p><pre>div {<br>  background-image: url(https://medium.com/&#39;background.jpg&#39;);<br>  background-size: cover;<br>  background-repeat: no-repeat;<br>  background-position: center;<br>}</pre><h4>Animation</h4><p>CSS animations breathe life into your web pages. Use @keyframes to define animations and apply them to elements.</p><pre>@keyframes spin {<br>  from { transform: rotate(0deg); }<br>  to { transform: rotate(360deg); }<br>}</pre><pre>div {<br>  animation: spin 4s linear infinite;<br>}</pre><h4>Center a Div</h4><p>Centering elements is a common task. You can use margin and display: flex for centering a div horizontally and vertically.</p><pre>.container {<br>  display: flex;<br>  justify-content: center;<br>  align-items: center;<br>}</pre><h4>Width</h4><p>Control the width of elements with the width property. This is essential for responsive web design.</p><pre>img {<br>  width: 100%;<br>}</pre><h4>Font Size</h4><p>The font-size property defines the size of text. Use pixel values, ems, or percentages for flexibility.</p><pre>h1 {<br>  font-size: 24px;<br>}</pre><h4>Margin</h4><p>Margins separate elements on the page. Setting margin values affects the space around an element.</p><pre>ul {<br>  margin: 10px;<br>}</pre><h4>Overflow</h4><p>The overflow property is used to control what happens when content overflows an element&#39;s box. Common values include visible, hidden, scroll, and auto.</p><pre>div {<br>  overflow: scroll;<br>}</pre><h4>Position</h4><p>The position property defines the positioning method for an element. Values like static, relative, absolute, and fixed control the element&#39;s placement.</p><pre>div {<br>  position: relative;<br>  top: 20px;<br>  left: 30px;<br>}</pre><h4>Absolute</h4><p>When you want to position an element absolutely within a container, use the position: absolute property.</p><pre>.container {<br>  position: relative;<br>}</pre><pre>.absolute-element {<br>  position: absolute;<br>  top: 0;<br>  left: 0;<br>}</pre><h3>Styling</h3><h4>Property</h4><p>The property property sets one or more CSS properties to a given value.</p><pre>button {<br>  property: value;<br>  another-property: another-value;<br>}</pre><h4>Rotate</h4><p>The rotate property is used to rotate an element in degrees. It&#39;s particularly handy for creating visually appealing animations.</p><pre>img {<br>  transform: rotate(45deg);<br>}</pre><h4>Transform</h4><p>The transform property enables you to apply transformations to elements. Common values include translate, rotate, scale, and more.</p><pre>div {<br>  transform: translate(20px, 30px);<br>}</pre><h3>Conclusion</h3><p>In conclusion, HTML and CSS serve as the cornerstone of web development and design. HTML structures your content, while CSS beautifies it. This guide has equipped you with the essentials, from creating web pages to styling them. Remember, the web is a dynamic landscape, so keep learning and building to unleash your full potential in web development.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8a96b15265b4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Normalization and SQL Commands in Relational Databases]]></title>
            <link>https://medium.com/@tarunjoshiji1/understanding-normalization-and-sql-commands-in-relational-databases-ff65a46eeb0a?source=rss-09e7b7ede5f8------2</link>
            <guid isPermaLink="false">https://medium.com/p/ff65a46eeb0a</guid>
            <category><![CDATA[database]]></category>
            <category><![CDATA[sql-queries]]></category>
            <category><![CDATA[mysql]]></category>
            <category><![CDATA[normalization]]></category>
            <category><![CDATA[sql]]></category>
            <dc:creator><![CDATA[Tarun Joshi]]></dc:creator>
            <pubDate>Sat, 28 Oct 2023 20:39:15 GMT</pubDate>
            <atom:updated>2023-10-30T04:08:25.831Z</atom:updated>
            <content:encoded><![CDATA[<h3>The Power of Normalization:</h3><p>Normalization is the process of organizing and structuring a relational database to minimize data redundancy and dependency. The primary goal is to ensure that the data is stored efficiently, making it easier to maintain and query. Normalization involves breaking down complex tables into smaller, related tables while establishing relationships between them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/927/0*zmKwN4cd5FG2JwL1.png" /></figure><h3>Key Benefits of Normalization:</h3><ol><li>Data Integrity: Normalization helps maintain data integrity by reducing the risk of anomalies, such as update, insert, and delete anomalies.</li><li>Efficient Storage: Smaller, well-structured tables take up less storage space, making data retrieval faster.</li><li>Simplified Maintenance: With normalized data, making changes or updates is more straightforward and less error-prone.</li><li>Improved Query Performance: Queries run more efficiently on normalized data.</li></ol><h3>Levels of Normalization:</h3><p>Normalization is typically divided into several levels, known as normal forms. The most common ones are:</p><p><strong>First Normal Form (1NF):</strong></p><ul><li>No more repeating rows.</li><li>Give each table a special ID (like a name tag).</li><li>Make sure all values are simple.</li><li>Names of columns should be unique.</li></ul><p><strong>Second Normal Form (2NF):</strong></p><ul><li>Follow the 1NF rules.</li><li>Get rid of the extra stuff that’s not needed.</li><li>Make separate lists for different things, each with its own special ID.</li></ul><p><strong>Third Normal Form (3NF):</strong></p><ul><li>Keep doing what you did for 2NF.</li><li>Don’t let one thing depend on another thing that’s not the special ID.</li><li>Make sure all other stuff depends only on the special ID.</li></ul><p><strong>Boyce-Codd Normal Form (BCNF):</strong></p><ul><li>Stick to 3NF rules.</li><li>If something really important depends on something else, both of them should be like special IDs.</li><li>A special ID is a set of things that can point to just one thing in the list.</li></ul><h3><strong>SQL Commands for Data Management:</strong></h3><p>SQL (Structured Query Language) is a powerful tool used to interact with relational databases. It provides a standardized way to manage and query data, making it a fundamental skill for anyone working with databases.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*3eYmuTQjayXqofMZ.jpg" /></figure><p><strong>1. DML (Data Manipulation Language):</strong></p><ul><li>DML commands are used to manipulate and query data stored in the database tables.</li><li>Common DML commands include <em>SELECT</em>, <em>INSERT</em>, <em>UPDATE</em>, and <em>DELETE</em>.</li></ul><p>INSERT (DML):</p><pre>-- Insert a new record into the &quot;employees&quot; table <br>INSERT INTO employees (employee_id, first_name, last_name, salary) <br>VALUES (101, &#39;John&#39;, &#39;Doe&#39;, 50000);</pre><p>UPDATE (DML):</p><pre>-- Update the salary of an employee <br>UPDATE employees SET salary = 55000 WHERE employee_id = 101;</pre><p>DELETE (DML):</p><pre>-- Delete a record from the &quot;employees&quot; table <br>DELETE FROM employees WHERE employee_id = 101;</pre><p><strong>2. DDL (Data Definition Language):</strong></p><ul><li>DDL commands are used to define and manage the structure of the database, including tables, indexes, and constraints.</li><li>Common DDL commands include <em>CREATE</em>, <em>ALTER</em>, and <em>DROP</em>.</li></ul><p>CREATE TABLE (DDL):</p><pre>-- Create a new table named &quot;customers&quot; <br>CREATE TABLE customers (<br>     customer_id INT PRIMARY KEY,<br>     first_name VARCHAR(50),<br>     last_name VARCHAR(50) );</pre><p>ALTER TABLE (DDL):</p><pre>-- Add a new column to an existing table <br>ALTER TABLE employees ADD COLUMN hire_date DATE;</pre><p>DROP TABLE (DDL):</p><pre>-- Delete an existing table <br>DROP TABLE customers;</pre><p><strong>3. DQL (Data Query Language):</strong></p><ul><li>DQL commands are used to retrieve data from the database tables.</li><li>The primary DQL command is <em>SELECT</em>, which is used to query and retrieve data.</li></ul><p>SELECT (DQL):</p><pre>-- Retrieve employee names from the &quot;employees&quot; table <br>SELECT first_name, last_name FROM employees;</pre><p><strong>4. TCL (Transaction Control Language):</strong></p><ul><li>TCL commands are used to manage transactions within the database.</li><li>Common TCL commands include <em>COMMIT</em>, <em>ROLLBACK</em>, and <em>SAVEPOINT</em>.</li></ul><p>COMMIT (TCL):</p><pre>-- Commit a transaction, making the changes permanent <br>COMMIT;</pre><p>ROLLBACK (TCL):</p><pre>-- Rollback a transaction, undoing any changes made within the transaction <br>ROLLBACK;</pre><p><strong>5. DCL (Data Control Language):</strong></p><ul><li>DCL commands are used to manage access to data in the database.</li><li>Common DCL commands include <em>GRANT</em> and <em>REVOKE</em>.</li></ul><p>GRANT (DCL):</p><pre>-- Grant SELECT permission on the &quot;employees&quot; table to a user <br>GRANT SELECT ON employees TO user_name;</pre><p>REVOKE (DCL):</p><pre>-- Revoke the SELECT permission on the &quot;employees&quot; table from a user <br>REVOKE SELECT ON employees FROM user_name;</pre><h3><strong>SQL Joins</strong></h3><p>SQL joins are essential for retrieving data from multiple related tables. They allow you to combine information from different sources in a single query. Common types of joins include <em>INNER JOIN</em>, <em>LEFT JOIN</em>, and <em>RIGHT JOIN</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*Htuptdb9S-tET-7R.png" /></figure><p>For Instance:</p><p>Suppose we have two tables, <em>employee</em> and <em>department</em>, with the following structures:</p><pre>-- Employees table<br>CREATE TABLE employees (<br>    employee_id INT PRIMARY KEY,<br>    first_name VARCHAR(50),<br>    last_name VARCHAR(50),<br>    department_id INT<br>);<br><br>-- Departments table<br>CREATE TABLE departments (<br>    department_id INT PRIMARY KEY,<br>    department_name VARCHAR(50)<br>);</pre><p>Now, let’s explore how to use different types of joins:</p><h4>INNER JOIN:</h4><p>An INNER JOIN returns only the rows that have matching values in both tables.</p><pre>SELECT e.first_name, e.last_name, d.department_name<br>FROM employees AS e<br>INNER JOIN departments AS d ON e.department_id = d.department_id;</pre><h4>LEFT JOIN (or LEFT OUTER JOIN):</h4><p>A LEFT JOIN returns all the rows from the left table and the matched rows from the right table. If there are no matches, NULL values are returned for columns from the right table.</p><pre>SELECT e.first_name, e.last_name, d.department_name<br>FROM employees AS e<br>LEFT JOIN departments AS d ON e.department_id = d.department_id;</pre><h4>RIGHT JOIN (or RIGHT OUTER JOIN):</h4><p>A RIGHT JOIN is the opposite of a LEFT JOIN. It returns all the rows from the right table and the matched rows from the left table. If there are no matches, NULL values are returned for columns from the left table.</p><pre>SELECT e.first_name, e.last_name, d.department_name<br>FROM employees AS e<br>RIGHT JOIN departments AS d ON e.department_id = d.department_id;</pre><h4>FULL JOIN (or FULL OUTER JOIN):</h4><p>A FULL JOIN returns all rows when there is a match in either the left or the right table. If there is no match, NULL values are returned for columns from the table without a match.</p><pre>SELECT e.first_name, e.last_name, d.department_name<br>FROM employees AS e<br>FULL JOIN departments AS d ON e.department_id = d.department_id;</pre><h3>SQL Functions and Aggregations</h3><p>SQL offers various built-in functions for manipulating data, performing calculations, and aggregating information. For instance:</p><ul><li><em>COUNT( )</em>: Counts the number of rows in a result set.</li><li><em>SUM( )</em>: Calculates the sum of values.</li><li><em>AVG( )</em>: Computes the average of values.</li><li><em>MAX( )</em>: Retrieves the maximum value.</li><li><em>MIN( )</em>: Retrieves the minimum value.</li></ul><p>Here’s an example of using the <em>SUM( )</em> function:</p><pre>SELECT department, SUM(salary) AS total_salary<br>FROM employees<br>GROUP BY department;</pre><p>This query sums up the salaries for each department, grouping the results by department.</p><h3>Basic Syntax of Window Functions</h3><p>A “window function” is a powerful tool for performing precise calculations within a designated subset of rows in a result set. Unlike standard aggregate functions, window functions provide flexibility and insights, making complex calculations efficient and elegant.</p><p>The basic syntax of a window function looks like this:</p><pre>&lt;window_function&gt; (&lt;expression&gt;) OVER (<br>    [PARTITION BY &lt;partition_column(s)&gt;]<br>    ORDER BY &lt;order_column(s)&gt;<br>    [ROWS &lt;frame_specification&gt;]<br>)</pre><ul><li><strong><em>&lt;WINDOW_FUNCTIONS&gt;</em>:</strong> The window function to apply (e.g., <em>SUM</em>, <em>AVG</em>, <em>RANK</em>, <em>ROW_NUMBER</em>, etc.).</li><li><strong><em>&lt;EXPRESSION&gt;</em>:</strong> The column or expression on which the function operates.</li><li><strong><em>PARTITION BY</em>:</strong> Divides the result set into partitions to apply the function independently within each partition.</li><li><strong><em>ORDER BY</em>: </strong>Defines the order in which rows are processed within the partition.</li><li><strong><em>ROWS</em>: </strong>Specifies a frame of rows within each partition.</li></ul><h3>Examples of Window Functions</h3><p><strong>ROW_NUMBER():</strong></p><p>The <em>ROW_NUMBER()</em> function assigns a unique number to each row within the result set, based on the specified order.</p><pre>SELECT employee_id, first_name, last_name,<br>LAG()       ROW_NUMBER() OVER (ORDER BY employee_id) AS row_num<br>FROM employees;</pre><p><strong>RANK( ):</strong></p><p>The <em>RANK( ) </em>function assigns a rank to each row within the result set based on the specified order. Rows with the same values get the same rank, and the next rank is skipped.</p><pre>SELECT department_id, employee_id, salary,<br>       RANK() OVER (PARTITION BY department_id ORDER BY salary DESC) AS department_rank<br>FROM employees;</pre><p>DENSE_RANK( ):</p><p>The <em>DENSE_RANK( )</em> function assigns a rank to each row within the result set, similar to <em>RANK( )</em>, but it doesn&#39;t skip ranks for tied values.</p><pre>SELECT department_id, employee_id, salary,<br>       DENSE_RANK() OVER (PARTITION BY department_id ORDER BY salary DESC) AS department_dense_rank<br>FROM employees;</pre><p><strong>SUM():</strong></p><p>The <em>SUM( )</em> function calculates the sum of a specified column within a defined window.</p><pre>SELECT order_date, order_amount,<br>       SUM(order_amount) OVER (ORDER BY order_date) AS running_total<br>FROM orders;</pre><p><strong>LEAD( ) and LAG( ):</strong></p><p>The <em>LEAD( )</em> function returns the value of a column in the next row, while <em>LAG( )</em> returns the value of a column in the previous row.</p><pre>SELECT order_date, order_amount,<br>       LAG(order_amount, 1, 0) OVER (ORDER BY order_date) AS prev_amount,<br>       LEAD(order_amount, 1, 0) OVER (ORDER BY order_date) AS next_amount<br>FROM orders;</pre><h3>Conclusion</h3><p>Normalization and SQL commands are essential components of effective database management. Normalization ensures data integrity and efficient storage, while SQL commands provide a standardized way to interact with and manipulate data. Mastering these concepts and techniques is crucial for anyone working with relational databases, as they form the foundation for building and maintaining efficient and reliable data systems.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ff65a46eeb0a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Object Oriented Programming (OOP)]]></title>
            <link>https://medium.com/@tarunjoshiji1/object-oriented-programming-oop-e151ad21233e?source=rss-09e7b7ede5f8------2</link>
            <guid isPermaLink="false">https://medium.com/p/e151ad21233e</guid>
            <category><![CDATA[objectorientedprogramming]]></category>
            <category><![CDATA[basics-of-development]]></category>
            <dc:creator><![CDATA[Tarun Joshi]]></dc:creator>
            <pubDate>Sun, 22 Oct 2023 13:08:59 GMT</pubDate>
            <atom:updated>2023-10-23T04:51:19.246Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Introduction:</strong></h3><p>Object-Oriented Programming (OOP) is a programming paradigm that has its roots in the 1960s and has since become a fundamental concept in software development. It is like a popular way of building computer programs. It’s all about making your code neat and easy to work with by using things called “objects”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4sn5l9i9bKFDOfJUvt4xww.png" /></figure><p>This blog explains OOP in a way that’s easy to understand, and it talks about the most important rules, ideas, and tricks in OOP. <br>Whether you’re just starting out or you’re already a pro, this paper will help you make your software better.</p><h3>Best Practices in OOP (SOLID):</h3><p><strong>Single Responsibility Principle (SRP):</strong></p><ul><li>Each class should do one job, just like each tool in a toolbox has a specific purpose.</li></ul><p><strong>Open/Closed Principle (OCP):</strong></p><ul><li>Software should be easily expandable without changing what’s already there, like adding new chapters to a book.</li></ul><p><strong>Liskov Substitution Principle (LSP):</strong></p><ul><li>If you replace one thing with another, everything should still work the same, like swapping one toy for another in a game.</li></ul><p><strong>Interface Segregation Principle (ISP):</strong></p><ul><li>Think of a remote control with only the buttons you need, not extras. Classes or interfaces should only provide what’s necessary.</li></ul><p><strong>Dependency Inversion Principle (DIP):</strong></p><ul><li>Make your code like LEGO blocks — easy to connect and swap out, not glued together.</li></ul><h3><strong>Access modifiers:</strong></h3><p><strong>Access modifiers</strong> in Java are keywords that control the visibility or accessibility of classes, methods, and fields within your code. They determine which parts of your code can access or modify a particular class or its members. Java provides four main access modifiers:</p><p><strong>Public (public):</strong></p><p>The most permissive access modifier.<br>Members with public access can be accessed from anywhere in your code, including other packages.<br>Often used for classes, methods, and fields that are intended to be part of a public API.</p><pre>public class PublicExample {<br>  public int publicField;<br>  public void publicMethod() { }<br>}</pre><p><strong>Protected (protected):<br></strong>Members with protected access can be accessed within their own class, within the same package, and by subclasses (even if the subclasses are in different packages).<br>It’s typically used for implementing inheritance, allowing derived classes to access and override these members.</p><pre>protected class ProtectedExample {<br>  protected int protectedField;<br>  protected void protectedMethod() { }<br>}</pre><p><strong>Default (Package-Private) (no modifier):</strong><br>If no access modifier is specified (default), members are accessible only within their own package.<br>This level of access is often referred to as “package-private” because members are not visible outside the package in which they are defined.</p><pre>class DefaultExample {<br>  int defaultField; // package-private (default)<br>  void defaultMethod() { }<br>}</pre><p><strong>Private (private):</strong><br>Members with private access are accessible only within their own class. They are not visible outside the class in which they are defined.<br>This is the strictest level of access control and is often used for implementation details that shouldn’t be exposed to other classes.</p><pre>public class Container {<br>  private int privateField;<br>  private void privateMethod() { }<br>}</pre><h3><strong>Fundamental OOP Concepts:</strong></h3><p><strong>Encapsulation (Keeping Secrets):</strong></p><p>Encapsulation is like putting your computer code in a safe box. It means you hide some parts of your code so that others can’t accidentally mess with them. <br>This helps keep your code safe and working as it should. It’s a bit like locking the important stuff in a secure box and only letting others access what they need.</p><pre>public class Student {<br>  private String name;<br><br>  public Student(String name) {<br>    this.name = name;<br>  }<br>  <br>  public String getName() {<br>    return name;<br>  }<br>  <br>  public static void main(String[] args) {<br>    Student student = new Student(&quot;Alice&quot;);<br>    System.out.println(&quot;Student Name: &quot; + student.getName());<br>  }<br>}</pre><p><strong>Inheritance (Sharing Code):</strong></p><p>Inheritance in programming is a bit like passing down traits from parents to children. <br>You can create a new piece of code (a child) based on an existing piece of code (a parent) and add or change things as needed. <br>It’s like a way to reuse code and save time. For example, if you have a “Animal” code, you can make a “Dog” code that inherits all the basic features of a Animal but adds specific things that are unique to a Dog, like how he speaks.</p><pre>class Animal {<br>  public void speak() {<br>    // Common code for all animals.<br>  }<br>}<br><br>class Dog extends Animal {<br>  public void speak() {<br>    System.out.println(&quot;Woof!&quot;);<br>  }<br>}<br><br>class Cat extends Animal {<br>  public void speak() {<br>    System.out.println(&quot;Meow!&quot;);<br>  }<br>}</pre><p><strong>Polymorphism (Many Faces):</strong></p><p>Polymorphism in programming is like having one word with different meanings depending on the context. <br>In this context, it means that you can use the same function or method name, but it can do different things for different objects. <br>It’s a way to make your code flexible and adaptable. Imagine if you had a “speak” command for both a dog and a cat. Even though it’s the same command, it would make different sounds.</p><pre>public static void animalSpeak(Animal animal) {<br>  animal.speak();<br>}<br><br>public static void main(String[] args) {<br>  // Usage<br>  Animal dog = new Dog();<br>  Animal cat = new Cat();<br>  animalSpeak(dog); // Outputs &quot;Woof!&quot;<br>  animalSpeak(cat); // Outputs &quot;Meow!&quot;<br>}</pre><p><strong>Abstraction (Simplicity):</strong></p><p>Abstraction in programming is like simplifying complex things to make them easier to work with. <br>It’s like using a TV remote without needing to know all the technical details of how it works inside. <br>Abstraction helps you focus on the essential parts and hide the complicated stuff. <br>For example, when you use a smartphone, you don’t need to understand all the complex electronics inside; you can just interact with the touch screen. Abstraction is about using simple, understandable commands while hiding the inner complexities.</p><pre>abstract class Shape {<br>  public abstract double area();<br>}<br><br>class Circle extends Shape {<br>  private double radius;<br>  public Circle(double radius) {<br>    this.radius = radius;<br>  }<br><br>  public double area() {<br>    return 3.14 * radius * radius;<br>  }<br>}<br><br>public static void main(String[] args) {<br>  // Usage<br>  Circle circle = new Circle(5);<br>  System.out.println(&quot;Circle area: &quot; + circle.area());<br>}</pre><h3><strong>OOP Design Patterns:</strong></h3><p><strong>Creational Patterns:</strong></p><ul><li><strong>Singleton:</strong> It ensures that only one instance of a class is created and provides a way to access that instance.</li><li><strong>Factory Method:</strong> It’s like a factory that creates objects without specifying their exact types, allowing flexibility in object creation.</li><li><strong>Abstract Factory:</strong> It’s a super factory that creates other factories for creating families of related objects without specifying their classes.</li><li><strong>Builder:</strong> It’s like an assembly line for creating complex objects, step by step, with various options.</li><li><strong>Prototype:</strong> It’s like making copies of an existing object to create new ones, making it easy to produce similar objects.</li></ul><p><strong>Structural Patterns:</strong></p><ul><li><strong>Adapter:</strong> It’s like a translator that allows two incompatible interfaces to work together by providing a middleman.</li><li><strong>Composite:</strong> It’s like organizing objects into a tree structure to work with both individual objects and groups of objects seamlessly.</li><li><strong>Decorator:</strong> It’s like adding features or behaviors to objects dynamically, without changing their core structure.</li><li><strong>Proxy:</strong> It’s like using a stand-in or placeholder to control access to another object.</li><li><strong>Facade:</strong> It’s like a simplified front door to a complex system, making it easier to use without dealing with its intricacies.</li></ul><p><strong>Behavioral Patterns:</strong></p><ul><li><strong>Observer:</strong> It’s like subscribing to updates; when one thing changes, all the interested parties are automatically notified.</li><li><strong>Strategy:</strong> It’s like having different strategies in your toolkit and choosing the right one for the job.</li><li><strong>Command:</strong> It’s like encapsulating a request as an object, allowing you to parameterize and queue requests.</li><li><strong>Chain of Responsibility:</strong> It’s like a relay race where different runners can handle a baton (request) until one successfully completes it.</li><li><strong>State:</strong> It’s like changing the behavior of an object when its internal state changes, making it act differently in different situations.</li></ul><h3><strong>Conclusion:</strong></h3><p>In simple terms, Object-Oriented Programming (OOP) is a vital part of making software today.<br>By grasping the main ideas, basic concepts, and smart ways of OOP, developers can create software that’s easy to manage and grow. <br>This blog is a helpful guide for developers who want to become OOP experts and use it well in their projects.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e151ad21233e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>