<?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 Chandan ravi on Medium]]></title>
        <description><![CDATA[Stories by Chandan ravi on Medium]]></description>
        <link>https://medium.com/@chandanravi54?source=rss-354770683ac4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*4DNLAgTLwIa0OZJX</url>
            <title>Stories by Chandan ravi on Medium</title>
            <link>https://medium.com/@chandanravi54?source=rss-354770683ac4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 07:56:41 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@chandanravi54/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[Inversion of control and Dependency Injection in Spring]]></title>
            <link>https://medium.com/@chandanravi54/inversion-of-control-and-dependency-injection-in-spring-5102acb547e6?source=rss-354770683ac4------2</link>
            <guid isPermaLink="false">https://medium.com/p/5102acb547e6</guid>
            <category><![CDATA[spring]]></category>
            <category><![CDATA[dependency-injection]]></category>
            <category><![CDATA[ioc-container]]></category>
            <dc:creator><![CDATA[Chandan ravi]]></dc:creator>
            <pubDate>Sun, 04 Jun 2023 10:34:42 GMT</pubDate>
            <atom:updated>2023-06-04T14:18:08.625Z</atom:updated>
            <content:encoded><![CDATA[<h3>Inversion of Control and Dependency Injection in Spring</h3><p>The biggest issue, any enterprise app can face is the complexity of wiring different elements or components together. Over a long period of time, a number of frameworks have been created to provide a facility to assemble and bind these elements from different layers. These frameworks are commonly known as <strong>Containers</strong> and some of the very popular examples of such frameworks are <strong>Pico Container</strong> and <strong>Spring</strong>. There are various interesting design principles used inside these containers and Inversion of Control is one such principle. In this article, we will understand what Inversion of Control exactly is and how it is used in a modern-day enterprise application.</p><h3>What is IOC???</h3><p>As the name suggests, Inversion of Control <strong>Principle </strong>(it’s a principle, not a design pattern) is basically about inverting the control flow of a program. This term was popularized by Stefano Mazzocchi in a defunct Apache Software Foundation project, <a href="https://en.wikipedia.org/wiki/Apache_Avalon">Avalon</a>, then further popularized in 2004 by <a href="https://en.wikipedia.org/wiki/Robert_Cecil_Martin">Robert C. Martin</a> and <a href="https://en.wikipedia.org/wiki/Martin_Fowler_(software_engineer)">Martin Fowler</a>.</p><p>As Martin Fowler said, “<em>Inversion of control is a common characteristic of frameworks, so saying that these lightweight containers (spring and pico container, etc.) are special because they use inversion of control is like saying my car is special because it has wheels.</em>” It is basically a defining characteristic of a framework. Inversion of Control is used to increase the modularity of the program and makes it extensible. But the question still is, “<strong>What aspect of control are they really inverting?</strong>”</p><h3>Inversion of Control</h3><p>It’s a concept that involves handing up control of things to a container or framework. It’s most commonly used in relation to object-oriented programming. In traditional programming, our custom code calls a library; however, IOC allows a framework to take control of a program’s flow and call our code. The person in charge of object generation keeps track of the object in memory. At runtime, IOC builds the class’s object and makes it available wherever it is required. It is primarily responsible for ensuring that an object’s life cycle is maintained.</p><p><strong>Bean:</strong> Beans are the objects in Spring that constitute the backbone of your application and are maintained by the Spring IOC container. A bean is an object that a Spring IOC container instantiates, assembles, and generally manages. A bean, on the other hand, is just one of many objects in your programme. Beans and their inter-dependencies are reflected in the container’s configuration metadata.</p><p>Spring Beans scope are divided into five categories of which two major are as follows:</p><p><strong>Singleton:</strong> Each container will only have one instance of the bean. Spring beans have this as their default scope. If you use this scope, make sure that the bean doesn’t have any shared instance variables, as this could cause data inconsistency.</p><p><strong>Prototype: </strong>A new instance will be created every time the bean is requested.</p><p>Spring provides containers called IOC<strong> containers</strong> for managing the work. These are of 2 types:</p><ol><li><strong><em>BeanFactory</em></strong><em>: </em>BeanFactory represents a basic<strong> </strong>IOC container which is a parent interface of ApplicationContext<strong>.</strong> BeanFactory uses Beans and their dependencies metadata to create and configure them at run-time. BeanFactory loads the bean definitions and dependency amongst the beans based on a configuration file(XML) or the beans can be directly returned when required using Java Configuration.</li><li><strong>ApplicationContext</strong>: the <em>ApplicationContext</em> is a sub-interface of the <em>BeanFactory</em>. Therefore, it offers all the functionalities of <em>BeanFactory. </em>Furthermore, it provides more enterprise-specific functionalities such as access to resources, event propagation to beans, loading of multiple (hierarchical) contexts resolving messages, supporting internationalization, and application-layer-specific contexts. This is why we use it as the default Spring container.</li></ol><p>Example of Application Context:</p><p><strong>Step 1:</strong> Create Student class under <strong><em>com.gfg.demo.domain</em> </strong>and<em> </em><strong>AppConfig class</strong> under <strong><em>com.gfg.demo.config</em></strong><em> </em>packages. The AppConfig is the configuration class that contains all the Java beans configured using Java Based Configuration. The Student class is the <a href="https://www.geeksforgeeks.org/pojo-vs-java-beans/">POJO class</a>.</p><ul><li><strong>Class 1:</strong> AppConfig class</li></ul><pre>@Configuration<br>// Class<br>public class AppConfig {<br>  @Bean<br>  // Method<br>  public Student student() {<br>    return new Student(1, &quot;Geek&quot;);<br>  }<br>}</pre><ul><li><strong>Class 2: </strong>Student class</li></ul><pre>// Class<br>public class Student {<br>// member variables<br>  private int id;<br>  private String name;<br>  // Constructor 1<br>  public Student() {}<br>  // Constructor 2<br>  public Student(int id, String name) {<br>    this.id = id;<br>    this.name = name;<br>  }<br>  // Method of this class<br>  // @Override<br>  public String toString() {<br>    return &quot;Student{&quot; + &quot;id=&quot; + id + &quot;, name=&#39;&quot; + name + &#39;\&#39;&#39; + &#39;}&#39;;<br>  }<br>}</pre><p><strong>Step 2:</strong> Now the Main Application class at the root contains the creation of a container.</p><pre>// Class<br>// @SpringBootApplication<br>public class DemoApplication {<br>// Main driver method<br>  public static void main(String[] args) {<br>    // SpringApplication.run(DemoApplication.class, args);<br>    // Creating its object<br>    ApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);<br>    Student student = context.getBean(Student.class);<br>    // Print and display<br>    System.out.println(student);<br>  }<br>}</pre><p><strong>Step 3: </strong>The <strong>SpringApplication.run() </strong>method is provided by default in the main class when the SpringBoot project is created. It creates the container, creates beans, manages dependency injection and life cycle of those beans.<strong> </strong>This is done using <a href="https://www.geeksforgeeks.org/introduction-to-spring-boot/">@SpringBootApplication annotation</a>.</p><pre>// Main driver method<br>public static void main(String[] args) {<br>ApplicationContext context = SpringApplication.run(DemoApplication.class, args);<br>  Student student = context.getBean(Student.class);<br>  // Print and display<br>  System.out.println(student);<br>}</pre><p>Now, we know that IOC is a mechanism through which a container acts as the third person to create and manage objects called beans. But, it needs to be referenced by classes whenever required right? but, HOW?. This is where Dependency Injection comes into the picture.</p><h3>Dependency Injection</h3><p>Dependency Injection is a pattern for implementing IoC. It enables the creation of dependant objects outside of a class and the providing of those objects to a class in a variety of ways. We use DI to move the creation and binding of dependent objects outside of the class on which they are dependent.</p><p><strong>Types of dependency injections</strong></p><ol><li>Constructor Injection</li><li>Setter Injection</li><li>Field Injection</li></ol><p>Dependency Injection (DI) is a widely used design pattern in software development to achieve loose coupling between components. In the Spring Framework, there are three ways to inject dependencies into a class: <strong>Field Injection,</strong> <strong>Constructor Injection</strong>, and <strong>Setter Injection</strong>. In this article, we’ll explore why constructor injection is preferred over field injection and how you can benefit from using it in your Spring projects.</p><h3>Field Injection</h3><p>Field Injection is the process of injecting dependencies into a class’s fields using the <em>@Autowired</em> annotation. This approach is easy to use and the code is more readable. However, it has some drawbacks.</p><p>Firstly, it leads to tight coupling with the DI Container/Framework. Secondly, it violates the Single Responsibility Principle (<strong>S </strong>from <strong>S</strong>OLID) by mixing. Thirdly, it may lead to <strong>NullPointerException </strong>as the initialization of the dependency is handled by the DI Container/Framework, and reflection is used internally for initialization. Fourthly, Unit Testing becomes difficult as we rely on the DI Container/Framework for initialization.</p><p>Here’s an example of how to use Field Injection in Spring:</p><pre>Class ClassA {<br>    @Autowired<br>    private ClassB classB<br>}</pre><h3>Constructor injection</h3><p>Constructor Injection is the process of injecting dependencies into a class’s constructor using arguments. This approach offers several benefits over field injection.</p><p>Firstly, it leads to loose coupling with the DI Container/Framework, making the code more maintainable and testable. Secondly, it does not violate the Single Responsibility Principle (S from SOLID). Thirdly, it avoids <strong>NullPointerExceptions </strong>as the constructor requires all not-null attributes. Fourthly, Unit Testing becomes easier as we are not dependent on the DI Container/Framework for initialization.</p><p>Here’s an example of how to use Constructor Injection in Spring:</p><pre>Class ClassA {<br>private ClassB classB<br>    <br>    public ClassA(ClassB classB){<br>        this.classB = classB;<br>    }<br>}</pre><h3>Setter Injection</h3><p>Setter Injection is the process of injecting dependencies into a class’s fields through a setter method. Setter injection is recommended for <em>optional dependencies</em>.</p><p>Here’s an example of how to use Setter Injection in Spring:</p><pre>Class ClassA {<br>private ClassB classB<br>    <br>    @Autowired<br>    public setClassB(ClassB classB){<br>        this.classB = classB;<br>    }<br>}</pre><p>In conclusion, Constructor Injection is the preferred method of dependency injection in Spring. It offers several benefits over Field Injection and Setter Injection, including loose coupling, separation of concerns, avoidance of <strong>NullPointerExceptions</strong>, and ease of Unit Testing.</p><h3>Reasons for use Inversion of control and Dependency Injection</h3><p>Here are some reasons for use Inversion of control and Dependency injection:</p><ul><li><strong>Decoupling:</strong> dependency injection makes your modules less coupled resulting in a more maintainable code base;</li><li><strong>Easier unit testing:</strong> instead of using hard coded dependencies you can pass them into the module you would like to use;</li><li><strong>Faster development:</strong> with dependency injection, after the interfaces are defined it is easy to work without any merge conflicts;</li></ul><p>I give you dependency injection for five-year-olds.</p><p><em>When you go and get things out of the refrigerator for yourself, you can cause problems. You might leave the door open, you might get something Mommy or Daddy doesn’t want you to have. You might even be looking for something we don’t even have or which has expired.</em></p><p><em>What you should be doing is stating a need, “I need something to drink with lunch,” and then we will make sure you have something when you sit down to eat.</em></p><p>What about this?</p><p>If you have a class Employee and this employee has an Address you can have the Employee class defined as follows:</p><pre>class Employee {<br>    private Address address;<br>// constructor <br>    public Employee( Address newAddress ) {<br>        this.address = newAddress;<br>    }<br>public Address getAddress() {<br>    return this.address;<br>    }<br>    public void setAddress( Address newAddress ) {<br>        this.address = newAddress;<br>    }<br>}</pre><p>Everything looks fine so far.</p><p>This code shows a <em>HAS-A</em> relationship between the employee and his address, that’s fine.</p><p>Now, this <em>HAS-A</em> relationship created a dependency between them. The problem comes within the constructor.</p><p>Each time you want to create an Employee instance you need an Address instance:</p><pre>Address someAddress = ....<br> Employee oscar = new Employee( someAddress );</pre><p>Working this way becomes problematic <strong><em>especially</em></strong> when you want to perform unit testing.</p><p>The main problem comes when you need to test one particular object, you need to create an instance of other object, and most likely you need to create an instance of yet <strong>other</strong> object to do that. The chain may become unmanageable.</p><p>To avoid this, you could change the constructor like this:</p><pre>public Employee(){<br>  }</pre><p>Using a no args constructor.</p><p>Then you can set the address when ever you want:</p><pre>Address someAddress = ....<br> Employee oscar = new Employee();<br> oscar.setAddress( someAddress );</pre><p>Now, this may be a drag, if you have several attributes or if the objects are hard to create.</p><p>Yet, think about this, let’s say, you add the Department attribute:</p><pre>class Employee {<br>      private Address address;<br>      private Department department;</pre><p>If you have 300 employees, and all of them need to have the <strong>same</strong> department, and plus that same department has to be shared between some other objects ( like the company list of departments, or the roles each department have etc ) then you’ll have a hard time with the visibility of the Department object and to share it through all the network of objects.</p><p>What the <strong>Dependency Injection</strong> is all about it to help you to, well, <strong><em>“inject”</em></strong> these dependencies in your code. Most of the frameworks allow you to do this by specifying in an external file, what object is to be injected.</p><p>Assume a properties file for a fictitious dependency injector:</p><pre>#mock employee<br>  employee.address = MockAddress.class<br>  employee.department = MockDepartment.class<br>#production setup <br>  employee.address = RealAddress.class<br>  employee.department = RealDepartment.class</pre><p>You’ll define what to inject for a given scenario.</p><p>What the Dependency Injector framework will do is to set the correct objects for you, so you don’t have to code setAddress or setDepartment. This would be done either by reflection or by code generation or other techniques.</p><p>So, the next time you need to test the Employee class you may inject mock Address and Departments objects without having to code all the set/get for all your test. Even better, you can inject <strong>real</strong> Address and Department objects in production code, and still have the confidence your code works as tested.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5102acb547e6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to Servlets and JSP]]></title>
            <link>https://medium.com/@chandanravi54/introduction-to-servlets-and-jsp-bc141f07d026?source=rss-354770683ac4------2</link>
            <guid isPermaLink="false">https://medium.com/p/bc141f07d026</guid>
            <category><![CDATA[java-ee]]></category>
            <category><![CDATA[servlet]]></category>
            <category><![CDATA[jsp]]></category>
            <dc:creator><![CDATA[Chandan ravi]]></dc:creator>
            <pubDate>Sat, 20 May 2023 13:04:50 GMT</pubDate>
            <atom:updated>2023-05-21T16:20:49.663Z</atom:updated>
            <content:encoded><![CDATA[<p>Below is the list of topics that I will be covering in this Servlet and JSP intro</p><p><strong>Servlet</strong></p><ul><li>HTTP</li><li>Introduction to Servlets</li><li>Servlet Life Cycle</li><li>Session Tracking</li><li>Cookies</li></ul><p><strong>JSP</strong></p><ul><li>Introduction to JSP</li><li>JSP vs Servlets</li><li>JSP Scripting Elements</li></ul><h3>HTTP (Hypertext Transfer Protocol)</h3><p>HTTP is used by clients and servers to communicate on the web. It is considered as <em>a stateless protocol </em>because it supports only one request per connection. With HTTP the clients connect to the server to send one request and then disconnect. And this mechanism allows more users to connect to a given server over a period of time. Here, the client sends an HTTP request, and the server answers with an HTML page to the client, using HTTP.</p><p>That was all about HTTP and Web. Now let’s dive deep into Servlets and understand its working mechanism.</p><h3>Introduction to Servlets</h3><p>Servlet is a server-side Java program module that handles client requests and implements the <em>servlet</em> interface. Servlets can respond to any type of request, and they are commonly used to extend the applications hosted by web servers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/352/0*nxoTfpPvd8iLRXy1.jpg" /><figcaption>Servlet Architecture</figcaption></figure><p>In this figure you can see, a client sends a request to the server and the server generates the response, analyses it and sends the response back to the client.</p><p>Now, let’s jump into the next concept and understand Servlet Life Cycle.</p><h3>Servlet Life Cycle</h3><p>The entire life cycle is managed by the <em>Servlet container</em> which uses the <em>javax.servlet.Servlet</em> interface to understand the Servlet object and manage it.</p><p><strong>Servlet Life Cycle</strong>: The Servlet life cycle mainly goes through these stages:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/270/0*D5hduEVyj4pWz31Q" /><figcaption>Servlet Life Cycle</figcaption></figure><p><strong>Loading a Servlet</strong>: The first stage of the Servlet life cycle involves loading and initializing the Servlet by the Servlet container. The Web container or Servlet Container can load the Servlet at either of the following two stages :</p><ul><li>Initializing the context, on configuring the Servlet with a zero or positive integer value.</li><li>If the Servlet is not preceding the stage, it may delay the loading process until the Web container determines that this Servlet is needed to service a request.</li></ul><p><strong>Initializing a Servlet</strong>: After the Servlet is instantiated successfully, the Servlet container initializes the instantiated Servlet object. The container initializes the Servlet object by invoking the <em>init(ServletConfig) </em>method which accepts ServletConfig object reference as a parameter.</p><p><strong>Handling request</strong>: After initialization, the Servlet instance is ready to serve the client requests. The Servlet container performs the following operations when the Servlet instance is located to service a request :</p><ul><li>It creates the <strong>ServletRequest </strong>and <strong>ServletResponse.</strong> In this case, if this is an HTTP request then the Web container creates <strong>HttpServletRequest </strong>and <strong>HttpServletResponse</strong> objects which are subtypes of the <strong>ServletRequest </strong>and <strong>ServletResponse</strong> objects respectively.</li></ul><p><strong>Destroying a Servlet</strong>: When a Servlet container decides to destroy the Servlet, it performs the following operations,</p><ul><li>It allows all the threads currently running in the service method of the Servlet instance to complete their jobs and get released.</li><li>After currently running threads have completed their jobs, the Servlet container calls the <strong>destroy() </strong>method on the Servlet instance.</li></ul><p>After the <strong>destroy()</strong> method is executed, the Servlet container releases all the references of this Servlet instance so that it becomes eligible for garbage collection.</p><p>Now that you have understood the basics of a servlet, let’s move further and understand what are the steps involved to create a Servlet application.</p><p>Lets talk about Scope variables.</p><p>1. <strong>Application Context </strong>— In other words we can say this is <strong>servletContext. </strong>You can use servletContext to store the global data which is going to share through out the application. This is <strong>not thread safe</strong>. You can easily access this context as follows.</p><pre>request.getServletContext();<br>request.getServletContext().setAttribute(&quot;attribute_name&quot;,&quot;value&quot;);</pre><p>2. <strong>Session Context </strong>— Session management is handling by the servlet container and you can store the user specific data on session. This object is <strong>not thread safe</strong>.</p><pre>request.getSession(); //going to create the session if session is not exist.<br>request.getSession(false); // Not going to create the session.</pre><p>3. <strong>Request Attributes</strong> — You can use this scope to carry the data in server side from one resource to another. As an example while you are doing the request forwarding. This is thread safe because one request is handle by one thread.</p><pre>request.setAttribute(&quot;attribute_name&quot;,&quot;value&quot;);<br>request.getAttribute(&quot;attribute_name&quot;); // return the Object you have to cast it</pre><p><strong><em>Servlet Example:</em></strong></p><p>Following is the sample source code structure of a servlet example to show Hello World −</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*YOW61xC37u-itIIx.png" /><figcaption>Servlet Example</figcaption></figure><h3>Session Tracking</h3><p><strong><em>Session</em> </strong>simply means a particular interval of time. And<strong> <em>session tracking</em> </strong>is a way to maintain state (data) of a user. It is also known as <em>session management</em> in servlet. We know that the HTTP protocol is stateless, so we need to maintain state using session tracking techniques. Each time user requests to the server, the server treats the request as the new request. So we need to maintain the state of a user to recognize a particular user.</p><h3><strong>Cookies</strong></h3><p>Cookies are the textual information that is stored in key-value pair format to the client’s browser during multiple requests. It is one of the state management techniques in session tracking. Basically, the server treats every client request as a new one so to avoid this situation cookies are used. When the client generates a request, the server gives the response with cookies having an id which are then stored in the client’s browser. Thus if the client generates a second request, a cookie with the matched id is also sent to the server. The server will fetch the cookie id, if found it will treat it as an old request otherwise the request is considered new.</p><p>The information stored in cookies is not safe since it is kept on the client-side in a text format that anybody can see. We can activate or disable cookies based on our needs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/475/0*VlVMGTcUuw_ZzH6i" /><figcaption>Session vs Cookies</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*rePqkUB4mX2mlgUv" /><figcaption>RequestDispatcher vs sendRedirect</figcaption></figure><h3>Java Server Pages</h3><p><strong>JSP</strong> or Java Server Pages is a technology that is used to create web application just like Servlet technology. It is an extension to Servlet — as it provides more functionality than servlet such as expression language, JSTL, etc. A JSP page consists of HTML tags and JSP tags. The JSP pages are easier to maintain than Servlet because we can separate designing and development. It provides some additional features such as Expression Language, Custom Tags, etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*gWY0Dy1HZ80ATPMt.jpeg" /><figcaption>JSP Architecture</figcaption></figure><ul><li><strong>Portable: </strong>JSP tags will process and execute by the server side web container, So that these are browser independent and J2EE server independent.</li><li><strong>Powerful: JSP </strong>consists of bytecode so that all Java features are applicable in case of JSP like robust, dynamic, secure, platform independent.</li><li><strong>Flexible: </strong>It allows to define custom tags so that the developer can fill conferrable to use any kind, framework based markup tags in JSP.</li><li><strong>Fast Development:</strong> If JSP page is modified, we don’t need to recompile and redeploy the project. The Servlet code needs to be updated and recompiled if we have to change the look and feel of the application.</li><li><strong>Tracking the User:</strong> JSP allows us to track the selections made by the user during user interaction with the website by maintaining the information in the session or cookies</li><li><strong>Easy: </strong>JSP is easy to learn, easy to understand and easy to develop. JSPs are more convenient to write than Servlets because they allow you to embed Java code directly into your HTML pages.</li></ul><p>Now that you understood what is JSP, let’s see how JSP and Servlets differ from each other and why JSP is better than Servlets with the help of below table.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*R-4XPSLf0s7Mlfys.png" /><figcaption>JSP vs Servlets</figcaption></figure><p>Difference Between JSP and Servlets- Advanced Java Tutorial</p><p>Now let’s dig deeper into Java Server Pages and understand Life Cycle of JSP.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*wt_JQPkXyVZO6hhW.png" /><figcaption>JSP Lifecycle</figcaption></figure><p>JSP conversion</p><p>JSP is internally converted into a servlet. Servlets are designed for dynamic web content, after all. However, there is no effective way to represent dynamic web content on a web page using Servlets. There are so many that we need to write down out.print() statements. There can’t be simply one web page in a web application. It’s a collection of web pages, actually. It is not suggested to create web pages in this manner.</p><p><strong>Scriptlet tag: </strong>Whatever is written into this tag is converted into a service function in the servlet. The business logic is written into this.</p><pre>&lt;%  java source code %&gt;</pre><p><strong>Directive tag:</strong> This element is used to declare anything that is used by the entire page, such as importing a file.</p><pre>&lt;%@ directive attribute=&quot;value&quot; %&gt;</pre><p><strong>Declarative tag:</strong> This tag is used to declare all variables and statements outside of the service function but within the class.</p><pre>&lt;%!  field or method declaration %&gt;</pre><p><strong>Expression tag: </strong>Everything inside this tag is printed on the screen.</p><pre>&lt;%=  statement %&gt;</pre><p><strong>Disadvantages of JSP:-</strong></p><ol><li>Difficult to debug for errors.</li><li>First-time access leads to wastage of time</li><li>Its output is HTML which lacks features.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bc141f07d026" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Normalization in SQL]]></title>
            <link>https://medium.com/@chandanravi54/normalization-in-sql-8759d84b0712?source=rss-354770683ac4------2</link>
            <guid isPermaLink="false">https://medium.com/p/8759d84b0712</guid>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[normalization]]></category>
            <dc:creator><![CDATA[Chandan ravi]]></dc:creator>
            <pubDate>Sun, 14 May 2023 07:24:11 GMT</pubDate>
            <atom:updated>2023-05-14T07:24:11.570Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*plwV4BBrNvyWu10k.jpeg" /><figcaption>NORMALIZATION</figcaption></figure><p>Normalization is a procedure used to reduce dependency and redundancy in a relational database. This method ensures that the data stored in a database is well-organized, accurate, and easy to maintain. Normalization in SQL involves dividing a database into two or more tables and defining the relationship between the tables.</p><h3>What is Normalization in SQL?</h3><p>In SQL, the process of structuring and resolving data in a database is known as normalization. It is achieved by applying a set of rules and procedures to a database, known as normalization forms.</p><p>There are several normalization forms, including the First Normal Form (1NF), Second Normal Form (2NF), Third Normal Form (3NF), Boyce-Codd Normal Form (BCNF), Fourth Normal Form (4NF) and the Fifth Normal Form (5NF). Each form builds on the previous one, providing a set of guidelines for organizing data in a way that meets the specific requirements of a database.</p><p><strong>Data redundancy</strong> occurs when the same piece of data exists in more than one place in the database. For example, you own an online books store and one specific customer has multiple orders. For every order, he has to enter his address. So that one customer has entered the same address multiple times. That address is redundant data in the system.</p><h3>What is Primary key?</h3><p>Primary key is a key in relational database that is unique for each record. A relational database must always have one and only one primary key. A Primary key is a combination of NOT NULL and UNIQUE.</p><h3>What is Foreign key?</h3><p>A foreign key provides a link between data in tables. It references the primary key of another table.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/284/0*r3zavrgdic2vZUNz.png" /><figcaption>FOREIGN KEY</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*P-FJ-qVaBqMsP8Hh.png" /><figcaption>TYPES OF NORMALIZATION</figcaption></figure><p><strong>First Normal Form(1NF):</strong></p><ul><li><strong>In the First Normal Form first rule is to break data into smaller logical pieces.</strong></li></ul><p>I have created the student table which stores the student data like Roll_No, Name, etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/569/0*DC7lxcb0KBpXTyPo.png" /><figcaption>STUDENT TABLE</figcaption></figure><p>I will find out those names whose surname is Sharma.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/572/0*MESBZ0jln4QQJNW2.png" /><figcaption><strong>QUERY AND RESULT</strong></figcaption></figure><p>Also, I will find out those names whose surname is Sharma but don’t have a middle name.</p><p>It is difficult to find out the result because of the database design. so we apply 1NF i.e. name is broken into F_Name, M_Name, and Surname.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/651/0*vxtQ42fpHQy8lwmJ.png" /><figcaption>1st Rule of 1NF</figcaption></figure><p>After applying the first rule searching is faster and a query is simpler.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/607/0*9Wz8_nC36bTim6S4.png" /><figcaption>QUERY AND RESULT</figcaption></figure><ul><li><strong>The second rule of 1NF is to Avoid duplicate data.</strong></li></ul><p>In this query, I will display those names whose Class is 10th.</p><p>It will display only one record but it doesn’t display another record because of the data entry problem. By avoiding duplicate data we apply the second rule of 1NF.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/311/0*Gh0kG9MB9jICov2N.png" /><figcaption>RESULT</figcaption></figure><p>We can create another table that is Class. And create a relationship between the class table and the student table via the foreign key.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/392/0*ho8HX7p_rGecDvRh.png" /><figcaption>CREATE A CLASS TABLE</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/180/0*FhLgJTPwYTddAw2s.png" /><figcaption>CLASS TABLE</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/390/0*tXnkcbYCt_ERGUGD.png" /><figcaption>APPLY FOREIGN KEY</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/643/0*lAZDVYHOfwh2_d67.png" /><figcaption>2nd RULE of 1NF</figcaption></figure><p>After applying the second rule remove duplicate records.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/475/0*U2EbHtt1Qtaa-S7-.png" /><figcaption>QUERY AND RESULT</figcaption></figure><blockquote><strong><em>Second Normal Form (2NF):-</em></strong></blockquote><ul><li><strong>In the second Normal Form, the first rule is table is a must in the First Normal Form.</strong></li><li><strong>The Second rule is all column data should depend on the primary key.</strong></li></ul><p>If added extra subject in the subject column then it will be updated to a per-student it is not good. This problem to solve by applying 2NF.</p><p>The subject is not directly connected to a student. So I will create three tables i.e. Syllabus table, Subject table, and Subject_Syllabus table.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/607/0*EdC_A0v7yrLb7zvB.png" /></figure><p>In database design shown the relationship between the tables.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/571/0*vgZKdnkcf6lM8iGO.png" /><figcaption>DATABASE DESIGN</figcaption></figure><p>The 2NF second rule is the subject is dependent on the syllabus, not a roll number.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/508/0*xH0OQ0LtU3fv5CO7.png" /><figcaption>QUERY AND RESULT</figcaption></figure><blockquote><strong><em>Third Normal Form (3NF):-</em></strong></blockquote><ul><li><strong>In the Third Normal Form, the first rule is table is a must in the Second Normal Form.</strong></li><li><strong>The second rule of 3NF is No column should depend on other columns.</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/547/0*ULEXkr1F5AWHCmjF.png" /><figcaption>TABLE</figcaption></figure><p>If we implement the 3NF we can delete the Average column because the Average depends on the marks and subject.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/491/0*Mz8KdBhp-ffgPj8D.png" /><figcaption>3NF</figcaption></figure><ul><li><strong>BCNF</strong>: It stands for Boyce-Codd Normal Form, and is often referred to as 3.5NF as it focuses on anomalies not covered by 3NF. Boyce &amp; Codd are credited for its invention. Boyce co-invented SQL², while Codd invented the relational model for database management³ and is behind the normalization steps we’ve been discussing. BCNF is a stronger version of the third normal form that requires that every determinant (a column or set of columns that uniquely determines another column) be a candidate key. In other words, every non-key column in a table should be functionally dependent on the entire primary key, not just a subset of it. For example, consider a table of employee information that includes columns for employee ID, project ID, and project manager. To meet the BCNF requirement, we would create separate tables for project information and manager information, each with their own primary key. The employee ID, project ID, and manager ID columns in the original table would then be linked to the corresponding tables through their respective primary keys.</li></ul><blockquote><strong><em>Fourth Normal Form (4NF):-</em></strong></blockquote><p>A table is said to be in fourth normal form if there is no two or more, independent and multi valued data describing the relevant entity.</p><blockquote><strong><em>Fifth Normal Form (5NF):-</em></strong></blockquote><p>A table is in fifth normal form if:</p><ul><li>It is in its fourth normal form.</li><li>It cannot be subdivided into any smaller tables without losing some form of information.</li></ul><p><strong>Anomalies</strong> are problems that can occur in a poorly planned and un-normalized database. There are three types of anomalies in the database. Insertion anomaly, Deletion anomaly, and Update anomaly.</p><p><strong><em>Insertion anomaly</em></strong> occurs when an inserting piece of data is dependent on the insertion of other data. For example, a user can not be registered into the transport system until he buys one train ticket.</p><p><strong><em>Deletion anomaly </em></strong>happens when deleting a record, results in the deletion of other related records. For example, a user deletes a booked train ticket resulted in the deletion of that particular train information.</p><p><strong><em>Update anomaly</em></strong> is by updating a single or multiple records leads to updating of many other records incorrectly.</p><p><strong>Conclusion:-</strong></p><p>Normalization helps to optimize database performance, reduce data inconsistencies, and make it easier to maintain and update the database over time. However, normalization is not always necessary or practical for all databases, and the process of normalization can sometimes lead to more complex database designs. The decision to normalize a database should be made on a case-by-case basis, weighing the benefits and drawbacks of normalization for each specific database.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8759d84b0712" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Oops Concept in Java]]></title>
            <link>https://medium.com/@chandanravi54/oops-concept-in-java-d3fb36af31b0?source=rss-354770683ac4------2</link>
            <guid isPermaLink="false">https://medium.com/p/d3fb36af31b0</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[oops-in-java]]></category>
            <dc:creator><![CDATA[Chandan ravi]]></dc:creator>
            <pubDate>Sun, 07 May 2023 17:38:37 GMT</pubDate>
            <atom:updated>2023-05-07T17:39:51.987Z</atom:updated>
            <content:encoded><![CDATA[<p>Object-Oriented Programming is a paradigm that provides many concepts such as <strong>inheritance</strong>, <strong>polymorphism</strong>,<strong> encapsulation</strong> etc.</p><p><strong>Simula</strong> is considered the first object-oriented programming language. The programming paradigm where everything is represented as an object is known as a truly object-oriented programming language.</p><p><strong>Smalltalk</strong> is considered the first truly object-oriented programming language.</p><p>The popular object-oriented languages are Java, C#, PHP, Python, C++, etc.</p><p>The main aim of object-oriented programming is to implement real-world entities for example object, classes, abstraction, inheritance, polymorphism, etc.</p><h3>Aim of OOPs in Java</h3><ol><li>To improve code readability and reusability by defining a Java program efficiently.</li><li>To bind together the data and the functions that operate on them so that no other part of the code can access this data except that function.</li><li>To keep the Java code DRY “Don’t Repeat Yourself”, and makes the code easier to maintain, modify, and debug.</li></ol><h3>OOPs (Object-Oriented Programming System)</h3><p><strong>Object</strong> means a real-world entity such as a pen, chair, table, computer, watch, etc. <strong>Object-Oriented Programming</strong> is a methodology or paradigm to design a program using classes and objects. It simplifies the software development and maintenance by providing some concepts:</p><ul><li>Object</li><li>Class</li><li>Inheritance</li><li>Polymorphism</li><li>Abstraction</li><li>Encapsulation</li></ul><h3>List of OOPs concept in Java</h3><h3>1. Object:-</h3><p>The object is a real-world entity that has a state, behavior, and identity. Is also known as an instance of the Java class. The object can be physical or logical.</p><p>An object has</p><ol><li><strong>State</strong>: It is represented by attributes of an object. It also reflects the properties of an object.</li><li><strong>Behavior</strong>: It is represented by the methods of an object. It also reflects the response of an object with other objects.</li><li><strong>Identity</strong>: It gives a unique name to an object and enables one object to interact with other objects.</li></ol><p><strong>Examples of object, state, and behavior</strong><br><strong>Object</strong>: House<br><strong>State</strong>: Address, Color, Area<br><strong>Behavior</strong>: Open door, close door</p><p>The class for the above example will be</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/298/0*HEN6OPw7im5LpiW1.png" /><figcaption>Fig: Java class</figcaption></figure><p>We can create the object of the Java class using a new keyword. Let us see an example.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/292/0*tUfBvcyKZ0HCVXz0.png" /><figcaption>Fig: Object creation in java</figcaption></figure><h3>2. Class:-</h3><p>A class is a user-defined blueprint or prototype from which objects are created. The Java class is not a real-world entity, it’s a logical entity. Java classes don’t consume any memory. A java class contains variables, methods, and objects of classes. Also class has both static and instance initializers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/712/0*Rv4BsH1As5uvZ3hg.png" /><figcaption>Fig: Examples of Class and Object</figcaption></figure><p>A class declaration consists of:-</p><ol><li><strong>Modifiers</strong>: The Java class can be public or default access.</li><li><strong>Class name: </strong>The class name should start with an initial letter (followed by camel case by convention).</li><li><strong>Superclass:</strong> The name of the superclass, if any, preceded by the keyword “extends”.</li><li><strong>Interfaces:</strong> A comma-separated list of interfaces implemented by the class, if any, preceded by the keyword “implements”. A class can implement more than one interface.</li><li><strong>Body:</strong> The class body surrounded by braces, { }.</li></ol><p>Let us see an example of Java class</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/811/0*Y2DFY4aD5K-Z4mzV.png" /><figcaption>Fig: Declaration of Java class</figcaption></figure><h3>3. Inheritance:-</h3><p>Inheritance in Java is a mechanism in which one object acquires all the properties and behaviors of a parent object. It is an important part of OOPs (Object Oriented programming system). We can inherit the classes by using the “extend” keyword.</p><p>Important terminology used in the interface</p><ol><li><strong>Super Class: </strong>The class whose features are inherited is known as superclass(or a base class or a parent class).</li><li><strong>Sub Class:</strong> The class that inherits the other class is known as a subclass(or a derived class, extended class, or child class). The subclass can add its own fields and methods in addition to the superclass fields and methods.</li><li><strong>Reusability: </strong>Inheritance supports the concept of “reusability”, i.e. when we want to create a new class and there is already a class that includes some of the code that we want, we can derive our new class from the existing class. By doing this, we are reusing the fields and methods of the existing class.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*b31hiO4ynbDLRrXWEFF4aQ.png" /><figcaption>Fig: Declaration of Inheritance in Java</figcaption></figure><p>Types of Inheritance</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*j5MM5JlVA4hRmBqQ.png" /><figcaption>Types of Inheritance</figcaption></figure><p>Java supports only three types of inheritance for classes: single, multilevel, and hierarchical. Multiple and hybrid inheritance is supported through interface only.</p><h3>4. Polymorphism:-</h3><p>The derivation of the word Polymorphism is from two different Greek words- poly and morphs. “Poly” means many and “Morphs” means forms. So polymorphism means many forms. Polymorphism is one of the most significant features of Object-Oriented Programming.</p><p><strong>A real-life example of polymorphism:</strong> A person at the same time can have different characteristics. Like a man at the same time is a father, a husband, an employee. So the same person posses different behavior in different situations. This is called polymorphism.</p><p><strong>In Java polymorphism is mainly divided into two types:</strong></p><ol><li>Compile-time Polymorphism</li></ol><p>Compile-time is also called static polymorphism and the method overloading. In a class, if two methods with the same name but a different number of parameters or different data type of parameter is present then its called compile-time polymorphism. A real-time example of Compile time polymorphism is Notepad, if we ctrl+A button then it selects all the characters and if we press ctrl+Z then it performs undo operation. Let’s see an example</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/336/0*amiEML48AOr7K4e1.png" /><figcaption>Fig: Compile time Polymorphism</figcaption></figure><p>2. Runtime Polymorphism</p><p>Runtime polymorphism is also called Dynamic polymorphism and Method overriding. If two or more classes present the methods with the same name, the same number of parameters, and the same data types of parameters. Let see a real-time example of runtime polymorphism. Tv remote, In tv remote, if we press the volume on home then it will work to increase or decrease volume, and if we to setting and press the volume key then it will increase or decrease the brightness of tv screen. Here the Home is one class and volume key is a parameter and the setting is another class. The volume key in the home class works to change volume and in setting class works to change the brightness of tv screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/380/0*HapGuxeXhFx1uEdV.png" /><figcaption>Fig: Method Overriding</figcaption></figure><h3>5. Encapsulation:-</h3><p>Encapsulation is the process that binds together the data and code into a single unit and keeps both from being safe from outside interference and misuse. In this process, the data is hidden from other classes and can be accessed only through the current class’s methods. Hence, it is also known as data hiding. Encapsulation acts as a protective wrapper that prevents the code and data from being accessed by outsiders.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/541/0*i6sebQJHoB-Y866G.jpeg" /></figure><p>Encapsulation is achieved by declaring the variables as private and providing public setter and getter methods to modify and view the variable values(It is also called POJO class). In encapsulation, the fields of a class are made read-only or write-only. This method also improves the re-usability. Let’s see the example of Encapsulation</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/429/0*7_2wcweGVp-kjX09.png" /><figcaption>Fig: Encapsulation</figcaption></figure><h3>6. Abstraction:-</h3><p>Data abstraction is a process of showing only essential things (functional things) and hiding details (internal working).</p><p>Let’s see some real-time examples of abstraction</p><p><strong>Car</strong>:- In a car, we know the functionality of breaks and accelerators. In breaks, we know that if we press the brake, the car stops, but we don’t know the internal mechanism of breaks. In the accelerator, we know that after pressing the accelerator the speed of the car is increased but how the speed was increased we don’t know that. That is the concept of abstraction.</p><p><strong>ATM:- </strong>In ATM we see options like withdrawal, mini statement, change pin, etc. but we don’t know how it actually works internally what is the internal working of that machine.</p><p>In Java, we can achieve abstraction using abstract class as well as interface. Let’s see one by one.</p><ol><li>Abstract Class:-</li></ol><p>The class which is declared by abstract keyword is known as abstract class. By using the abstract class we can achieve 0 to 100% of abstraction. We can not create the object (Instance) of an abstract class. An abstract class contains abstract methods as well as non-abstract methods. The abstract method(only signature, no implementation) defined in the abstract class is must be implemented by the child class.</p><p>Let’s see the declaration of abstract class and abstract method.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/308/0*cnaCdOYLv2FHczXA.png" /><figcaption>Fig: Declaration of abstract class</figcaption></figure><p>2. Interface:-</p><p>The interface is a blueprint of class in which all the methods are abstract, as well as all the variables, are final, static, and public. By using the interface we can achieve 100% of abstraction. An interface can not contain any constructor. We can not create objects of the interface. To use interface methods and variables must be inherited and implemented all the methods by the child class. And one interface can inherit another interface by using extends keyword.</p><p>Let’s see the declaration of the interface</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/499/0*wSa0RDdUrB-cY9zo.png" /><figcaption>Fig: Declaration of Interface</figcaption></figure><p>Advantages of interfaces in Java</p><ol><li>We can achieve 100% abstraction by the interface.</li><li>By using interfaces we can achieve multiple inheritances in java which is not supported by using class.</li><li>It is also used to achieve loose coupling.</li></ol><h3>Association</h3><p>Association is the relation between two different classes that is established via their objects. Association can be in many forms:</p><ul><li>One-to-One</li><li>One-to-Many</li><li>Many-to-One</li><li>Many-to-Many.</li></ul><h3>Aggregation</h3><p>Aggregation is a special form of Association which represents <strong>the Has-A</strong> relationship. It is an uni-directional Association where both the entries can survive individually.</p><h3>Composition</h3><p>Composition is a more restrictive form of aggregation that makes two entities highly dependent on each other. It represents the <strong>part-of </strong>relationship where the composed object <strong>cannot exist</strong> without the other entity.</p><p><strong>Java Oop CheatSheet</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*SkI-biF7oLSvP1BD.png" /><figcaption><strong>Java Oop CheatSheet</strong></figcaption></figure><p>When designing object-oriented software in Java, it’s important to know when to use inheritance, polymorphism, abstraction, and encapsulation. Here are some guidelines:</p><ol><li>Inheritance: Use inheritance when you have classes that share common attributes and behaviors. The superclass can define the common attributes and behaviors, while the subclasses can add or override attributes and behaviors as needed. Inheritance can help reduce code duplication and make your code more modular and extensible.</li><li>Polymorphism: Use polymorphism when you have classes that have different behaviors but share a common interface or superclass. Polymorphism allows you to write code that can work with different objects in a uniform way, without having to know the exact type of each object. This can make your code more flexible and easier to maintain.</li><li>Abstraction: Use abstraction when you want to hide the implementation details of a class and expose only its essential features. Abstraction can be achieved using abstract classes and interfaces. Abstract classes define the essential features of a class, while leaving the implementation details to the subclasses. Interfaces define a common set of methods that classes can implement, without providing any implementation details.</li><li>Encapsulation: Use encapsulation when you want to hide the internal state of a class and control access to its methods. Encapsulation can help ensure that the internal state of a class is consistent and valid, while also providing a clear and secure interface for interacting with the class.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d3fb36af31b0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is Git?]]></title>
            <link>https://medium.com/@chandanravi54/what-is-git-1aed493dc323?source=rss-354770683ac4------2</link>
            <guid isPermaLink="false">https://medium.com/p/1aed493dc323</guid>
            <dc:creator><![CDATA[Chandan ravi]]></dc:creator>
            <pubDate>Sun, 23 Apr 2023 16:42:17 GMT</pubDate>
            <atom:updated>2023-04-23T16:42:17.327Z</atom:updated>
            <content:encoded><![CDATA[<p>Git is a powerful and popular version control system that has revolutionized the way software developers collaborate and manage their code. But what if I told you that Git is more than just a version control system? What if I told you that Git is actually a time machine?</p><p>Yes, you read that right. Git is a time machine. Think about it. When you commit changes to your code in Git, you’re essentially creating a snapshot of your code at that moment in time. You can then go back in time and view that snapshot whenever you want. But it doesn’t stop there.</p><p>Let’s say you make a mistake and accidentally delete an important file from your codebase. With Git, you can use the time machine to go back in time to a previous commit where that file still exists, and restore it. It’s like going back in time to prevent a disaster!</p><p>But wait, there’s more. With Git, you can also create branches, which are essentially alternate timelines for your code. You can work on a new feature in a branch without affecting the main codebase, and then merge that branch back into the main codebase when you’re ready. It’s like creating a parallel universe for your code.</p><p>And if you’re working on a project with multiple developers, Git’s time machine capabilities become even more powerful. You can collaborate on the same codebase, and use Git to keep track of who made what changes, when they made them, and why. It’s like having a time machine that lets you see who did what, when they did it, and why they did it.</p><p>So there you have it. Git is not just a version control system. It’s a time machine that lets you go back in time, prevent disasters, create parallel universes, and collaborate with other developers in a powerful and efficient way. So next time you use Git, remember that you’re not just managing code. You’re traveling through time.</p><p>Here are some common Git commands and what they do:</p><ul><li>git init: Initializes a new Git repository in the current directory.</li><li>git add .: Adds all changes in the current directory to the staging area.</li><li>git commit -m &quot;commit message&quot;: Commits changes in the staging area to the repository with a commit message describing the changes.</li><li>git status: Shows the status of the working directory and the staging area.</li><li>git branch: Lists all branches in the repository.</li><li>git checkout -b new_branch: Creates a new branch named &quot;new_branch&quot; and switches to it.</li><li>git merge other_branch: Merges changes from &quot;other_branch&quot; into the current branch.</li><li>git pull: Fetches changes from the remote repository and merges them into the local repository.</li><li>git push: Pushes changes from the local repository to the remote repository.</li></ul><h4>Learn Git Commands in easy and fun way with visuals</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kw1nPwGFJvVjEukKfpR2IA.png" /><figcaption><strong>Git Commands Visually Representation</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d9u3vdkKVqQRzMCWUgbTQg.png" /><figcaption><strong>Git Merge Visual Representation</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zevoDb-ISnSZtZ_FvdOkdg.png" /><figcaption><strong>Git Push Visual Representation</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IG6ueh_1nxj534ADvg5EOw.png" /><figcaption><strong>Git Pull Visual Representation</strong></figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1aed493dc323" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>