<?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 Vishal Das on Medium]]></title>
        <description><![CDATA[Stories by Vishal Das on Medium]]></description>
        <link>https://medium.com/@vdas53073?source=rss-3e6b75a77f7f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*7Yj_IMw4Buk4akj1iV3bCg.jpeg</url>
            <title>Stories by Vishal Das on Medium</title>
            <link>https://medium.com/@vdas53073?source=rss-3e6b75a77f7f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 10:42:53 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vdas53073/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[Protocol Buffers…Is JSON getting replaced in apis ?]]></title>
            <link>https://medium.com/@vdas53073/protocol-buffers-is-json-getting-replaced-in-apis-9b3abc43d031?source=rss-3e6b75a77f7f------2</link>
            <guid isPermaLink="false">https://medium.com/p/9b3abc43d031</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[json]]></category>
            <category><![CDATA[google]]></category>
            <category><![CDATA[protobuf]]></category>
            <dc:creator><![CDATA[Vishal Das]]></dc:creator>
            <pubDate>Mon, 19 Jan 2026 11:21:23 GMT</pubDate>
            <atom:updated>2026-01-19T11:21:23.278Z</atom:updated>
            <content:encoded><![CDATA[<h3>Protocol Buffers…Is JSON getting replaced in apis ?</h3><p>For long we have used json to communicate between two entities wether it is client-server or between two services. The first thing that comes to our mind for data transfer is JSON format( XML crying in corner 🥹). But now even JSON is getting replaced in some places quietly with prof or protocol buffers developed by Google. So what is it ? Lets dive deeper into it.</p><ol><li>What Protobuf really is</li><li>How it works internally</li><li>.proto syntax (in detail)</li><li>Field rules &amp; types</li><li>Versioning &amp; evolution rules (edges)</li><li>Common pitfalls &amp; best practices</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZafnXOKp9xlv7gauwCweEQ.jpeg" /><figcaption>Prof vs JSON</figcaption></figure><ol><li>What Protocol Buffers REALLY Are ? 🤔</li></ol><p><strong>Protocol Buffers =</strong></p><ul><li>A <strong>schema language</strong> (.proto)</li><li>A <strong>binary serialization format</strong></li><li>A <strong>code generator</strong></li></ul><p>They define:</p><ul><li><strong>What data looks like</strong></li><li><strong>How it’s serialized.</strong></li><li><strong>How different services agree on structure.</strong></li></ul><p>2. How Protobuf Works (End-to-End)</p><ul><li>You write a .proto file</li><li>protoc compiles it</li><li>Language-specific classes are generated</li><li>You build objects using <strong>Builder</strong></li><li>Protobuf encodes object → binary</li><li>Binary is sent over network / stored</li><li>Receiver decodes binary → object</li></ul><pre>syntax = &quot;proto3&quot;; // mandatory, tells which version to use<br><br>package user; <br><br>option java_package = &quot;com.example.user&quot;;<br>option java_multiple_files = true;</pre><ul><li><strong>package</strong></li></ul><pre>package user;</pre><ul><li>Namespace inside Protobuf world</li><li>Prevents name collision</li><li>Not same as Java package</li><li><strong>option :- Used to customize code generation.</strong></li></ul><pre>option java_package = &quot;com.example.user&quot;;<br>option java_outer_classname = &quot;UserProto&quot;;<br>option java_multiple_files = true;</pre><p># <strong>option java_package</strong> :- Defines the <strong>Java package name</strong> for generated classes.</p><p>$ .proto files are language-neutral</p><p>$ Java <strong>requires</strong> a package.</p><p>$ Protobuf does <strong>not</strong> automatically follow folder structure.</p><p>❌ Without this option</p><pre>package user;</pre><p>✅ With this option</p><pre>package com.example.user;</pre><h3>❌ Default behavior (confusing)</h3><p>If your file is user.proto, Protobuf generates:</p><pre>public final class UserOuterClass {<br>   public static final class User { ... }<br>}</pre><p>✅ With java_outer_classname</p><pre>public final class UserProto {<br>   public static final class User { ... }<br>}</pre><p># <strong>option java_outer_classname</strong> :- Defines the <strong>wrapper (outer) Java class name</strong>.</p><p>$ Protobuf generates:</p><ul><li>Message classes</li><li>Enums</li><li>Service stubs</li></ul><p>Java requires them to live inside <strong>a class</strong> (unless multiple_files=true).</p><p># Generates <strong>one Java class per message/service</strong>, instead of nesting everything.</p><h3>❌ Default behavior (false)</h3><p>Everything inside one outer class:</p><pre>UserProto.User<br>UserProto.UserRequest<br>UserProto.UserResponse<br>UserProto.UserServiceGrpc</pre><h3>✅ With true</h3><p>Each message becomes its <strong>own Java file</strong>:</p><pre>User.java<br>UserRequest.java<br>UserResponse.java<br>UserServiceGrpc.java<br><br>All inside:<br>package com.example.user;</pre><ul><li>Messages :-</li></ul><p>message ≈ class / struct</p><p>Fields must have:</p><ul><li>type</li><li>name</li><li>unique number</li></ul><pre>message User {<br>  int64 id = 1;<br>  string name = 2;<br>}</pre><ul><li><strong>Field Numbers (VERY IMPORTANT):-</strong></li><li>Used in binary encoding</li><li>Determines compatibility</li><li>Range:</li><li>1–15 → 1 byte (fast)</li><li>16–2047 → 2 bytes</li></ul><p>⚠️ <strong>Never reuse or change numbers</strong></p><pre>int64 id = 1;</pre><ul><li>Message Types :-</li></ul><p>a. Nested objects :-</p><pre>message Address {<br>  string city = 1;<br>}<br><br>message User {<br>  Address address = 3;<br>}</pre><p>b. Repeated Fields (Lists) :-</p><ul><li>Ordered list</li><li>Can be empty</li><li>No nulls</li></ul><pre>repeated string roles = 4;</pre><p>c. Enums:-</p><ul><li>First value MUST be 0</li><li>Unknown values are preserved</li></ul><pre>enum Status {<br>  UNKNOWN = 0;<br>  ACTIVE = 1;<br>  BLOCKED = 2;<br>}</pre><p>d. Optional Fields (proto3)</p><pre>optional string phone = 5;</pre><ul><li>Allows presence check:-</li></ul><pre>user.hasPhone();</pre><p>Without optional:</p><ul><li>Field has default value so you cann’t do hasPhone and checked if it was send.</li></ul><p>e. Reserved fields(ADVANCED):-</p><p><strong>Reserved fields prevent field numbers or names from being reused in the future.</strong></p><p>They are used when:</p><ul><li>You <strong>remove</strong> a field</li><li>You want to <strong>avoid breaking old clients.</strong></li></ul><p>If you reuse a field number:<br> ➡ <strong>Data corruption</strong> (silent &amp; dangerous)</p><p>❌<strong> Dangerous Scenario (Without reserved)</strong></p><p><strong>Old Version</strong></p><pre>message User {<br>  string email = 1;<br>}</pre><p>New Version</p><pre>message User {<br>  int32 age = 1;  // reused number<br>}</pre><p>Old client sends:</p><pre>email = &quot;abc@gmail.com&quot;</pre><p>New server reads:</p><pre>age = ???   (garbage)</pre><p>💥 <strong>No error, wrong data</strong></p><p>✅ Correct Way: Use reserved</p><pre>message User {<br>  reserved 1;<br>  reserved &quot;email&quot;;<br><br>  int32 age = 2;<br>}</pre><p>Now if you use any reserved word/number then compile error:-</p><pre>Field number 1 has been reserved</pre><p>f. Oneof (Advanced)</p><pre>oneof contact {<br>  string email = 1;<br>  string phone = 2;<br>}</pre><ul><li>Only one field can be set</li><li>Saves memory</li><li>Replaces unions</li></ul><p>4. Best Practices (Production):-</p><p>✔ Reserve removed fields<br> ✔ Keep field numbers stable<br> ✔ Use low numbers for hot fields<br> ✔ Use oneof instead of many optionals<br> ✔ Version via new messages, not edits</p><p>5. Where it can be used:-</p><p>1️⃣ <strong>Service-to-Service Communication (Microservices)</strong></p><p><strong>Example:</strong></p><ul><li>Spring Boot service A → service B</li><li>Internal APIs (not exposed to browser)</li></ul><p><strong>Why Protobuf wins:</strong></p><ul><li>60–80% smaller payloads</li><li>Much faster serialization/deserialization</li><li>Strong contract via .proto</li><li>Version-safe</li></ul><p>👉 <strong>Best choice:</strong> gRPC + Protobuf</p><p>2️⃣ Mobile Apps (Android / iOS):-</p><p>Mobile constraints:</p><ul><li>Low bandwidth</li><li>High latency</li><li>Battery sensitive</li></ul><p><strong>Why Protobuf:</strong></p><ul><li>Smaller network payload</li><li>Faster parsing</li><li>Lower battery usage</li></ul><p>Many mobile backends use:</p><ul><li>gRPC + Protobuf</li></ul><p>3️⃣ <strong>High-Traffic APIs:-</strong></p><p>If your API handles:</p><ul><li>Millions of requests/day</li><li>Low-latency requirements</li></ul><p><strong>Why:</strong></p><ul><li>JSON parsing is CPU heavy</li><li>Protobuf is binary &amp; fast</li></ul><p>Used by:</p><ul><li>Google</li><li>Netflix</li><li>Uber</li></ul><p>4️⃣ <strong>Streaming &amp; Real-Time Systems</strong></p><p>Examples:</p><ul><li>Chat apps</li><li>Live feeds</li><li>Gaming servers</li><li>Stock tickers</li></ul><p><strong>Why Protobuf:</strong></p><ul><li>Streaming support (gRPC)</li><li>Binary framing</li><li>Low latency</li></ul><p>5️⃣ <strong>Event-Driven Systems (Kafka, Pub/Sub)</strong></p><p>Use Protobuf:</p><ul><li>Schema evolution</li><li>Backward compatibility</li><li>Smaller message size</li></ul><p>Common in:</p><ul><li>Kafka</li><li>Google Pub/Sub</li><li>Pulsar</li></ul><p>6️⃣ Long-Term Data Storage (Structured):-</p><p>Examples:</p><ul><li>Logs</li><li>Snapshots</li><li>State storage</li></ul><p>Benefits:</p><ul><li>Compact</li><li>Schema enforced</li><li>Faster read/write</li></ul><p>❌ Where You SHOULD NOT Replace JSON with Protobuf</p><p>1️⃣ <strong>Public REST APIs</strong></p><p>Browsers:</p><ul><li>Can’t read Protobuf</li><li>Hard to debug</li><li>Hard to document</li></ul><p>👉 JSON wins.</p><p>2️⃣<strong> Simple CRUD Apps</strong></p><p>If:</p><ul><li>Low traffic</li><li>Few endpoints</li></ul><p>Protobuf adds:</p><ul><li>Tooling overhead</li><li>Learning curve</li></ul><p>Not worth it.</p><p>3️⃣<strong> Config Files</strong></p><p>Human readability matters.</p><p>Use:</p><ul><li>JSON</li><li>YAML</li><li>TOML</li></ul><p>4️⃣<strong> Frontend Communication (Browser)</strong></p><p>Browsers:</p><ul><li>No native Protobuf support</li><li>DevTools can’t inspect</li></ul><p>JSON is better.</p><p><strong>Summary of JSON vs Prof.</strong></p><pre>Use Case       JSON Protobuf<br>Browser APIs    ✅     ❌<br>Microservices   ❌     ✅<br>Mobile backend  ⚠️.    ✅<br>Streaming       ❌     ✅<br>Kafka events    ⚠️     ✅<br>Debugging       ✅     ❌</pre><p>I hope this article was deep enough to make you understand about protocol buffers and its uses. In next artcile we will see a complete code of prof. and how it can be used in <strong>SpringBoot</strong> and <strong>gRPC</strong>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9b3abc43d031" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Beyond Objects: IOC Container and Dependency Injection]]></title>
            <link>https://blog.stackademic.com/beyond-objects-ioc-conatiner-and-dependency-injection-ba5dd81d107d?source=rss-3e6b75a77f7f------2</link>
            <guid isPermaLink="false">https://medium.com/p/ba5dd81d107d</guid>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[spring]]></category>
            <category><![CDATA[dependency-injection]]></category>
            <category><![CDATA[backend]]></category>
            <category><![CDATA[backend-development]]></category>
            <dc:creator><![CDATA[Vishal Das]]></dc:creator>
            <pubDate>Wed, 29 Nov 2023 04:13:24 GMT</pubDate>
            <atom:updated>2023-11-30T01:35:06.583Z</atom:updated>
            <content:encoded><![CDATA[<p>This blog for sure will help you to understand the concepts of dependency injection(DI) and inversion of control (IoC). On top of that, it will also help you to create a sample Spring application with Java installation.</p><p>This blog will also explains dependency injection in detail.</p><p><strong>Dependency injection</strong> is also called as DI and it is a kind of design pattern that makes code loosely coupled and easy to manage.</p><p>In Spring framework, dependency injection can be achieved using below methods:<br>1. constructor<br>2. Getter and Setter bean class methods</p><p>There are multiple ways to create an instance of class:</p><h3>using new keyword</h3><blockquote><em>Person person = new Person();</em></blockquote><h3>Using static method of that class</h3><blockquote><em>public static Person getPersonInstance() {<br>person = new Person();<br>}<br>Person person = Person.getPersonInstance();</em></blockquote><p>There is an issue with above instance creation as mentioned below:</p><p><strong>Tight coupling</strong>: Above instance creation approach will be tightly coupled. To change a instance type will require a lot of changes in core files and testing. On top of that, it will require a complete code deployment.</p><h3>Inversion of Control</h3><p>Whenever we talk about dependency injection, there is one more topic that comes up for discussion, which is Inversion of Control (IoC).</p><p>IoC container uses dependency injection and inversion of control which helps us to instantiates, configures, and assembles beans or pojo classes by reading XML configurations, Java annotations, and/or Java code in the configuration files.</p><p>IoC is achieved through DI .Inversion of Control is a type of prototype that Dependency Injection operates on.This actually inverts control or changes the way we do things.</p><p>Previously, we used to create an instance of a class using the new keyword, and to make a change in the reference, we required a complete build. We can create an instance of a class in the SpringConfig.xml file using dependency injection without adding a new keyword or changing the Java file. Making a change will also not require a build or code change, as it will be just a config change. The way we are creating an instance is called Inversion of Control, where we invert or transfer the control or responsibility.</p><p>The container is all about xml file which instantiate application classes and manage the dependency in between therse objects.</p><p>To achieve loose coupling and less dependency we ust dependency injection. IoC container is respnsible for managing dependencies in between objects using DI.</p><p>Spring provides two types of containers:</p><p>BeanFactoryContainer<br>BeanfactoryContainer class is an implementation of org.springframework.beans.factory.BeanFactory interface.<br>Below is the code snippet to create BeanFactory instance:</p><blockquote><em>Resource resource=new ClassPathResource(“applicationContext.xml”);<br>BeanFactory factory=new XmlBeanFactory(resource);</em></blockquote><p>ApplicationContext Container<br>ApplicationContext is the child interface of BeanFactory interface.</p><p>ClassPathXmlApplicationContext class is an implementation of org.springframework.context.ApplicationContext interface.</p><p>Below is the code snippet to create BeanFactory instance:</p><blockquote><em>ApplicationContext context =<br>new ClassPathXmlApplicationContext(“applicationContext.xml”);</em></blockquote><p><strong>Note:</strong><br>It is always suggested to use ApplicationContext as it is a child of the BeanFactory interface and has more rich extra features. It provides support for i18n, annotation-based dependency injection, and integration with AOP without writing extra code. If the project requires little memory, use BeanFactory.</p><h3>Note:</h3><p>If you require a help to setup and create Spring project in local. Please follow <a href="https://medium.com/@toimrank/spring-boot-project-setup-in-5-min-c1e6d2541027">link</a> which will help you to create Spring project within 5 min with custom output.</p><h3>Dependency Injection using Constructor</h3><p>As mentioned above, dependency injection can be achieved using constructor and setter method.</p><p>Let’s follow below steps to achieve dependency injection using constructor:</p><ol><li>Create sample Spring project and create Person.java file.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*_iSOwhV7SInQGRRG.png" /></figure><p>2. Create <strong>SpringConfig.xml</strong> file in parallel to <strong>com.example.demo</strong> package which will help us to create bean class instance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*06NAeemT4CKyWuMo.png" /></figure><p><strong>Note: </strong>In below code snippet, line number 8 helps us to create an instance of Person class with default constructor and line number 10 help us to create an instance of same Person class using parameterized constructor.</p><p>Creation of instance using SpringConfig.xml file helps us to achieve loose coupling.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*oSPfBUOHyEO_ApvQ.png" /></figure><p>3. Create public Java class with main method to class Person bean class object.</p><p>Line number 9 ClassPathXmlApplicationContext will load and it will load all beans defined in SpringConfig.xml as mentioned in above steps.</p><p>At line number 11 create a instance of Person class using context instance as pass “person” as a parameter defined in SpringConfig.xml</p><p>Line number 14 will call getPersonName() method defined in Person class using instance created at line number 11.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*tIFrzRmMoOhekziG.png" /></figure><p>OUTPUT:-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*BxK50CTRgRshAahN.png" /></figure><h3>Dependency Injection using Setter method</h3><p>Let’s follow below steps to achieve dependency injection using setter method.</p><p>Setter method helps us to create an instance of a class and assign same instance variable to different class.</p><p><strong>Step1:</strong> Lets create new Spring project and Address.java class with below content.</p><p>Below Address class contains a constructor and public method.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*WRvFb327_vMKxEJh.png" /></figure><p><strong>Step2:</strong> Create a Person class having one Address variable with setAddress() method.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*nbwKZWFPv44UOkrj.png" /></figure><p><strong>Step3:</strong> Create <strong>SpringConfig.xml</strong> file and paste/write below code from line number 8 to 12. Line number 8 and 12 will help us to create Person and Address class instance.</p><p>Below line number 9 in <strong>SpringConfig.xml</strong> will call <strong>setAddress()</strong> method form <strong>Person</strong> class to set a value of <strong>address</strong> variable which got create at line number 12.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*c9Kq8sMNYmTbveJQ.png" /></figure><p>Output:-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*oY87pJmkyRuwrx9g.png" /></figure><p>I hope you found out this article interesting and informative. Please share it with your friends to spread the knowledge.</p><h3>Stackademic</h3><p><em>Thank you for reading until the end. Before you go:</em></p><ul><li><em>Please consider </em><strong><em>clapping</em></strong><em> and </em><strong><em>following</em></strong><em> the writer! 👏</em></li><li><em>Follow us on </em><a href="https://twitter.com/stackademichq"><strong><em>Twitter(X)</em></strong></a><em>, </em><a href="https://www.linkedin.com/company/stackademic"><strong><em>LinkedIn</em></strong></a><em>, and </em><a href="https://www.youtube.com/c/stackademic"><strong><em>YouTube</em></strong></a><strong><em>.</em></strong></li><li><em>Visit </em><a href="http://stackademic.com/"><strong><em>Stackademic.com</em></strong></a><em> to find out more about how we are democratizing free programming education around the world.</em></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ba5dd81d107d" width="1" height="1" alt=""><hr><p><a href="https://blog.stackademic.com/beyond-objects-ioc-conatiner-and-dependency-injection-ba5dd81d107d">Beyond Objects: IOC Container and Dependency Injection</a> was originally published in <a href="https://blog.stackademic.com/">Stackademic</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Servlets and JSP : Building Dynamic Web Applications]]></title>
            <link>https://blog.stackademic.com/servlets-and-jsp-building-dynamic-web-applications-7097bfde56d3?source=rss-3e6b75a77f7f------2</link>
            <guid isPermaLink="false">https://medium.com/p/7097bfde56d3</guid>
            <category><![CDATA[jsp]]></category>
            <category><![CDATA[servers]]></category>
            <category><![CDATA[servlet]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Vishal Das]]></dc:creator>
            <pubDate>Mon, 13 Nov 2023 03:38:32 GMT</pubDate>
            <atom:updated>2023-11-13T09:41:08.044Z</atom:updated>
            <content:encoded><![CDATA[<h3>Servlets and JSP : Building Dynamic Web Applications</h3><p>Servlets is a simple Java program that runs on server and capable of handling the request obtained from the webserver, process the request, produce the response, then send a response back to the webserver.</p><p>What is server?</p><p><strong>Server</strong> is a computer program not a device. It is a computer program that provides functionality or services to other programs known as clients.</p><p>Types:-</p><ol><li><strong>Web Server</strong>:- It handles all incoming HTTP requests from clients and serves static content. They also act as connectors to servlet containers or application servers for dynamic content. It serves only web-based applications. e.g:- Apache Http Server, Nginx.</li><li><strong>Application Server</strong>:- It is a framework (servlet container, EJB container, JSP engine, MQ container, etc.) for handling Web applications. It handles requests from all protocols, including HTTP, and serves dynamic content. It uses multithreading to handle multiple requests simultaneously. It serves web and enterprise-based applications. e.g:- Apache Tomcat.</li></ol><p><strong>Servlet Container(Web Container)</strong>:- It is a component of a web server that interacts with Java servlets. A web container manages the life cycle of servlets; it maps a URL to a particular servlet while ensuring that the requester has relevant access rights.</p><h4>How web container handles the servlet request?</h4><ul><li>maps the request with the servlet in the web.xml file.</li><li>creates request and response objects for this request</li><li>calls the service method on the thread</li><li>The public service method internally calls the protected service method</li><li>The protected service method calls the doGet method depending on the type of request.</li><li>The doGet method generates the response and it is passed to the client.</li><li>After sending the response, the web container deletes the request and response objects. The thread is contained in the thread pool or deleted depends on the server implementation.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/660/0*UL_E3jDR85a6NCQG.png" /><figcaption>Servlet Architecture</figcaption></figure><h4><strong>Hierachy of Servlet:-</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*b31hiO4ynbDLRrXWEFF4aQ.png" /><figcaption>Servlet Hierachy</figcaption></figure><ol><li><strong>Servlet Interface</strong>:- The <strong>Servlet interface</strong> is the root interface of the servlet class hierarchy. All Servlets need to either directly or indirectly implement the Servlet interface. It defines 5 methods (3 lifecycle and 2 non lifecycle methods):-</li></ol><ul><li><strong>public abstract void init(ServletConfig config)</strong> throws Servlet Exception :- The Web container calls this method after creating a servlet instance.</li><li><strong>public ServletConfig getServletConfig()</strong> :- Returns a ServletConfig object that contains configuration information, such as initialization parameters, to initialize a servlet.</li><li><strong>public void service(ServletRequest req,ServletResponse response) :- </strong>Everytime a new request comes to a servlet then request method of that servlet is called.</li><li><strong>public abstract String getServletInfo() </strong>:- Returns a string that contains information about the servlet, such as author, version, and copyright.</li><li><strong>public abstract void destory()</strong> :- The Web container calls the destroy() method just before removing the servlet instance from service during server shutdown or when we no longer need that servlet.</li></ul><pre>import java.io.*;  <br>import javax.servlet.*;  <br>  <br>public class First implements Servlet{  <br>ServletConfig config=null;  <br>  <br>public void init(ServletConfig config){  <br>this.config=config;  <br>System.out.println(&quot;servlet is initialized&quot;);  <br>}  <br>  <br>public void service(ServletRequest req,ServletResponse res)  <br>throws IOException,ServletException{  <br>  <br>res.setContentType(&quot;text/html&quot;);  <br>  <br>PrintWriter out=res.getWriter();  <br>out.print(&quot;&lt;html&gt;&lt;body&gt;&quot;);  <br>out.print(&quot;&lt;b&gt;hello simple servlet&lt;/b&gt;&quot;);  <br>out.print(&quot;&lt;/body&gt;&lt;/html&gt;&quot;);  <br>  <br>}  <br>public void destroy(){System.out.println(&quot;servlet is destroyed&quot;);}  <br>public ServletConfig getServletConfig(){return config;}  <br>public String getServletInfo(){return &quot;copyright 2007-1010&quot;;}  <br>  <br>} </pre><p>2. <strong>Generic Servlet</strong>:- The <strong>GenericServlet </strong>is a abstract<strong> </strong>class of the <strong>Servlet API</strong> implements the Servlet interface. In addition to the Servlet interface, the GenericServlet class implements the <strong>ServletConfig interface of the Servlet API</strong> and the Serializable interface of the standard java.io. package. It provides implementation to every methods of servlet interface except the service method.</p><ol><li><strong>public void init(ServletConfig config)</strong> is used to initialize the servlet.</li><li><strong>public abstract void service(ServletRequest request, ServletResponse response)</strong> provides service for the incoming request. It is invoked at each time when user requests for a servlet.</li><li><strong>public void destroy()</strong> is invoked only once throughout the life cycle and indicates that servlet is being destroyed.</li><li><strong>public ServletConfig getServletConfig()</strong> returns the object of ServletConfig.</li><li><strong>public String getServletInfo()</strong> returns information about servlet such as writer, copyright, version etc.</li><li><strong>public void init()</strong> it is a convenient method for the servlet programmers, now there is no need to call super.init(config)</li><li><strong>public ServletContext getServletContext()</strong> returns the object of ServletContext.</li><li><strong>public String getInitParameter(String name)</strong> returns the parameter value for the given parameter name.</li><li><strong>public Enumeration getInitParameterNames()</strong> returns all the parameters defined in the web.xml file.</li><li><strong>public String getServletName()</strong> returns the name of the servlet object.</li><li><strong>public void log(String msg)</strong> writes the given message in the servlet log file.</li><li><strong>public void log(String msg,Throwable t)</strong> writes the explanatory message in the servlet log file and a stack trace.</li></ol><pre>import java.io.*;  <br>import javax.servlet.*;  <br>  <br>public class First extends GenericServlet{  <br>public void service(ServletRequest req,ServletResponse res)  <br>throws IOException,ServletException{  <br>  <br>res.setContentType(&quot;text/html&quot;);  <br>  <br>PrintWriter out=res.getWriter();  <br>out.print(&quot;&lt;html&gt;&lt;body&gt;&quot;);  <br>out.print(&quot;&lt;b&gt;hello generic servlet&lt;/b&gt;&quot;);  <br>out.print(&quot;&lt;/body&gt;&lt;/html&gt;&quot;);  <br>  <br>}  <br>}  </pre><blockquote>The object of the ServletConfig interface is used by the Web container to pass the configuration information to a servlet when a servlet is initialized.</blockquote><p>3. <strong>HttpServlet</strong> :- To develop a servlet that communicates using HTTP, we need to extend the<strong> HttpServlet</strong> class in our servlet. The HttpServlet class extends the GenericServlet class and provides built-in HTTP functionality like doGet, doPost, doPut etc.</p><ol><li><strong>public void service(ServletRequest req,ServletResponse res)</strong> dispatches the request to the protected service method by converting the request and response object into http type.</li><li><strong>protected void service(HttpServletRequest req, HttpServletResponse res)</strong> receives the request from the service method, and dispatches the request to the doXXX() method depending on the incoming http request type.</li><li><strong>protected void doGet(HttpServletRequest req, HttpServletResponse res)</strong> handles the GET request. It is invoked by the web container.</li><li><strong>protected void doPost(HttpServletRequest req, HttpServletResponse res)</strong> handles the POST request. It is invoked by the web container.</li><li><strong>protected void doHead(HttpServletRequest req, HttpServletResponse res)</strong> handles the HEAD request. It is invoked by the web container.</li><li><strong>protected void doOptions(HttpServletRequest req, HttpServletResponse res)</strong> handles the OPTIONS request. It is invoked by the web container.</li><li><strong>protected void doPut(HttpServletRequest req, HttpServletResponse res)</strong> handles the PUT request. It is invoked by the web container.</li><li><strong>protected void doTrace(HttpServletRequest req, HttpServletResponse res)</strong> handles the TRACE request. It is invoked by the web container.</li><li><strong>protected void doDelete(HttpServletRequest req, HttpServletResponse res)</strong> handles the DELETE request. It is invoked by the web container.</li><li><strong>protected long getLastModified(HttpServletRequest req)</strong> returns the time when HttpServletRequest was last modified since midnight January 1, 1970 GMT.</li></ol><pre>// Import required java libraries<br>import java.io.*;<br>import javax.servlet.*;<br>import javax.servlet.http.*;<br><br>// Extend HttpServlet class<br>public class HelloWorld extends HttpServlet {<br> <br>   private String message;<br><br>   public void init() throws ServletException {<br>      // Do required initialization<br>      message = &quot;Hello World&quot;;<br>   }<br><br>   public void doGet(HttpServletRequest request, HttpServletResponse response)<br>      throws ServletException, IOException {<br>      <br>      // Set response content type<br>      response.setContentType(&quot;text/html&quot;);<br><br>      // Actual logic goes here.<br>      PrintWriter out = response.getWriter();<br>      out.println(&quot;&lt;h1&gt;&quot; + message + &quot;&lt;/h1&gt;&quot;);<br>   }<br><br>   public void destroy() {<br>      // do nothing.<br>   }<br>}</pre><p>4. ServletConfig Interface:- The<strong> javax.servlet.ServletConfig</strong> interface is implemented by a Web container to pass configuration information to a servlet, during initialization of a servlet. A servlet is initialized by passing an object of ServiceConfig to its init() method by the Web container. The ServletConfig object contains initialization information and provides access to the ServletContext object.</p><p><strong>Initialization parameters</strong> are name value pairs that we can use to pass information to a servlet.</p><ul><li>public String <strong>getInitParameter</strong>(String param):- Returns a String containing the value of the specified initialization parameters or null if the parameter does not exist.</li><li>public Enumeration <strong>getInitParameterNames</strong>():- Returns the names of all initialization parameters as an Enumeration of String objects. If no initialization parameters have been defined, an empty Enumeration is returned.</li><li>public ServletContext<strong> getServletContext</strong>():- Returns the ServletContext object for the servlet, which allows interaction with the Web container.</li></ul><h4><strong>LifeCycle of Servlet</strong>:-</h4><p>The web container maintains the life cycle of a servlet instance. Let’s see the life cycle of the servlet:</p><ol><li>Servlet class is loaded.</li><li>Servlet instance is created.</li><li>init method is invoked.</li><li>service method is invoked.</li><li>destroy method is invoked.</li></ol><h3>1) Servlet class is loaded</h3><p>The classloader is responsible to load the servlet class. The servlet class is loaded when the first request for the servlet is received by the web container.</p><h3>2) Servlet instance is created</h3><p>The web container creates the instance of a servlet after loading the servlet class. The servlet instance is created only once in the servlet life cycle.</p><h3>3) init method is invoked</h3><p>The web container calls the init method only once after creating the servlet instance. The init method is used to initialize the servlet. It is the life cycle method of the javax.servlet.Servlet interface. Syntax of the init method is given below:</p><blockquote><strong>public</strong> <strong>void</strong> init(ServletConfig config) <strong>throws</strong> ServletException</blockquote><h3>4) service method is invoked</h3><p>The web container calls the service method each time when request for the servlet is received. If servlet is not initialized, it follows the first three steps as described above then calls the service method. If servlet is initialized, it calls the service method. Notice that servlet is initialized only once. The syntax of the service method of the Servlet interface is given below:</p><blockquote><strong>public</strong> <strong>void</strong> service(ServletRequest request, ServletResponse response)<strong>throws</strong> ServletException, IOException</blockquote><h3>5) destroy method is invoked</h3><p>The web container calls the destroy method before removing the servlet instance from the service. It gives the servlet an opportunity to clean up any resource for example memory, thread etc. The syntax of the destroy method of the Servlet interface is given below:</p><blockquote><strong>public</strong> <strong>void</strong> destroy()</blockquote><h3>What is written inside the public service method?</h3><p>The public service method converts the ServletRequest object into the HttpServletRequest type and ServletResponse object into the HttpServletResponse type. Then, calls the service method passing these objects.</p><pre>public void service(ServletRequest req, ServletResponse res)  <br>        throws ServletException, IOException  <br>    {  <br>        HttpServletRequest request;  <br>        HttpServletResponse response;  <br>        try  <br>        {  <br>            request = (HttpServletRequest)req;  <br>            response = (HttpServletResponse)res;  <br>        }  <br>        catch(ClassCastException e)  <br>        {  <br>            throw new ServletException(&quot;non-HTTP request or response&quot;);  <br>        }  <br>        service(request, response);  <br>    }  </pre><h3>What is written inside the protected service method?</h3><p>The protected service method checks the type of request, if request type is get, it calls doGet method, if request type is post, it calls doPost method, so on.</p><pre>protected void service(HttpServletRequest req, HttpServletResponse resp)  <br>        throws ServletException, IOException  <br>    {  <br>        String method = req.getMethod();  <br>        if(method.equals(&quot;GET&quot;))  <br>        {  <br>            long lastModified = getLastModified(req);  <br>            if(lastModified == -1L)  <br>            {  <br>                doGet(req, resp);  <br>            }   <br>    ....  <br>    //rest of the code  <br>        }  <br>    }</pre><p><strong>Deployment Descriptor</strong>:- In a java web application a file named <strong>web.xml</strong> is known as deployment descriptor. It is a xml file and <strong>&lt;web-app&gt; </strong>is the root element for it. When a request comes web server uses web.xml file to map the URL of the request to the specific code that handle the request.</p><pre>&lt;web-app&gt;<br> <br> &lt;servlet&gt;<br>  &lt;servlet-name&gt;servletName&lt;/servlet-name&gt;<br>  &lt;servlet-class&gt;servletClass&lt;/servlet-class&gt;<br> &lt;/servlet&gt;<br> <br> &lt;servlet-mapping&gt;<br>  &lt;servlet-name&gt;servletName&lt;/servlet-name&gt;<br>  &lt;url-pattern&gt;*.*&lt;/url-pattern&gt;<br> &lt;/servlet-mapping&gt;<br> <br>&lt;/web-app&gt;</pre><h4>How web.xml works?</h4><p>When a request comes it is matched with url pattern in servlet mapping attribute. In the above example all urls mapped with the servlet. You can specify a url pattern according to your need. When url matched with url pattern web server try to find the servlet name in servlet attributes same as in servlet mapping attribute. When match found control is goes to the associated servlet class.</p><h4>welcome-file-list in web.xml:-</h4><p>The <strong>welcome-file-list</strong> element of <strong>web-app</strong>, is used to define a list of welcome files. Its sub element is <strong>welcome-file</strong> that is used to define the welcome file.</p><p>A <strong>welcome file</strong> is the file that is invoked automatically by the server, if you don’t specify any file name.</p><p>By default server looks for the welcome file in following order:</p><ol><li>welcome-file-list in web.xml</li><li>index.html</li><li>index.htm</li><li>index.jsp</li></ol><p>If none of these files are found, server renders 404 error.</p><pre>&lt;web-app&gt;  <br> ....  <br>  <br>  &lt;welcome-file-list&gt;  <br>   &lt;welcome-file&gt;home.html&lt;/welcome-file&gt;  <br>   &lt;welcome-file&gt;default.html&lt;/welcome-file&gt;  <br>  &lt;/welcome-file-list&gt;  <br>&lt;/web-app&gt;  </pre><h3>load-on-startup:</h3><p>The load-on-startup is the sub attribute of servlet attribute in web.xml. It is used to control when the web server loads the servlet. As we discussed that servlet is loaded at the time of first request. In this case response time is increased for first request. If load-on-startup is specified for a servlet in web.xml then this servlet will be loaded when the server starts. So the response time will not increase for fist request.</p><p>Any positive or negative value can be passed in the load-on-startup. If positive value is passed then all servlets having load-on-startup sub attribute will be loaded when server starts but a servlet having low positive value will be loaded first. In case of negative value servlet will be loaded at the time of first request.</p><pre>&lt;web-app&gt;<br> <br>   //other attributes  <br> <br>   &lt;servlet&gt;  <br>  &lt;servlet-name&gt;servlet1&lt;/servlet-name&gt;  <br>   &lt;servlet-class&gt;com.w3spoint.business.Servlet1 &lt;/servlet-class&gt;<br>    &lt;load-on-startup&gt;0&lt;/load-on-startup&gt;  <br>   &lt;/servlet&gt;  <br> <br>  &lt;servlet&gt;  <br>    &lt;servlet-name&gt;servlet2&lt;/servlet-name&gt;  <br>    &lt;servlet-class&gt; com.w3spoint.business.Servlet2&lt;/servlet-class&gt;<br>    &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;  <br>  &lt;/servlet&gt;    <br> <br>  &lt;servlet&gt;  <br>   &lt;servlet-name&gt;servlet3&lt;/servlet-name&gt;  <br>    &lt;servlet-class&gt; com.w3spoint.business.Servlet3&lt;/servlet-class&gt;<br>    &lt;load-on-startup&gt;-1&lt;/load-on-startup&gt;  <br>  &lt;/servlet&gt;  <br> <br>  //other attributes<br> <br>&lt;/web-app&gt;</pre><p>In the above example Servlet1 and Servlet2 will be loaded when server starts because positive value is passed in there load-on-startup. Servlet3 will be loaded at the time of first request because negative value is passed in there load-on-startup.</p><h4>Sending data from one Servlet to another Servlet:-</h4><ol><li>Request Dispatcher:- The RequestDispatcher interface provides the facility of dispatching the request to another resource it may be html, servlet or jsp. This interface can also be used to include the content of another resource also. It is one of the way of servlet collaboration.</li></ol><p>Methods:-</p><ol><li><strong>public void forward(ServletRequest request,ServletResponse response)throws ServletException,java.io.IOException:</strong>Forwards a request from a servlet to another resource (servlet, JSP file, or HTML file) on the server.</li><li><strong>public void include(ServletRequest request,ServletResponse response)throws ServletException,java.io.IOException:</strong>Includes the content of a resource (servlet, JSP page, or HTML file) in the response.</li></ol><pre>RequestDispatcher rd=request.getRequestDispatcher(&quot;servlet2&quot;);  <br>//servlet2 is the url-pattern of the second servlet  <br>  <br>rd.forward(request, response);//method may be include or forward  </pre><p>2. Send Redirect:- The <strong>sendRedirect()</strong> method of <strong>HttpServletResponse</strong> interface can be used to redirect response to another resource, it may be servlet, jsp or html file.</p><p>It accepts relative as well as absolute URL.It works at client side because it uses the url bar of the browser to make another request. So, it can work inside and outside the server.</p><pre>response.sendRedirect(&quot;http://www.javatpoint.com&quot;); </pre><h4>Session Tracking</h4><p><strong>Session Tracking</strong> is a way to maintain state (data) of an user. It is also known as <strong>session management</strong> in servlet.</p><p>Http protocol is a stateless so we need to maintain state using session tracking techniques. Each time user requests to the server, server treats the request as the new request. So we need to maintain the state of an user to recognize to particular user.</p><ul><li>Cookies</li><li>Hidden form field</li><li>Url Rewriting</li><li>HttpSession</li></ul><ol><li><strong>Cookies</strong>:- Textual information stored in key value pair.</li></ol><p>Types:-</p><ul><li>Non-persistent cookie:- It is <strong>valid for single session</strong> only. It is removed each time when user closes the browser</li><li>Persistent cookie:- It is <strong>valid for multiple session</strong> . It is not removed each time when user closes the browser. It is removed only if user logout or signout.</li></ul><h3>Advantage of Cookies</h3><ol><li>Simplest technique of maintaining the state.</li><li>Cookies are maintained at client side.</li></ol><h3>Disadvantage of Cookies</h3><ol><li>It will not work if cookie is disabled from the browser.</li><li>Only textual information can be set in Cookie object.</li></ol><p>2. <strong>Hidden Form Field</strong>:- In case of Hidden Form Field <strong>a hidden (invisible) textfield</strong> is used for maintaining the state of an user.</p><pre>&lt;input type=&quot;hidden&quot; name=&quot;uname&quot; value=&quot;Vimal Jaiswal&quot;&gt;  </pre><p>3. <strong>Url Rewriting:</strong>- In URL rewriting, we append a token or identifier to the URL of the next Servlet or the next resource. We can send parameter name/value pairs using the following format:</p><p>url?name1=value1&amp;name2=value2&amp;??</p><p>A name and a value is separated using an equal = sign, a parameter name/value pair is separated from another parameter using the ampersand(&amp;). When the user clicks the hyperlink, the parameter name/value pairs will be passed to the server. From a Servlet, we can use getParameter() method to obtain a parameter value.</p><h3>Advantage of URL Rewriting</h3><ol><li>It will always work whether cookie is disabled or not (browser independent).</li><li>Extra form submission is not required on each pages.</li></ol><h3>Disadvantage of URL Rewriting</h3><ol><li>It will work only with links.</li><li>It can send Only textual information.</li></ol><p>4. <strong>HtppSession:- </strong>container creates a session id for each user.The container uses this id to identify the particular user.An object of HttpSession can be used to perform two tasks:</p><ol><li>bind objects</li><li>view and manipulate information about a session, such as the session identifier, creation time, and last accessed time.</li></ol><h3>How to get the HttpSession object ?</h3><p>The HttpServletRequest interface provides two methods to get the object of HttpSession:</p><ol><li><strong>public HttpSession getSession():</strong>Returns the current session associated with this request, or if the request does not have a session, creates one.</li><li><strong>public HttpSession getSession(boolean create):</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><h3>Commonly used methods of HttpSession interface</h3><ol><li><strong>public String getId():</strong>Returns a string containing the unique identifier value.</li><li><strong>public long getCreationTime():</strong>Returns the time when this session was created, measured in milliseconds since midnight January 1, 1970 GMT.</li><li><strong>public long getLastAccessedTime():</strong>Returns the last time the client sent a request associated with this session, as the number of milliseconds since midnight January 1, 1970 GMT.</li><li><strong>public void invalidate():</strong>Invalidates this session then unbinds any objects bound to it.</li></ol><h3>Disadvantages of Servlets:-</h3><ol><li>Static content are generated by java inside servlet. Designing in servlet is difficult.</li><li>For request in servlet we have to write service method which is very tiresome.</li><li>Whenever modification is made in static content then servlet needs to recompiled and redeployed.</li></ol><h3><strong>JSP(Java Server Pages)</strong></h3><p>Jsp is extension of servlet technology that provides more functionality such as Expression Language, Custom Tags, etc.</p><h3>The Lifecycle of a JSP Page</h3><p>The JSP pages follow these phases:</p><ul><li>Translation of JSP Page</li><li>Compilation of JSP Page</li><li>Classloading (the classloader loads class file)</li><li>Instantiation (Object of the Generated Servlet is created).</li><li>Initialization ( the container invokes jspInit() method).</li><li>Request processing ( the container invokes _jspService() method).</li><li>Destroy ( the container invokes jspDestroy() method).</li></ul><h3>The JSP API</h3><ol><li><a href="https://www.javatpoint.com/jsp-api#">The JSP API</a></li><li><a href="https://www.javatpoint.com/jsp-api#jsppackage">javax.servlet.jsp package</a></li><li><a href="https://www.javatpoint.com/jsp-api#jsppage">The JspPage interface</a></li><li><a href="https://www.javatpoint.com/jsp-api#httpjsppage">The HttpJspPage interface</a></li></ol><p>The JSP API consists of two packages:</p><ol><li>javax.servlet.jsp</li><li>javax.servlet.jsp.tagext</li></ol><h3>javax.servlet.jsp package</h3><p>The javax.servlet.jsp package has two interfaces and classes.The two interfaces are as follows:</p><ol><li>JspPage</li><li>HttpJspPage</li></ol><p>The classes are as follows:</p><ul><li>JspWriter</li><li>PageContext</li><li>JspFactory</li><li>JspEngineInfo</li><li>JspException</li><li>JspError</li></ul><h3>The JspPage interface</h3><p>According to the JSP specification, all the generated servlet classes must implement the JspPage interface. It extends the Servlet interface. It provides two life cycle methods.</p><h3>Methods of JspPage interface</h3><ol><li><strong>public void jspInit():</strong> It is invoked only once during the life cycle of the JSP when JSP page is requested firstly. It is used to perform initialization. It is same as the init() method of Servlet interface.</li><li><strong>public void jspDestroy():</strong> It is invoked only once during the life cycle of the JSP before the JSP page is destroyed. It can be used to perform some clean up operation.</li></ol><h3>The HttpJspPage interface</h3><p>The HttpJspPage interface provides the one life cycle method of JSP. It extends the JspPage interface.</p><h3>Method of HttpJspPage interface:</h3><ol><li><strong>public void _jspService():</strong> It is invoked each time when request for the JSP page comes to the container. It is used to process the request. The underscore _ signifies that you cannot override this method.</li></ol><h3>Stackademic</h3><p><em>Thank you for reading until the end. Before you go:</em></p><ul><li><em>Please consider </em><strong><em>clapping</em></strong><em> and </em><strong><em>following</em></strong><em> the writer! 👏</em></li><li><em>Follow us on </em><a href="https://twitter.com/stackademichq"><strong><em>Twitter(X)</em></strong></a><em>, </em><a href="https://www.linkedin.com/company/stackademic"><strong><em>LinkedIn</em></strong></a><em>, and </em><a href="https://www.youtube.com/c/stackademic"><strong><em>YouTube</em></strong></a><strong><em>.</em></strong></li><li><em>Visit </em><a href="http://stackademic.com/"><strong><em>Stackademic.com</em></strong></a><em> to find out more about how we are democratizing free programming education around the world.</em></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7097bfde56d3" width="1" height="1" alt=""><hr><p><a href="https://blog.stackademic.com/servlets-and-jsp-building-dynamic-web-applications-7097bfde56d3">Servlets and JSP : Building Dynamic Web Applications</a> was originally published in <a href="https://blog.stackademic.com/">Stackademic</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Styling the Web: Mastering HTML and CSS Magic]]></title>
            <link>https://blog.stackademic.com/styling-the-web-mastering-html-and-css-magic-a0f12d2f8678?source=rss-3e6b75a77f7f------2</link>
            <guid isPermaLink="false">https://medium.com/p/a0f12d2f8678</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[html]]></category>
            <category><![CDATA[front-end-development]]></category>
            <dc:creator><![CDATA[Vishal Das]]></dc:creator>
            <pubDate>Sun, 05 Nov 2023 06:09:03 GMT</pubDate>
            <atom:updated>2023-11-06T00:45:45.097Z</atom:updated>
            <content:encoded><![CDATA[<p>Whether you are new to HTML/CSS or have some experience, you will surely learn something new in this blog.</p><p>First of all, let’s see what is the work of HTML/CSS or why we need them through a picture.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/754/1*tfoHyu_p-8shPpkYP0HjoQ.png" /><figcaption>html css</figcaption></figure><p>As shown in the picture above HTML (Hyper Text Markup Language) is the skeleton of a website where we define the raw structure of the website, and CSS (Cascading Style Sheets) is used for designing or adding colors to our website. Then JavaScript is used to add functions or make our website responsive to user actions.</p><p>Now let&#39;s dive deep into HTML:-</p><p>HTML uses “markup” to annotate text, images, and other content for display in a Web browser. HTML markup includes special “elements” such as <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/head">&lt;head&gt;</a>, <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/title">&lt;title&gt;</a>, <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/body">&lt;body&gt;</a>, <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/header">&lt;header&gt;</a>, <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/footer">&lt;footer&gt;</a>, <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/article">&lt;article&gt;</a>, <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/section">&lt;section&gt;</a>, <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/p">&lt;p&gt;</a>, <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/div">&lt;div&gt;</a>, <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/span">&lt;span&gt;</a>, <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img">&lt;img&gt;</a>, <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/aside">&lt;aside&gt;</a>, <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio">&lt;audio&gt;</a>, <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/canvas">&lt;canvas&gt;</a>, <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/datalist">&lt;datalist&gt;</a>, <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/details">&lt;details&gt;</a>, <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/embed">&lt;embed&gt;</a>, <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/nav">&lt;nav&gt;</a>, <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/search">&lt;search&gt;</a>, <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/output">&lt;output&gt;</a>, <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/progress">&lt;progress&gt;</a>, <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/video">&lt;video&gt;</a>, <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ul">&lt;ul&gt;</a>, <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ol">&lt;ol&gt;</a>, <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/li">&lt;li&gt;</a> and many others.</p><p>HTML differentiates its special elements from the text content with the help of <strong>tags</strong>. Tags are opening and middle tags and elements are present in middle of them i.e &lt; element_name &gt; . The element names inside the tag are case sensitive i.e &lt;title&gt; and &lt;TITLE&gt; both work.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/821/1*PHrGbCGm-Zk7_1bDBI_9CA.png" /><figcaption>structure</figcaption></figure><p>Elements can also have attributes that look like the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ltvb0uDHVPq_WlGVDTPWlA.png" /><figcaption>attribute</figcaption></figure><p>Attributes contain extra information about the element that you don’t want to appear in the actual content. Here, class is the attribute <em>name</em> and editor-note is the attribute <em>value</em>.</p><p>Nested Tags:-</p><pre>&lt;p&gt;My cat is &lt;strong&gt;very grumpy.&lt;/p&gt;&lt;/strong&gt;</pre><p>Void elements:- Elements having no content are called void elements.</p><pre>&lt;img src=&quot;images/firefox-icon.png&quot; alt=&quot;My test image&quot; /&gt;</pre><p>Structure of an HTML document:-</p><pre>&lt;!doctype html&gt;<br>&lt;html lang=&quot;en-US&quot;&gt;<br>  &lt;head&gt;<br>    &lt;meta charset=&quot;utf-8&quot; /&gt;<br>    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width&quot; /&gt;<br>    &lt;title&gt;My test page&lt;/title&gt;<br>  &lt;/head&gt;<br>  &lt;body&gt;<br>    &lt;img src=&quot;images/firefox-icon.png&quot; alt=&quot;My test image&quot; /&gt;<br>  &lt;/body&gt;<br>&lt;/html&gt;</pre><ul><li>&lt;!doctype html&gt; :- It is not an HTML tag; rather, it is a Document Type Declaration (DTD) that tells the browser about the version of HTML the page is written in and helps the browser render the web page correctly.</li><li>&lt;html&gt;&lt;/html&gt;:-It wraps all the content on the entire page and is sometimes known as the root element. It also includes the lang attribute setting the primary language of the document.</li><li>&lt;head&gt;&lt;/head&gt; :- It acts as a container for all the stuff you want to include on the HTML page that <em>isn’t</em> the content you are showing to your page’s viewers. This includes things like <a href="https://developer.mozilla.org/en-US/docs/Glossary/Keyword">keywords</a> and a page description that you want to appear in search results, CSS to style our content, character set declarations, and more.</li><li>&lt;meta charset=”utf-8&quot;&gt;:- This element sets the character set your document should use to UTF-8 which includes most characters from the vast majority of written languages.</li><li>&lt;meta name=”viewport” content=”width=device-width”&gt;:- The viewport element ensures the page renders at the width of viewport, preventing mobile browsers from rendering pages wider than the viewport and then shrinking them down.</li><li>&lt;title&gt;&lt;/title&gt;:-This sets the title of your page, which is the title that appears in the browser tab the page is loaded in.</li><li>&lt;body&gt;&lt;/body&gt;:-This contains <em>all</em> the content that you want to show to web users when they visit your page, whether that’s text, images, videos, games, playable audio tracks, or whatever else.</li></ul><p>Image Tag:-</p><pre>&lt;img src=&quot;images/firefox-icon.png&quot; alt=&quot;My test image&quot; /&gt;</pre><p>In the <strong>alt</strong> attribute, you specify descriptive text for users who cannot see the image.</p><p>Heading Tag:- The heading size decreases from h1 to h6.</p><pre>&lt;h1&gt;My main title&lt;/h1&gt;</pre><p>Paragraph Tag:- This is used for containing paragraphs of text.</p><pre>&lt;p&gt;This is a single paragraph&lt;/p&gt;</pre><p>List tag:- It is used for list tags.</p><ul><li>Ordered list :- These are ordered list using &lt;ol&gt;&lt;/ol&gt; tags.</li></ul><pre>&lt;ol&gt;<br>  &lt;li&gt;technologists&lt;/li&gt;<br>  &lt;li&gt;thinkers&lt;/li&gt;<br>  &lt;li&gt;builders&lt;/li&gt;<br>&lt;/ol&gt;</pre><ul><li>Unordered list:- These are unordered lists using &lt;ul&gt;&lt;/ul&gt; tags.</li></ul><pre>&lt;ul&gt;<br>  &lt;li&gt;technologists&lt;/li&gt;<br>  &lt;li&gt;thinkers&lt;/li&gt;<br>  &lt;li&gt;builders&lt;/li&gt;<br>&lt;/ul&gt;</pre><p>Links:- These are given using anchor tags &lt;a&gt;&lt;/a&gt;.</p><pre>&lt;a href=&quot;https://www.mozilla.org/en-US/about/manifesto/&quot;&gt;<br>  Mozilla Manifesto<br>&lt;/a&gt;</pre><p>Button:-</p><pre>&lt;button type=&quot;button&quot;&gt;Click Me!&lt;/button&gt;</pre><p>Break Tag:-</p><pre>&lt;br&gt; line breaks&lt;br&gt; in a text,&lt;br&gt;</pre><p>Div Tag:-</p><pre>&lt;div class=&quot;myDiv&quot;&gt;<br>  &lt;h2&gt;This is a heading in a div element&lt;/h2&gt;<br>  &lt;p&gt;This is some text in a div element.&lt;/p&gt;<br>&lt;/div&gt;</pre><p>Bold Tag:-</p><pre>&lt;strong&gt;This text is important!&lt;/strong&gt;</pre><p>Textarea tag:-</p><pre>&lt;textarea id=&quot;w3review&quot; name=&quot;w3review&quot; rows=&quot;4&quot; cols=&quot;50&quot;&gt;<br>At w3schools.com you will learn how to make a website. They offer free tutorials in all web development technologies.<br>&lt;/textarea&gt;</pre><p>Table tag:-</p><pre>&lt;table&gt;<br>  &lt;tr&gt;<br>    &lt;th&gt;Month&lt;/th&gt;<br>    &lt;th&gt;Savings&lt;/th&gt;<br>  &lt;/tr&gt;<br>  &lt;tr&gt;<br>    &lt;td&gt;January&lt;/td&gt;<br>    &lt;td&gt;$100&lt;/td&gt;<br>  &lt;/tr&gt;<br>  &lt;tr&gt;<br>    &lt;td&gt;February&lt;/td&gt;<br>    &lt;td&gt;$80&lt;/td&gt;<br>  &lt;/tr&gt;<br>&lt;/table&gt;</pre><p>Underline tag:-</p><pre>&lt;u class=&quot;spelling-error&quot;&gt;mispeled&lt;/u&gt;</pre><p>Progress bar:-</p><pre>&lt;progress id=&quot;file&quot; value=&quot;32&quot; max=&quot;100&quot;&gt; 32% &lt;/progress&gt;</pre><p>Mark Tag:-</p><pre>&lt;p&gt;Do not forget to buy &lt;mark&gt;milk&lt;/mark&gt; today.&lt;/p&gt;</pre><p>Figure tag:- To mark up a photo in a document, and a &lt;figcaption&gt; element to define a caption for the photo</p><pre>&lt;figure&gt;<br>  &lt;img src=&quot;pic_trulli.jpg&quot; alt=&quot;Trulli&quot; style=&quot;width:100%&quot;&gt;<br>  &lt;figcaption&gt;Fig.1 - Trulli, Puglia, Italy.&lt;/figcaption&gt;<br>&lt;/figure&gt;</pre><p>Iframe :- To embed another document within the current HTML document.</p><pre>&lt;iframe src=&quot;https://www.w3schools.com&quot;&gt;&lt;/iframe&gt;</pre><p>Abbr :- Defines an abbreviation or an acronym, like “HTML”, “CSS”, “Mr.”, “Dr.”, “ASAP”, “ATM”.</p><pre>&lt;abbr title=&quot;World Health Organization&quot;&gt;WHO&lt;/abbr&gt;</pre><p>CSS (Cascading Style Sheets):-</p><p>Cascading Style Sheets (CSS) is a <a href="https://developer.mozilla.org/en-US/docs/Web/API/StyleSheet">stylesheet</a> language used to describe the presentation of a document written in <a href="https://developer.mozilla.org/en-US/docs/Web/HTML">HTML</a> or <a href="https://developer.mozilla.org/en-US/docs/Web/XML/XML_introduction">XML</a> (including XML dialects such as <a href="https://developer.mozilla.org/en-US/docs/Web/SVG">SVG</a>, <a href="https://developer.mozilla.org/en-US/docs/Web/MathML">MathML</a> or <a href="https://developer.mozilla.org/en-US/docs/Glossary/XHTML">XHTML</a>). CSS describes how elements should be rendered on screen, on paper, in speech, or on other media.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/0*qi4LED8K7psqP0ct.png" /><figcaption>css</figcaption></figure><p>The whole structure is called a ruleset. (The term <em>ruleset</em> is often referred to as just <em>rule</em>.) Note the names of the individual parts:</p><p><a href="https://developer.mozilla.org/en-US/docs/Learn/Getting_started_with_the_web/CSS_basics#selector">Selector</a></p><p>This is the HTML element name at the start of the ruleset. It defines the element(s) to be styled (in this example, <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/p">&lt;p&gt;</a> elements). To style a different element, change the selector.</p><p><a href="https://developer.mozilla.org/en-US/docs/Learn/Getting_started_with_the_web/CSS_basics#declaration">Declaration</a></p><p>This is a single rule like color: red;. It specifies which of the element&#39;s properties you want to style.</p><p><a href="https://developer.mozilla.org/en-US/docs/Learn/Getting_started_with_the_web/CSS_basics#properties">Properties</a></p><p>These are ways in which you can style an HTML element. (In this example, color is a property of the <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/p">&lt;p&gt;</a> elements.) In CSS, you choose which properties you want to affect in the rule.</p><p><a href="https://developer.mozilla.org/en-US/docs/Learn/Getting_started_with_the_web/CSS_basics#property_value">Property value</a></p><p>To the right of the property — after the colon — there is the property value. This chooses one out of many possible appearances for a given property. (For example, there are many color values in addition to red.)</p><p>To modify multiple property values in one ruleset, write them separated by semicolons, like this:</p><pre>p {<br>  color: red;<br>  width: 500px;<br>  border: 1px solid black;<br>}</pre><h3><a href="https://developer.mozilla.org/en-US/docs/Learn/Getting_started_with_the_web/CSS_basics#selecting_multiple_elements">Selecting multiple elements</a></h3><p>You can also select multiple elements and apply a single ruleset to all of them. Separate multiple selectors by commas. For example:</p><pre>p,<br>li,<br>h1 {<br>  color: red;<br>}</pre><h3><a href="https://developer.mozilla.org/en-US/docs/Learn/Getting_started_with_the_web/CSS_basics#different_types_of_selectors">Different types of selectors</a></h3><p>There are many different types of selectors. The examples above use element selectors, which select all elements of a given type. But we can make more specific selections as well. Here are some of the more common types of selectors:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/0*tk58lrppdzuidwip.jpg" /><figcaption>types of css selectors</figcaption></figure><h3>Flexbox:-</h3><p><a href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_flexible_box_layout">Flexbox</a> is a one-dimensional layout method for arranging items in rows or columns. Items <em>flex</em> (expand) to fill additional space or shrink to fit into smaller spaces. This article explains all the fundamentals.</p><p>To start with, we need to select which elements are to be laid out as flexible boxes. To do this, we set a special value of <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/display">display</a> on the parent element of the elements you want to affect.</p><pre>section {<br>  display: flex;<br>}</pre><p>This causes the &lt;section&gt; element to become a flex container and its children to become flex items.</p><h3><a href="https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Flexbox#the_flex_model">The flex model</a>:-</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/563/0*AgeB3aPSfa-VrDZ1.png" /><figcaption>Flex model</figcaption></figure><p>When elements are laid out as flex items, they are laid out along two axes:</p><ul><li>The main axis is the axis running in the direction the flex items are laid out in (for example, as a row across the page, or a column down the page.) The start and end of this axis are called the main start and main end.</li><li>The cross axis is the axis running perpendicular to the direction the flex items are laid out in. The start and end of this axis are called the cross start and cross end.</li><li>The parent element that has display: flex set on it (the <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/section">&lt;section&gt;</a> in our example) is called the flex container.</li><li>The items laid out as flexible boxes inside the flex container are called flex items (the <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/article">&lt;article&gt;</a> elements in our example).</li></ul><h4><a href="https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Flexbox#columns_or_rows">Columns or rows?</a></h4><p>Flexbox provides a property called <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/flex-direction">flex-direction</a> that specifies which direction the main axis runs (which direction the flexbox children are laid out in). By default this is set to row, which causes them to be laid out in a row in the direction your browser&#39;s default language works in (left to right, in the case of an English browser).</p><pre>flex-direction: column;</pre><h4><a href="https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Flexbox#wrapping">Wrapping</a>:-</h4><p>One issue that arises when you have a fixed width or height in your layout is that eventually your flexbox children will overflow their container, breaking the layout.</p><p>One way in which you can fix this is to add the following declaration to parent element.</p><pre>flex-wrap: wrap;</pre><p>Also, add the following declaration to the children element:-</p><pre>flex: 200px;</pre><p>Each row has as many flexbox children fitted into it as is sensible. Any overflow is moved down to the next line. The flex: 200px declaration set on the articles means that each will be at least 200px wide.</p><h4><a href="https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Flexbox#flexible_sizing_of_flex_items">Flexible sizing of flex items</a>:-</h4><p>We can control what proportion of space flex items take up compared to the other flex items.</p><pre>article {<br>  flex: 1;<br>}</pre><p>This is a unitless proportion value that dictates how much available space along the main axis each flex item will take up compared to other flex items. In this case, we’re giving each <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/article">&lt;article&gt;</a> element the same value (a value of 1), which means they&#39;ll all take up an equal amount of the spare space left after properties like padding and margin have been set.</p><pre>article:nth-of-type(3) {<br>  flex: 2;<br>}</pre><p>We will see that the third <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/article">&lt;article&gt;</a> takes up twice as much of the available width as the other two. There are now four proportion units available in total (since 1 + 1 + 2 = 4). The first two flex items have one unit each, so they each take 1/4 of the available space. The third one has two units, so it takes up 2/4 of the available space.</p><p>We also specify a minimum size value within the flex value.</p><pre><br>article:nth-of-type(3) {<br>  flex: 2 200px;<br>}</pre><p>Each flex item will first be given 200px of the available space. After that, the rest of the available space will be shared according to the proportion units.</p><h4><a href="https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Flexbox#flex_shorthand_versus_longhand">flex: shorthand versus longhand</a>:-</h4><p><a href="https://developer.mozilla.org/en-US/docs/Web/CSS/flex">flex</a> is a shorthand property that can specify up to three different values:</p><ul><li>The unitless proportion value we discussed above. This can be specified separately using the <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/flex-grow">flex-grow</a> longhand property.</li><li>A second unitless proportion value, <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/flex-shrink">flex-shrink</a>, which comes into play when the flex items are overflowing their container. This value specifies how much an item will shrink in order to prevent overflow. This is quite an advanced flexbox feature and we won&#39;t be covering it any further in this article.</li><li>The minimum size value we discussed above. This can be specified separately using the <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/flex-basis">flex-basis</a> longhand value.</li></ul><h4><a href="https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Flexbox#horizontal_and_vertical_alignment">Horizontal and vertical alignment</a>:-</h4><p>1. <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/align-items">align-items</a> controls where the flex items sit on the cross axis.</p><ul><li>By default, the value is stretch, which stretches all flex items to fill the parent in the direction of the cross axis. If the parent doesn&#39;t have a fixed height in the cross axis direction, then all flex items will become as tall as the tallest flex item. This is how our first example had columns of equal height by default.</li><li>The center value that we used in our above code causes the items to maintain their intrinsic dimensions, but be centered along the cross axis. This is why our current example&#39;s buttons are centered vertically.</li><li>You can also have values like flex-start and flex-end, which will align all items at the start and end of the cross axis respectively</li></ul><p>We can override the <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/align-items">align-items</a> behavior for individual flex items by applying the <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/align-self">align-self</a> property to children.</p><p>2. <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/justify-content">justify-content</a> controls where the flex items sit on the main axis.</p><ul><li>The default value is flex-start, which makes all the items sit at the start of the main axis.</li><li>You can use flex-end to make them sit at the end.</li><li>center is also a value for justify-content. It&#39;ll make the flex items sit in the center of the main axis.</li><li>The value we’ve used above, space-around, is useful — it distributes all the items evenly along the main axis with a bit of space left at either end.</li><li>There is another value, space-between, which is very similar to space-around except that it doesn&#39;t leave any space at either end.</li></ul><p>The <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/justify-items">justify-items</a> property is ignored in flexbox layouts.</p><h4><a href="https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Flexbox#ordering_flex_items">Ordering flex items</a> :-</h4><p>Flexbox also has a feature for changing the layout order of flex items without affecting the source order.</p><pre>button:first-child {<br>  order: 1;<br>}</pre><ul><li>By default, all flex items have an <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/order">order</a> value of 0.</li><li>Flex items with higher specified order values will appear later in the display order than items with lower order values.</li><li>Flex items with the same order value will appear in their source order. So if you have four items whose order values have been set as 2, 1, 1, and 0 respectively, their display order would be 4th, 2nd, 3rd, then 1st.</li></ul><h3>Grids:-</h3><p><a href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_grid_layout">CSS grid layout</a> is a two-dimensional layout system for the web. It lets you organize content into rows and columns and offers many features to simplify the creation of complex layouts.</p><p>Unlike Flexbox, the items will not immediately look any different. Declaring display: grid gives you a one column grid, so your items will continue to display one below the other as they do in normal flow.</p><pre>.container {<br>  display: grid;<br>  grid-template-columns: 200px 200px 200px;<br>}</pre><p>We’ll need to add some columns to the grid. Let’s add three 200-pixel columns.</p><h4><a href="https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Grids#flexible_grids_with_the_fr_unit">Flexible grids with the fr unit</a>:-</h4><p>The first track gets 2fr of the available space and the other two tracks get 1fr, making the first track larger. You can mix fr units with fixed length units. In this case, the space needed for the fixed tracks is used up first before the remaining space is distributed to the other tracks.</p><pre>.container {<br>  display: grid;<br>  grid-template-columns: 2fr 1fr 1fr;<br>}</pre><h4><a href="https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Grids#gaps_between_tracks">Gaps between tracks</a> :-</h4><p>To create gaps between tracks, we use the properties:</p><ul><li><a href="https://developer.mozilla.org/en-US/docs/Web/CSS/column-gap">column-gap</a> for gaps between columns</li><li><a href="https://developer.mozilla.org/en-US/docs/Web/CSS/row-gap">row-gap</a> for gaps between rows</li><li><a href="https://developer.mozilla.org/en-US/docs/Web/CSS/gap">gap</a> as a shorthand for both</li></ul><h4><a href="https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Grids#repeating_track_listings">Repeating track listings</a></h4><p>You can repeat all or merely a section of your track listing using the CSS repeat() function.</p><pre>.container {<br>  display: grid;<br>  grid-template-columns: repeat(3, 1fr);<br>  gap: 20px;<br>}</pre><h4><a href="https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Grids#implicit_and_explicit_grids">Implicit and explicit grids</a> :-</h4><ul><li>Explicit grid is created using grid-template-columns or grid-template-rows.</li><li>Implicit grid extends the defined explicit grid when content is placed outside of that grid, such as into the rows by drawing additional grid lines.</li></ul><p>By default, tracks created in the implicit grid are auto sized, which in general means that they&#39;re large enough to contain their content. If you wish to give implicit grid tracks a size, you can use the <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/grid-auto-rows">grid-auto-rows</a> and <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/grid-auto-columns">grid-auto-columns</a> properties.</p><h4><a href="https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Grids#the_minmax_function">The minmax() function</a>:-</h4><p>The tracks that are <em>at least</em> 100 pixels tall and can still expand if more content becomes added. The <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/minmax">minmax()</a> function lets us set a minimum and maximum size for a track, for example, minmax(100px, auto).</p><p>Sometimes it’s helpful to be able to ask grid to create as many columns as will fit into the container. We do this by setting grid-template-columns using the <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/repeat">repeat()</a> function, pass in the keyword auto-fit. For the second parameter of the function we use minmax() with a minimum value equal to the minimum track size that we would like to have and a maximum of 1fr.</p><pre>.container {<br>  display: grid;<br>  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));<br>  grid-auto-rows: minmax(100px, auto);<br>  gap: 20px;<br>}</pre><h4><a href="https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Grids#line-based_placement">Line-based placement</a>:-</h4><p>These properties accept line numbers as their values, so we can specify that an item should start on line 1 and end on line 3, for example. Alternatively, you can also use shorthand properties that let you specify the start and end lines simultaneously, separated by a forward slash /:</p><ul><li><a href="https://developer.mozilla.org/en-US/docs/Web/CSS/grid-column">grid-column</a> shorthand for grid-column-start and grid-column-end</li><li><a href="https://developer.mozilla.org/en-US/docs/Web/CSS/grid-row">grid-row</a> shorthand for grid-row-start and grid-row-end</li></ul><pre>header {<br>  grid-column: 1 / 3;<br>  grid-row: 1;<br>}</pre><h4><a href="https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Grids#positioning_with_grid-template-areas">Positioning with grid-template-areas</a></h4><p>An alternative way to arrange items on your grid is to use the <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/grid-template-areas">grid-template-areas</a> property and give the various elements of your design a name.</p><pre>.container {<br>  display: grid;<br>  grid-template-areas:<br>    &quot;header header&quot;<br>    &quot;sidebar content&quot;<br>    &quot;footer footer&quot;;<br>  grid-template-columns: 1fr 3fr;<br>  gap: 20px;<br>}<br><br>header {<br>  grid-area: header;<br>}<br><br>article {<br>  grid-area: content;<br>}<br><br>aside {<br>  grid-area: sidebar;<br>}<br><br>footer {<br>  grid-area: footer;<br>}</pre><p>The rules for grid-template-areas are as follows:</p><ul><li>You need to have every cell of the grid filled.</li><li>To span across two cells, repeat the name.</li><li>To leave a cell empty, use a . (period).</li><li>Areas must be rectangular — for example, you can’t have an L-shaped area.</li><li>Areas can’t be repeated in different locations.</li></ul><h3>Floats</h3><p>The <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/float">float</a> property was introduced to allow web developers to implement layouts involving an image floating inside a column of text, with the text wrapping around the left or right of it.</p><h4><a href="https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Floats#clearing_floats">Clearing floats</a></h4><pre>.cleared {<br>  clear: left;<br>}</pre><ul><li>left: Clear items floated to the left.</li><li>right: Clear items floated to the right.</li><li>both: Clear any floated items, left or right.</li></ul><h4><a href="https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Floats#display_flow-root">display: flow-root</a></h4><h3>Positioning</h3><p>Positioning allows you to take elements out of normal document flow and make them behave differently.</p><h4><a href="https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Positioning#static_positioning">1. Static positioning</a>:-</h4><p>Default that every element gets. It just means “put the element into its normal position in the document flow.</p><h4><a href="https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Positioning#relative_positioning">2.Relative positioning</a>:-</h4><p>Relative to its current position.We can make it overlap other elements on the page.</p><h4><a href="https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Positioning#absolute_positioning">3. Absolute positioning</a>:-</h4><p>Positioning relative to its parent or ancestor element.</p><h4><a href="https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Positioning#fixed_positioning">4. Fixed positioning</a>:-</h4><p>Same way as absolute positioning, with one key difference: whereas absolute positioning fixes an element in place relative to its nearest positioned ancestor (the initial containing block if there isn’t one), fixed positioning <em>usually</em> fixes an element in place relative to the visible portion of the viewport.</p><p>We can create useful UI items that are fixed in place, like persistent navigation menus that are always visible no matter how much the page scrolls.</p><pre>h1 {<br>  position: fixed;<br>  top: 0;<br>  width: 500px;<br>  margin-top: 0;<br>  background: white;<br>  padding: 10px;<br>}</pre><h4><a href="https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Positioning#sticky_positioning">5. Sticky positioning</a>:-</h4><p>Hybrid between relative and fixed position. It allows a positioned element to act like it’s relatively positioned until it’s scrolled to a certain threshold (e.g., 10px from the top of the viewport), after which it becomes fixed.</p><pre>dt {<br>  background-color: black;<br>  color: white;<br>  padding: 10px;<br>  position: sticky;<br>  top: 0;<br>  left: 0;<br>  margin: 1em 0;<br>}</pre><h3>Multiple-column layout</h3><p>This provides us with a method for laying content out in columns, as we might see in a newspaper.</p><p>We enable multicol by using one of two properties: <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/column-count">column-count</a> or <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/column-width">column-width</a>. The column-count property takes a number as its value and creates that number of columns.</p><p>The browser will now give you as many columns as it can of the size that you specify; any remaining space is then shared between the existing columns. This means that you won’t get exactly the width that you specify unless your container is exactly divisible by that width.</p><h4><a href="https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Multiple-column_Layout#styling_the_columns">Styling the columns</a></h4><p>The columns created by multicol cannot be styled individually. There’s no way to make one column bigger than other columns or to change the background or text color of a single column. You have two opportunities to change the way that columns display:</p><ul><li>Changing the size of the gap between columns using the <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/column-gap">column-gap</a>.</li><li>Adding a rule between columns with <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/column-rule">column-rule</a>.</li></ul><pre>.container {<br>  column-count: 3;<br>  column-gap: 20px;<br>  column-rule: 4px dotted rgb(79, 185, 227);<br>}</pre><h4><a href="https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Multiple-column_Layout#spanning_columns">Spanning columns</a>:-</h4><p>We can cause an element to span across all the columns. In this case, the content breaks where the spanning element is introduced and then continues below the element, creating a new set of columns. To cause an element to span all the columns, specify the value of all for the <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/column-span">column-span</a> property.</p><h3><strong>Conclusion:-</strong></h3><p>Wrapping u this blog, I want to say HTML and CSS are vast topics and cannot be covered in one blog. So keep exploring by doing projects.</p><h3>Stackademic</h3><p><em>Thank you for reading until the end. Before you go:</em></p><ul><li><em>Please consider </em><strong><em>clapping</em></strong><em> and </em><strong><em>following</em></strong><em> the writer! 👏</em></li><li><em>Follow us on </em><a href="https://twitter.com/stackademichq"><strong><em>Twitter(X)</em></strong></a><em>, </em><a href="https://www.linkedin.com/company/stackademic"><strong><em>LinkedIn</em></strong></a><em>, and </em><a href="https://www.youtube.com/c/stackademic"><strong><em>YouTube</em></strong></a><strong><em>.</em></strong></li><li><em>Visit </em><a href="http://stackademic.com/"><strong><em>Stackademic.com</em></strong></a><em> to find out more about how we are democratizing free programming education around the world.</em></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a0f12d2f8678" width="1" height="1" alt=""><hr><p><a href="https://blog.stackademic.com/styling-the-web-mastering-html-and-css-magic-a0f12d2f8678">Styling the Web: Mastering HTML and CSS Magic</a> was originally published in <a href="https://blog.stackademic.com/">Stackademic</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Database Normalization and SQL Commands: The Power Duo for Data Management]]></title>
            <link>https://blog.stackademic.com/database-normalization-and-sql-commands-the-power-duo-for-data-management-89a40a99fe43?source=rss-3e6b75a77f7f------2</link>
            <guid isPermaLink="false">https://medium.com/p/89a40a99fe43</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[normalization]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[dbms]]></category>
            <category><![CDATA[sql]]></category>
            <dc:creator><![CDATA[Vishal Das]]></dc:creator>
            <pubDate>Sun, 29 Oct 2023 04:52:15 GMT</pubDate>
            <atom:updated>2023-10-31T00:20:23.804Z</atom:updated>
            <content:encoded><![CDATA[<p>You must have heard these two topics most in DBMS, right? So what are these complex-sounding terms?</p><p>Let&#39;s look into them one by one, starting with <strong>Normalization</strong>.</p><figure><img alt="normalization" src="https://cdn-images-1.medium.com/max/1024/1*-Q7dNKA_AP6IE3T0S_g0Aw.jpeg" /><figcaption>Levels of Normalization</figcaption></figure><p>Normalization is a process to improve the design of a database to meet specific rules.When you create database tables and add columns, you’re able to create them in almost any way and configuration that you like.</p><p>However, to use the benefits of a database and to have an effective design, it helps to follow a certain set of rules. The process of applying these rules is called normalization, and it has several benefits, like that data is stored in one place or table and isn&#39;t repeated in every table where we need it. This reduces our code and also makes the table less complex.</p><h3><strong>Types of normalization:</strong></h3><p>There are basically five types of normalization:</p><ul><li>First Normal Form (1NF)</li><li>Second Normal Form (2NF)</li><li>Third Normal Form (3NF)</li><li>Fourth Normal Form (4NF)</li><li>Fifth Normal Form (5NF)</li></ul><ol><li><strong>First Normal Form (1NF): </strong>This is the most basic level of normalization. In 1NF, each table cell should contain only a single value, and each column should have a unique name. The first normal form helps to eliminate duplicate data and simplify queries.</li></ol><p>For example, Lets look at the following table:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/367/1*dPOOTpDw4tUUF0rXcw9ZGQ.png" /><figcaption>Table 1</figcaption></figure><p>Now, after normalization, the normalized tables for Dept. and Employee look like below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/356/1*fif-MaCjqPZ2ncGk1_AK7w.png" /><figcaption>Table 1.1</figcaption></figure><p>2.<strong> Second Normal Form (2NF) :- </strong>First, the table should be in 1NF. 2NF eliminates redundant data by requiring that each non-key attribute be dependent on the primary key. This means that each column should be directly related to the primary key and not to other columns.</p><blockquote>Note: Second Normal Form (2 NF) is only ever a problem when we’re using a composite primary key. That is, a primary key made of two or more columns.</blockquote><p>In the following example, the relationship is established between the employee and department tables.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/493/1*fnPsGLbrPiqdoVVUcd36vg.png" /><figcaption>Table 2.1</figcaption></figure><p>In this example, the <em>title</em> column is functionally dependent on the name<em> and date</em> columns. These two keys form a composite key. In this case, it only depends on the name and is partially dependent on the date column. Let’s remove the course details and form a separate table. Now, the course details are based on the entire key. We are not going to use a composite key.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/371/1*yPRE-dX3ZfmKYRC-aNj8Cg.png" /><figcaption>Table 2.2</figcaption></figure><p><strong>3. Third Normal Form (3NF): </strong>The table should be in 2NF. 3NF builds on 2NF by requiring that all non-key attributes be independent of each other. This means that each column should be directly related to the primary key and not to any other columns in the same table.</p><p>For example, consider the following example: in the table employee, empID determines the department ID of an employee, and department ID determines the department name. Therefore, the department name column is indirectly dependent on the empID column. So, it satisfies the transitive dependency. So this cannot be in third-normal form.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/779/1*qg_EgeNyvOVZvDEKKNeoZQ.png" /><figcaption>Table 3.1</figcaption></figure><p>In order to bring the table to 3 NF, we split the employee table into two.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/855/1*eVDtWyuHWfDGyQ9ZYq-8dA.png" /><figcaption>Table 3.2</figcaption></figure><p><strong>Boyce-Codd Normal Form (BCNF):</strong> It is a stricter form of 3NF that ensures that each determinant in a table is a candidate key. In other words, BCNF ensures that each non-key attribute is dependent only on the candidate key.</p><p><strong>4. Fourth Normal Form (4NF): </strong>4NF is a further refinement of BCNF that ensures that a table does not contain any multi-valued dependencies.</p><p><strong>5. Fifth Normal Form (5NF): This</strong> is the highest level of normalization and involves decomposing a table into smaller tables to remove data redundancy and improve data integrity.</p><h3>Advantages:-</h3><ul><li>Normalization helps to minimize data redundancy.</li><li>Greater overall database organization.</li><li>Data consistency within the database.</li><li>Much more flexible database design.</li><li>It reinforces the concept of relational integrity.</li></ul><h3><strong>Disadvantages:-</strong></h3><ul><li>You cannot start building the database without knowing what the user needs.</li><li>The performance degrades when normalizing the relations to higher normal forms, i.e., 4NF and 5NF.</li><li>It is very time-consuming and difficult to normalize relations to a higher degree.</li><li>Careless decomposition may lead to a bad database design, leading to serious problems.</li></ul><h3>Applications:-</h3><ul><li><strong>Data consistency:</strong> Normal forms ensure that the data is consistent and does not contain any redundant information. This helps to prevent inconsistencies and errors in the database.</li><li><strong>Data redundancy: </strong>Normal forms minimize data redundancy by organizing data into tables that contain only unique data. This reduces the amount of storage space required for the database and makes it easier to manage.</li><li><strong>Query performance:</strong> Normal forms can improve query performance by reducing the number of joins required to retrieve data. This helps to speed up query processing and improve overall system performance.</li><li><strong>Database maintenance: </strong>Normal forms make it easier to maintain the database by reducing the amount of redundant data that needs to be updated, deleted, or modified. This helps to improve database management and reduce the risk of errors or inconsistencies.</li><li><strong>Database design:</strong> Normal forms provide guidelines for designing databases that are efficient, flexible, and scalable. This helps to ensure that the database can be easily modified, updated, or expanded as needed.</li></ul><h3><strong>Denormalization:-</strong></h3><p>DEnormalization is a database optimization technique in which we add redundant data to one or more tables. This can help us avoid costly joins in a relational database.</p><blockquote><strong>Note</strong> that <em>denormalization</em> does not mean ‘reversing normalization’ or ‘not to normalize’. It is an optimization technique that is applied after normalization.</blockquote><h3>SQL Commands:-</h3><p>SQL commands are like instructions to a table. It is used to interact with the database with some operations. It is also used to perform specific tasks, functions, and queries of data.</p><p>Here, we will look at the most basic and important SQL commands that we require in our database management.</p><h3>Types of SQL Commands:</h3><ul><li>DDL : Data Definition Language</li><li>DML : Data Manipulation Language</li><li>DQL : Data Query Language</li><li>DCL : Data Control Language</li><li>TCL : Transaction Control Language</li></ul><ol><li><strong>Data Defination Language (DDL):</strong> To make or perform changes to the physical structure of any table residing inside a database, DDL is used. These commands, when executed, are auto-commit in nature, and all the changes in the table are reflected and saved immediately.</li></ol><p>List of DDL Commands:</p><ul><li><strong>Create</strong> : This command is used to create the database or its objects (like tables, indexes, functions, views, store procedures, and triggers).</li></ul><p><strong>Syntax:-</strong></p><ol><li><strong>Create Database:-</strong></li></ol><blockquote>CREATE DATABASE DATABASE_NAME;</blockquote><p>2.<strong> Create a table:</strong></p><blockquote>CREATE TABLE Persons (<br> PersonID int,<br> LastName varchar(255),<br> FirstName varchar(255),<br> Address varchar(255),<br> City varchar(255)<br>);</blockquote><p>3. <strong>Create a table using Another table:</strong></p><ul><li><strong>Simple Cloning:</strong> Data + Structure:</li></ul><blockquote><strong>Here, clone table inherits only the basic column definitions like the NULL settings and default values from the original table. It does not inherit the indices and AUTO_INCREMENT definitions.</strong></blockquote><blockquote>CREATE TABLE TestTable AS<br>SELECT customername, contactname<br>FROM customers;</blockquote><ul><li><strong>Shallow Cloning:</strong> Only Structure (Empty New Table)</li></ul><blockquote>CREATE TABLE new_table LIKE original_table;</blockquote><ul><li>Deep Cloning:-</li></ul><blockquote><strong>Here, the new table will have all the contents from existing table and all the attributes including indices and the AUTO_INCREMENT definitions.</strong></blockquote><blockquote>CREATE TABLE new_table LIKE original_table; INSERT INTO new_table SELECT * FROM original_table;</blockquote><p>4. <strong>Create Index: </strong>The following SQL creates an index named “idx_lastname” on the “LastName” column in the “Persons” table:</p><blockquote>CREATE INDEX idx_lastname<br>ON Persons (LastName);</blockquote><p>If you want to create an index on a <strong>combination of columns</strong>, you can list the column names within the parentheses, separated by commas:</p><blockquote>CREATE INDEX idx_pname<br>ON Persons (LastName, FirstName);</blockquote><p>5. <strong>Create Unique Index: </strong>The CREATE UNIQUE INDEX command creates a unique index on a table (no duplicate values allowed)</p><blockquote>CREATE UNIQUE INDEX uidx_pid<br>ON Persons (PersonID);</blockquote><p>6. <strong>Create View:</strong></p><blockquote>CREATE VIEW [Brazil Customers] AS<br>SELECT CustomerName, ContactName<br>FROM Customers<br>WHERE Country = “Brazil”;</blockquote><p>7. <strong>Create or Replace View:</strong></p><blockquote>CREATE OR REPLACE VIEW [Brazil Customers] AS<br>SELECT CustomerName, ContactName, City<br>FROM Customers<br>WHERE Country = “Brazil”;</blockquote><p>8.<strong> Create a procedure:</strong></p><blockquote>CREATE PROCEDURE SelectAllCustomers<br>AS<br>SELECT * FROM Customers<br>GO;</blockquote><ul><li><strong>Drop</strong> : This command is used to delete objects from the database.</li></ul><ol><li><strong>Drop Column:-</strong></li></ol><blockquote>ALTER TABLE TABLE_NAME<br>DROP COLUMN COLUMN_NAME;</blockquote><p>2. <strong>Drop Constraint:</strong></p><blockquote>ALTER TABLE Persons<br>DROP CONSTRAINT_NAME COLUMN_NAME;</blockquote><p>3. <strong>Drop Table:</strong></p><blockquote>DROP TABLE TABLE_NAME;</blockquote><p>4. <strong>Drop View: “Brazil Customer” is the view name.</strong></p><blockquote>DROP VIEW [Brazil Customers];</blockquote><ul><li><strong>Alter</strong> : This is used to alter the structure of the database.</li></ul><ol><li><strong>Alter Table: </strong>TheALTER TABLE command adds, deletes, or modifies columns in a table.</li></ol><ul><li><strong>Add Column:-</strong></li></ul><blockquote>ALTER TABLE Customers<br>ADD Email varchar(255);</blockquote><ul><li><strong>Delete Column:-</strong></li></ul><blockquote>ALTER TABLE Customers DROP COLUMN Email;</blockquote><ul><li><strong>Change Column DataType:</strong></li></ul><blockquote>ALTER TABLE Employees<br>ALTER COLUMN BirthDate year;</blockquote><ul><li><strong>Truncate</strong> : This is used to remove all records from a table, including all spaces allocated for the records.</li></ul><ol><li><strong>Truncate Table:-</strong></li></ol><blockquote>TRUNCATE TABLE Categories;</blockquote><ul><li><strong>Comment</strong> : This is used to add comments to the data dictionary.</li><li><strong>Rename </strong>: This is used to rename an object existing in the database.</li></ul><ol><li><strong>Rename Table:-</strong></li></ol><blockquote>RENAME TABLE table_name TO new_table_name;</blockquote><p><strong>2. Database Manipulation Language (DML):</strong> Once the tables are created and the database is generated using DDL commands, manipulation inside those tables and databases is done using <a href="https://www.scaler.com/topics/dml-commands-in-sql/">DML</a> commands. The advantage of using DML commands is that if any wrong changes or values are made, they can be changed and rolled back easily.</p><p>List of DML Commands:</p><ul><li><strong>Insert </strong>: It is used to insert data into a table.</li></ul><ol><li>Insert into Table:</li></ol><ul><li>Specify both columns and values:-</li></ul><blockquote>INSERT INTO <em>table_name</em> (<em>column1</em>,<em> column2</em>,<em> column3</em>, …)<br>VALUES (<em>value1</em>,<em> value2</em>,<em> value3</em>, …);</blockquote><ul><li>Specify only the following values:</li></ul><blockquote>INSERT INTO <em>table_name</em><br>VALUES (<em>value1</em>,<em> value2</em>,<em> value3</em>, …);</blockquote><ul><li>Insert Multiple rows:</li></ul><blockquote>INSERT INTO <em>table_name</em> (<em>column1</em>,<em> column2</em>,<em> column3</em>, …)<br>VALUES (<em>value1</em>,<em> value2</em>,<em> value3</em>, …), (value2.1, value2.2, value2.3);</blockquote><ul><li><strong>Update </strong>: It is used to update existing data within a table.</li></ul><ol><li><strong>Update Column:-</strong></li></ol><blockquote>UPDATE <em>table_name</em><br>SET <em>column1 </em>=<em> value1</em>,<em> column2 </em>=<em> value2</em>, …<br>WHERE <em>condition</em>;</blockquote><ul><li><strong>Delete </strong>: It is used to delete records from a database table.</li></ul><ol><li><strong>Delete a row:</strong></li></ol><blockquote>DELETE FROM <em>table_name </em>WHERE <em>condition</em>;</blockquote><p>2. <strong>Delete all rows: -</strong></p><blockquote>DELETE FROM <em>table_name</em>;</blockquote><ul><li><strong>Lock</strong> : Table control concurrency</li><li><strong>Call </strong>: Call a PL/SQL or JAVA subprogram.</li><li><strong>Explain Plan </strong>: It describes the access path to data.</li></ul><p><strong>3. Data Query Language (DQL):</strong> The data query language consists of only one command upon which data selection in SQL relies. The <strong>SELECT</strong> command, in combination with other SQL clauses, is used to retrieve and fetch data from databases or tables based on certain conditions applied by the user.</p><p>List of DQL Commands:</p><ul><li><strong>Select </strong>:- It is used to retrieve data from the database.</li></ul><ol><li><strong>Select particular column:</strong></li></ol><blockquote>SELECT <em>column1</em>,<em> column2, … </em>FROM <em>table_name</em>;</blockquote><p>2. <strong>Select all columns:</strong></p><blockquote>SELECT * FROM TABLE_NAME;</blockquote><p><strong>4. Data Control Language (DCL)</strong>:DCL includes commands such as GRANT and REVOKE, which mainly deal with the rights, permissions, and other controls of the database system.</p><p>List of DCL Commands:</p><ul><li><strong>Grant </strong>: This command<strong> </strong>gives users access privileges to the database.</li></ul><blockquote><em>GRANT privileges_names ON object TO user;</em></blockquote><p><strong>Parameters Used</strong>:</p><ul><li><strong>privileges_name</strong>: These are the access rights or privileges granted to the user.</li><li><strong>object: </strong>It is the name of the database object to which permissions are being granted. In the case of granting privileges to a table, this would be the table name.</li><li><strong>user: </strong>It is the name of the user to whom the privileges would be granted.</li></ul><ol><li><strong>Grant specific privileges:</strong></li></ol><blockquote>GRANT SELECT ON Users TO ‘Amit’@’localhost;’</blockquote><p>2. <strong>Grant multiple privileges:-</strong></p><blockquote>GRANT SELECT, INSERT, DELETE, UPDATE ON Users TO ‘Amit’@’localhost’;</blockquote><p>3. <strong>Grant all privileges:-</strong></p><blockquote>GRANT ALL ON Users TO ‘Amit’@’localhost’;</blockquote><p>4. <strong>Grant privileges to all users:-</strong></p><blockquote>GRANT SELECT ON Users TO ‘*’@’localhost’;</blockquote><p>5 . <strong>Granting Privileges on Functions and Procedures:</strong></p><blockquote>GRANT EXECUTE ON [ PROCEDURE | FUNCTION ] object TO user;</blockquote><h4>Different ways of granting executive privileges:</h4><p>6. <strong>Granting EXECUTE privileges on a function:</strong></p><blockquote>GRANT EXECUTE ON FUNCTION Calculatesalary TO ‘Amit’@’localhost’;</blockquote><p>7. <strong>Granting EXECUTE privileges to all Users on a function :</strong></p><blockquote>GRANT EXECUTE ON FUNCTION Calculatesalary TO ‘*’@’localhost’;</blockquote><p>8. <strong>Granting EXECUTE privilege to a Users on a procedure:</strong></p><blockquote>GRANT EXECUTE ON PROCEDURE DBMSProcedure TO ‘Amit’@’localhost’;</blockquote><p>9. <strong>Granting EXECUTE privileges to all Users on a procedure:</strong></p><blockquote>GRANT EXECUTE ON PROCEDURE DBMSProcedure TO ‘*’@’localhost’;</blockquote><p>10. <strong>Checking the Privileges Granted to a User:</strong></p><blockquote>SHOW GRANTS FOR ‘Amit’@’localhost’;</blockquote><ul><li><strong>Revoke </strong>: This command withdraws the user’s access privileges given by using the GRANT command.</li></ul><p><strong>Parameters Used</strong>:</p><ul><li><strong>object: </strong>It is the name of the database object from which permissions are being revoked. In the case of revoking privileges from a table, this would be the table name.</li><li><strong>user: </strong>It is the name of the user from whom the privileges are being revoked.</li></ul><blockquote><em>REVOKE privileges ON object FROM user;</em></blockquote><ol><li><strong>Revoking SELECT Privilege to a User in a Table:</strong></li></ol><blockquote>REVOKE SELECT ON Users FROM ‘Amit’@’localhost’;</blockquote><p>2. <strong>Revoking more than Privilege to a User in a table:</strong></p><blockquote>REVOKE SELECT, INSERT, DELETE, UPDATE ON Users FROM ‘Amit’@’localhost’;</blockquote><p>3. <strong>Revoking All the Privilege to a User in a Table:</strong></p><blockquote>REVOKE ALL ON Users FROM ‘Amit’@’localhost’;</blockquote><p>4. <strong>Revoking a Privilege to all Users in a Table:</strong></p><blockquote>REVOKE SELECT ON Users FROM ‘*’@’localhost’;</blockquote><p>5. <strong>Revoking Privileges on Functions and Procedures:</strong></p><blockquote>REVOKE EXECUTE ON [ PROCEDURE | FUNCTION ] object FROM User;</blockquote><p>6. <strong>Revoking executive privileges on a function:</strong></p><blockquote>REVOKE EXECUTE ON FUNCTION Calculatesalary FROM ‘Amit’@’localhost’;</blockquote><p>7. <strong>Revoking EXECUTE privileges to all Users on a function:</strong></p><blockquote>REVOKE EXECUTE ON FUNCTION Calculatesalary FROM ‘*’@’localhost’;</blockquote><p>8. <strong>Revoking EXECUTE privilege to a Users on a procedure:</strong></p><blockquote>REVOKE EXECUTE ON PROCEDURE DBMSProcedure FROM ‘Amit’@’localhost’;</blockquote><p>9. <strong>Revoking EXECUTE privileges to all Users on a procedure:</strong></p><blockquote>REVOKE EXECUTE ON PROCEDURE DBMSProcedure FROM ‘*’@’localhost’;</blockquote><p><strong>5. Transaction Control Language (TCL):</strong> <a href="https://www.scaler.com/topics/tcl-commands-in-sql/">Transaction Control Language</a> as the name suggests, manages the issues and matters related to the transactions in any database. They are used to roll back or commit the changes in the database.</p><p>List of TCL Commands:</p><ul><li><strong>Commit: </strong>This commits a transaction.</li></ul><blockquote>COMMIT;</blockquote><ul><li><strong>Rollback </strong>: Rollbacks a transaction in case any error occurs.</li></ul><blockquote>ROLLBACK;</blockquote><ul><li><strong>Savepoint </strong>: Sets a save point within a transaction.</li></ul><blockquote>SAVEPOINT savepoint_name;</blockquote><blockquote>ROLLBACK TO savepoint_name;</blockquote><ul><li>Release Savepoint: remove an existing SAVEPOINT</li></ul><blockquote>RELEASE SAVEPOINT SAVEPOINT_NAME;</blockquote><ul><li><strong>SET TRANSACTION: </strong>Places a name on a transaction.</li></ul><p>The SET TRANSACTION command can be used to initiate a database transaction. This command is used to specify characteristics for the transaction that follows. For example, you can specify a transaction to be read-only or read-write.</p><blockquote>SET TRANSACTION [ READ WRITE | READ ONLY ];</blockquote><h3>Conclusion:-</h3><p>All commands can’t be written in one blog. However, I have included nearly all important commands required in SQL. Still, you may find some new commands so keep learning. I hope you find this blog helpful.</p><p>If you want to become a backend engineer then it’s important for you to master Database Management and have a good grasp on writing good SQL queries.</p><h3>Stackademic</h3><p><em>Thank you for reading until the end. Before you go:</em></p><ul><li><em>Please consider </em><strong><em>clapping</em></strong><em> and </em><strong><em>following</em></strong><em> the writer! 👏</em></li><li><em>Follow us on </em><a href="https://twitter.com/stackademichq"><strong><em>Twitter(X)</em></strong></a><em>, </em><a href="https://www.linkedin.com/company/stackademic"><strong><em>LinkedIn</em></strong></a><em>, and </em><a href="https://www.youtube.com/c/stackademic"><strong><em>YouTube</em></strong></a><strong><em>.</em></strong></li><li><em>Visit </em><a href="http://stackademic.com/"><strong><em>Stackademic.com</em></strong></a><em> to find out more about how we are democratizing free programming education around the world.</em></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=89a40a99fe43" width="1" height="1" alt=""><hr><p><a href="https://blog.stackademic.com/database-normalization-and-sql-commands-the-power-duo-for-data-management-89a40a99fe43">Database Normalization and SQL Commands: The Power Duo for Data Management</a> was originally published in <a href="https://blog.stackademic.com/">Stackademic</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Object Oriented Programming(OOPs)]]></title>
            <link>https://medium.com/@vdas53073/object-oriented-programming-oops-5b0090b9ec04?source=rss-3e6b75a77f7f------2</link>
            <guid isPermaLink="false">https://medium.com/p/5b0090b9ec04</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[oops-concepts]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[interfaces]]></category>
            <category><![CDATA[inheritance]]></category>
            <dc:creator><![CDATA[Vishal Das]]></dc:creator>
            <pubDate>Sun, 22 Oct 2023 13:34:42 GMT</pubDate>
            <atom:updated>2023-10-22T13:34:42.683Z</atom:updated>
            <content:encoded><![CDATA[<p>If you are new to programming then you must be wondering <strong>What is OOPs ?</strong> Is this a new programming language or any new concept ? Hold on after reading this blog your all doubts will be cleared.</p><p>First of all OOP is one of the major category to classify programming languages. Basically there are 5 major categories to classify various programming languages. Some programming languages may fall in more than one category.</p><p>Lets have a glimpse of these 5 major categories:-</p><h4>1. Procedural programming languages:-</h4><p>A procedural language follows a sequence of statements or commands in order to achieve a desired output. Each series of steps is called a procedure, and a program written in one of these languages will have one or more procedures within it. Example of languages:-</p><ul><li>C++</li><li>Java</li><li>Pascal</li></ul><h4>2. Functional programming languages:-</h4><p>Rather than focusing on the execution of statements, functional languages focus on the output of mathematical functions and evaluations. Each function–a reusable module of code–performs a specific task and returns a result. Example:-</p><ul><li>Scala</li><li>Elang</li></ul><h4>3. Object-oriented programming languages (OOP):-</h4><p>This type of language treats a program as a group of objects composed of data and program elements, known as attributes and methods. Objects can be reused within a program or in other programs. Example:-</p><ul><li>C++</li><li>Java</li><li>Python</li><li>PHP</li></ul><h4>4. Scripting languages:-</h4><p>Programmers use scripting languages to automate repetitive tasks, manage dynamic web content, or support processes in larger applications. Example:-</p><ul><li>PHP</li><li>Python</li><li>Ruby</li><li>Bash</li></ul><h4>5. Logic programming languages:-</h4><p>Instead of telling a computer what to do, a logic programming language expresses a series of facts and rules to instruct the computer on how to make decisions. Example:-</p><ul><li>Prolog</li><li>Absys</li><li>Datalog</li></ul><p>If you&#39;re still confused about <strong>OOPs</strong>, don’t worry; let’s dive deep into OOPs and their concepts.</p><p><strong>OOPs</strong> refers to languages that use <strong>objects</strong> in programming, they use objects as a primary source to implement what is to happen in the code.</p><h3><strong>Structure of OOPs:-</strong></h3><ul><li><strong>Classes:- </strong>They<strong> </strong>are user-defined data types that act as the blueprint for individual objects. They define the properties and functionalities of the objects. For example, Car is a class and your car(May be Verna) is an instance of it.</li><li><strong>Objects:- </strong>An object is an instance of a Class. They have all the properties and functionality of their class. Objects can correspond to real-world objects or an abstract entity.</li><li><strong>Methods:-</strong> They are functions that are defined inside a class that describe the behaviors of an object. Each method contained in class definitions starts with a reference to an instance object. Additionally, the subroutines contained in an object are called instance methods. Programmers use methods for reusability or keeping functionality encapsulated inside one object at a time.</li><li><strong>Attributes:- </strong>They are defined in the class template and represent the state of an object. Objects will have data stored in the attributes field. Class attributes belong to the class itself.</li></ul><figure><img alt="Oops" src="https://cdn-images-1.medium.com/max/575/1*fJGQNkQJZvle83yay98GcA.png" /><figcaption>OOP</figcaption></figure><h3>What are the main principles of OOP?</h3><ol><li>Abstraction.</li><li>Encapsulation.</li><li>Polymorphsim.</li><li>Inheritance.</li><li>Association.</li><li>Aggregation.</li><li>Composition.</li></ol><p>Let’s look into each of these principles one by one.</p><ol><li><strong>Abstraction:- </strong>Abstraction is the concept of hiding the internal details and describing things in simple terms. Objects only reveal internal mechanisms that are relevant for the use of other objects, hiding any unnecessary implementation code. The derived class can have its functionality extended. For example, a method that adds two integers. The internal processing of the method is hidden from the outer world. There are many ways to achieve abstraction in object-oriented programmings, such as encapsulation and inheritance. In Java, we can achieve abstraction with the help of <strong>Abstract Classes </strong>or <strong>Interfaces</strong>.</li></ol><pre>abstract class Car{<br>    int speed;<br>   <br>   public abstract void setSpeed();<br><br>    public void forward(){<br>        System.out.println(&quot;Moving Forward&quot;);<br>    }<br><br>    public void breakk(){<br>        System.out.println(&quot;Break Applied&quot;);<br>    } <br>}<br><br>class Verna extends Car{<br>    String color = &quot;Black&quot;;<br>    public void setSpeed(){<br>        speed = 200;<br>    }<br><br>    public void setColor(String color){<br>        this.color = color;<br>    }<br>}<br><br>public class Main{<br>    public static void main(String[] args){<br>        Verna verna = new Verna();<br>        verna.setSpeed();<br>        System.out.println(&quot;Current speed :- &quot; + verna.speed);<br>       verna.forward();<br>    }<br>}</pre><p>2. <strong>Encapsulation:- </strong>This principle states that all important information is contained inside an object and only select information is exposed. The implementation and state of each object are privately held inside a defined class. Other objects do not have access to this class or the authority to make changes. They are only able to call a list of public functions or methods.</p><pre><br><br>class Person { <br>    private String name; <br>    private int age; <br><br>    public int getAge() { return age; } <br>  <br>    public void setAge(int age) { this.age = age; }<br>  <br>    public String getName() { return name; } <br>  <br>    public void setName(String name) { this.name = name; } <br>  <br>   <br>} <br>  <br>public class Main { <br>    public static void main(String[] args) <br>    { <br>        Person person = new Person(); <br>        person.setName(&quot;Vishal&quot;); <br>        person.setAge(22); <br>  <br>        System.out.println(&quot;Name: &quot; + person.getName()); <br>        System.out.println(&quot;Age: &quot; + person.getAge()); <br>    } <br>}</pre><p>3. <strong>Polymorphism:- </strong>It is the concept where an object behaves differently in different situations. There are two types of polymorphism: compile-time polymorphism and runtime polymorphism.</p><ul><li><strong>Compile Time Polymorphism:- </strong>It is also known as <strong>static polymorphism</strong> or <strong>early binding</strong>. It is resolved during the compilation process. It is achieved by <strong>method overloading </strong>and <strong>operator overloading </strong>(not allowed in Java). <br>* <strong>Method Overloading:-</strong> It is a concept where we have methods of same class with same name and with difference in type of paramaters or no of parameters.</li></ul><pre>class Overload{<br>    public void show(String s1){<br>        System.out.println(s1);<br>    }<br><br>    public void show(int num){<br>        System.out.println(num);<br>    }<br><br>    public void show(int num1,int num2){<br>        System.out.println(num1 + &quot; &quot; + num2);<br>    }<br>}<br><br>public class Main{<br>    public static void main(String[] args){<br>        Overload overload = new Overload();<br>        overload.show(&quot;Vishal&quot;);<br>        overload.show(9);<br>        overload.show(6,9);<br>    }<br>}</pre><ul><li><strong>Run Time Polymorphism:- </strong>It is also known as <strong>dynamic polymorphism</strong> or <strong>late binding</strong>. It is a process in which a function call to the overridden method is resolved at Runtime. It is achieved by <strong>method overriding</strong> and <strong>virtual functions</strong>(not present in Java). <br>* <strong>Method Overriding:-</strong> It can be achieved when we extend a class and implement its function again in our class in our own defination.</li></ul><pre>class Parent{<br>    int value = 0;<br>    public void show(){<br>        System.out.println(&quot;Inside parent class&quot;);<br>    }<br>    public void setValue(){<br>        value = 10;<br>        System.out.println(&quot;current value:- &quot; + value);<br>    }<br>}<br><br>class Child extends Parent{<br>    public void show(){<br>        System.out.println(&quot;Inside child class&quot;);<br>    }<br><br>     public void setValue(){<br>        value = 20;<br>        System.out.println(&quot;current value:- &quot; + value);<br>    }<br>}<br><br>public class Main{<br>    public static void main(String[] args){<br>        Child child = new Child();<br>        child.show();<br>        child.setValue();<br>    }<br>}</pre><p>4. <strong>Inheritance:- </strong>It is a concept in which one class is allowed to inherit the features(fields and methods) of another class. A class that inherits from another class can reuse the methods and fields of that class. In addition, we can add new fields and methods to your current class as well.</p><p><strong>Important Terminologies in Inheritance:-</strong></p><ul><li><strong>Super Class/Parent Class/Base Class:- </strong>The class whose features are inherited.</li><li><strong>Sub Class/Child Class/Derived Class:- </strong>The class that is inheriting the parent class.</li></ul><p><strong>Types:- <br></strong>1. Single Inheritance. <strong><br></strong>2. Multilevel Inheritance. <strong><br>3. </strong>Hierarchical Inheritance. <br>4. Multiple Inheritance. <br>5. Hybrid Inheritance.</p><ul><li><strong>Single Inheritance:-</strong> In this, subclasses inherit the features of one superclass.</li></ul><figure><img alt="Single Inheritance example" src="https://cdn-images-1.medium.com/max/660/1*3r04HpQtP5omo7WiWVvWVg.jpeg" /><figcaption>Single Inheritance</figcaption></figure><pre>class Father //Base<br>{<br>    public void house()<br>    {<br>        System.out.println(&quot;Have Own 2BHK House.&quot;);<br>    }<br>}<br>class Son extends Father //Derived<br>{<br>    public void car()<br>    {<br>        System.out.println(&quot;Have Own Audi Car.&quot;);<br>    }<br>}<br> <br>public class single {<br>    public static void main(String args[])<br>    {<br>        Son o =new Son();<br>        o.car();<br>        o.house();<br>    }<br>}</pre><ul><li><strong>Multilevel Inheritance:- A </strong>derived class will be inheriting a base class, and as well as the derived class also acts as the base class for other sub-classes.</li></ul><figure><img alt="Multilevel" src="https://cdn-images-1.medium.com/max/660/1*y6XnkDe6NqOgMqJ9UA8Nlg.jpeg" /><figcaption>Multilevel Inheritance</figcaption></figure><pre>class GrandFather {<br>    public void house() {<br>        System.out.println(&quot;3 BHK House.&quot;);<br>    }<br>}<br>class father  extends GrandFather{<br>    public void land() {<br>        System.out.println(&quot;5 Arcs of Land..&quot;);<br>    }<br>}<br> <br>class son extends father {<br>    public void car() {<br>        System.out.println(&quot;Own Audi Car..&quot;);<br>    }<br>}<br> <br>public class multilevel {<br>    public static void main(String args[]) {<br>        son o = new son();<br>        o.car();<br>        o.house();<br>        o.land();<br>    }<br>}</pre><ul><li><strong>Hierarchical Inheritance:- </strong>In this,<strong> </strong>one class serves as a superclass (base class) for more than one subclass.</li></ul><figure><img alt="Heir" src="https://cdn-images-1.medium.com/max/322/1*6ldz-87CHEB-nhAavaXQRg.jpeg" /><figcaption>Hierarchical Inheirtance</figcaption></figure><pre>class shape {<br>    float length, breadth, radius;<br>}<br>class rect extends shape {<br>    public rect(float l, float b) {<br>        length = l;<br>        breadth = b;<br>    }<br>    float rectangle_area() {<br>        return length * breadth;<br>    }<br>}<br>class circle extends shape {<br>    public circle(float r) {<br>        radius = r;<br>    }<br>    float circle_area() {<br>        return 3.14f * (radius * radius);<br>    }<br>}<br>class square extends shape {<br>    public square(float l) {<br>        length = l;<br>    }<br> <br>    float square_area() {<br>        return (length * length);<br>    }<br>}<br> <br> <br>public class Hierarchical {<br>    public static void main(String[] args) {<br> <br>        rect o1 =new rect(2,5);<br>        System.out.println(&quot;Area of Rectangle : &quot;+o1.rectangle_area());<br> <br>        circle o2 =new circle(5);<br>        System.out.println(&quot;Area of Circle : &quot;+ o2.circle_area());<br> <br>        square o3 =new square(3);<br>        System.out.println(&quot;Area of Square : &quot;+o3.square_area());<br> <br>    }<br>}</pre><ul><li><strong>Multiple Inheritance (Through Interfaces In Java):-</strong> Here, one class can have more than one superclass and inherit features from all parent classes.</li></ul><blockquote>Please note that Java does <strong>not</strong> support <a href="https://www.geeksforgeeks.org/java-and-multiple-inheritance/">multiple inheritances</a> with classes. In Java, we can achieve multiple inheritances only through <a href="https://www.geeksforgeeks.org/interfaces-in-java/">Interfaces</a>.</blockquote><figure><img alt="Multiple Inheritance" src="https://cdn-images-1.medium.com/max/660/1*-t5eo6N_7s-gj3A-77KgHg.jpeg" /><figcaption>Multiple Inheritance</figcaption></figure><pre>interface Dog {<br>   void bark();<br>}<br><br>interface Cat {<br>  void meow();<br>}<br><br>class Animal implements Dog, Cat {<br>  public void bark() {<br>     System.out.println(&quot;Dog is barking&quot;);<br>  }<br><br>  public void meow() {<br>     System.out.println(&quot;Cat is meowing&quot;);<br>   }<br>}<br><br>class Main {<br>   public static void main(String args[]) {<br>       Animal a = new Animal();<br>       a.bark();<br>       a.meow();<br>   }<br>}</pre><ul><li><strong>Hybrid Inheritance:- </strong>It is a mix of two or more of the above types of inheritance.</li></ul><blockquote>Since Java doesn’t support multiple inheritances with classes, hybrid inheritance involving multiple inheritance is also not possible with classes.</blockquote><blockquote>In Java, we can achieve hybrid inheritance only through <a href="https://www.geeksforgeeks.org/interfaces-in-java/">Interfaces</a> if we want to involve multiple inheritance to implement Hybrid inheritance.</blockquote><blockquote>However, it is important to note that Hybrid inheritance does not necessarily require the use of Multiple Inheritance exclusively. It can be achieved through a combination of Multilevel Inheritance and Hierarchical Inheritance with classes, Hierarchical and Single Inheritance with classes.</blockquote><figure><img alt="Hybrid" src="https://cdn-images-1.medium.com/max/660/1*3oMn6FlanIK_nz3lRm-gtg.jpeg" /><figcaption>Hybrid Inheritance</figcaption></figure><pre>class Father {<br>   public void disp() {<br>       System.out.println(&quot;This is the father class&quot;);<br>   }<br>}<br>class Son extends Father {<br>   public void disp() {<br>       System.out.println(&quot;The Son class extends the Father Class&quot;);<br>   }<br>}<br>class Daughter extends Father {<br>   public void disp() {<br>       System.out.println(&quot;The Daughter class extends the Father Class&quot;);<br>   }<br>}<br>public class Student extends Daughter {<br>   public void disp() {<br>       System.out.println(&quot;Method defined inside the Student class&quot;);<br>   }<br>   public static void main(String args[]) {<br>       Student obj = new Student();<br>       System.out.println(&quot;Example of Hybrid Inheritance using <br>                   Hierarchical and Single Inheritance&quot;);<br>       obj.disp();<br>   }<br>}</pre><p>5. <strong>Association:- </strong>It is the OOPS concept to define the relationship between objects. The association defines the multiplicity between objects. For example Teacher and Student objects. There is a one-to-many relationship between a teacher and students. Similarly, a student can have a one-to-many relationship with teacher objects. However, both student and teacher objects are independent of each other.</p><figure><img alt="Association1" src="https://cdn-images-1.medium.com/max/427/1*xg35rwX24rOGyttOm9OIuQ.png" /><figcaption>Association1</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/402/1*f9uRbRxASS3Q78O-BsZYbw.png" /><figcaption>Association</figcaption></figure><pre>public class Teacher {<br>   private String name;<br>   private List&lt;Student&gt; students;<br>   // getter and setter methods <br>}<br>public class Student {<br>   private String name;<br>   private List&lt;Teacher&gt; teachers;<br>   // getter and setter methods <br>}</pre><p>6. <strong>Aggregation:- </strong>It is a special type of association. In aggregation, objects have their own life cycle but there is ownership. Whenever we have <strong>“HAS-A” </strong>relationship between objects and ownership then it’s a case of aggregation.</p><pre>class Chair{<br>      public void show(){<br>            System.out.println(&quot;show chair details.&quot;);<br>      }<br>}<br> <br>public class RoomTest {<br>      public static void main(String args[]){<br>            //Chair class object in RoomTest class<br>            Chair obj = new Chair();<br>            obj.show();<br>      }<br>}</pre><p>7.<strong> Composition:- </strong>The composition is a special case of aggregation. The composition is a more restrictive form of aggregation. When the contained object in “HAS-A” relationship can’t exist on its own, then it’s a case of composition. For example, House has-a Room. Here the room can’t exist without the house. Composition is said to be better than inheritance.</p><figure><img alt="Composition" src="https://cdn-images-1.medium.com/max/660/1*-u_KNh_0k3OlCPrnmukAXw.jpeg" /><figcaption>Composition</figcaption></figure><h3><strong>Advantages of OOPs:-</strong></h3><p>Benefits of Oops are:-</p><ul><li><strong>Modularity:-</strong> Encapsulation enables objects to be self-contained, making troubleshooting and collaborative development easier.</li><li><strong>Reusability:- </strong>Code can be reused through inheritance, meaning a team does not have to write the same code multiple times.</li><li><strong>Security:- </strong>Using encapsulation and abstraction, complex code is hidden, software maintenance is easier and internet protocols are protected.</li><li><strong>Flexibility:- </strong>Polymorphism enables a single function to adapt to the class it is placed in. Different objects can also pass through the same interface.</li></ul><h3><strong>Disadvantages of OOPs:-</strong></h3><ol><li><strong>Can be hard to understand</strong> — Object-oriented programming can sometimes be tricky to grasp, especially for beginners, due to its complex concepts like inheritance and polymorphism.</li><li><strong>Slower execution speed</strong> — The execution speed in OOP can be slower as it requires more CPU time to deal with the additional features it provides.</li><li><strong>More memory use</strong> — OOP uses more memory as it requires additional storage for data. This can lead to increased costs, especially for large-scale applications.</li></ol><h3><strong>Conclusion:-</strong></h3><p>In conclusion, object-oriented programming (OOP) represents a powerful paradigm that supports modular, flexible, and scalable software development. By emphasizing concepts such as encapsulation, inheritance, and polymorphism, OOP encourages the creation of clean, organized code that reflects real-world entities. Through this blog journey, we have explored the key principles of OOP and delved into their practical applications and benefits. As we concluded, it is evident that mastering OOP is not just a programming skill; it’s a mindset that enables developers to design robust, maintainable systems that adapt to evolving requirements. Embrace the principles of OOP and you’ll be on your way to creating software solutions that stand the test of time.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5b0090b9ec04" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Bajaj Finserv Health Interview Experience(Oncampus)]]></title>
            <link>https://medium.com/@vdas53073/bajaj-finserv-interview-health-oncampus-a427e8ade0db?source=rss-3e6b75a77f7f------2</link>
            <guid isPermaLink="false">https://medium.com/p/a427e8ade0db</guid>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[backend]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Vishal Das]]></dc:creator>
            <pubDate>Fri, 07 Apr 2023 13:04:28 GMT</pubDate>
            <atom:updated>2023-04-07T13:08:44.023Z</atom:updated>
            <content:encoded><![CDATA[<p>Package:-@<strong>13lpa</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*6syxc5RIY_O9ka1tDCqMyg.png" /><figcaption>Bajaj finserv health</figcaption></figure><p>The interview happened on my campus on March <strong>31, 2023. </strong>Two profiles were there: <strong>frontend</strong> and <strong>backend. </strong>There were <strong>four rounds</strong> for the front end and <strong>three</strong> for the back end.</p><p>For the first round, there was CV shortlisting, after which there was a machine-coding round in which we were given an API and had to fetch data and show it in the form of a list. We also have to apply <strong>pagination</strong> and <strong>search</strong> functionality. We have to use either <strong>ReactJs</strong> or <strong>NextJs</strong> and also code in the online compiler.</p><p>After this total, out of 460 students, <strong>50</strong> were selected for the next round for both profiles.</p><p>For frontend next round was a coding round where there were <strong>10</strong> MCQs related to <strong>javascript</strong>, <strong>react,</strong> and <strong>react native,</strong> and a coding question that was easy to<strong> medium,</strong> but you had to code it in only <strong>JavaScript</strong>. Duration of the test was <strong>45 min</strong>.</p><p>Then there was a 1–1 interview round, for which <strong>12</strong> were selected from the front end.</p><p>Here the interviewer asked me about core <strong>JS</strong> and <strong>React</strong> concepts like how to write short code to implement an <strong>infinite carousel,</strong> then the implementation of <strong>Redux</strong> and how to update state without rendering, then some scenario-based questions related to <strong>hooks</strong> and <strong>lifecycle</strong> methods. Some of my friends also got questions about basic DSA, like <strong>the Fibonacci</strong> series. At last, the interviewer asked me how much time I would need to learn React Native if she puts me in an Android development role.</p><p>After this, they shortlisted 3 CVs, out of which only one girl got into the next round, which was the interview cum Hr round.</p><p>So during the whole process, they were focused on <strong>development</strong> and asked very few or no DSA questions.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a427e8ade0db" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Chrome Extensions for November 2022]]></title>
            <link>https://medium.com/@vdas53073/chrome-extensions-for-november-2022-1b5fbf349ca9?source=rss-3e6b75a77f7f------2</link>
            <guid isPermaLink="false">https://medium.com/p/1b5fbf349ca9</guid>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[productivity]]></category>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[extension]]></category>
            <category><![CDATA[chrome]]></category>
            <dc:creator><![CDATA[Vishal Das]]></dc:creator>
            <pubDate>Tue, 22 Nov 2022 14:40:24 GMT</pubDate>
            <atom:updated>2022-11-22T14:40:24.924Z</atom:updated>
            <content:encoded><![CDATA[<p>Yaa I’m back after a long time because I was busy in my college stuffs.</p><p>So let’s get into business now, and get ready to explore some of the cool chrome extensions I have discovered this month. Hold your breath!😎</p><h3>1. Fake Data</h3><p>It is the most advanced tool for filling forms with fake and random data. Fake Data will help you insert random values in any form field. Generate random names, emails, addresses, phone numbers and many more types of data. Create your own types of data using JavaScript code, which opens unlimited possibilities. You can fill single fields or entire form at once.</p><p>Download: <a href="https://chrome.google.com/webstore/detail/fake-data-a-form-filler-y/gchcfdihakkhjgfmokemfeembfokkajj"><strong>Fake Data</strong></a></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FQyof2PvDfKE%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DQyof2PvDfKE&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FQyof2PvDfKE%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/478d4e4249930f0541eafb3f45624c0b/href">https://medium.com/media/478d4e4249930f0541eafb3f45624c0b/href</a></iframe><h3>2. JSON Viewer Pro</h3><p>If you are from tech then you must be knowing the importance of JSON.So yeah, this is my personal favourite.</p><p>A completely free extension to visualize JSON response in awesome Tree and Chart view with great user experience and options. You can also import import local JSON file.</p><p>Download:<a href="https://chrome.google.com/webstore/detail/json-viewer-pro/eifflpmocdbdmepbjaopkkhbfmdgijcc"> <strong>JSON</strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*tgOQWvJhRf6DHpdcIN2vDw.jpeg" /><figcaption>JSON</figcaption></figure><h3>3. SEO META in 1 CLICK</h3><p>This one for analytics nerds.😂 Sorry if I’m sounding bit biased😛</p><p>It is a tool that displays all meta tags/data and main SEO information clearly. By using this tool, we hope you can better manage and improve your SEO and visibility on Internet.</p><p>Download:<a href="https://chrome.google.com/webstore/detail/seo-meta-in-1-click/bjogjfinolnhfhkbipphpdlldadpnmhc"><strong> SEO META in 1 CLICK</strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*ubSiQ2MvnNPdvi1mW_o1RA.jpeg" /><figcaption>Seo</figcaption></figure><h3>4. 30 Seconds of Knowledge</h3><p>Gain new developer skills every time you open a New Tab! Choose which programming languages you want to get better at in extension options and get smarter every time you open a New Tab. All you need is 30 seconds to read and understand snippets of code and improve your knowledge.</p><p>Download:- <a href="https://chrome.google.com/webstore/detail/30-seconds-of-knowledge/mmgplondnjekobonklacmemikcnhklla"><strong>30 Seconds of Knowledge</strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*EfM9O5mpQwmUe8WCWYZMvQ.jpeg" /><figcaption>30 Seconds of Knowledge</figcaption></figure><h3>5. Responsive Viewer</h3><p>Again one of the most useful extension.</p><p>A Chrome extension to show multiple screens in one view. the extension will help front-end developers to test multiple screens while developing responsive websites/applications.</p><p>Download:-<a href="https://chrome.google.com/webstore/detail/responsive-viewer/inmopeiepgfljkpkidclfgbgbmfcennb"> <strong>Responsive Viewer.</strong></a></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F2HI4H4zhhqo%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D2HI4H4zhhqo&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F2HI4H4zhhqo%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/97a55d24fec32324ee6fd8e3d6ef3019/href">https://medium.com/media/97a55d24fec32324ee6fd8e3d6ef3019/href</a></iframe><h3>6. tabExtend</h3><p>It can manage your tabs. You can also create notes and to-dos that will be sync between devices. You can also import bookmarks and top sites. Save selected text-snippets. It also supports dark theme. You can also share categories via public link.</p><p>Download:-<strong> </strong><a href="https://chrome.google.com/webstore/detail/tabextend/ffikidnnejmibopbgbelephlpigeniph"><strong>tabExtend.</strong></a></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FmDcytkiJOqg%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DmDcytkiJOqg&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FmDcytkiJOqg%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/1b5bc07e76f71f148fb97c73bb08d1a1/href">https://medium.com/media/1b5bc07e76f71f148fb97c73bb08d1a1/href</a></iframe><h3>7. Text Blaze</h3><p>Text Blaze lets you insert text templates anywhere using keyboard shortcuts. Save hours and avoid mistakes by eliminating repetitive typing using customizable templates.</p><p>Download:- <a href="https://chrome.google.com/webstore/detail/text-blaze/idgadaccgipmpannjkmfddolnnhmeklj"><strong>Text Blaze</strong></a><strong>.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*jyTPFE3R-JhVwUgirp-9ow.jpeg" /><figcaption>textBlaze</figcaption></figure><h3>8. Ghostery</h3><p><a href="https://chrome.google.com/webstore/detail/ghostery-%E2%80%93-privacy-ad-blo/mlomiejdfkolichcflejclcbmpeaniij">Ghostery</a> is a powerful privacy extension. Block ads, stop trackers, and speed up websites. Ghostery’s built-in ad blocker removes advertisements from a webpage to eliminate clutter so you can focus on the content you want. Ghostery allows you to view and block trackers on websites you browse to control who collects your data.</p><p>Download:- <a href="https://chrome.google.com/webstore/detail/ghostery-%E2%80%93-privacy-ad-blo/mlomiejdfkolichcflejclcbmpeaniij"><strong>Ghostery.</strong></a></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FWOo6HK48Kjo%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DWOo6HK48Kjo&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FWOo6HK48Kjo%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/a2c807d35e86f9ae29cc0870189be47c/href">https://medium.com/media/a2c807d35e86f9ae29cc0870189be47c/href</a></iframe><h3>9. Tab for a Cause</h3><p>Raise money for charity with every tab you open in Chrome! Just by surfing the web, you can build libraries, plant trees, send emergency aid, give clean water, and more. It’s not a productive extension but it deserves a try to help people.</p><p>Download:- <a href="https://chrome.google.com/webstore/detail/tab-for-a-cause/gibkoahgjfhphbmeiphbcnhehbfdlcgo"><strong>Tab For A Cause.</strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*WE5uznoGacbW-0_tsGilwQ.jpeg" /><figcaption>tabCause</figcaption></figure><h3>10. Initab</h3><p>This extension is insane for tech ones.</p><p><a href="https://chrome.google.com/webstore/detail/initab/igmbdimmfbpdplpahpapkploofmgaipl">Initab</a> is a new tab extension that replaces Chrome’s new tab page with a dashboard of useful tools to make your job as a programmer easier. Get a quick view of your GitHub/GitLab Issue activity, Stack Overflow activity, and much more.</p><p>Download:- <a href="https://chrome.google.com/webstore/detail/initab/igmbdimmfbpdplpahpapkploofmgaipl"><strong>Initab</strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*pltH5C5ZhReaNgXDxw09Xg.jpeg" /><figcaption>Initab</figcaption></figure><h3><strong>Conclusion:-</strong></h3><blockquote><strong>So these were some of the extensions I felt interesting and thought of sharing with you. I hope you all find it useful and interesting. I will be coming up with new cool extensions next month.</strong></blockquote><blockquote><strong>Comment your favourite extension😉</strong></blockquote><blockquote><strong>Subscribe for tech related posts.🙂</strong></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1b5fbf349ca9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Sending Data between different windows using Javascript.]]></title>
            <link>https://javascript.plainenglish.io/sending-data-between-different-windows-using-javascript-566846e79d60?source=rss-3e6b75a77f7f------2</link>
            <guid isPermaLink="false">https://medium.com/p/566846e79d60</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[frontend-development]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[full-stack-developer]]></category>
            <dc:creator><![CDATA[Vishal Das]]></dc:creator>
            <pubDate>Sat, 08 Oct 2022 15:52:16 GMT</pubDate>
            <atom:updated>2022-10-08T15:52:16.500Z</atom:updated>
            <content:encoded><![CDATA[<p>What if I tell you that you can send messages or rather communicate from one window to another using javascript? Sounds Crazy to build right?</p><p>But hang on it’s not that hard rather I will show a simple example using few lines of code.</p><p><a href="https://drive.google.com/file/d/1n5Lcsqy2WLNXi5ofpgwv6YZJxMYw8RR6/view?usp=sharing">Media1.mp4</a></p><p>Setup:-</p><p>The setup is very simple,first create a new folder and then we have to create just three files:- <strong>index.html, sub.html,index.js.</strong></p><p>Starting with the index.html file:-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*omNigJU3CHixH2aDgSP0Bg.png" /><figcaption>index.hml</figcaption></figure><p>Moving on to sub.html:-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vpJDZwYsinCHeshmFhG7JA.png" /><figcaption>sub.html</figcaption></figure><p><strong>JavaScript code:-</strong></p><p>Now done with the setup, coming to the main logic part</p><p>I have created a single common JavaScript file for both index and sub HTML, but you can divide it into two.</p><p>Now going to index.js file . First thing to add is to open a new window when we click on open new tab:-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cs2Ksm3-IscdlB70_jYbuA.png" /></figure><p>When we will click on<strong> “Open new tab”</strong> button in<strong> index.html</strong> then it will call <strong>“openNewWindow()”</strong> function. Using open method, we will open a new window. I have several parameters to open:-</p><ol><li><strong>‘sub.html’ </strong>:- The page you want to open</li><li><strong>‘sub’</strong> :- Name you want to give to the new page opened(can be anything).</li><li><strong>params</strong>:- Options for this new window like width and height of window etc.</li></ol><p>Now you have must notice we have taken the reference of newly opened window in a variable called “<strong>newWindow</strong>” so that in future we will be sending messages to this new window with the help of this variable.</p><p>To send message we have another method called <strong>“postMessage()”.</strong></p><p>Let’s first see the code :-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rn5Z8Gk7Sw7n8i9eebEneQ.png" /></figure><p>When we will click on “<strong>Send Message</strong>” button then it will call the <strong>sendMessage()</strong> function where we are sending message using <strong>postMessage()</strong> in the form of object. We can modify it to take input from user in the window then send that custom message but here we are keeping it simple by sending a default message ‘<strong>bar</strong>’.</p><p>Now let’s lookup at the receiving end i.e <strong>sub.html </strong>page .</p><p>Now to receive the message in the sub page we will use a event listener which is ‘message’. It is activated whenever window/page receives any message.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z0_ih3lpE4iNT0gbTBD5yg.png" /></figure><p>Pretty much self-understandable code, I guess .</p><p>Wait we have to also send back message also from sub to index page right?</p><p>Now don’t say I should start eating almonds to keep things remembered.🙂</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Caw2zH8jxa3GVwe2De5YOw.png" /></figure><p>Now here, when we will click on any of the three buttons in sub page then it will call the<strong> closeWindow</strong> message with custom message and then we have to called the same method <strong>postMessage()</strong> which we called in<strong> index</strong>. We are opening the original window using <strong>opener</strong> and then we are closing this <strong>sub page</strong> using <strong>window.close()</strong>.</p><p>Now we are left to recieve back the message from<strong> sub </strong>in index page. For this we can modify the listener function used for <strong>sub</strong> page as both will have same event ‘<strong>message</strong>’ so we can put condition that if object has <strong>msg </strong>as key then it is for<strong> index</strong> page and if <strong>foo</strong> as key then it is for <strong>sub</strong> page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fYvSw2Vz5zQDziuf1Tl1gw.png" /></figure><p>Bingo! Now we can send message between two windows.</p><p>For source code and some other cool projects you can visit my github:-</p><p><a href="https://github.com/vdas01/Message-between-two-windows-Javascript-">GitHub - vdas01/Message-between-two-windows-Javascript-: We can communicate between two windows using javaScript</a></p><blockquote><strong>Thankyou for keeping patience and reading till the end.</strong></blockquote><blockquote><strong>I hope you learned something new.</strong></blockquote><blockquote><strong>Feel free to subscribe to my email newsletter for weekly posts and we can connect on </strong><a href="https://www.linkedin.com/in/vishal-das01/"><strong>LinkedIn</strong></a><strong>.🙂</strong></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=566846e79d60" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/sending-data-between-different-windows-using-javascript-566846e79d60">Sending Data between different windows using Javascript.</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Detect When A User Switches Tabs Using JavaScript]]></title>
            <link>https://javascript.plainenglish.io/detect-when-a-user-switches-tabs-using-javascript-711a6c883c99?source=rss-3e6b75a77f7f------2</link>
            <guid isPermaLink="false">https://medium.com/p/711a6c883c99</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[frontend]]></category>
            <dc:creator><![CDATA[Vishal Das]]></dc:creator>
            <pubDate>Mon, 19 Sep 2022 04:16:43 GMT</pubDate>
            <atom:updated>2022-09-19T04:16:43.763Z</atom:updated>
            <content:encoded><![CDATA[<h4>2 ways of detecting when users switch browser tabs: <strong>Using focus and blur event listeners &amp; using the ‘visibilitychange’ event listener</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/474/1*QGe0_rTUr1IZhrh-4NGssA.jpeg" /><figcaption>JavaScript</figcaption></figure><p>If you are a student who gave tests in online mode, especially during those Covid days then you must remember the pain of getting notified when you tried to change your exam tab.</p><p>Yeah, I know ALT + C was also an option for cheating or a rather smart search option during exams😜 but then aren’t you curious to know how it’s happening? I mean how are they able to detect when we are changing our tabs or clicking somewhere outside the exam window?🤔</p><p>So, be ready now I am going to introduce you to some of the event listeners which will help you detect when your client or user changes your website to another website or clicks outside your website/tab area.</p><p>There are two methods:</p><p><strong>Method 1: Using focus and blur event listeners</strong></p><p>In this method, we use two event listeners <strong>‘focus’</strong> and <strong>‘blur’.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/506/1*fCo8LOK1KEEeTkWivit8qg.png" /><figcaption>Method 1</figcaption></figure><p>When you switch to another tab or click outside the tab somewhere else in your window then <strong>‘blur’ </strong>gets activated.</p><p><a href="https://drive.google.com/file/d/1eGWeO9Pi_fPgUm0apyp5mCc7qC6uVMHu/view?usp=sharing">video1.mp4</a></p><p>And then again come back to the tab or click on the tab area then <strong>‘focus’</strong> gets activated.</p><p><strong>Method 2: Using the ‘visibilitychange’ event listener</strong></p><p>In this method, we will use only ‘visibilitychange’ event listener which has a property called ‘vsisibilityState’ which returns the value ‘hidden’ when you switch the tab and ‘visible’ when you come back again.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/589/1*mlj31dta6NTNmMfhezx4wQ.png" /><figcaption>Method 2.</figcaption></figure><p><a href="https://drive.google.com/file/d/1tZNqqrz0_BT4w9qwKVmetihtrf6AVNaY/view?usp=sharing">video2.mp4</a></p><p>The difference between Method 1 and Method 2 is that the former detects even when you click outside the tab area but the latter detects only when you switch tabs.</p><p><em>I hope you learned something new.</em></p><p><em>Tell me in the comments which method you find easy.😉</em></p><p><em>Subscribe for weekly tech posts.</em></p><p><em>More content at </em><a href="https://plainenglish.io/"><strong><em>PlainEnglish.io</em></strong></a><em>. Sign up for our </em><a href="http://newsletter.plainenglish.io/"><strong><em>free weekly newsletter</em></strong></a><em>. Follow us on </em><a href="https://twitter.com/inPlainEngHQ"><strong><em>Twitter</em></strong></a>, <a href="https://www.linkedin.com/company/inplainenglish/"><strong><em>LinkedIn</em></strong></a><em>, </em><a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong><em>YouTube</em></strong></a><em>, and </em><a href="https://discord.gg/GtDtUAvyhW"><strong><em>Discord</em></strong></a><em>. Interested in Growth Hacking? Check out </em><a href="https://circuit.ooo/"><strong><em>Circuit</em></strong></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=711a6c883c99" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/detect-when-a-user-switches-tabs-using-javascript-711a6c883c99">Detect When A User Switches Tabs Using JavaScript😎</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>