<?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 Suyash Thonte on Medium]]></title>
        <description><![CDATA[Stories by Suyash Thonte on Medium]]></description>
        <link>https://medium.com/@suyashthonte0?source=rss-2dfaab368a47------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Ums56zDONU02w1MSdFIk3g.jpeg</url>
            <title>Stories by Suyash Thonte on Medium</title>
            <link>https://medium.com/@suyashthonte0?source=rss-2dfaab368a47------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 10:25:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@suyashthonte0/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[Spring Framework]]></title>
            <link>https://suyashthonte0.medium.com/spring-framework-5dd2d5ff9e95?source=rss-2dfaab368a47------2</link>
            <guid isPermaLink="false">https://medium.com/p/5dd2d5ff9e95</guid>
            <category><![CDATA[spring]]></category>
            <category><![CDATA[spring-framework]]></category>
            <category><![CDATA[java-spring]]></category>
            <dc:creator><![CDATA[Suyash Thonte]]></dc:creator>
            <pubDate>Mon, 14 Dec 2020 02:03:34 GMT</pubDate>
            <atom:updated>2020-12-14T02:03:34.347Z</atom:updated>
            <content:encoded><![CDATA[<p>Hey Guys, Of all the seasons in the year, Spring is considered the best season. You guys must be wondering is this a technical blog or a weather blog ??</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/225/1*rtX5hVpBvd65DDL2Gh9FmQ.jpeg" /></figure><p>So basically every normal person likes the Spring. Same is the choice in case of Java Developers. So here I am referring to the best and most preferred Java Framework i.e <strong>Java Spring</strong>. So let us get started with Spring Core and its concepts.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y3buDKXxF5ns8ZRU4gjuSQ.jpeg" /></figure><h4>Why Spring?</h4><p>In the early, most of the software was created using <strong>Java Platform, Enterprise Edition (J2EE) </strong>that had many drawbacks i.a. applications were really heavy even though they’re business logic was really small. Also time spent on them was not proportionate to the outcome, because many of configurations had to made by the developer.</p><p>Hence Spring was developed to overcome the drawbacks of J2EE. The main goal of Spring framework is to simplify the development of enterprise software so it can be done quicker, because most of boilerplate configuration code are handled by the framework.</p><p>Spring makes programming Java quicker, easier, and safer for everybody. Spring’s focus on speed, simplicity, and productivity has made it the <a href="https://snyk.io/blog/jvm-ecosystem-report-2018-platform-application/">world’s most popular</a> Java framework.</p><h4>What is Spring?</h4><p>Spring Framework is an open source Java platform that provides comprehensive infrastructure support for developing Java applications. Spring handles the infrastructure so you can focus on your application.Spring enables you to build applications from “plain old Java objects” (POJOs) and to apply enterprise services to POJOs.</p><p>For example using Spring a developer can :</p><ul><li>Make a Java method execute in a database transaction without having to deal with transaction APIs.</li><li>Make a local Java method a remote procedure without having to deal with remote APIs.</li><li>Make a local Java method a management operation without having to deal with JMX APIs.</li><li>Make a local Java method a message handler without having to deal with JMS APIs.</li></ul><p>To achieve all the advantages above, Spring relies on these following concepts:</p><ol><li><strong>Modular Architecture</strong></li><li><strong>Plain Old Java Objects (POJOs)</strong></li><li><strong>Dependency Injection/Inversion of Control (IoC)</strong></li><li><strong>Aspect Oriented Programming (AOP)</strong></li></ol><h4>1. Modular Architecture</h4><p>The whole idea of Spring is to modularize whole framework into smaller pieces which allows you to decide which ones to use in your application. Also, the functionality of a program is split into independent modules, such that each module contains one specific functionality<em>.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/851/1*rT4KWGkp8ywC0kVmq4FmpQ.jpeg" /><figcaption>Spring Architecture</figcaption></figure><p><strong>A.) Core Container.</strong></p><p>The Core container from Spring consists of four modules: <strong>SpEL , Context, Core, Beans.</strong></p><ul><li><strong>SpEL</strong> module provides a powerful expression language for manipulating objects during execution.</li><li><strong>Context</strong> is built on the basis of Beans and Core and allows you to access any object that is defined in the settings. The key element of the Context module is the ApplicationContext interface.</li><li><strong>Core</strong> module provides key parts of the framework including IoC and DI properties.</li><li><strong>Bean</strong> module is responsible for creating and managing Spring Beans.</li></ul><p><strong>B.) Spring Framework Web:</strong></p><p>Spring Framework Web layer consists of Web, Web-MVC, Web-Socket, Web-Portlet etc.</p><ul><li><strong>WEB</strong> module provides functions such as downloading files, creating web application, rest web service etc..</li><li><strong>Web-MVC</strong> contains a Spring MVC implementation for web applications.</li><li><strong>Web-Socket</strong> provides support for communication between the client and the server, using Web-Sockets in web applications.</li><li><strong>Web-Portlet</strong> provides MVC implementation with portlet environment.</li></ul><p><strong>C.) Spring Framework Data Access:</strong></p><p>The Data Access/Integration container consists of JDBC, ORM, OXM, JMS and the Transactions module.</p><ul><li><strong>JDBC </strong>provides an abstract layer of JDBC and eliminates the need for the developer to manually register the monotonous code associated with connecting to the database.</li><li><strong>Spring ORM</strong> provides integration with such popular ORMs as Hibernate, JDO, JPA, etc.</li><li><strong>OXM</strong> module is responsible for linking the Object / XML — XMLBeans, JAXB, etc.</li><li><strong>JMS (Java Messaging Service)</strong> module is responsible for creating, sending and receiving messages.</li><li><strong>Transactions</strong> supports transaction management for classes that implement certain methods and POJOs.</li></ul><p><strong>D.) Test:</strong></p><p>Spring supports Test Driven Development by providing mock-up objects for unit testing and also many features that allows to make integration tests.</p><h4>2. Plain Old Java Objects (POJOs)</h4><p>POJOs are simple Java Objects that do not contains any dependencies in it. They don’t implement any interface or extend any class as it is required by many frameworks. The benefits of such approach is that a solution to a problem is not directly tied to the framework or it is not directly tied to other solutions, so if wechange some part of the application other part won’t be affected.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NDOOS8Dp1aX51zhuyOB1ng.jpeg" /></figure><pre>public class EmployeePojo {<br>      public String firstName;<br>      public String lastName;<br>      private LocalDate startDate;<br>      <br>      public EmployeePojo(String firstName, String lastName,       LocalDate startDate) {<br>         this.firstName = firstName;<br>         this.lastName = lastName;<br>         this.startDate = startDate;<br>     }      <br>      public String name() {<br>         return this.firstName + <strong>&quot; &quot;</strong> + this.lastName;<br>     }<br>      public LocalDate getStart() {<br>         return this.startDate;<br>     } <br>}</pre><p>This class can be used by any Java program as it’s not tied to any framework.</p><h4>3. Dependency Injection/Inversion of Control (IoC)</h4><p><strong>Dependency Injection</strong> : It is a design pattern, in which for each function of the application there is one, a conditionally independent object (service) that can have the need to use other objects (dependencies) known to it by interfaces. Dependencies are transferred (implemented) to the service at the time of its creation. In practice, DI is implemented by passing parameters to the constructor or using setters. Libraries that implement this approach are also called <strong>IoC containers.</strong></p><p>So, what exactly is inversion of control?</p><p>IoC is also known as dependency injection (DI). It is a process whereby objects define their dependencies (that is, the other objects they work with) only through constructor arguments, arguments to a factory method, or properties that are set on the object instance after it is constructed or returned from a factory method. The container then injects those dependencies when it creates the bean. This process is fundamentally the inverse (hence the name, Inversion of Control) of the bean itself controlling the instantiation or location of its dependencies by using direct construction of classes or a mechanism such as the Service Locator pattern.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/454/1*WfA2sSrhnH6ak6W_284sAw.jpeg" /></figure><p><strong><em>Spring IOC Container :</em></strong> Spring IoC container classes are part of org.springframework.beans and org.springframework.context packages. Spring IoC container provides us different ways to decouple the object dependencies.</p><p>BeanFactory is the root interface of Spring IoC container. ApplicationContext is the child interface of BeanFactory interface that provide Spring AOP features, i18n etc.</p><p><strong><em>Spring Bean : </em></strong>Any object in the Spring framework that we initialize through Spring container is called Spring Bean. Any normal Java POJO class can be a Spring Bean if it’s configured to be initialized via container by providing configuration metadata information.</p><p>Bean has following scopes :</p><ol><li><strong>singleton</strong> — Single bean object instance per spring IoC container</li><li><strong>prototype</strong> — A new instance will be created every time the bean is requested.</li><li><strong>request</strong> — This is same as prototype scope, however it’s meant to be used for web applications. A new instance of the bean will be created for each HTTP request.</li><li><strong>session</strong> — A new bean will be created for each HTTP session by the container.</li><li><strong>global-session</strong> — This is used to create global session beans for Portlet applications.</li><li><strong>websocket — </strong>A single instance will be created and available during complete lifecycle of WebSocket.</li></ol><p>Also there are three ways to configure Spring Beans :</p><ol><li><strong>XML Based Configuration</strong> — It is considered as an old-fashioned. It was introduced in first releases of Spring, so you can find it in the old projects, but it is still used. The idea is to have single or multiple XML files that contains a list of Beans (i.e. Java objects) that can be registered into Spring container. If you are using Spring MVC framework, the xml based configuration can be loaded automatically by writing some boiler plate code in web.xml file.</li><li><strong>Annotation Based Configuration</strong> — Using this, Spring will scan for Java classes with special annotations. So in this we only add annotation above class name and the framework will do all the work for us. Following are the annotations :</li></ol><ul><li><strong>@Component </strong>— it is a standard annotation and can be added to any type of Java class.</li><li><strong>@Repository</strong> — it is used for Data Access Objects (DAO) that are responsible for retrieving information from the database,</li><li><strong>@Service</strong> — this one is used for service layer classes, they working as a middleman between UI and DAO and responsible for processing data and whole business logic,</li><li><strong>@Controller</strong> — classes with these annotations are taking care of user requests in UI.</li></ul><blockquote>Scope details can be provided with @Scope annotation.</blockquote><ol><li><strong>Java Based Configuration</strong> — Starting from Spring 3.0, we can configure Spring beans using java programs. Some important annotations used for java based configuration are :</li></ol><ul><li>@Configuration : This tells Spring that it is a config file.</li><li>@ComponentScan :This tells Spring that the User bean will be created after the Address, not before.</li><li>@Bean.</li></ul><h4>4. Aspect Oriented Programming (AOP)</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*omhRoi8fWuobb-LcRlQ_Kw.jpeg" /></figure><p>Aspect-oriented Programming (AOP) complements Object-oriented Programming (OOP) by providing another way of thinking about program structure. The key unit of modularity in OOP is the class, whereas in AOP the unit of modularity is the aspect. <strong>Aspects</strong> enable the modularization of concerns (such as transaction management) that cut across multiple types and objects. (Such concerns are often termed “crosscutting” concerns in AOP literature). So in short, It allows the separation of cross-cutting concerns from the business logic. By “cross-cutting concerns” we mean features that span across different parts of the application and tend to affect the entire application like logging, security, caching etc.</p><p>📣 But, why exactly would be face such requirements?</p><p>Let’s say you want to make a specific security consideration in the application. If the security consideration is used across many methods, then this changed is gonna be a huge one. That’s when AOP could save us.</p><p>AOP can solve this problem by allowing us to express cross-cutting concerns in stand-alone modules i.e the aspects.</p><p>So in short, AOP is used in the Spring Framework to:</p><ul><li>Provide declarative enterprise services. The most important such service is <a href="https://docs.spring.io/spring-framework/docs/current/reference/html/data-access.html#transaction-declarative">declarative transaction management</a>.</li><li>Let users implement custom aspects, complementing their use of OOP with AOP.</li></ul><p><strong>Some Extra Modules of Spring:</strong></p><p>Spring also includes a number of other important modules, such as Aspects, Instrumentation, Messaging, and Test.</p><ul><li>The Aspects module provides integration with AspectJ, which is also a powerful AOP framework.</li><li>Instrumentation is responsible for supporting class instrumentation and class loader, which are used in server applications.</li><li>The Messaging module provides STOMP support.</li><li>Finally, the Test module provides testing using TestNG or the JUnit Framework.</li></ul><p>So that was all about Spring Framework and its concepts!</p><p>See you Guys in the next Blog!!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5dd2d5ff9e95" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Java Servlets and JSP]]></title>
            <link>https://suyashthonte0.medium.com/java-servlets-and-jsp-3050485b678d?source=rss-2dfaab368a47------2</link>
            <guid isPermaLink="false">https://medium.com/p/3050485b678d</guid>
            <category><![CDATA[jsp]]></category>
            <category><![CDATA[servlet]]></category>
            <category><![CDATA[client-server-model]]></category>
            <category><![CDATA[java-servlet]]></category>
            <dc:creator><![CDATA[Suyash Thonte]]></dc:creator>
            <pubDate>Mon, 07 Dec 2020 03:52:34 GMT</pubDate>
            <atom:updated>2020-12-07T03:52:34.969Z</atom:updated>
            <content:encoded><![CDATA[<p>So You would have heard of Client and Server. So what is Client and Server?</p><ul><li>So a <strong>Client</strong> is a computer which is capable of receiving information or using a particular service from the service providers (<strong>Servers</strong>).</li><li>Similarly, a <strong>Server</strong> is a remote computer which provides information (data) or access to particular services.</li></ul><p><strong>What happens between the client and server is pretty simple to understand </strong>, i.e ,<strong> </strong>the Client requests for something and the Server serves it as long as its present in it’s database.</p><p>So let’s start with Client Server Architecture.</p><p>So What is Client-Server Architecture?</p><p><strong>Client Server Architecture</strong> is a computing model in which the server hosts, delivers and manages most of the resources or services or data which is required by the client. This type of architecture has one or more client computers connected to a central server over a network or internet connection.</p><p>Such an architecture is also known as a networking computing model or client/server network because all the requests and services are delivered over a network.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/303/1*jKfoKu2PAYHxs-3_bRKY3A.gif" /></figure><p>Now, let’s dive into Servlets.</p><h3>Servlets</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5PFcgkM1Cb9kGZFwAXEnrA.png" /></figure><p><strong>Servlet</strong> is a java program that runs inside JVM on the web server. It is basically used for developing dynamic web applications. You need to use the Servlet API to create servlets.</p><p>There are two packages that you must remember while using API, the javax.servlet package that contains the classes to support generic servlet (protocol-independent servlet) and the javax.servlet.http package that contains classes to support http servlet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/870/1*BKsrHcLrsHA1qkuoQjIGfw.jpeg" /></figure><h4>LifeCycle of Servlet :</h4><ol><li>Servlet class is loaded : A Servlet class is loaded when first request for the servlet is received by the Web Container.</li><li>Servlet instance is created : After the Servlet class is loaded, Web Container creates the instance of it. Servlet instance is created only once in the life cycle.</li><li>init() method is invoked : Step 1, Step 2, Step 3 are executed only once, when the servlet is initially loaded. The init() method is called by the Web Container on servlet instance to initialize the servlet. For e.g, Syntax :<strong>public void init(ServletConfig config) throws ServletException</strong></li><li>service() method is invoked : executed multiple times — once for every HTTP request to the servlet. The containers call the service() method each time the request for servlet is received. The service() method will then call the doGet() or doPost() method based on the type of the HTTP request. Syntax : <strong>public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException</strong></li><li>destroy() method is invoked : executed when the servlet container unloads the servlet. The Web Container call the destroy() method before removing servlet instance, giving it a chance for cleanup activity.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/356/1*4OIsae1ihWDy9zoqEj3mGw.png" /></figure><h4>ServletRequest Interface</h4><p>ServletRequest interface is used to provide client request information to the servlet. Servlet container creates ServletRequest object from client request and pass it to the servlet service() method for processing. The child interface of ServletRequest is <strong>HttpServletRequest</strong> interface which adds the methods that relates to the <strong>HTTP</strong> protocol. It contains methods for session management, cookies and authorization of request.</p><p>Following are some of the methods of ServletRequest Interface :</p><ol><li><strong>String getParameter(String name)</strong> — This method returns the request parameter as String.</li><li><strong>Object getAttribute(String name)</strong> — This method returns the value of named attribute as Object and null if it’s not present. This interface also provide methods for setting and removing attributes.</li><li><strong>setAttribute(String name, Object o)</strong> — stores an attribute in this request.</li><li><strong>String getServerName()</strong> — returns the hostname of the server.</li><li><strong>int getServerPort()</strong> — returns the port number of the server on which it’s listening.</li><li><strong>Cookies getCookies() — </strong>returns an array containing all of the Cookie objects the client sent with this request</li><li><strong>String getMethod() — </strong>Returns the name of the HTTP method with which this request was made, for example, GET, POST, or PUT.</li><li><strong>HttpSession getSession() —</strong> returns the current HttpSession associated with this request or, if there is no current session and create is true, returns a new session</li></ol><h4>ServletResponse Interface</h4><p>Servlet API provides two important interfaces <strong>ServletResponse</strong> and <strong>HttpServletResponse</strong> to assist in sending response to client. In <strong>HttpServletResponse, </strong>Servlet container creates the ServletResponse object and passes it to Servlet service() method and later uses the response object to generate the HTML response for client.</p><p>Following are some of the methods of ServletResponse Interface :</p><ol><li>PrintWriter getWriter()returns a PrintWriter object that can send character text to the client.</li><li><strong>void addCookie(Cookie cookie)</strong> — Used to add cookie to the response.</li><li><strong>void addHeader(String name, String value)</strong> — used to add a response header with the given name and value.</li><li><strong>String encodeURL(java.lang.String url)</strong> — encodes the specified URL by including the session ID in it, or, if encoding is not needed, returns the URL unchanged.</li><li><strong>String getHeader(String name)</strong> — return the value for the specified header, or null if this header has not been set.</li><li><strong>void sendRedirect(String location)</strong> — used to send a temporary redirect response to the client using the specified redirect location URL.</li></ol><h4><strong>void setStatus(int sc)</strong> — used to set the status code for the response.</h4><h4>Request Dispatcher Interface</h4><p>Request Dispatcher can be used whenever we want to call a servlet from another servlet. It is used to forward the request to another resource that can be HTML, JSP or another servlet in the same context.</p><p>Following are the methods of Request Dispatcher Interface :</p><ol><li><strong>void forward(ServletRequest request, ServletResponse response)</strong> — forwards the request from a servlet to another resource (servlet, JSP file, or HTML file) on the server.</li><li><strong>void include(ServletRequest request, ServletResponse response)</strong> — includes the content of a resource (servlet, JSP page, HTML file) in the response.</li></ol><pre>RequestDispatcher rd = request.getRequestDispatcher(&quot;index.html&quot;);<br>rs.forward(request,response);</pre><pre>RequestDispatcher rd = request.getRequestDispatcher(&quot;index.html&quot;);<br>rs.include(request,response);</pre><h4>sendRedirect() Method</h4><p>sendRedirect() method redirects the response to another resource. This method actually makes the client(browser) to create a new request to get to the resource. The client can see the new url in the browser.</p><h4><strong>Session Management</strong></h4><p><strong>Session Management</strong> is a mechanism used by the <strong>Web container</strong> to store session information for a particular user. There are four different techniques used by Servlet application for session management. They are as follows:</p><ol><li><strong>Cookies : Cookies</strong> are small pieces of information that are sent in response from the web server to the client. They are stored on client’s computer.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*2FM73oKon6XlHHMjpvncZA.jpeg" /></figure><pre>pCookies ck =  new Cookie(&quot;username&quot;, Suyash); //Create a Cookie object<br>ck.setMaxAge(30*60); //Set the maximum Age:<br>response.addCookie(ck); //Place the Cookie in HTTP response header:<br>Cookie[] cks = request.getCookies(); // getting the cookie for response object.</pre><p><strong>2. Hidden form field : </strong>Hidden form field can also be used to store session information for a particular client. In case of hidden form field a hidden field is used to store client state. In this case user information is stored in hidden field value and retrieved from another servlet.</p><p><strong>3. URL Rewriting : </strong>In URL rewriting, a token(parameter) is added at the end of the URL. The token consist of name/value pair seperated by an equal(=) sign. When the User clicks on the URL having parameters, the request goes to the <strong>Web Container</strong> with extra bit of information at the end of URL. The <strong>Web Container</strong> will fetch the extra part of the requested URL and use it for session management. The getParameter() method is used to get the parameter value at the server side.</p><p><strong>4. HttpSession : HttpSession</strong> object is used to store entire session with a specific client. We can store, retrieve and remove attribute from <strong>HttpSession</strong> object. Any servlet can have access to <strong>HttpSession</strong> object throughout the getsession() method of the <strong>HttpServletRequest</strong> object.</p><pre>protected void doPost(HttpServletRequest req,<br> HttpServletResponse res)<br> throws ServletException, IOException {<br> HttpSession session = req.getSession();<br>}</pre><h4>Sevlet Filter</h4><p><strong>Filter</strong> is a compontent that you can use and configure to perform some filtering tasks. It is mainly used to perform filtering tasks such as conversion, logging, compression, encryption and decryption, input validation etc. The F<strong>ilter is pluggable</strong>, i.e. its entry is defined in the web.xml file, if we remove the entry of filter from the web.xml file, filter will be removed automatically and we don’t need to change the servlet. The filtering API is defined by the Filter, FilterChain, and FilterConfig interfaces in the javax.servlet package. For creating a filter, we must implement Filter interface.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/260/1*pxCaOxsmd3sqBgce3qo_Iw.jpeg" /></figure><p>Following are the methods of filter life cycle :</p><ol><li>void init(FilterConfig filterConfig): invoked by the web container to indicate to a filter that it is being placed into service.</li><li>void doFilter(ServletRequest request, ServletResponse response, FilterChain chain): invoked by the container each time a request/response pair is passed through the chain due to a client request for a resource at the end of the chain.</li><li>void destroy(): invoked by the web container to indicate to a filter that it is being taken out of service.</li></ol><h3>Java Server Pages</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/520/1*okUU3D67ZDbtOc_RFjFwbg.png" /></figure><p>Now, Java Server Pages (JSP) also follow a similar client-server architecture. However, unlike client-server , it is a 3 -tier architecture. It can be thought of as an extension to Servlet because it provides more functionality than servlet such as expression language, JSTL, etc.</p><p>A server (generally referred to as application or web server) supports the Java Server Pages. This server will act as a mediator between the client browser and a database. The following diagram shows the <strong>JSP architecture</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*oRe-RVV7t8WHWOAkoV2ZBw.png" /><figcaption>JSP Architecture</figcaption></figure><p><strong>Here’s what happens 👇</strong></p><ul><li>The user goes to a JSP page and makes the request via internet in user’s web browser.</li><li>The JSP request is sent to the Web Server.</li><li>Web server accepts the requested <strong>.jsp</strong> file and passes the JSP file to the JSP Servlet Engine.</li><li>If the JSP file has been called the first time then the JSP file is parsed otherwise servlet is instantiated. The next step is to generate a servlet from the JSP file.</li><li>The generated servlet output is sent via the Internet form web server to users web browser.</li><li>Now in last step, HTML results are displayed on the users web browser.</li></ul><blockquote>jspInit(), _jspService() and jspDestroy() are the life cycle methods of JSP.</blockquote><p>What differentiates JSP from HTML is the ability to use java code inside HTML. In JSP, you can embed Java code in HTML using JSP tags.</p><pre>&lt;HTML&gt;<br>&lt;BODY&gt;<br>Hello World! <br>Current time is: &lt;%= new java.util.Date() %&gt;<br>&lt;/BODY&gt;<br>&lt;/HTML&gt;</pre><p><strong>Here’s how the life cycle flows in JSP :</strong></p><p>1) Whenever container receives request from client, it does translation only when servlet class is older than JSP page otherwise it skips this phase.</p><p>2) Then the container –</p><ul><li>Compiles the corresponding servlet program</li><li>Loads the corresponding servlet class</li><li>Instantiates the servlet class</li><li>Calls the <strong>jspInit() method</strong> to initialize the servlet instance (JSP container will do this job only when the instance of servlet file is not running or if it is older than the JSP file.)</li></ul><p>3) A new thread then gets created, which invokes the<strong>_jspService() method</strong>, with a request (HttpServletRequest) and response (HttpServletRespnse) objects as parameters.</p><p>4) And finally, invokes the <strong>jspDestroy() method</strong> to destroy the instance of the servlet class.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/426/1*vUcOvJMcwfT1QhLLEhNr5g.png" /><figcaption>JSP Life-Cycle</figcaption></figure><p>The scripting elements provides the ability to insert java code inside the jsp. There are three types of scripting elements:</p><p><strong>1.Directives — </strong>JSP directives are used for controlling the processing of a JSP page. Directives provide information to the server on how the page should be processed. There are three types of directives:</p><ul><li><strong>page directive : </strong>The page directive defines attributes that apply to an entire JSP page.</li></ul><pre>&lt;%@ page attribute=”value” %&gt;</pre><ul><li><strong>include directive :</strong> The include directive is used to include the contents of any resource it may be jsp file, html file or text file.</li></ul><pre>&lt;%@ include file=&quot;header.html&quot; %&gt;</pre><ul><li><strong>taglib directive :</strong> The JSP taglib directive is used to define a tag library that defines many tags. We use the TLD (Tag Library Descriptor) file to define the tags.</li></ul><pre>&lt;%@ taglib uri = &quot;http://www.myWebPage.com/tags&quot; prefix=&quot;mytag&quot; %&gt;</pre><p><strong>2. Scriptlets — </strong>We can use java code in JSP using scriptlets. The JSP container moves the scriptlet content into the _jspService() method which is available to the server during processing of the request. In Scriplets there are these 3 tags :</p><ul><li><strong>scriptlet tag :</strong> A scriptlet tag is used to execute java source code in JSP.</li></ul><pre><strong>&lt;</strong>% out.print(&quot;welcome to jsp&quot;); %<strong>&gt;</strong></pre><ul><li><strong>expression tag :</strong> The code placed within <strong>JSP expression tag</strong> is <em>written to the output stream of the response. </em>It is mainly used to print the values of variable or method.</li></ul><pre><strong>&lt;</strong>%= “welcome to jsp” %<strong>&gt;</strong></pre><ul><li><strong>declaration tag :</strong> The <strong>JSP declaration tag</strong> is used <em>to declare fields and methods</em>.</li></ul><pre><strong>&lt;</strong>%! int cube(int n){ return n*n*n*; } %&gt;</pre><ul><li><strong>Action Tags — </strong>They are used for performing an action during request processing phase of JSP life cycle. There are many JSP action tags or elements. Each JSP action tag is used to perform some specific tasks. The action tags are used to control the flow between pages and to use Java Bean.</li></ul><pre><strong>&lt;jsp:forward page=&quot;relativeURL | &lt;%= expression %&gt;&quot; /&gt; <br>//</strong>used to forward the request to another resource it may be jsp, html or another resource.<strong><br>&lt;jsp:include page=&quot;relativeURL | &lt;%= expression %&gt;&quot; /&gt;<br></strong>//used to include the content of another resource it may be jsp, html or servlet. <br><strong>&lt;jsp:useBean id= &quot;instanceName&quot; scope= &quot;page | request | session | application&quot; class= &quot;packageName.className&quot; type= &quot;packageName.className&quot; beanName=&quot;packageName.className | &lt;%= expression &gt;&quot; &gt; &lt;/jsp:useBean&gt;</strong><br>//used to locate or instantiate a bean class.<br><strong>&lt;jsp:setProperty name=&quot;instanceOfBean&quot; property= &quot;*&quot;   | property=&quot;propertyName&quot; param=&quot;parameterName&quot;  | property=&quot;propertyName&quot; value=&quot;{ string | &lt;%= expression %&gt;}&quot; /&gt;</strong><br>//sets a property value or values in a bean using the setter method.<strong>&lt;jsp:getProperty name=&quot;instanceOfBean&quot; property=&quot;propertyName&quot; /&gt;</strong><br> //returns the value of the property.</pre><p>So this was all about Servlets and JSP, Thank You so much for taking out time for reading this article, will see you guys in the next blog!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3050485b678d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CSS Flex Layout]]></title>
            <link>https://suyashthonte0.medium.com/css-flex-layout-68fdaf54d89b?source=rss-2dfaab368a47------2</link>
            <guid isPermaLink="false">https://medium.com/p/68fdaf54d89b</guid>
            <category><![CDATA[flexbox]]></category>
            <category><![CDATA[flex]]></category>
            <category><![CDATA[css-flexbox]]></category>
            <category><![CDATA[css]]></category>
            <dc:creator><![CDATA[Suyash Thonte]]></dc:creator>
            <pubDate>Mon, 30 Nov 2020 04:19:53 GMT</pubDate>
            <atom:updated>2020-11-30T04:19:53.753Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Hey Guyss !!</em></p><p><em>So,today I’m gonna light on a very interesting topic which makes CSS (Cascading Style Sheet) really stylish and flexible.</em></p><p>When i started my journey in Web Development, I used to think how the web pages looks so interactive and beautiful, which increased my interest in CSS.</p><p>CSS provide various properties that make a website look more beautiful and make it flexible and we are gonna discuss one such property today in this blog, i.e FLEX.</p><p>So before starting the actual content I wanna give you an overview about the flex(FlexBox) property in CSS.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HGXoBi1rjUFrv7LBtynokQ.jpeg" /></figure><p>The Flexible Box Module, usually referred to as Flexbox, makes it simple to align items vertically and horizontally using rows and columns. Here items means HTML elements. This method was designed to offer some space distribution between elements in a web page. In short Flexbox is used to position the elements.</p><p>Flexbox is one dimensional . When we describe flexbox as being one dimensional we are describing the fact that flexbox deals with layout in one dimension at a time — either as a row or as a column.</p><p>In flex box there is flex container , which is parent element of flex item<strong>.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/297/1*ci2cZm4nOG7g4C7gc4T_eA.png" /><figcaption><strong>Flexbox Container</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/296/1*1b-xecK4oyjXc2M0erwqoA.png" /><figcaption><strong>Flexbox item</strong></figcaption></figure><p>When working with flexbox you need to think in terms of two axes — the main axis and the cross axis. The main axis is defined by the <em>flex-direction</em> property, and the cross axis runs perpendicular to it.</p><p>Now we will look at properties for the Parent<br>(flex container)</p><h4><strong>Properties for the Parent<br>(flex container)</strong></h4><h3><strong>display:</strong></h3><p>This defines a flex container; inline or block depending on the given value</p><h3><strong>Flex-direction:</strong></h3><p>This property is responsible for direction of the main axis.</p><p>Its values can be →</p><ol><li><strong>row : </strong>left to right.</li><li><strong>row- reverse</strong> : right to left.</li><li><strong>column</strong> : top to bottom.</li><li><strong>column- reverse</strong> : bottom to top.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/486/1*UukSoQywdES_BtkpP-r0LA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/806/1*Tai9RnJhu9rYaBf436ADXw.png" /><figcaption><strong>row : from left to right</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/781/1*s3AYlfgxEtHJnat86dYlKw.png" /><figcaption><strong>row-reverse : right to left</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/348/1*nwwhBNn5NZSBh6u2Ijl8fA.png" /><figcaption><strong>column and column-reverse respectively.</strong></figcaption></figure><h3><em>Flex Wrap :</em></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/344/1*wkMAKA4Doq9iM4xtA9CcIg.png" /><figcaption>flex- wrap</figcaption></figure><p>By default, flex items will all try to fit onto one line. You can change that and allow the items to wrap as needed with this property.</p><blockquote><strong><em>.container {</em></strong></blockquote><blockquote><strong><em>flex-wrap: nowrap | wrap | wrap-reverse;</em></strong></blockquote><blockquote><strong><em>}</em></strong></blockquote><p>→(default): all flex items will be on one line</p><p>→wrap: flex items will wrap onto multiple lines, from top to bottom.</p><p>→wrap-reverse: flex items will wrap onto multiple lines from bottom to top.</p><h3>flex-flow:</h3><p>This is a shorthand for the flex-direction and flex-wrap properties, which together define the flex container’s main and cross axes. The default value is row nowrap.</p><blockquote><strong><em>.container {</em></strong></blockquote><blockquote><strong><em>flex-flow: column wrap;</em></strong></blockquote><blockquote><strong><em>}</em></strong></blockquote><h3>justify-content:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/632/1*WKusXF3GN_oaogpIxP6smA.png" /></figure><p>This defines the alignment along the main axis. It helps distribute extra free space leftover when either all the flex items on a line are inflexible, or are flexible but have reached their maximum size. It also exerts some control over the alignment of items when they overflow the line.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/371/1*xWnUrCidMYDtfJoT1FST3w.png" /></figure><h4>→flex-start (default):</h4><p>Items are packed toward the start of the flex-direction.</p><h4>→flex-end:</h4><p>Items are packed toward the end of the flex-direction.</p><h4>→start :</h4><p>Items are packed toward the start of the writing-mode direction.</p><h4>→end:</h4><p>Items are packed toward the end of the writing-mode direction.</p><h4>→left:</h4><p>Items are packed toward left edge of the container, unless that doesn’t make sense with the flex-direction, then it behaves like start.</p><h4>→right:</h4><p>Items are packed toward right edge of the container, unless that doesn’t make sense with the flex-direction, then it behaves like start.</p><h4>→center:</h4><p>Items are centred along the line</p><h4>→space-between:</h4><p>Items are evenly distributed in the line; first item is on the start line, last item on the end line</p><h4>→space-around:</h4><p>Items are evenly distributed in the line with equal space around them. Note that visually the spaces aren’t equal, since all the items have equal space on both sides. The first item will have one unit of space against the container edge, but two units of space between the next item because that next item has its own spacing that applies.</p><h4>→space-evenly:</h4><p>Items are distributed so that the spacing between any two items (and the space to the edges) is equal.</p><h3>align-items:</h3><p>This defines the default behaviour for how flex items are laid out along the <strong>cross axis</strong> on the current line. Think of it as the justify-content version for the cross-axis (perpendicular to the main-axis).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/424/1*mm7CCKYxZXniEpKlSrxWkQ.png" /></figure><blockquote><strong><em>.container {</em></strong></blockquote><blockquote><strong><em>align-items: stretch | flex-start | flex-end | center | baseline | first baseline | last baseline | start | end | self-start | self-end + … safe | unsafe;</em></strong></blockquote><blockquote><strong><em>}</em></strong></blockquote><h4>→ (default):</h4><p>Items are packed in their default position as if no value was set.</p><h4>→flex-start :</h4><p>Items packed to the start of the container. The (more supported) flex-start honours the flex-direction while start honours the editing-mode direction.</p><h4>→flex-end:</h4><p>Items packed to the end of the container. The (more support) flex-end honours the flex-direction while end honours the writing-mode direction.</p><h4>→center:</h4><p>Items centred in the container</p><h4>→space-between:</h4><p>Items evenly distributed; the first line is at the start of the container while the last one is at the end</p><h4>→space-around:</h4><p>Items evenly distributed with equal space around each line</p><p>→space-evenly: items are evenly distributed with equal space around them</p><h4>→stretch :</h4><p>Lines stretch to take up the remaining space</p><p>SO this is it Guys, in this way we learnt about the CSS Flex-Layout Property and its various types as well as their functionalities, which help to build a more responsive and rich UI-based web-pages.</p><p>In the next blog, we will be discussing about another such powerful property of CSS which enhances web-page’s responsiveness.</p><p>Thank You for reading this blog, See you in the next one!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=68fdaf54d89b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CSS Grid Layout]]></title>
            <link>https://suyashthonte0.medium.com/css-grid-layout-90444dccd952?source=rss-2dfaab368a47------2</link>
            <guid isPermaLink="false">https://medium.com/p/90444dccd952</guid>
            <category><![CDATA[grid]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[css-grid]]></category>
            <category><![CDATA[grid-layout]]></category>
            <dc:creator><![CDATA[Suyash Thonte]]></dc:creator>
            <pubDate>Mon, 30 Nov 2020 04:00:11 GMT</pubDate>
            <atom:updated>2020-11-30T04:00:11.919Z</atom:updated>
            <content:encoded><![CDATA[<p><strong><em>Hey Guyss, in my last blog we have discussed about flex-box properties which is a one dimensional property, in this blog we will see one more interesting topic, i.e ‘Grid’ which is a two-dimensional property</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gcXtf3zpYLr7-dEOeTDcOg.jpeg" /></figure><p>CSS Grid Layout is the most powerful layout system available in CSS. It is a 2-dimensional system, meaning it can handle both columns and rows, unlike flex-box which is largely a 1-dimensional system.<strong>CSS Grid</strong> was built with <strong>responsiveness</strong> in mind, it’ll take less code than writing media queries all over the place.</p><p>Following are the properties of the grid which provide various different responsiveness and positioning to our web-page :</p><h3><strong>display:</strong></h3><p>Defines the element as a grid container and establishes a new grid formatting context for its contents.</p><p>Values:</p><p><strong>→grid</strong> : generates a block-level grid</p><p><strong>→inline-grid</strong> : generates an inline-level grid</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/326/1*qZ-WhZ0kGHlQg_CSS_6U8A.png" /></figure><h3><strong>grid-template-columns || grid-template-rows :</strong></h3><p>Defines the columns and rows of the grid with a space-separated list of values. The values represent the track size, and the space between them represents the grid line.</p><p>Values:</p><p><strong>→ &lt;track-size&gt;: </strong>can be a length, a percentage, or a fraction of the free space in the grid (using the fr unit)</p><p><strong>→&lt;line-name&gt;: </strong>an arbitrary name of your choosing</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/301/1*lWPqs4-dxm8dqBNgXZuH_Q.png" /></figure><h3>grid-template-areas :</h3><p>Defines a grid template by referencing the names of the grid areas which are specified with the grid area property. Repeating the name of a grid area causes the content to span those cells. A period signifies an empty cell. The syntax itself provides a visualisation of the structure of the grid.</p><p>Values:</p><p><strong>→&lt;grid-area-name&gt;</strong> : the name of a grid area specified with grid-area</p><p><strong>→ </strong>a period signifies an empty grid cell</p><p><strong>→none: </strong>no grid areas are defined</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/299/1*GHtlMm9z8mYLRu9WdW7Rsw.png" /></figure><h3>grid-template</h3><p>A shorthand property for setting grid-template row, grid-template-column, and grid-template-area in a single declaration.</p><p>Values:</p><p><strong>→none: </strong>sets all three properties to their initial values</p><p><strong>→&lt;grid-template-rows&gt; / &lt;grid-template-columns&gt; : </strong>sets and grid-template-row to the specified values, respectively, and sets grid-template-area none.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/299/1*WsfkkXxAOZNDlWLPzV9cQA.png" /></figure><h3><strong>column-gape || row-gap || grid-column-gap || grid-row-gap.</strong></h3><p>Specifies the size of the grid lines. You can think of it like setting the width of the gutters between the columns/rows.</p><p>Values:</p><p><strong>→ &lt;line-size&gt;:</strong>a length value</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/341/1*_fW3__XS4c0nA6GhMG2wjQ.png" /></figure><h3>gap || grid-gap</h3><p>A shorthand for row-gap and column-gap</p><p>Values:</p><p><strong>→ &lt;grid-row-gap&gt; &lt;grid-column-gap&gt;: </strong>length values</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/328/1*s4MeXhONEhfsO6hiBc1cFg.png" /></figure><h3>justify-items</h3><p>It aligns grid items along the <em>inline (row)</em> axis or horizontally (as opposed to align-item which aligns along the <em>block (column)</em> axis). This value applies to all grid items inside the container.</p><p>Values:</p><p><strong>→start: </strong>aligns items to be flush with the start edge of their cell</p><p><strong>→end: </strong>aligns items to be flush with the end edge of their cell</p><p><strong>→center</strong> : aligns items in the centre of their cell</p><p><strong>→stretch: </strong>fills the whole width of the cell (this is the default)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/308/1*qHi37S9KU3EhBfWTJe2l_A.png" /></figure><h3>align-items :</h3><p>It aligns grid items along the <em>block (column)</em> axis or vertically(as opposed to justify-item which aligns along the <em>inline (row)</em> axis). This value applies to all grid items inside the container.</p><p>Values:</p><p><strong>→start :</strong>aligns items to be flush with the start edge of their cell</p><p><strong>→end</strong> : aligns items to be flush with the end edge of their cell</p><p><strong>→center :</strong>aligns items in the centre of their cell</p><p><strong>→stretch : f</strong>ills the whole height of the cell (this is the default)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*3IIj852ArXSvXJpUj-JWgA.png" /></figure><h3>place-items</h3><p>“place-items” sets both the align-items and justify-items properties in a single declaration.</p><p>Values:</p><p><strong>→&lt;align-items&gt; / &lt;justify-items&gt;</strong> — The first value sets align-items, the second value justify-items . If the second value is omitted, the first value is assigned to both properties.</p><h3>justify-content</h3><p>Sometimes the total size of your grid might be less than the size of its grid container. This could happen if all of your grid items are sized with non-flexible units like px. In this case you can set the alignment of the grid within the grid container. This property aligns the grid along the <em>inline (row)</em> axis (as opposed to align-content which aligns the grid along the <em>block (column)</em> axis).</p><p>Values:</p><p><strong>→start:</strong>aligns the grid to be flush with the start edge of the grid container</p><p><strong>→end</strong> :aligns the grid to be flush with the end edge of the grid container</p><p><strong>→center: </strong>aligns the grid in the center of the grid container</p><p><strong>→stretch</strong> : resizes the grid items to allow the grid to fill the full width of the grid container</p><p><strong>→space-around: </strong>places an even amount of space between each grid item, with half-sized spaces on the far ends</p><p><strong>→space-between</strong> : places an even amount of space between each grid item, with no space at the far ends</p><p><strong>→space-evenly: </strong>places an even amount of space between each grid item, including the far ends</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/310/1*zzZxU3v2zeaRTs1-BbUzUQ.png" /></figure><h3>align-content</h3><p>Sometimes the total size of your grid might be less than the size of its grid container. This could happen if all of your grid items are sized with non-flexible units like px. In this case you can set the alignment of the grid within the grid container. This property aligns the grid along the <em>block (column)</em> axis (as opposed to justify-content which aligns the grid along the <em>inline (row)</em> axis).</p><p>Values:</p><ul><li><strong>start</strong> : aligns the grid to be flush with the start edge of the grid container</li><li><strong>end: </strong>aligns the grid to be flush with the end edge of the grid container</li><li><strong>center</strong> : aligns the grid in the center of the grid container</li><li><strong>stretch</strong> : resizes the grid items to allow the grid to fill the full height of the grid container</li><li><strong>space-around: </strong>places an even amount of space between each grid item, with half-sized spaces on the far ends</li><li><strong>space-between</strong> : places an even amount of space between each grid item, with no space at the far ends</li><li><strong>space-evenly: </strong>places an even amount of space between each grid item, including the far ends</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/270/1*TBS-QOtzpmU5msk8To8GPg.png" /></figure><h3>place-content</h3><p>place-content sets both the align-content and justify-content properties in a single declaration.</p><p>Values:</p><ul><li><strong>&lt;align-content&gt; / &lt;justify-content&gt;</strong> : The first value sets align-content , the second value justify-content . If the second value is omitted, the first value is assigned to both properties.</li></ul><p>All major browsers except Edge support the place-content shorthand property.</p><h4>→ grid-auto-columns || grid-auto-rows</h4><p>Specifies the size of any auto-generated grid tracks (aka <em>implicit grid tracks</em>). Implicit tracks get created when there are more grid items than cells in the grid or when a grid item is placed outside of the explicit grid.</p><p>Values:</p><ul><li><strong>&lt;track-size&gt;</strong> : can be a length, a percentage, or a fraction of the free space in the grid (using the fr unit)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/318/1*pcg_m77zlcDNwV9CX6LHVg.png" /></figure><h3>grid-auto-flow</h3><p>If you have grid items that you don’t explicitly place on the grid, the <em>auto-placement algorithm</em> kicks in to automatically place the items. This property controls how the auto-placement algorithm works.</p><p>Values:</p><p><strong>→row</strong> : tells the auto-placement algorithm to fill in each row in turn, adding new rows as necessary (default)</p><p><strong>→column</strong> : tells the auto-placement algorithm to fill in each column in turn, adding new columns as necessary</p><p><strong>→ dense: </strong>tells the auto-placement algorithm to attempt to fill in holes earlier in the grid if smaller items come up later</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/402/1*obrHY2Xc8a8c928ReVXgQg.png" /></figure><p>So, this was all about the CSS Grid and all its properties and their respective values. So in this manner, CSS Grid is a powerful mechanism which allows a rather more “dynamicity” to our webpage and support in developing a rich UI.</p><p><em>Thank You, for taking out the time for reading this blog, see you guys in the next one !!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=90444dccd952" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[NormaliZation in DBMS !]]></title>
            <link>https://suyashthonte0.medium.com/normalization-in-dbms-1760a617f90d?source=rss-2dfaab368a47------2</link>
            <guid isPermaLink="false">https://medium.com/p/1760a617f90d</guid>
            <category><![CDATA[dbms]]></category>
            <category><![CDATA[normalization]]></category>
            <dc:creator><![CDATA[Suyash Thonte]]></dc:creator>
            <pubDate>Mon, 23 Nov 2020 03:48:42 GMT</pubDate>
            <atom:updated>2020-11-23T03:48:42.928Z</atom:updated>
            <content:encoded><![CDATA[<h3>NormaliZation in DBMS !</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*KkBTrX-TtEIOkUc2KdPb0A.png" /></figure><p>Hey Guys!! <em>So , first of all we will see what exactly Normaliztion is</em></p><p>Normalization : Normalization is used to organize the data and remove redundancy(repetition) of data . Normalization actually decomposes (divides) larger table into smaller ones and ensure that the data is logically stored without any repetition.</p><p><strong>So , why Normalization came into existance ??</strong></p><p>The normalization process was created largely in order to reduce the negative effects of creating tables that will introduce anomalies into the database.</p><p><strong>Now, what is anomalies??</strong></p><p>Anomalies is occured when there is too much redundancy in data. or it can also occure when there is poor construction . what poor construction means here is, when the designer creates the database and doesn’t identify the entities that depend on each other for existence.</p><p>there are 3 type of anomalies</p><ol><li>Insertion anomalies.</li><li>Deletion anomalies.</li><li>Updation anomalies .</li></ol><p><strong>Update Anomalies </strong>happen when the person charged with the task of keeping all the records current and accurate, is asked, for example, to change an employee’s title due to a promotion. If the data is stored redundantly in the same table, and the person misses any of them, then there will be multiple titles associated with the employee. The end user has no way of knowing which is the correct title.</p><p><strong>Insertion Anomalies</strong> happen when inserting vital data into the database is not possible because other data is not already there. For example, if a system is designed to require that a customer be on file before a sale can be made to that customer, but you cannot add a customer until they have bought something, then you have an insert anomaly. It is the classic “catch-22” situation.</p><p><strong>Deletion Anomalies</strong> happen when the deletion of unwanted information causes desired information to be deleted as well. For example, if a single database record contains information about a particular product along with information about a salesperson for the company and the salesperson quits, then information about the product is deleted along with salesperson information</p><p>So far now we have disscused about the problem more, rather than disscussing on solution so, lets dive into solution more deeper.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/288/1*c0nuO_O7aulB8C57qDzwIA.png" /></figure><p>There are basically 7 normalization form</p><p><strong>1</strong>. 1NF (First Normal Form)</p><p><strong>2.</strong> 2NF (Second Normal Form)</p><p><strong>3</strong>. 3NF (Third Normal Form)</p><p><strong>4</strong>. BCNF (Boyce-Codd Normal Form)</p><p><strong>5.</strong> 4NF (Fourth Normal Form)</p><p><strong>6</strong>. 5NF (Fifth Normal Form)</p><p><strong>7</strong>. 6NF (Sixth Normal Form)</p><p>The Theory of Data Normalization in SQL is still being developed further. But in most practical applications, normalization achieves its best in 3rd Normal Form !!</p><p><strong>1 . First Normal Form (1 NF) :</strong></p><p>In this Each record needs to be unique i.e Each table cell should contain a single value.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/345/0*7D3OVlbwFzjd0yz9.png" /></figure><p>after 1 NF →</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/344/0*qZulanTgR1pFvBTk.png" /></figure><p><strong>2. Second Normal Form (2 NF) :</strong></p><p>The very first condition for 2 NF is be in 1 NF and there should be single column Primary key .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/530/0*w1cLECRA9vPxUi8I.png" /></figure><p>after 2 NF →</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*Xry-VXKYSvN8kJta.png" /></figure><p>The prime key attributes are Stu_ID and Proj_ID</p><p>Non-key attributes are Stu_Name and Proj_Name which should be depend on primary key attributes But we find that Stu_Name can be identified by Stu_ID and Proj_Name can be identified by Proj_ID independently. This is called <strong>partial dependency</strong>, which is not allowed in Second Normal Form.</p><p>We broke the relation in two as depicted in the above picture. So there exists no partial dependency.</p><p><strong>3 . Third Normal Form :</strong></p><p>For a relation to be in Third Normal Form, it must be in Second Normal form and should not have any transitive functional dependencies .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/0*VTu4nTeKDHdbZRd_.png" /></figure><p>after 3 NF →</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*XdxmlFF5HvviQJvm.png" /></figure><p>Here, Stu_ID is the key and only prime key attribute and City can be identified by Stu_ID as well as Zip itself. zip is not superkey and city is not prime attribute Additionally, Stu_ID → Zip → City, so there exists <strong>transitive dependency</strong>.</p><p>To bring this relation into third normal form, we break the relation into two relations</p><p><strong>4 . Boyce-Codd Normal Form</strong></p><p>Boyce-Codd Normal Form (BCNF) is an extension of Third Normal Form on strict terms. BCNF is also referred as <strong>3.5 Normal Form.</strong></p><p>So it states that, For any non-trivial functional dependency, X → A, X must be a super-key.</p><p>In the above image, Stu_ID is the super-key in the relation Student_Detail and Zip is the super-key in the relation ZipCodes. So,</p><p>Stu_ID → Stu_Name, Zip and</p><p>Zip → City So, both the relations are in BCNF.</p><p><strong>5 . Fourth Normal Form (4 NF) :</strong></p><p>4 NF came into existance when there is <strong>Multi-valued Dependency</strong> occur in any relation</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WJiq3CsNYDEWhKF5UvAD4Q.png" /></figure><p>s_id <strong>1</strong> has opted for two courses, <strong>Science</strong> and <strong>Maths</strong>, and has two hobbies, <strong>Cricket</strong> and <strong>Hockey</strong>.And in the table below, there is no relationship between the columns course and hobby. They are independent of each other.</p><p>So there is multi-value dependency, which leads to un-necessary repetition of data and other anomalies as well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RClagOSzSsQy2Xzcwc4llw.png" /></figure><p>After 4 NF →</p><p>The functionally dependent columns are moved in a separate table and the multi-valued dependent columns are moved to separate tables.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2Ox9rXLYSz4-dpvyX9himA.jpeg" /></figure><p><strong>6 . Fifth Normal Form (5 NF) :</strong></p><ul><li>A relation is in 5NF if it is in 4NF and not contains any join dependency and joining should be lossless.</li><li>5NF is satisfied when all the tables are broken into as many tables as possible in order to avoid redundancy.</li><li>5NF is also known as Project-join normal form (PJ/NF).</li></ul><p><strong>7 . Sixth Normal Form (6 NF) :</strong></p><p>In 6NF, the relation variable is decomposed into irreducible components. A relation is in 6NF, only if, It is in 5NF, and every join dependency on the relation is trivial.</p><p>So this was all about Normalization and its various forms and how it is used in Database Management System. Will See you guys in next blog!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1760a617f90d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Collections In Java | A Helpful Framework]]></title>
            <link>https://suyashthonte0.medium.com/collections-in-java-a-helpful-framework-49330fb9de2b?source=rss-2dfaab368a47------2</link>
            <guid isPermaLink="false">https://medium.com/p/49330fb9de2b</guid>
            <category><![CDATA[collections-framework]]></category>
            <category><![CDATA[collections-in-java]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Suyash Thonte]]></dc:creator>
            <pubDate>Mon, 16 Nov 2020 03:32:59 GMT</pubDate>
            <atom:updated>2020-11-16T20:41:43.192Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*ZSWsEGLsERI7G8cYW9VMRQ.jpeg" /></figure><p>The Java <strong>collections</strong> framework provides a set of interfaces and classes to implement various data structures and algorithms.</p><p>So yes, we don’t exactly have to write the code again for Linked-list, Queue, etc data structures.</p><p>Cool !! Isn&#39;t it ?</p><p>Also Collections were introduced to overcome the demerits of Arrays i.e contiguous memory, no heterogeneous data type support, and no dynamic size functionality.</p><p>So let’s see what exactly the Collections constitute of :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_viHXY0P-XYXgd2Rr3KS8A.png" /><figcaption><strong>Collection Hierarchy</strong></figcaption></figure><h3>Iterable</h3><p>The Iterable interface is the root of all the collection classes. The Collection interface extends the Iterable interface and hence all sub classes of Collections also implement the Iterable interface.</p><h3>Collection</h3><p>Collection is the interface which is implemented by all the classes in the Collections framework. It consists of all the common methods that will be required in each every collection.</p><p>It has 3 child interfaces :</p><ol><li>List</li><li>Queue</li><li>Set</li></ol><p>These 3 are differentiated on the basis of their implementations and their functionality.</p><h3>1. List</h3><p>List is child of Collection interface. So it basically stores a list type data structure in which we can have order collection of objects as well as duplicate values.</p><p>To initialise we need to write :</p><blockquote>List &lt;data-type&gt; list1= <strong>new</strong> TypeOfList();</blockquote><p>Some of the commonly used methods of the Collection interface that&#39;s also available in the List interface are:</p><ul><li>add() - adds an element to a list</li><li>addAll() - adds all elements of one list to another</li><li>get() - helps to randomly access elements from lists</li><li>iterator() - returns iterator object that can be used to sequentially access elements of lists</li><li>set() - changes elements of lists</li><li>remove() - removes an element from the list</li><li>removeAll() - removes all the elements from the list</li><li>clear() - removes all the elements from the list (more efficient than removeAll())</li><li>size() - returns the length of lists</li><li>toArray() - converts a list into an array</li><li>contains() - returns true if a list contains specified element</li></ul><p>List Interface further have the following sub classes which implement it:</p><h4><strong>a) ArrayList</strong></h4><p>ArrayList uses a dynamic array to store duplicate values as well.</p><p>It maintains the insertion order i.e the output is printed as it was inserted.</p><p>Since it is a type of Array, more-over a dynamic one, elements stored in it can be randomly accessed, unlike Linked List.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/670/1*LadwZazTHHNw-GCxibG4kA.png" /></figure><pre>public static void main(String args[]){ </pre><pre>//Creating arraylist<br>ArrayList&lt;String&gt; list=new ArrayList&lt;String&gt;();</pre><pre>//Adding object in arraylist<br>list.add(&quot;Ravi&quot;); <br>list.add(&quot;Vijay&quot;); <br>list.add(&quot;Ravi&quot;); <br>list.add(&quot;Ajay&quot;); </pre><pre>//Traversing list through Iterator Iterator itr=list.iterator(); </pre><pre>while(itr.hasNext()){ <br>System.out.println(itr.next()); <br>} <br>}<br>Output :<br>Ravi<br>Vijay<br>Ravi<br>Ajay</pre><p>So the Time Complexity of this collection can be determined by its operations i.e :</p><p><em>add() -&gt; O(1)</em></p><p><em>get() -&gt; O(1)</em></p><p><em>remove() -&gt; O(n)</em></p><p><em>contains() -&gt; O(n)</em></p><p>So here we can conclude that adding the elements and getting the element is the fastest, Hence Array-list is preferred whenever there is continuous access calls to the items in the list.</p><p>But what if we were working on an list of elements and the current Array-list falls short of size but only a few elements are remaining to be appended.</p><p>So can we use ArrayList?</p><p>Yes of course, we can. It is dynamic it will increase its size, but not according to the elements required instead it has a “double the size when full” strategy for some or all of the space utilization. And hence it is not preferred in these situations , rather a LinkedList is preferred.</p><h4>b) LinkedList</h4><p>LinkedList uses a doubly linked list internally to store the elements and therefore no shifting is required , hence it is incredibly fast for manipulation.</p><p>It stores duplicate values and also maintains the insertion order.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/907/1*M8OI5w8cS4idbtYyr-iNag.png" /></figure><pre>public static void main(String args[]){</pre><pre>//Creating arraylist<br>LinkedList&lt;String&gt; list=new LinkedList&lt;String&gt;();</pre><pre>//Adding object in arraylist<br>list.add(&quot;Ravi&quot;); <br>list.add(&quot;Vijay&quot;); <br>list.add(&quot;Ravi&quot;); <br>list.add(&quot;Ajay&quot;);</pre><pre>//Traversing list through Iterator Iterator itr=list.iterator();</pre><pre>while(itr.hasNext()){ <br>System.out.println(itr.next()); <br>} <br>}<br>Output:<br>Ravi<br>Vijay<br>Ravi<br>Ajay</pre><p>So the Time Complexity of this collection can be determined by its operations i.e :</p><p><em>add() -&gt; O(1)</em></p><p><em>get() -&gt; O(n)</em></p><p><em>remove() -&gt; O(1)</em></p><p><em>contains() -&gt; O(n)</em></p><p>So here we can conclude that adding the elements and removing them is the fastest operation , Hence Linked-list is preferred whenever there is continuous updation and deletion of items in the list. Here it getting the element by index is not possible as Linked List traverses its elements through pointers and hence it will take linear time to arrive at that element, on the contrary , unlike array-list or arrays, it doesn&#39;t have to shift the whole list of elements in the case of adding or removing elements from anywhere in the list.</p><h4>c) Vector</h4><p>Vector is similiar to ArrayList , i.e it uses dynamic array only the difference is that it is synchronized i.e can be used for multi-threading unlike ArrayList and also it contains several methods apart from those in Collections framework which are mentioned below :</p><ul><li>set()changes an element of the vector</li><li>size()returns the size of the vector</li><li>toArray()converts the vector into an array</li><li>toString()converts the vector into a String</li><li>contains()searches the vector for specified element and returns a boolean result</li></ul><pre>public static void main(String args[]){</pre><pre>//Creating arraylist<br>Vector&lt;String&gt; v=new Vector&lt;String&gt;();</pre><pre>//Adding object in arraylist<br>v.add(&quot;Ravi&quot;); <br>v.add(&quot;Vijay&quot;); <br>v.add(&quot;Ravi&quot;); <br>v.add(&quot;Ajay&quot;);</pre><pre>//Traversing list through Iterator Iterator itr=list.iterator();</pre><pre>while(itr.hasNext()){ <br>System.out.println(itr.next()); <br>} <br>}<br>Output:<br>Ravi<br>Vijay<br>Ravi<br>Ajay</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/523/1*kfcn1x0QlCWwVTTdVvS76A.png" /></figure><ul><li>ArrayList is not thread safe as its methods are not synchronized, whereas Vector’s methods are synchronized. So, in multithreading environment, we can use Vector without making any extra efforts.</li><li>Time Complexity of Vector in case of : get() →O(1)</li><li>Adding and removing elements from the end : O(1)</li></ul><blockquote><strong>Stack</strong></blockquote><p>Stack is subclass of Vector Class. It implements the Last-In-First-Out (LIFO) principle.</p><p>It has all the methods of Vector as well as provides methods like push, pop for insertion and deletion of elements.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/738/1*pRk4dqCwgU3ti8uEnB3wFQ.png" /></figure><pre>public static void main (String[] args) { <br>//creating an object of Stack class <br>Stack stk = new Stack(); <br>//pushing elements into stack <br>stk.push(&quot;BMW&quot;); <br>stk.push(&quot;Audi&quot;); <br>stk.push(&quot;Ferrari&quot;); <br>stk.push(&quot;Bugatti&quot;); <br>stk.push(&quot;Jaguar&quot;); <br>//iteration over the stack <br>Iterator iterator = stk.iterator(); <br>while(iterator.hasNext()) <br>{ <br>Object values = iterator.next(); <br>System.out.println(values); <br>} <br>}<br>Output:<br>BMW<br>Audi<br>Ferrari<br>Bugatti<br>Jaguar</pre><h3><strong>2. Queue</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/259/1*RYbsO2co4i5mxjN1oVA1Qg.jpeg" /></figure><p>Queue is also child of Collection interface. So it basically stores elements in an ordered list maintaining the First-In-First-Out (FIFO) Principle.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/741/1*8jYjomnq4CeAwULMgMIVBw.png" /></figure><p>To initialise we need to write :</p><blockquote>Queue &lt;data-type&gt; q1= <strong>new</strong> TypeOfQueue();</blockquote><blockquote><em>Following are methods of Queue Interface :</em></blockquote><blockquote>boolean add(object) : It is used to insert the specified element into this queue and return true upon success.</blockquote><blockquote>boolean offer(object) : It is used to insert the specified element into this queue.</blockquote><blockquote>Object remove() : It is used to retrieves and removes the head of this queue.</blockquote><blockquote>Object poll() : It is used to retrieves and removes the head of this queue, or returns null if this queue is empty.</blockquote><blockquote>Object element() : It is used to retrieves, but does not remove, the head of this queue.</blockquote><blockquote>Object peek() : It is used to retrieves, but does not remove, the head of this queue, or returns null if this queue is empty.</blockquote><p>Queue Interface further have the following sub classes which implement it:</p><h4>a.) PriorityQueue</h4><p>In this, it hold the elements which are to be processed by their priorities.</p><p>It does not allow null values.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*JXEkXuyWKLXBrJHPO8G7jQ.png" /></figure><pre>public static void main(String args[]){ <br>PriorityQueue&lt;String&gt; queue=new PriorityQueue&lt;String&gt;(); queue.add(“Amit”); <br>queue.add(“Vijay”); <br>queue.add(“Karan”); <br>queue.add(“Jai”); <br>queue.add(“Rahul”); <br>System.out.println(“head:”+queue.element()); System.out.println(“head:”+queue.peek()); System.out.println(“iterating the queue elements:”); <br>Iterator itr=queue.iterator(); <br>while(itr.hasNext())<br>{ <br>System.out.println(itr.next()); <br>} <br>queue.remove(); <br>queue.poll(); <br>System.out.println(“after removing two elements:”); <br>Iterator&lt;String&gt; itr2=queue.iterator(); <br>while(itr2.hasNext())<br>{ <br>System.out.println(itr2.next()); <br>} <br>}</pre><p>So the Time Complexity of this collection can be determined by its operations i.e :</p><p><em>offer() -&gt; O(log n)</em></p><p><em>peak() -&gt; O(1)</em></p><p><em>poll() -&gt; O(logn)</em></p><p><em>size() -&gt; O(1)</em></p><blockquote><strong><em>Deque</em></strong></blockquote><p>Deque extends the Queue Interface. In this we can insert and delete elements from both the side of the queue. Deque stands for double-ended queue.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mA7QP2f9ncOIj1XIR9Dayw.png" /></figure><p>Following are methods of Deque Interface :</p><blockquote>boolean add(object) : It is used to insert the specified element into this deque and return true upon success.</blockquote><blockquote>boolean offer(object) : It is used to insert the specified element into this deque.</blockquote><blockquote>Object remove() : It is used to retrieves and removes the head of this deque.</blockquote><blockquote>Object poll() : It is used to retrieves and removes the head of this deque, or returns null if this deque is empty.</blockquote><blockquote>Object element() : It is used to retrieves, but does not remove, the head of this deque.</blockquote><blockquote>Object peek() : It is used to retrieves, but does not remove, the head of this deque, or returns null if this deque is empty.</blockquote><h4><strong>b.) ArrayDeque</strong></h4><p>ArrayDeque implements the Deque Interface and hence provides facility of using deque as well as resizable array.</p><p>As we can update from both the ends, it is faster than ArrayList and Stack.</p><p>Null elements are not allowed in it.</p><pre>public static void main(String[] args) { <br>//Creating Deque and adding elements <br>Deque&lt;String&gt; deque = new ArrayDeque&lt;String&gt;(); <br>deque.add(“Ravi”); <br>deque.add(“Vijay”); <br>deque.add(“Ajay”); <br>//Traversing elements <br>for (String str : deque) <br>{ <br>System.out.println(str); <br>} <br>} <br>Output : <br>Ravi<br>Vijay<br>Ajay</pre><p>So the Time Complexity of this collection can be determined by its operations i.e :</p><p><em>offer() -&gt; O(1)</em></p><p><em>peak() -&gt; O(1)</em></p><p><em>poll() -&gt; O(1)</em></p><p><em>size() -&gt; O(1)</em></p><p>So as you can see, all the operations have time complexity of O(1), and also we know that we can update it from both the ends, it is faster than ArrayList as well as Stack.</p><h3>3.Set</h3><p>Set is child of Collection interface. So it basically consists of unordered set of elements and also doesn&#39;t allow duplicate items. Only 1 null value is allowed in a set.</p><blockquote>Set &lt;data-type&gt; set1= <strong>new</strong> TypeOfSet();</blockquote><p>So Set interface has following associated methods with it :</p><blockquote><a href="https://www.javatpoint.com/java-hashset-add-method">add(E e)</a> : It is used to add the specified element to this set if it is not already present.</blockquote><blockquote><a href="https://www.javatpoint.com/java-hashset-clear-method">clear()</a> : It is used to remove all of the elements from the set.</blockquote><blockquote><a href="https://www.javatpoint.com/java-hashset-clone-method">clone()</a> : It is used to return a shallow copy of this HashSet instance: the elements themselves are not cloned.</blockquote><blockquote><a href="https://www.javatpoint.com/java-hashset-contains-method">contains(Object o)</a> : It is used to return true if this set contains the specified element.</blockquote><blockquote><a href="https://www.javatpoint.com/java-hashset-isempty-method">isEmpty()</a> : It is used to return true if this set contains no elements.</blockquote><blockquote><a href="https://www.javatpoint.com/java-hashset-iterator-method">iterator()</a> : It is used to return an iterator over the elements in this set.</blockquote><blockquote><a href="https://www.javatpoint.com/java-hashset-remove-method">remove(Object o)</a> : It is used to remove the specified element from this set if it is present.</blockquote><blockquote><a href="https://www.javatpoint.com/java-hashset-size-method">size()</a> : It is used to return the number of elements in the set.</blockquote><blockquote><a href="https://www.javatpoint.com/java-hashset-spliterator-method">spliterator()</a> : It is used to create a late-binding and fail-fast Spliterator over the elements in the set.</blockquote><p>Set Interface further have the following sub classes which implement it:</p><h4><strong>a.) HashSet</strong></h4><p>HashSet consists of elements stored in it according to their hash-values calculated through hash-table. It implements hashing technique and stored only unique items.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mzWV7GmoxxoU0w1Yifaelw.png" /></figure><pre>public static void main(String args[]){ <br>//Creating HashSet and adding elements <br>HashSet&lt;String&gt; set=new HashSet&lt;String&gt;(); <br>set.add(“Ravi”); <br>set.add(“Vijay”); <br>set.add(“Ravi”); s<br>et.add(“Ajay”); <br>//Traversing elements <br>Iterator&lt;String&gt; itr=set.iterator(); <br>while(itr.hasNext())<br>{ <br>System.out.println(itr.next()); <br>} <br>}</pre><pre>Output : <br>Vijay<br>Ravi   // Duplicate item, i.e &quot;Ravi&quot; is ignored!!<br>Ajay </pre><p>So the Time Complexity of this collection can be determined by its operations i.e :</p><p><em>add() -&gt; O(1)</em></p><p><em>remove() -&gt; O(1)</em></p><p><em>contains() -&gt; O(1)</em></p><p><em>next() -&gt; O(h/n)</em></p><h4>b.) LinkedHashSet</h4><p>LinkedHashSet basically is an implementation of both Linked List and a Hash Set. Like LinkedList it maintains the insertion order and permits null elements as well as like Hash Set it contains Unique elements.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*l4APfbSmErUpyg6OjjJ8mA.jpeg" /></figure><pre>public static void main(String args[]){ <br>//Creating HashSet and adding elements <br>LinkedHashSet&lt;String&gt; set=new LinkedHashSet&lt;String&gt;(); <br>set.add(“Ravi”); <br>set.add(“Vijay”); <br>set.add(“Ravi”); s<br>et.add(“Ajay”); <br>//Traversing elements <br>Iterator&lt;String&gt; itr=set.iterator(); <br>while(itr.hasNext())<br>{ <br>System.out.println(itr.next()); <br>} <br>}</pre><pre>Output : <br>Ravi<br>Vijay<br>Ajay</pre><p>So the Time Complexity of this collection can be determined by its operations i.e :</p><p><em>add() -&gt; O(1)</em></p><p><em>remove() -&gt; O(1)</em></p><p><em>contains() -&gt; O(1)</em></p><p><em>next() -&gt; O(1)</em></p><p>So from above we can conclude that almost every operation takes O(1) time complexity in LinkedHashSet as it is combination of Linked List as well as Hash Set</p><h3><strong>SortedSet</strong></h3><p>SortedSet is also and interface similar to Set interface, only the difference is in SortedSet, elements are arranged in increasing (ascending) order.</p><p>The SortedSet can be instantiated as:</p><blockquote>SortedSet&lt;data-type&gt; set = <strong>new</strong> TreeSet();</blockquote><h4><strong>c.) TreeSet</strong></h4><p>TreeSet is similar to HashSet as it contains unique elements but it uses Tree structure for storage and hence the data access and retrieval time is fast and also the elements are stored in ascending order.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/783/1*YT2An80PD-7uG_6yYnygbw.png" /></figure><pre>public static void main(String args[]){ <br>//Creating HashSet and adding elements <br>TreeSet&lt;String&gt; set=new TreeSet&lt;String&gt;(); <br>set.add(“Ravi”); <br>set.add(“Vijay”); <br>set.add(“Ravi”); s<br>et.add(“Ajay”); <br>//Traversing elements <br>Iterator&lt;String&gt; itr=set.iterator(); <br>while(itr.hasNext())<br>{ <br>System.out.println(itr.next()); <br>} <br>}</pre><pre>Output : <br>Ajay<br>Ravi<br>Vijay</pre><p>So the Time Complexity of this collection can be determined by its operations i.e :</p><p><em>add() -&gt; O(logn)</em></p><p><em>remove() -&gt; O(logn)</em></p><p><em>contains() -&gt; O(logn)</em></p><p><em>next() -&gt; O(logn)</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/321/1*16sfoZ86zR6x7R_aZf7baA.png" /></figure><p>So from above we can conclude that almost every operation takes O(logn) time complexity in TreeHashSet as it is Red-Black tree data structure.</p><p>So we can conclude that introduction to collections framework in java reduced the effort to code the useful Data Structures and algorithms as well as provided re-usability of them, also furthermore increased the efficiency and ease to code bigger programs as well as overcame the problem with the Primitive Arrays and provided a much more efficient and complex functionalities.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*U8jHg5bluteg6AmkLkngVg.gif" /></figure><p>This was a quick Glance of Collections Framework in Java.</p><p>Thanks for Reading, See you Guys in next Blog !!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=49330fb9de2b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Time Complexity and Space Complexity | All you need to know !]]></title>
            <link>https://suyashthonte0.medium.com/time-complexity-and-space-complexity-all-you-need-to-know-965fee10f796?source=rss-2dfaab368a47------2</link>
            <guid isPermaLink="false">https://medium.com/p/965fee10f796</guid>
            <category><![CDATA[space-complexity]]></category>
            <category><![CDATA[time-complexity]]></category>
            <category><![CDATA[algorithms]]></category>
            <dc:creator><![CDATA[Suyash Thonte]]></dc:creator>
            <pubDate>Mon, 16 Nov 2020 02:00:01 GMT</pubDate>
            <atom:updated>2020-11-16T02:00:01.559Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Time Complexity and Space Complexity | All you need to know !</strong></h3><p>Hey Guys!</p><p>So in this blog, I would like to discuss about the Time and Space Complexity of an algorithm.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EsdxFwJ453nBKxd7hJxkLw.png" /></figure><h3><strong>What is a Complexity of an Algorithm??</strong></h3><p>Complexity , generally means the complication or the difficulty or the complicatedness . But then what does Complexity of an Algorithm means??</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*t3_cuEIELP6i1NOucTo1iQ.gif" /><figcaption>Is complexity of an algorithm very complex ?? :( !!</figcaption></figure><p>But here it does not refer to the complication or the difficulty of an algorithm, instead Complexity of an Algorithm is a concept in Algorithm Analysis which deals with the execution or running time(number of computer instructions executed per second) of various operations involved.</p><p>Suppose an example : ‘X’ is an algorithm and ’n’ be the size of input data provided to algorithm to work upon. So here the <strong>time</strong> and <strong>space</strong> implemented by this algorithm ‘X’ are the 2 main factors responsible for efficiency of ‘X’.</p><p>So to design a algorithm there are multiple ways but we must always consider the time and space complexity during developing it.</p><h3><strong>Time Complexity</strong></h3><p>So, the Time Complexity of a program is not the actual time taken for the program to execute, rather it is the number of times a logical statement gets executed to produced the output. Or in other words, it is the amount of number of operations performed by a program with respect to input size.</p><p>Let’s see an example:</p><pre>main()<br>{<br>  int i, n = 5;<br>  for (i = 1; i &lt;= n; i++) {<br>  print(&quot;Hello&quot;);<br> } <br>}<br>Output : <br>Hello<br>Hello<br>Hello<br>Hello<br>Hello</pre><p>So when u run above such command, u will see that compiler has given the above output and along with that it also shows that the code was executed in 1.166 secs.</p><p>So is this (1.166 secs) the time complexity??</p><p>NO !!</p><p>A lot us may assume that this is time complexity but it isn&#39;t.</p><p>Instead Time-Complexity is dependent on the the number of times the statements get executed. SO in above code, the loop gets executed ‘5’ times, i.e n = 5, i.e ’n’ times , hence complexity is O(n).</p><p>So basically there are 3 types in which a time complexity of an algorithm can be represented , these are called Asymptotic Notations :</p><ul><li><strong>Θ Notation (theta)</strong></li><li><strong>Big O Notation</strong></li><li><strong>Ω Notation</strong></li></ul><h4>Big O Notation</h4><p>So Big O notation is the most used notation to express the time complexity of an algorithm.</p><p>So it defines the upper bound of any algorithm i.e. you algorithm can’t take more time than this time.</p><p>In other words, we can say that the big O notation denotes the maximum time taken by an algorithm or the worst-case time complexity of an algorithm.</p><h4><strong><em>How to find Time Complexity of a code?</em></strong></h4><p>As we did earlier, we calculated the number of times a loop runs in a code and determined the time complexity to be O(n).</p><p>Similarly lets try out some more examples:</p><pre>for (let i = 0; i &lt; n; ++i) <br>{<br>  print(i);<br>}</pre><pre>for (let j = 0; j &lt; n; ++j) <br>{<br> print(j);<br>}<br></pre><p>Here there are 2 loops running , so yes loops run 2n times but it is just expressed as O(n) as the value is linear not quadratic, i.e in case of very much larger values, the constant ‘2’ wont affect drastically in the way the ’n’ does, hence the constant ‘2’ is ignored.</p><p>Similarly, every program’s time complexity is calculated based on the polynomial expression it forms and thus considering the highest degree of expression(as for higher values, only the highest degree affects).</p><pre>for (int i = 0; i &lt; n; i++) {<br> for (int j = 0; j &lt; n; j++) {<br> print(i, j);<br> }<br>}</pre><p>Here there are 2 loops running but during each iteration in the first loop , there is an inner loop being iterated, hence here the loop will run <strong><em>n² times. </em></strong>Hence the time complexity : <strong>O(n²)</strong></p><pre>for (int i = 1; i &lt;= n; i *= 2) {<br>    print(i);<br>}</pre><p>Now, here in this statement the iterator proceeds exponentially, i.e the iterations get reduced logarithmically. Hence time complexity : <strong>O(log n)</strong></p><h3>Space Complexity</h3><p>Space Complexity is the total amount of space or memory consumed by an algorithm along with the memory of input values.</p><p>So basically,</p><blockquote>Space Complexity = Auxiliary space + Space of Input Values.</blockquote><p>Here Auxiliary space refers to temporary or extra space used by the algorithm while it is being executed.</p><blockquote>The best algorithm/program should have the least space complexity. The lesser the space used, the faster it executes.</blockquote><p>Space complexity plays a vital role in algorithmic efficiency. If an algorithm takes some time to execute we can still wait for it to complete, but if a program takes up a lot of memory space, the compiler will not let us run it!</p><p>Let’s see an example to calculate Space Complexity:</p><pre>int main()<br>{<br>  int a = 5, b = 5, c;<br>  c = a + b;<br>  print(c);<br>}</pre><pre>Output:<br>CPU time: 0.00 sec(s), Memory: 1364 Kilobytes(s)</pre><pre>10</pre><p>In the above program, 3 integer variables are used. The size of the integer data type is 4 bytes which depends on the compiler. So, the total space occupied by the above-given program is 4 * 3 = 12 bytes.</p><p>Hence Space Complexity : O(1) or constant</p><p>Now let’s see another example:</p><pre>int main()<br>{<br>  int n, i, sum = 0;<br>  cin&gt;&gt;n;<br>  int arr[n];<br>  for(i = 0; i &lt; n; i++)<br>  {<br>    cin&gt;&gt;arr[i];<br>    sum = sum + arr[i];<br>  }<br>  cout&lt;&lt;sum;<br>}</pre><pre>Output:<br>10</pre><p>In the above code, array consists of n elements, So space occupied by array is 4*n. Also we have variables like n , i and sum each with 4 bytes size. So the total space consumed by program will be 4*n + 12 bytes. So in this expression the highest order is considered i.e ’n’ , hence Space Complexity : O(n)</p><p>So in this way, we can calculate the Time and Space complexities and try to implement efficient Algorithms .</p><p>See You in next Blog, Thank You For Your Time !!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=965fee10f796" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[O.O.P (Object Oriented Programming) or OOPs !! in Java…]]></title>
            <link>https://suyashthonte0.medium.com/o-o-p-object-oriented-programming-or-oops-in-java-8c43bf927c3c?source=rss-2dfaab368a47------2</link>
            <guid isPermaLink="false">https://medium.com/p/8c43bf927c3c</guid>
            <category><![CDATA[oops-concepts]]></category>
            <category><![CDATA[java-oop]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[oops-interview-questions]]></category>
            <category><![CDATA[object-oriented]]></category>
            <dc:creator><![CDATA[Suyash Thonte]]></dc:creator>
            <pubDate>Mon, 09 Nov 2020 01:22:34 GMT</pubDate>
            <atom:updated>2020-11-09T05:06:34.674Z</atom:updated>
            <content:encoded><![CDATA[<h3>O.O.P (Object Oriented Programming) or OOPs !! in Java…</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/225/1*O3MyaeKKAtLzuAND8DY87Q.jpeg" /><figcaption>Not the word Ooops!! It’s O.O.P’s (i.e Object Oriented Programming)!!!</figcaption></figure><p>HEY ! So in this post I will be highlighting and describing the OOPs concepts in Java and where they get applied in a Java Program.</p><p>Before starting with OOPs concepts let us see the 2 programming paradigms namely :</p><ol><li>Procedural Oriented (More focus on procedure rather than data.)</li><li>Object Oriented (More focus on data rather than procedure.)</li></ol><p>So Structured / Procedural Programming lacks whenever programs grow larger and complex. So to manage the increasing complexity , that’s when Object-Oriented Programming comes into the scene.</p><h3><strong><em>Object Oriented Programming :</em></strong></h3><p>Object Oriented Programming is a programming methodology that helps organise complex programs using the concept of <strong>Objects</strong> that interact with the real world and implementing concepts like Abstraction, Polymorphism, Encapsulation, Inheritance,etc.</p><p><strong><em>OOPs Concepts :</em></strong></p><ol><li>Class</li><li>Object</li><li>Abstraction</li><li>Encapsulation</li><li>Inheritance</li><li>Polymorphism</li></ol><p>The last 4 (i.e Abstraction, Encapsulation, Inheritance and Polymorphism) are also referred to as the 4 Pillars of Object Oriented Programming or OOPs.</p><figure><img alt="Abstraction Encapsulation Inheritance Polymorphism" src="https://cdn-images-1.medium.com/max/1024/1*owmL4SCHlVrkNfiQtGPgHQ.jpeg" /><figcaption><strong>Abstraction ~~~~~~~~~~~ Encapsulation ~~~~~~~~~~~ Inheritance ~~~~~~~~~~~~ Polymorphism</strong></figcaption></figure><h3><strong><em>1. Class :</em></strong></h3><p>Class is a logical construct which defines the state, behaviour and identity of an object. So basically it is a blueprint which contains elements or data which have certain common traits or nature , i.e , they perform same functions or posses similar features. Speaking in other words, Class can be visualised as a mold which stamps out the object (in the form of structure and behaviour) in its own shape.</p><p>Class may consist of :</p><ul><li>Class name</li><li>Blocks</li><li>Variables (also called instance variables)</li><li>Methods</li><li>Constructors</li><li>Interface</li></ul><h3><strong><em>2. Object</em></strong></h3><p>Object is a physical entity in an object-oriented system, i.e it physically exists !! An object can represent a person, a bank account, a place, a table of data. It may also represent user-defined data types like lists and vectors.</p><p>As I mentioned earlier, class is like a mold which stamps out an object, so this stamped out object has the <em>structure</em> and <em>behaviour</em> as designed by the class, hence objects are also known as <strong><em>instances of a class.</em></strong></p><p>Hence object has got 2 characteristics i.e a structure or a state and a behaviour, below is the example for these :</p><p><strong>Object</strong>: House<br><strong>State</strong>: Address, Color, Area<br><strong>Behaviour</strong>: Open door, close door</p><p>So if I had to write a class based on these 2 characteristics of the House, It will be like : State will be considered as instance variables and Behaviours as methods of the class. Below will be the code :</p><pre>class House {<br>   String address;<br>   String color;<br>   double are;<br>   void openDoor() {<br>      //Write code here<br>   }<br>   void closeDoor() {<br>      //Write code here<br>   }<br> ...<br> ...<br>}</pre><h3><strong><em>3. Abstraction</em></strong></h3><p>Abstraction is the concept of hiding implementation details from the user. Humans manage complexity through abstraction, for e.g Let’s assume a case of mobile phone. When user buys a phone, he doesn’t see how that phone had developed but sees only the working of phone such as calling, music, videos, etc. while inner implementations of cell phone remains hidden. This is called abstraction.</p><p>Abstraction can be achieved through 2 ways :</p><blockquote><strong>Abstract class :</strong></blockquote><p>Abstract class is used when you currently don’t know the implementation of a class or method, i.e. hidden part that user can’t see. In abstract class, atleast one method must be declared as abstract consisting of several other concrete methods. Through abstract class, we achieve 0 - 100 % abstraction.</p><pre><strong>abstract</strong> <strong>class</strong> <strong>Car</strong><br>{<br> Car()<br> {<br>  System.<strong>out</strong>.println(&quot;Car is built. &quot;);<br> }<br> <strong>abstract</strong> <strong>void</strong> <strong>drive</strong>();<br> <strong>void</strong> <strong>gearChange</strong>()<br> {<br>  System.<strong>out</strong>.println(&quot;Gearchanged!!&quot;);<br> }<br>} <br><br><strong>class</strong> <strong>Tesla</strong> <strong>extends</strong> <strong>Car</strong><br> {<br>  <strong>void</strong> <strong>drive</strong>()<br>  {<br>   System.<strong>out</strong>.println(&quot;Drive Safely&quot;);<br>  }<br> }<br><br><strong>class</strong> <strong>Abstraction</strong> <br> {<br>  <strong>public</strong> <strong>static</strong> <strong>void</strong> <strong>main</strong> (String args[])<br>  {<br>   Car obj = <strong>new</strong> Tesla();<br>   obj.drive();<br>   obj. gearChange();<br>  }<br> }</pre><blockquote><strong>Interface :</strong></blockquote><p>Interface in Java is a blueprint of a class or you can say it is a collection of abstract methods and static constants. In an interface, each method is public and abstract but it does not contain any constructor. Along with abstraction, interface also helps to achieve multiple inheritance in Java. So unlike Abstract class, every method in interface is abstract or is a group of methods with empty bodies. Through in Interface, we achieve 100 % abstraction.</p><pre>// Interface<br>interface Animal {<br>  public void animalSound(); // interface method (does not have a body)<br>  public void sleep(); // interface method (does not have a body)<br>}<br><br>// Pig &quot;implements&quot; the Animal interface<br>class Pig implements Animal {<br>  public void animalSound() {<br>    // The body of animalSound() is provided here<br>    System.out.println(&quot;The pig says: wee wee&quot;);<br>  }<br>  public void sleep() {<br>    // The body of sleep() is provided here<br>    System.out.println(&quot;Zzz&quot;);<br>  }<br>}<br><br>class MyMainClass {<br>  public static void main(String[] args) {<br>    Pig myPig = new Pig();  // Create a Pig object<br>    myPig.animalSound();<br>    myPig.sleep();<br>  }<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*oSqErZPRBOdkoNPfIZNxyA.png" /></figure><h3>4. Encapsulation</h3><p>Encapsulation, as the name suggests is the process of encapsulating or capsulating your code. It is a mechanism where you bind your data and code together into a single unit. Also it means that ensuring that “sensitive” data is hidden from users. WHAT ?? What does this mean? So, lets take an example of medical capsule, in which the medicine powder or the drug is always safe and wrapped up inside the capsule, similiarly, the methods and instance variables are safe inside a class and well hidden due to encapsulation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/528/1*-S7fK3S9HdFsGTHLsxT7LA.png" /><figcaption>Methods and variables safe inside the class capsule</figcaption></figure><p>Encapsulation can be achieved by :</p><ol><li>Declaring the instance variables as private.</li><li>Providing getter and setter methods to access and modify the private variables.</li></ol><pre>public class Person {<br>  private String name; // private = restricted access<br><br>  // Getter<br>  public String getName() {<br>    return name;<br>  }<br><br>  // Setter<br>  public void setName(String newName) {<br>    this.name = newName;<br>  }<br>}</pre><pre>public class MyClass {<br>  public static void main(String[] args) {<br>    Person myObj = new Person();<br>    myObj.setName(&quot;John&quot;); // Set the value of the name variable to &quot;John&quot;<br>    System.out.println(myObj.getName());<br>  }<br>}<br><br>// Outputs &quot;John&quot;</pre><h3>5. Inheritance</h3><p>There are times when we require the code from the previous program or class and thus hence in Java, it is possible to inherit the attributes and methods from the previous classes or different classes. Thus doing so will ease the reuse of code i.e improving the re-usability and also reducing the complexity of code to a further extent.</p><p>So in Inheritance, the new class adopts or inherits all the properties from the another class. Here, the new class or inheriting class is often referred as “sub-class” or “child class” or “base class” and the original class is often termed as “super-class” or “parent class” or “derived class”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/619/1*gkxw2zh3A73wT-5ma3LLfA.png" /><figcaption>Example of Inheritance : Parent Class and Child Class</figcaption></figure><p>But what if there are 2 or more child or sub classes which are required to inherit from the same parent or super class ?? Is it even possible!!</p><p>Also if a child class has got all the properties from parent and also has its own features / properties , but these all properties from the child (i.e parent features and its own features) are further required into a new class where they would be required, so is it even possible?? Will there be a grand-child class !!?</p><p>Guys don’t panic !!! , all the above conditions are actually possible and these are divided into different types of Inheritance in Java namely :</p><ul><li>Single Inheritance</li><li>Multi-Level Inheritance</li><li>Hierarchical Inheritance</li><li>Hybrid Inheritance</li></ul><p><strong><em>1. Single Inheritance :</em></strong> A single subclass inherits the property of a super class.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/144/1*d7KPjhqLgWdw5G_gJnZOeA.png" /><figcaption>Single Inheritance (parent -&gt; child)</figcaption></figure><pre>public class A{<br>// statements<br>}<br>public class B extends A{<br>// statements<br>}</pre><p><strong><em>2. Multi-level Inheritance :</em></strong> When a class is derived from a class which is also derived from another class. Yes like the Grand-Child Class !! Exactly Ha Ha !!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/489/1*Eb0daxawr5SPPr1cILKHCw.png" /><figcaption>Multi-level Inheritance (parent -&gt; child -&gt; grandchild)</figcaption></figure><pre>public class A{<br>// statements<br>}<br>public class B extends A{<br>// statements<br>}<br>public class C extends B{<br>//statements<br>}</pre><p><strong><em>3. Hierarchical Inheritance :</em></strong> When there are more than one child class inheriting the same parent class, then it is hierarchical.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/339/1*9j4rUHMrVJ-0FXmfT490RQ.png" /><figcaption>Hierarchical Inheritance (same parent -&gt; 2 or more children)</figcaption></figure><pre>public class A{<br>// statements<br>}<br>public class B extends A{<br>//statements<br>}<br>public class C extends A{<br>// statements<br>}<br>public class D extends A{<br>// statements<br>}</pre><blockquote><em>Multiple Inheritance :</em></blockquote><blockquote><em>Wait !!! What ??? Where does this come from now ? You would be confused that I mentioned only 4 types and this type is not even mentioned in the above list. Exactly!, it actually doesn’t exist in Java. But it exists in other languages say C / C++. So here I am referring to this type so as to get you guys understand the last type.</em></blockquote><blockquote>~ In multiple inheritance, one direct sub-class inherits two or more than two direct super classes.</blockquote><blockquote>But in Java, Multiple Inheritance is not allowed as it is possible that 2 or more direct super-classes may have the same methods and variables and hence when child calls the parent class’s method, the JVM will get confused whether which method to call and hence will output an error.</blockquote><blockquote><em>But To solve this problem, concept of Interface was introduced. In Java, multiple interface is allowed but multiple inheritance is not allowed.</em></blockquote><pre>public class A{<br>// statements<br>}<br>public class B{<br>// statements<br>}<br>public class C extends A, B{<br>// statements<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/316/1*r1ZDmtIKgXGa9BdeWmkSIQ.png" /></figure><p><strong><em>4. Hybrid Inheritance : </em></strong>So Hybrid Inheritance is actually the combination of Multi-level and Multiple Inheritance. But we know that multiple inheritance is not allowed in Java then how come it’s possible to apply for Hybrid inheritance?</p><p>The answer is simple, as I mentioned earlier that multiple inheritance is not allowed but I did say that though multiple interface is allowed, so yess!, Hybrid can be achieved through use of interfaces.</p><pre>public class A{<br>// statements<br>}<br>public class B extends A{<br>// statements<br>}<br>public class C extends A{<br>// statements<br>}<br>public class D extends B, C{<br>// statements<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/284/1*mzGrTqML5a-ngJcIFJqdNQ.png" /><figcaption>Hybrid Inheritance (parent -&gt; 2 or more children -&gt; new child of all the previous children)</figcaption></figure><h3><strong>6. Polymorphism</strong></h3><p>Polymorphism simple means ‘means many forms’ as the word suggests - ‘poly’ meaning “many” and ‘morph’ meaning “form”.</p><p>Got Confused ??</p><p>Let’s see a real life example : What say Cricket !!</p><p>Let’s say there is a Bowler Class and it is a parent which contains a bowlingMethod() and there are different child classes according to types of bowlers in cricket namely - FastPacer, MediumPacer and Spinner and all of them inherit the parent class Bowler Class’s bowlingMethod().</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QRFuzb9tHetJIV2LDjuxuA.png" /><figcaption>Polymorphism</figcaption></figure><p>So in the picture above, all 3 children are inheriting the method but in each and every respective child class, the implementation of the bowlingMethod() will be different as compared to others.</p><p>So you see, the method name is same i.e ‘bowlingMethod’ but its implementation is different for every child class, so that’s it we achieved Polymorphism !!</p><p>Polymorphism in Java is of 2 types :</p><ol><li><strong><em>Compile Time Polymorphism : </em></strong>Also known as Static polymorphism or early binding, this can be achieved through Method Overloading which is a process which allows a class to have two or more methods with the same name but 1) the arguments or data types passed to these methods are different and / or 2) the numbers of arguments in these methods are different.</li></ol><pre>class Addition {<br>Static int add(int a, int b)     //return type int and 2 arguments<br>{<br>return a+b;           <br>}<br>static double add( double a, double b) //return type double<br>{<br>return a+b;<br>}<br>static int add(int a, int b, int c) //return type int but 3 args<br>{<br>return a+b+c;<br>} <br>public static void main(String args[])<br>{<br>System.out.println(Addition.add(11,11));<br>System.out.println(Addition.add(12.3,12.6));<br>System.out.println(Addition.add(11,12,13));<br>}<br>}</pre><p><strong><em>2. Run Time Polymorphism : </em></strong>Also known as Dynamic polymorphism or late binding, this can be achieved through Method Overriding or dynamic dispatch which is a process of implementing parent class methods in child class with same name or signature or simple overriding the parent class method. So in this way a programmer can run a method in different ways by simply invoking object of that respective class (i.e parent class or child class).</p><pre>public Class BowlerClass{<br>void bowlingMethod()<br>{<br>System.out.println(“ bowler “);<br>}<br>public Class FastPacer{<br>void bowlingMethod()<br>{<br>System.out.println(“ fast bowler “);<br>}<br>Public static void main(String[] args)<br>{<br>FastPacer obj= new FastPacer();<br>obj.bowlingMethod();<br>}<br>}<br>// So here, we override the parent class(BowlerClass) method with the child class method by simple creating object for child class and calling the method !!</pre><p>So in this way, we have finally covered all the OOPs concepts which form the core principles or building blocks of Java. So grasping these OOPs concept is the key to understand how Java works!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*rdQl0Qdg9uIq9Prrq1mjIw.gif" /></figure><p>Finally we have come to an end !! So this was all about OOPs concept in Java. That is it from my end , will meet you guys in my next blog !!</p><p>So In this way we covered the OOPs concepts and um... um… um……… Oops! Bye !</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*rB630SCdVPDwPYGNL2nJCg.gif" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8c43bf927c3c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>