<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Raj</title>
    <description>The latest articles on DEV Community by Raj (@rajasekar1998).</description>
    <link>https://dev.to/rajasekar1998</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4022101%2Fb0a65021-21e6-44d1-b6e6-e21d94e1d37a.jpg</url>
      <title>DEV Community: Raj</title>
      <link>https://dev.to/rajasekar1998</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rajasekar1998"/>
    <language>en</language>
    <item>
      <title>Inheritance type in java</title>
      <dc:creator>Raj</dc:creator>
      <pubDate>Wed, 25 Nov 2026 20:20:46 +0000</pubDate>
      <link>https://dev.to/rajasekar1998/inheritance-type-in-java-4gp8</link>
      <guid>https://dev.to/rajasekar1998/inheritance-type-in-java-4gp8</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When we start learning Java we come across many important concepts in Object Oriented Programming (OOP). One of those concepts is Inheritance.&lt;/p&gt;

&lt;p&gt;Inheritance is a concept that allows one class to acquire the properties and methods of another class. In simple words instead of writing the same code again and again we can create one common class and allow other classes to reuse its functionality. &lt;/p&gt;

&lt;p&gt;We can understand inheritance using a real world family example. A child may inherit certain characteristics from their parents. Similarly in Java a child class can inherit properties and methods from a parent class.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What Is Inheritance in Java?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Inheritance is an Object-Oriented Programming concept in which one class acquires the properties and methods of another class.&lt;/p&gt;

&lt;p&gt;The class that provides its properties and methods is called the Parent Class or Superclass. The class that inherits those properties and methods is called the Child Class or Subclass.&lt;/p&gt;

&lt;p&gt;Example imagine a father has a house. His son wants to use that property. in Java the Son class can inherit the properties and methods of the Father class.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Father&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;house&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;out&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Father has a house"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Son&lt;/span&gt; &lt;span class="k"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Father&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;bike&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;out&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Son has a bike"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Main&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

        &lt;span class="nc"&gt;Son&lt;/span&gt; &lt;span class="n"&gt;obj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Son&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="n"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;house&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;bike&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Father has a house
Son has a bike
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Father class contains the house() method. The Son class uses the extends keyword to inherit the Father class.&lt;/p&gt;

&lt;p&gt;When we create an object of the Son class, we can access both the inherited house() method and its own bike() method.&lt;/p&gt;

&lt;p&gt;** Why Do We Use Inheritance?**&lt;/p&gt;

&lt;p&gt;Imagine you are developing a school management application. In that application you need to create three classes: Student Teacher and Staff.&lt;/p&gt;

&lt;p&gt;All three classes have some common information such as name, age, and address.&lt;/p&gt;

&lt;p&gt;Without inheritance we might write the same properties in all three classes. This creates code duplication.&lt;/p&gt;

&lt;p&gt;Instead, we can create one common class called Person and allow Student, Teacher and Staff to inherit it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Person&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="kt"&gt;String&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;display&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;out&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;out&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;age&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Student&lt;/span&gt; &lt;span class="k"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Person&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Teacher&lt;/span&gt; &lt;span class="k"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Person&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Staff&lt;/span&gt; &lt;span class="k"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Person&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now Student, Teacher, and Staff can reuse the common properties and methods from the Person class.&lt;/p&gt;

&lt;p&gt;The main advantages of inheritance are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Code Reusability – We can reuse existing code instead of writing it again.&lt;/li&gt;
&lt;li&gt;Code Duplication Reduction – Common properties and methods can be maintained in one parent class.&lt;/li&gt;
&lt;li&gt;Easy Maintenance – Changes to common functionality can be managed in one place.&lt;/li&gt;
&lt;li&gt;Extensibility – We can create new child classes using existing parent classes.&lt;/li&gt;
&lt;li&gt;Method Overriding – Child classes can provide their own implementation of inherited methods.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Types of Inheritance in Java&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Inheritance can be implemented in different ways depending on the relationship between classes.&lt;/p&gt;

&lt;p&gt;Java commonly discusses five types of inheritance:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Single Inheritance&lt;/li&gt;
&lt;li&gt;Multilevel Inheritance&lt;/li&gt;
&lt;li&gt;Hierarchical Inheritance&lt;/li&gt;
&lt;li&gt;Multiple Inheritance&lt;/li&gt;
&lt;li&gt;Hybrid Inheritance&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;1.Single Inheritance&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Single inheritance means one child class inherits from one parent class.&lt;/p&gt;

&lt;p&gt;For example, imagine a Father has a house and a Son inherits the property.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Java Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Father&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;property&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;out&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Father has a house"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Son&lt;/span&gt; &lt;span class="k"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Father&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;vehicle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;out&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Son has a car"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Main&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

        &lt;span class="nc"&gt;Son&lt;/span&gt; &lt;span class="n"&gt;obj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Son&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="n"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;property&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;vehicle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Father has a house
Son has a car
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here the Son class inherits the Father class. Therefore, the Son object can access the inherited property() method and its own vehicle() method.&lt;/p&gt;

&lt;p&gt;This relationship between one parent and one child is called Single Inheritance.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Multilevel Inheritance&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Multilevel inheritance means one class inherits another class, and a third class inherits the second class.&lt;/p&gt;

&lt;p&gt;We can understand this through a family relationship:&lt;/p&gt;

&lt;p&gt;Grandfather → Father → Son.&lt;/p&gt;

&lt;p&gt;The Father inherits from Grandfather and the Son inherits from Father.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Java Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Grandfather&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;land&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;out&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Grandfather has land"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Father&lt;/span&gt; &lt;span class="k"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Grandfather&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;house&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;out&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Father has a house"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Son&lt;/span&gt; &lt;span class="k"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Father&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;bike&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;out&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Son has a bike"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Main&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

        &lt;span class="nc"&gt;Son&lt;/span&gt; &lt;span class="n"&gt;obj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Son&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="n"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;land&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;house&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;bike&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Grandfather has land
Father has a house
Son has a bike
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here the Son class directly inherits Father but it can also access the inherited method from Grandfather because Father already inherits Grandfather.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Hierarchical Inheritance&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Hierarchical inheritance means multiple child classes inherit from one common parent class.&lt;/p&gt;

&lt;p&gt;For example one parent has two children: a Son and a Daughter.&lt;/p&gt;

&lt;p&gt;Both children can inherit common properties from their parent but they can also have their own individual properties.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Java Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Parent&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;property&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;out&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Parent has property"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Son&lt;/span&gt; &lt;span class="k"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Parent&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;bike&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;out&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Son has a bike"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Daughter&lt;/span&gt; &lt;span class="k"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Parent&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;car&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;out&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Daughter has a car"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Main&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

        &lt;span class="nc"&gt;Son&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Son&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nc"&gt;Daughter&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Daughter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;property&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;bike&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;property&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;car&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Parent has property
Son has a bike
Parent has property
Daughter has a car
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here both Son and Daughter inherit the same Parent class.&lt;/p&gt;

&lt;p&gt;The Son can access the parent's property and his own bike method. Similarly, the Daughter can access the parent's property and her own car method.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4.Multiple Inheritance&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Multiple inheritance means one child class inherits from more than one parent class.&lt;/p&gt;

&lt;p&gt;For example imagine a child wants to access properties from both Father and Mother.&lt;/p&gt;

&lt;p&gt;However Java does not support multiple inheritance through classes.&lt;/p&gt;

&lt;p&gt;Why? Imagine both parent classes have a method with the same name. If the child inherits both classes it may become confusing to decide which parent's method should be executed. This situation is related to the Diamond Problem.&lt;/p&gt;

&lt;p&gt;However Java provides another way to achieve multiple inheritance using interfaces.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Java Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="k"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;Father&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;house&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;Mother&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;car&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Child&lt;/span&gt; &lt;span class="k"&gt;implements&lt;/span&gt; &lt;span class="nc"&gt;Father&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Mother&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;house&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;out&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Father has a house"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;car&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;out&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Mother has a car"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Main&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

        &lt;span class="nc"&gt;Child&lt;/span&gt; &lt;span class="n"&gt;obj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Child&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="n"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;house&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;car&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Father has a house
Mother has a car
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here the Child class implements two interfaces: Father and Mother.&lt;/p&gt;

&lt;p&gt;Java allows a class to implement multiple interfaces. This is how we achieve Multiple Inheritance in Java.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5.Hybrid Inheritance&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Hybrid inheritance means combining two or more types of inheritance.&lt;/p&gt;

&lt;p&gt;For example, we can combine hierarchical inheritance and multiple inheritance.&lt;/p&gt;

&lt;p&gt;Java does not support hybrid inheritance using classes alone when it requires multiple class inheritance.&lt;/p&gt;

&lt;p&gt;However we can achieve hybrid inheritance by combining classes and interfaces.&lt;/p&gt;

&lt;p&gt;This is useful when an application needs to reuse functionality from different types of relationships.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Difference Between All Types of Inheritance&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Inheritance Type&lt;/th&gt;
&lt;th&gt;Meaning&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Single&lt;/td&gt;
&lt;td&gt;One child inherits one parent&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Multilevel&lt;/td&gt;
&lt;td&gt;One class inherits another class in a chain&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Hierarchical&lt;/td&gt;
&lt;td&gt;Multiple children inherit one parent&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Multiple&lt;/td&gt;
&lt;td&gt;One child inherits multiple parents&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Hybrid&lt;/td&gt;
&lt;td&gt;Combination of two or more inheritance types&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;
&lt;/blockquote&gt;

&lt;p&gt;In Java, Single, Multilevel and Hierarchical inheritance are supported through classes. Multiple inheritance is supported through interfaces and Hybrid inheritance can be achieved using classes and interfaces together.&lt;/p&gt;

&lt;p&gt;** Important Keywords Used in Inheritance**&lt;/p&gt;

&lt;p&gt;When working with inheritance in Java two important keywords are extends and implements.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;extends:&lt;/strong&gt; We use the extends keyword when one class inherits another class.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Son&lt;/span&gt; &lt;span class="k"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Father&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;implements:&lt;/strong&gt; We use the implements keyword when a class implements an interface.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Child&lt;/span&gt; &lt;span class="k"&gt;implements&lt;/span&gt; &lt;span class="nc"&gt;Father&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Mother&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Remember:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Class to class – extends&lt;/li&gt;
&lt;li&gt;Class to interface – implements&lt;/li&gt;
&lt;li&gt;Interface to interface – extends&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;** Where Is Inheritance Used in Real Time Projects?**&lt;/p&gt;

&lt;p&gt;Inheritance is not only used for learning Java concepts. Developers also use it when building real world applications.&lt;/p&gt;

&lt;p&gt;For example consider an online banking application.&lt;/p&gt;

&lt;p&gt;A banking application may have different types of accounts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Savings Account&lt;/li&gt;
&lt;li&gt;Current Account&lt;/li&gt;
&lt;li&gt;Salary Account&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All these accounts have some common features such as account number, account holder name, deposit and withdrawal.&lt;/p&gt;

&lt;p&gt;Instead of writing the same code in every account class, developers can create a common BankAccount class.&lt;/p&gt;

&lt;p&gt;Then Savings Account, Current Account, and Salary Account can inherit the common properties and methods.&lt;/p&gt;

&lt;p&gt;This makes the application easier to develop, understand, and maintain.&lt;/p&gt;

</description>
      <category>java</category>
      <category>basic</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>Data Types &amp; Operators in Python</title>
      <dc:creator>Raj</dc:creator>
      <pubDate>Fri, 20 Nov 2026 08:05:16 +0000</pubDate>
      <link>https://dev.to/rajasekar1998/data-types-operators-in-python-290i</link>
      <guid>https://dev.to/rajasekar1998/data-types-operators-in-python-290i</guid>
      <description>&lt;p&gt;&lt;strong&gt;1. Data Types in Python&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Data types are used to identify what kind of value a variable stores. In Python we can store different types of data such as numbers text and True or False values. Python automatically identifies the data type based on the value assigned to a variable.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Rajasekar"&lt;/span&gt;
&lt;span class="n"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt;
&lt;span class="n"&gt;price&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;99.50&lt;/span&gt;
&lt;span class="n"&gt;is_student&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;True&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;age&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;price&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;is_student&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;class 'str'&amp;gt;
&amp;lt;class 'int'&amp;gt;
&amp;lt;class 'float'&amp;gt;
&amp;lt;class 'bool'&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here str represents text int represents whole numbers float represents decimal numbers and bool represents True or False values.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Integer (int)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;An integer is a data type used to store whole numbers without decimal points. It can contain positive numbers, negative numbers and zero.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt;
&lt;span class="n"&gt;temperature&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;
&lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;age&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;temperature&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;25
-10
0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here 25 is a positive integer -10 is a negative integer and 0 is also an integer.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Float&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A float is used to store numbers that contain decimal points. It is useful when working with prices, measurements and percentages.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;price&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;99.50&lt;/span&gt;
&lt;span class="n"&gt;height&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;5.8&lt;/span&gt;
&lt;span class="n"&gt;percentage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;85.5&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;price&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;height&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;percentage&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;99.5
5.8
85.5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4. String (str)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A string is used to store text, characters and words. In Python we can create strings using single quotes or double quotes.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Rajasekar"&lt;/span&gt;
&lt;span class="n"&gt;city&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Chennai'&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;city&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Rajasekar
Chennai
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Strings are commonly used to store names, addresses, messages and other text information.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Boolean (bool)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Boolean is a data type that stores only two values: True or False. It is mainly used in conditions and decision making.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;is_logged_in&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;True&lt;/span&gt;
&lt;span class="n"&gt;is_admin&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;False&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;is_logged_in&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;is_admin&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;True
False
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When a user enters the correct password a program can return True. If the password is incorrect it can return False.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. Operators in Python&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Operators are special symbols or keywords used to perform operations on values and variables. Python provides different types of operators, such as arithmetic, comparison, logical, assignment and membership operators.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Arithmetic Operators&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Arithmetic operators are used to perform mathematical calculations such as addition, subtraction, multiplication and division.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;
&lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;   &lt;span class="c1"&gt;# Addition&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;   &lt;span class="c1"&gt;# Subtraction&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;   &lt;span class="c1"&gt;# Multiplication&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;   &lt;span class="c1"&gt;# Division&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# Floor Division&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;   &lt;span class="c1"&gt;# Modulus&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# Exponentiation&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;13
7
30
3.3333333333333335
3
1
1000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The / operator performs normal division and returns a float. The // operator performs floor division and returns the quotient rounded down. The % operator returns the remainder after division while  ** is used for exponentiation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Comparison Operators&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Comparison operators are used to compare two values. They return either True or False.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;
&lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;False
True
True
False
True
False
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Logical Operators&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Logical operators are used to combine multiple conditions. Python provides three main logical operators: and or and not.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;age&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;18&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;age&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;18&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;True
True
False
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Assignment Operators&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Assignment operators are used to assign values to variables and update their values.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;

&lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="o"&gt;-=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="o"&gt;*=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;15
13
26
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Membership Operators&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Membership operators are used to check whether a value exists inside a sequence, such as a string, list or tuple. Python provides in and not in.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Python"&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"P"&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Java"&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;True
True
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Negative Indexing&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Indexing is used to access individual elements from a string or sequence. Python supports both positive and negative indexing.&lt;/p&gt;

&lt;p&gt;Positive indexing starts from 0 on the left side while negative indexing starts from -1 on the right side.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Python"&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;P
y
n
o
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here name[0] accesses the first character while name[-1] accesses the last character. Negative indexing is useful when we want to access elements from the end without calculating their positions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Slicing in Python&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Slicing is used to extract a portion of a string or sequence. Instead of accessing only one character we can access multiple characters using slicing.&lt;/p&gt;

&lt;p&gt;The syntax is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;variable&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;start&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;step&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here  start represents the starting position end represents the stopping position (the end position is not included) and step determines how many positions to move each time.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Python"&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;::-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Pyt
yth
Pyth
Pto
nohtyP
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Slicing is useful when we want to extract specific parts of a string skip characters or reverse a sequence.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Length (len) in Python&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The len() function is used to find the total number of elements in a sequence such as a string, list or tuple. When used with a string it returns the total number of characters including spaces.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Python"&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;6
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here the word Python contains six characters so the len() function returns 6.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step in Python&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The step value is used in slicing to control how many positions Python moves when accessing elements. A positive step moves from left to right while a negative step moves from right to left.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;numbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;::-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[1, 3, 5, 7]
[1, 4, 7]
[8, 7, 6, 5, 4, 3, 2, 1]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here 2 skips one element between selected elements 3 moves three positions at a time and -1 reverses the sequence.&lt;/p&gt;

</description>
      <category>python</category>
      <category>basic</category>
    </item>
    <item>
      <title>Dynamic Binding &amp; Late Binding in JDBC Connection with PostgreSQL</title>
      <dc:creator>Raj</dc:creator>
      <pubDate>Fri, 20 Nov 2026 07:40:53 +0000</pubDate>
      <link>https://dev.to/rajasekar1998/dynamic-binding-late-binding-in-jdbc-connection-with-postgresql-23o2</link>
      <guid>https://dev.to/rajasekar1998/dynamic-binding-late-binding-in-jdbc-connection-with-postgresql-23o2</guid>
      <description>&lt;p&gt;&lt;strong&gt;What is Dynamic Binding (Late Binding)?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Dynamic Binding also known as Late Binding is a concept in Java where the actual method implementation is decided at runtime instead of compile time.  Java decides which method should execute when the program is running.&lt;/p&gt;

&lt;p&gt;Example Imagine you are using a mobile phone and connecting it to different Bluetooth devices such as headphones, speakers or smartwatches. Your phone does not need to know the internal working of every device. It uses a common way to connect and each device handles the connection according to its own implementation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why Do We Use Dynamic Binding in JDBC?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When we connect a Java application to a database like PostgreSQL or MySQL we use JDBC (Java Database Connectivity). JDBC provides common interfaces that help Java applications communicate with different databases.&lt;/p&gt;

&lt;p&gt;We are developing a college management application. Initially we use PostgreSQL as our database. Later the company decides to change the database to MySQL. Instead of writing completely different connection code we can use the common JDBC interfaces and change the database driver and connection details.&lt;/p&gt;

&lt;p&gt;This is one of the reasons JDBC is flexible.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How Does It Work?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;First we need to understand that Connection is an interface in Java JDBC. An interface defines methods but it does not provide the complete database specific implementation. The PostgreSQL JDBC driver provides its own implementation of the Connection interface.&lt;/p&gt;

&lt;p&gt;When we call DriverManager.getConnection() JDBC identifies a suitable driver based on the database URL and asks that driver to establish the connection. The driver returns a connection object.&lt;/p&gt;

&lt;p&gt;Connecting Java with PostgreSQL&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Import JDBC packages&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="n"&gt;java&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;java&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sql&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Connection&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;java&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sql&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;DriverManager&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;java&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sql&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;SQLException&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These imports allow us to use JDBC classes and interfaces. Connection represents the database connection DriverManager helps obtain the connection and SQLException handles database related errors.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Create the database connection&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="n"&gt;java&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;DatabaseConnection&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

        &lt;span class="kt"&gt;String&lt;/span&gt; &lt;span class="n"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"jdbc:postgresql://localhost:5432/college"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="kt"&gt;String&lt;/span&gt; &lt;span class="n"&gt;username&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"postgres"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="kt"&gt;String&lt;/span&gt; &lt;span class="n"&gt;password&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"password"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

  &lt;span class="nc"&gt;Connection&lt;/span&gt; &lt;span class="n"&gt;con&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;DriverManager&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getConnection&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;username&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

            &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;out&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Database Connected Successfully"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;SQLException&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

            &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;out&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation of the Code&lt;/p&gt;

&lt;p&gt;We create a database URL that contains the database type server address, port number and database name. Here jdbc:postgresql tells JDBC that we want to connect to PostgreSQL. localhost means the database is running on our own computer 5432 is the default PostgreSQL port and college is the database name.&lt;/p&gt;

&lt;p&gt;Next we provide the username and password required to access the database.&lt;/p&gt;

&lt;p&gt;After that we use DriverManager.getConnection() to establish the connection. This method identifies the suitable JDBC driver and asks it to connect to the database.&lt;/p&gt;

&lt;p&gt;The returned object is stored in the con variable whose type is Connection. Even though we use the common Connection interface the actual connection implementation is provided by the PostgreSQL JDBC driver.&lt;/p&gt;

&lt;p&gt;If the connection is successful the program prints a success message. If something goes wrong the catch block handles the database error.&lt;/p&gt;

</description>
      <category>java</category>
      <category>jdbc</category>
      <category>postgres</category>
    </item>
    <item>
      <title>Package in Java</title>
      <dc:creator>Raj</dc:creator>
      <pubDate>Thu, 19 Nov 2026 09:40:46 +0000</pubDate>
      <link>https://dev.to/rajasekar1998/package-in-java-2e8m</link>
      <guid>https://dev.to/rajasekar1998/package-in-java-2e8m</guid>
      <description>&lt;p&gt;&lt;strong&gt;What is a Package in Java?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A package in Java is used to organize related classes, interfaces and other files in one place. It helps developers keep their code clean, organized and easy to maintain.&lt;br&gt;
In simple words a package is like a folder on our computer. We create different folders to store different types of files. In the same way Java packages help us organize our program.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why Do We Use Packages in Java?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When we work on a small Java program, we may not need many classes. But when we develop a large application we may have hundreds of classes. Managing all those classes in one place becomes difficult.&lt;/p&gt;

&lt;p&gt;The main reasons for using packages are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Code Organization: We can group related classes together.&lt;/li&gt;
&lt;li&gt;Code Reusability: We can use existing classes in other programs.&lt;/li&gt;
&lt;li&gt;Avoid Naming Conflicts: We can create classes with the same name in different packages.&lt;/li&gt;
&lt;li&gt;Access Protection: Packages help control access to classes and their members.&lt;/li&gt;
&lt;li&gt;Easy Maintenance: We can easily find, update, and manage our code.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Types of Packages in Java&lt;/strong&gt;&lt;br&gt;
Java has two main types of packages.&lt;br&gt;
&lt;strong&gt;1. Built in Packages&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Built in packages are already provided by Java. We can directly use them in our programs.&lt;/p&gt;

&lt;p&gt;Some examples are:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"java.lang" – Used for String, Math, System, etc.
 "java.util" – Used for Scanner, ArrayList, HashMap, etc.
 "java.io" – Used for file handling.
 "java.net" – Used for networking.
 "java.sql" – Used for database connectivity.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;when we want to get input from the user we can use the Scanner class from the "java.util" package.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. User defined Packages&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;User defined packages are packages created by developers.&lt;/p&gt;

&lt;p&gt;We are developing an employee management system, we can create separate packages for employee details, salary calculations and database connections.&lt;/p&gt;

&lt;p&gt;This makes the project easier to understand and manage.&lt;/p&gt;

&lt;p&gt;Example&lt;/p&gt;

&lt;p&gt;we are creating an Employee Management System.&lt;br&gt;
We can organize our project like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; Employee Package – Stores employee information.
 Salary Package – Handles salary calculations.
 Database Package – Manages database connections.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Instead of keeping all classes in one place we separate them based on their purpose.This makes our application more structured and professional.&lt;/p&gt;

</description>
      <category>java</category>
      <category>learning</category>
      <category>packageinjava</category>
    </item>
    <item>
      <title>Database and PostgreSQL</title>
      <dc:creator>Raj</dc:creator>
      <pubDate>Wed, 18 Nov 2026 08:57:29 +0000</pubDate>
      <link>https://dev.to/rajasekar1998/database-and-postgresql-3lcm</link>
      <guid>https://dev.to/rajasekar1998/database-and-postgresql-3lcm</guid>
      <description>&lt;p&gt;&lt;strong&gt;1. What is a Database?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A database is an organized collection of data that is stored electronically. It helps us store, manage, access, update and delete information easily.&lt;/p&gt;

&lt;p&gt;For example in a company, we need to maintain employee names, phone numbers, email addresses, salaries, and other details. Instead of storing everything manually we can use a database to manage all this information in one place.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. What Are the Types of Databases?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;There are different types of databases available. Each database has its own way of storing and managing information.&lt;/p&gt;

&lt;p&gt;Some common types of databases are:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Relational Database (SQL)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A relational database stores information in tables with rows and columns. It is commonly used for banking systems, employee management and business applications.&lt;/p&gt;

&lt;p&gt;Examples: PostgreSQL, MySQL, Oracle Database, and SQLite.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Document Database&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A document database stores information in document formats, usually JSON-like structures. It is useful for applications that need flexible data storage.&lt;/p&gt;

&lt;p&gt;Examples: MongoDB and CouchDB.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Key-Value Database&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This database stores information as key-value pairs. It is mainly used for caching, session management, and fast data access.&lt;/p&gt;

&lt;p&gt;Examples: Redis and Amazon DynamoDB.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Hierarchical Database&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A hierarchical database stores information in a tree-like structure with parent and child relationships. It is useful for managing data with a fixed hierarchy.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Network Database&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A network database connects information through multiple relationships. It is useful for handling complex data connections.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. Graph Database&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A graph database stores information using nodes and relationships. It is commonly used in social networks, recommendation systems and fraud detection.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;7. Object-Oriented Database&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;An object-oriented database stores information in the form of objects. It is useful for applications that work with complex objects.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. What is PostgreSQL?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;PostgreSQL is an open-source relational database management system (RDBMS). It is used to store, organize, manage and retrieve information.&lt;br&gt;
PostgreSQL supports SQL (Structured Query Language), which allows developers to communicate with the database using queries.&lt;/p&gt;

&lt;p&gt;For example, when we develop an employee management application, we can use PostgreSQL to store employee names, email addresses, salaries and other details.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. How to Work with PostgreSQL Using SQL?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;PostgreSQL uses SQL commands to create databases, create tables, insert data, retrieve information, update records and delete records.&lt;/p&gt;

&lt;p&gt;Let's understand with a simple employee example.&lt;/p&gt;

&lt;p&gt;Step 1: Create a Database&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;
&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;DATABASE&lt;/span&gt; &lt;span class="n"&gt;company&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command creates a database named company.&lt;/p&gt;

&lt;p&gt;Step 2: Create a Table&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;
&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;employees&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="kt"&gt;SERIAL&lt;/span&gt; &lt;span class="k"&gt;PRIMARY&lt;/span&gt; &lt;span class="k"&gt;KEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="kt"&gt;VARCHAR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;email&lt;/span&gt; &lt;span class="kt"&gt;VARCHAR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;salary&lt;/span&gt; &lt;span class="kt"&gt;INTEGER&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command creates an employees table.&lt;/p&gt;

&lt;p&gt;Step 3: Insert Data&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;INSERT&lt;/span&gt; &lt;span class="k"&gt;INTO&lt;/span&gt; &lt;span class="n"&gt;employees&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;email&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;salary&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;VALUES&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Raj'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'raj@gmail.com'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;25000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command adds employee information to the table.&lt;/p&gt;

&lt;p&gt;Step 4: Retrieve Data&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;
&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;employees&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command displays all employee records.&lt;/p&gt;

&lt;p&gt;Step 5: Update Data&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;
&lt;span class="k"&gt;UPDATE&lt;/span&gt; &lt;span class="n"&gt;employees&lt;/span&gt;
&lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="n"&gt;salary&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;30000&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command updates the employee's salary.&lt;/p&gt;

&lt;p&gt;Step 6: Delete Data&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;DELETE&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;employees&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command deletes the employee record.&lt;/p&gt;

&lt;p&gt;By using these SQL commands, we can easily manage information in PostgreSQL.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. What Are the Advantages of PostgreSQL?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;PostgreSQL provides several advantages for developers.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open Source: PostgreSQL is free to use.&lt;/li&gt;
&lt;li&gt;Reliable: It provides reliable data storage and transaction management.3. Data Security: It supports user permissions and access control.&lt;/li&gt;
&lt;li&gt;Advanced Features: It supports complex queries, joins, indexing and transactions.&lt;/li&gt;
&lt;li&gt;Flexible: It supports different data types, including JSON.&lt;/li&gt;
&lt;li&gt;Cross-Platform: It works on Windows, Linux and macOS.&lt;/li&gt;
&lt;li&gt;Scalable: It can handle growing amounts of data and application workloads.&lt;/li&gt;
&lt;li&gt;Data Management: It makes inserting, updating, deleting and retrieving information easier.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;6. What Are the Disadvantages of PostgreSQL?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Although PostgreSQL has many advantages it also has some disadvantages.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Learning Difficulty: Beginners may need some time to understand PostgreSQL and its advanced features.&lt;/li&gt;
&lt;li&gt;Configuration: Advanced configuration requires technical knowledge.&lt;/li&gt;
&lt;li&gt;Resource Usage: Some workloads may require more memory and processing power.&lt;/li&gt;
&lt;li&gt;Performance Tuning: Large databases may need proper indexing and query optimization.&lt;/li&gt;
&lt;li&gt;Database Administration: Managing large databases requires additional technical knowledge.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;.&lt;/p&gt;

</description>
      <category>database</category>
      <category>postgressql</category>
      <category>java</category>
    </item>
    <item>
      <title>My Logical Thinking Practice – Chocolate Wrapper &amp; Chapathi Problems</title>
      <dc:creator>Raj</dc:creator>
      <pubDate>Tue, 17 Nov 2026 10:39:16 +0000</pubDate>
      <link>https://dev.to/rajasekar1998/my-logical-thinking-practice-chocolate-wrapper-chapathi-problems-2o38</link>
      <guid>https://dev.to/rajasekar1998/my-logical-thinking-practice-chocolate-wrapper-chapathi-problems-2o38</guid>
      <description>&lt;p&gt;Today I practised two interesting logical thinking problems.&lt;/p&gt;

&lt;p&gt;My main goal was not to write a program immediately. Instead, I wanted to understand the problems think about the logic and solve them step by step.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Chocolate Wrapper Problem&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Chocolate Wrapper Problem&lt;br&gt;
Given:&lt;br&gt;
Total money = ₹100&lt;br&gt;
1 chocolate = ₹5&lt;br&gt;
3 wrappers = 1 additional chocolate&lt;br&gt;
Step 1: Buy chocolates&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;₹100 ÷ ₹5 = 20 chocolates.
Step 2: Exchange wrappers
Initially, 20 chocolates = 20 wrappers.
Exchange 18 wrappers for 6 chocolates.
Now you have 2 old wrappers + 6 new wrappers = 8 wrappers.
Exchange 6 wrappers for 2 chocolates.
Now you have 2 wrappers + 2 new wrappers = 4 wrappers.
Exchange 3 wrappers for 1 chocolate.
Now you have 2 wrappers + 1 new wrapper = 3 wrappers.
Exchange 3 wrappers for 1 chocolate

20 + 6 + 2 + 1 + 1 = 30 chocolates
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I had ₹100 and each chocolate cost ₹5.&lt;/p&gt;

&lt;p&gt;Initially I could buy 20 chocolates. After that I used the wrappers to exchange them for additional chocolates.&lt;/p&gt;

&lt;p&gt;I repeated the exchange process until I could not exchange any more wrappers.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;My final answer: 30 chocolates.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Chapathi Story&lt;/strong&gt;&lt;br&gt;
Next morning 8 chapathis were remaining.&lt;br&gt;
We need to find the original number of chapathis (n).&lt;br&gt;
Step 1: Work backwards&lt;br&gt;
After dinner remaining chapathis = 8.&lt;br&gt;
He ate 1/3 at dinner so 2/3 remained.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Therefore:
8*3/2=12
Before dinner = 12 chapathis.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 2: Before lunch&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;He ate 1/3 at lunch, so 2/3 remained.
12*3/2=18
Before lunch = 18 chapathis.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 3: Before breakfast&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;He ate 1/3 at breakfast so 2/3 remained.
18*3/2=27
Original chapathis = 27.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this problem Viyan ate one-third of the remaining chapathis during breakfast, lunch and dinner.&lt;br&gt;
The next morning 8 chapathis were remaining.&lt;br&gt;
Instead of calculating forwards I decided to work backwards.&lt;br&gt;
After doing the calculations I found that the maid originally prepared 27 chapathis.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;My final answer: 27 chapathis.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;What I Learned&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Logical thinking is important before programming.&lt;/li&gt;
&lt;li&gt;Dry runs help us understand each calculation.&lt;/li&gt;
&lt;li&gt;Flowcharts help us visualise the solution.&lt;/li&gt;
&lt;li&gt;Working backwards is a useful problem-solving technique.&lt;/li&gt;
&lt;li&gt;Programming becomes easier when the logic is clear.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>python</category>
      <category>programming</category>
      <category>learning</category>
    </item>
    <item>
      <title>What is a Reader in Java?</title>
      <dc:creator>Raj</dc:creator>
      <pubDate>Sat, 14 Nov 2026 07:42:35 +0000</pubDate>
      <link>https://dev.to/rajasekar1998/what-is-a-reader-in-java-bc5</link>
      <guid>https://dev.to/rajasekar1998/what-is-a-reader-in-java-bc5</guid>
      <description>&lt;p&gt;&lt;strong&gt;What is a Reader in Java?&lt;/strong&gt;&lt;br&gt;
In Java a Reader is an abstract class used to read character-based data from different sources such as files text streams and input sources.&lt;/p&gt;

&lt;p&gt;It is mainly used when we want to read text data character by character or in groups of characters.&lt;/p&gt;

&lt;p&gt;For example if we have a text file containing names or sentences we can use Java Reader classes to read that information.&lt;br&gt;
**&lt;br&gt;
Types of Reader in Java**&lt;/p&gt;

&lt;p&gt;Java provides different Reader classes for reading character data.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;FileReader: Used to read character data from a file.&lt;/li&gt;
&lt;li&gt;BufferedReader: Used to read text efficiently by buffering characters. It can also read a complete line using readLine().&lt;/li&gt;
&lt;li&gt;InputStreamReader: Converts byte-based input into character-based input.&lt;/li&gt;
&lt;li&gt;CharArrayReader: Used to read characters from a character array.&lt;/li&gt;
&lt;li&gt;StringReader: Used to read character data from a string.
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;java&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;io&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;FileReader&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Main&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;throws&lt;/span&gt; &lt;span class="nc"&gt;Exception&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

        &lt;span class="nc"&gt;FileReader&lt;/span&gt; &lt;span class="n"&gt;reader&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;FileReader&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"test.txt"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;out&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;char&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="n"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;close&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;How it works:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; FileReader opens the text file.&lt;/li&gt;
&lt;li&gt; read() reads one character at a time.&lt;/li&gt;
&lt;li&gt; -1 indicates that the end of the file has been reached.&lt;/li&gt;
&lt;li&gt; (char) data converts the integer into a character.&lt;/li&gt;
&lt;li&gt; close() closes the reader after reading.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In Java Reader is an abstract class available in the java.io package. It is used to read character-based data from different sources.&lt;/p&gt;

&lt;p&gt;Java provides different types of Reader classes because we may need to read text from files, strings, character arrays, or byte-based input sources.&lt;/p&gt;

&lt;p&gt;Let's understand each Reader class with examples.&lt;br&gt;
&lt;strong&gt;1. FileReader&lt;/strong&gt;&lt;br&gt;
FileReader is used to read character data directly from a text file.&lt;/p&gt;

&lt;p&gt;For example imagine we have a file called test.txt containing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Hello Java
Welcome to Programming
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. BufferedReader&lt;/strong&gt;&lt;br&gt;
BufferedReader is used to read text more efficiently by temporarily storing characters in a buffer (memory area).&lt;/p&gt;

&lt;p&gt;Instead of reading each character directly from the source, it reads a larger block of characters into memory and then provides the data when needed.&lt;/p&gt;

&lt;p&gt;It also provides a useful method called readLine(), which allows us to read an entire line at once.&lt;br&gt;
import java.io.BufferedReader;&lt;br&gt;
import java.io.FileReader;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Main&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;throws&lt;/span&gt; &lt;span class="nc"&gt;Exception&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

        &lt;span class="nc"&gt;FileReader&lt;/span&gt; &lt;span class="n"&gt;file&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;FileReader&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"test.txt"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="nc"&gt;BufferedReader&lt;/span&gt; &lt;span class="n"&gt;reader&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;BufferedReader&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;file&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="kt"&gt;String&lt;/span&gt; &lt;span class="n"&gt;line&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;line&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;readLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;out&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;line&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="n"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;close&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;How it works:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; FileReader opens the file.&lt;/li&gt;
&lt;li&gt; BufferedReader wraps the FileReader to provide buffered reading.&lt;/li&gt;
&lt;li&gt; readLine() reads one complete line at a time.&lt;/li&gt;
&lt;li&gt;The loop continues until readLine() returns null, meaning the end of the file.&lt;/li&gt;
&lt;li&gt; close() closes the reader and its underlying file reader.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;3. InputStreamReader&lt;/strong&gt;&lt;br&gt;
InputStreamReader is used to convert byte-based input into character-based input.&lt;/p&gt;

&lt;p&gt;In Java, some input sources provide data in bytes rather than characters. For example, keyboard input and network streams can provide byte-based input.&lt;/p&gt;

&lt;p&gt;InputStreamReader acts as a bridge between byte streams and character streams. It converts bytes into characters using a character encoding.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;java&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;io&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;InputStreamReader&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Main&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;throws&lt;/span&gt; &lt;span class="nc"&gt;Exception&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

        &lt;span class="nc"&gt;InputStreamReader&lt;/span&gt; &lt;span class="n"&gt;reader&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
            &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;InputStreamReader&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;in&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;out&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Enter your name: "&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="s1"&gt;'\n'&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;out&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;char&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="n"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;close&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;How it works:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; System.in receives input from the keyboard as bytes.&lt;/li&gt;
&lt;li&gt; InputStreamReader converts those bytes into characters.&lt;/li&gt;
&lt;li&gt; reader.read() reads one character at a time.&lt;/li&gt;
&lt;li&gt; The loop stops when the user presses Enter (or the input ends).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;4. CharArrayReader&lt;/strong&gt;&lt;br&gt;
CharArrayReader is used to read character data from an existing character array.&lt;/p&gt;

&lt;p&gt;A character array is a collection of characters stored in an array. Instead of reading data from a file, we can directly read characters from an array in memory.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;java&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;io&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;CharArrayReader&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Main&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;throws&lt;/span&gt; &lt;span class="nc"&gt;Exception&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

        &lt;span class="kt"&gt;char&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s1"&gt;'H'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'e'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'l'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'l'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'o'&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="nc"&gt;CharArrayReader&lt;/span&gt; &lt;span class="n"&gt;reader&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;CharArrayReader&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;out&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;char&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="n"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;close&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;output:

Hello
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;How it works:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;First, we create a character array containing the word Hello.&lt;/li&gt;
&lt;li&gt;CharArrayReader takes that character array as input.&lt;/li&gt;
&lt;li&gt;read() reads one character at a time.&lt;/li&gt;
&lt;li&gt;The loop continues until all characters are read.&lt;/li&gt;
&lt;li&gt;close() closes the reader.&lt;/li&gt;
&lt;li&gt;StringReader
StringReader is used to read character data directly from a String.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example, if we already have a sentence stored in a String variable, we can use StringReader to read its characters one by one.&lt;br&gt;
import java.io.StringReader;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Main&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;throws&lt;/span&gt; &lt;span class="nc"&gt;Exception&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

        &lt;span class="kt"&gt;String&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Hello Java"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="nc"&gt;StringReader&lt;/span&gt; &lt;span class="n"&gt;reader&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;StringReader&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;out&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;char&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="n"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;close&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;How it works:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;First we store the text inside a String variable.&lt;/li&gt;
&lt;li&gt;StringReader takes that String as input.&lt;/li&gt;
&lt;li&gt;read() reads one character at a time.&lt;/li&gt;
&lt;li&gt;The loop continues until all characters are read.&lt;/li&gt;
&lt;li&gt;close() closes the reader.&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>What is looping in python</title>
      <dc:creator>Raj</dc:creator>
      <pubDate>Sat, 14 Nov 2026 06:35:45 +0000</pubDate>
      <link>https://dev.to/rajasekar1998/what-is-looping-in-python-co2</link>
      <guid>https://dev.to/rajasekar1998/what-is-looping-in-python-co2</guid>
      <description>&lt;p&gt;&lt;strong&gt;What is Looping in Python?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Looping in Python means executing the same block of code repeatedly until a particular condition is met or a given sequence is completed.&lt;/p&gt;

&lt;p&gt;In programming sometimes we need to perform the same task multiple times. Instead of writing the same code again and again we can use loops to repeat the task automatically. This makes the code shorter easier to understand and reduces unnecessary repetition.&lt;/p&gt;

&lt;p&gt;For example if we want to print "Hello" five times we don't need to write five separate print statements. We can simply use a loop to do it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Python mainly provides two types of loops:&lt;/strong&gt;&lt;br&gt;
For Loop and While Loop.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. For Loop&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A &lt;code&gt;for&lt;/code&gt; loop is used when we want to repeat something a certain number of times or work with items in a sequence.&lt;br&gt;
For example if we want to print numbers from 1 to 5 we can use a for loop.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;
&lt;span class="n"&gt;python&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nb"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, &lt;code&gt;range(1, 6)&lt;/code&gt; generates numbers from 1 to 5. The variable &lt;code&gt;i&lt;/code&gt; takes each number one by one, and the print statement displays it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. While Loop&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A &lt;code&gt;while&lt;/code&gt; loop works a little differently. It keeps repeating the code as long as the given condition is True.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;
&lt;span class="n"&gt;python&lt;/span&gt;
&lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;

&lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We start with the value 1. The loop checks whether the value is less than or equal to 5. If the condition is True it prints the number and increases the value by 1. This continues until the condition becomes False.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Break Statement&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Sometimes, we may want to stop a loop before it finishes. For that Python provides the &lt;code&gt;break&lt;/code&gt; statement.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;python&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nb"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;break&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The loop stops when the value reaches 3. So it prints only 1 and 2.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Continue Statement&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The &lt;code&gt;continue&lt;/code&gt; statement is used when we want to skip a particular iteration and move to the next one.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;python&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nb"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;continue&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When the value becomes 3 it skips that number and continues with the remaining numbers.&lt;br&gt;
Loops are an important part of Python programming because they help us repeat tasks without writing the same code multiple times. A &lt;code&gt;for&lt;/code&gt; loop is useful when working with a sequence or a fixed number of repetitions while a &lt;code&gt;while&lt;/code&gt; loop is useful when repetition depends on a condition.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Python looping task</title>
      <dc:creator>Raj</dc:creator>
      <pubDate>Sat, 14 Nov 2026 06:21:05 +0000</pubDate>
      <link>https://dev.to/rajasekar1998/python-looping-task-m33</link>
      <guid>https://dev.to/rajasekar1998/python-looping-task-m33</guid>
      <description>&lt;p&gt;1.Tenali Raman promises to share his reward with the guards at each gate. At every gate, he gives half of the remaining lashes to the guard and proceeds to the next gate.&lt;/p&gt;

&lt;p&gt;The process continues until only one lash remains. Tenali Raman receives that final one lash.&lt;/p&gt;

&lt;p&gt;We need to write a Python program to find:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;How many lashes each guard receives.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;How many guards are there in total.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Get the Input&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;lashes = int(input("Enter total number of lashes: "))&lt;br&gt;
The program asks the user to enter the total number of lashes. The entered value is stored in the lashes variable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Initialize the Guard Count&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;guard = 0&lt;br&gt;
Initially, the guard count is zero because no guard has received any lashes yet.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Check the While Loop&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;while lashes &amp;gt; 1:&lt;br&gt;
The while loop checks whether the remaining lashes are greater than If the condition is true, the loop continues.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Calculate the Lashes&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;received = lashes // 2&lt;br&gt;
The `// operator performs floor division. It divides the remaining lashes by 2 and gives the whole-number result.&lt;br&gt;
**&lt;br&gt;
Increase the Guard Count**&lt;/p&gt;

&lt;p&gt;python&lt;br&gt;
guard += 1&lt;/p&gt;

&lt;p&gt;Every time a guard receives lashes the guard count increases by &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Display the Guard's Lashes&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;python&lt;br&gt;
print("Guard", guard, "receives", received, "lashes")&lt;br&gt;
This statement displays the guard number and the number of lashes received.&lt;br&gt;
**&lt;br&gt;
Update the Remaining Lashes**&lt;/p&gt;

&lt;p&gt;python&lt;br&gt;
lashes = lashes - received&lt;br&gt;
After giving half of the lashes to the current guard, the program subtracts the received lashes from the total remaining lashes.&lt;br&gt;
**&lt;br&gt;
Display the Final Result**&lt;/p&gt;

&lt;p&gt;python&lt;br&gt;
print("Total number of guards:", guard)&lt;br&gt;
print("Tenali Raman receives:", lashes, "lash")&lt;/p&gt;

&lt;p&gt;When only one lash remains, the loop stops. The program displays the total number of guards and the final lash received by Tenali Raman.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Program Execution – Example&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Input:&lt;/p&gt;

&lt;p&gt;text&lt;br&gt;
Enter total number of lashes: 16&lt;/p&gt;

&lt;p&gt;Slashes = int(input("Enter total number of lashes: "))&lt;/p&gt;

&lt;p&gt;guard = 0&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;`python&lt;br&gt;
while lashes &amp;gt; 1:&lt;br&gt;
    received = lashes // 2&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;guard += 1

print("Guard", guard, "receives", received, "lashes")

lashes = lashes - received
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;print("Total number of guards:", guard)&lt;br&gt;
print("Tenali Raman receives:", lashes, "lash")&lt;/p&gt;

&lt;p&gt;`&lt;code&gt;&lt;/code&gt;&lt;br&gt;
&lt;strong&gt;Final Output&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;plaintext&lt;br&gt;
text&lt;br&gt;
Guard 1 receives 8 lashes&lt;br&gt;
Guard 2 receives 4 lashes&lt;br&gt;
Guard 3 receives 2 lashes&lt;br&gt;
Guard 4 receives 1 lashes&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Total number of guards: 4&lt;br&gt;
Tenali Raman receives: 1 lash&lt;/p&gt;

&lt;p&gt;**2.Two trains stop at regular intervals. Train 1 stops at every 3rd station, and Train 2 stops at every 5th station. We need to find the first common station, the last common station, and all common stations where both trains stop.&lt;/p&gt;

&lt;p&gt;The total number of stations is unknown, so we get the total number of stations as input from the user.**&lt;/p&gt;

&lt;p&gt;`&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;total_stations&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Enter total number of stations: "&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;train1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;
&lt;span class="n"&gt;train2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;

&lt;span class="n"&gt;common_stations&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;station&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nb"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;total_stations&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;station&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="n"&gt;train1&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;station&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="n"&gt;train2&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;common_stations&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;station&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;common_stations&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;

    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"First common station:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;common_stations&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Last common station:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;common_stations&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"All common stations:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;common_stations&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"No common stations found."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;`&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How the Program Works&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Get the Total Number of Stations&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The input() function gets the total number of stations from the user. The int() function converts the input into an integer and stores it in the total_stations variable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Define Train Intervals&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We assign 3 to train1 and 5 to train2. These values represent the stopping intervals of the two trains.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Create an Empty List&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We create an empty list called common_stations. This list stores all the station numbers where both trains stop.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Check Every Station&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The for loop checks every station from 1 to the total number of stations. The range() function generates the station numbers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Check Common Stations&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The % operator checks whether a station is divisible by another number without leaving a remainder.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;`plaintext&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;station % 3 == 0 checks whether Train 1 stops at that station.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;station % 5 == 0 checks whether Train 2 stops at that station.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The and operator checks whether both conditions are true.&lt;br&gt;
`&lt;code&gt;&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Store Common Stations&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The append() method adds the station number to the common_stations list whenever both trains stop at the same station.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Find the First and Last Common Stations&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The len() function checks whether the list contains any common stations.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;common_stations[0] returns the first common station.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;common_stations[-1] returns the last common station.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Step 8: Display All Common Stations&lt;/p&gt;

&lt;p&gt;Finally, the print() function displays the first common station, last common station, and all common stations. If no common stations exist, the program displays a message.&lt;/p&gt;

&lt;p&gt;Execution – Example&lt;/p&gt;

&lt;p&gt;Input:&lt;/p&gt;

&lt;p&gt;Enter total number of stations: 100&lt;br&gt;
Calculation:&lt;/p&gt;

&lt;p&gt;The first common station is 15 because 15 is divisible by both 3 and 5.&lt;/p&gt;

&lt;p&gt;The common stations are obtained by adding 15 repeatedly until reaching the total number of stations.&lt;/p&gt;

&lt;p&gt;15&lt;br&gt;
30&lt;br&gt;
45&lt;br&gt;
60&lt;br&gt;
75&lt;br&gt;
90&lt;br&gt;
Final Output&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;plaintext&lt;br&gt;
First common station: 15&lt;br&gt;
Last common station: 90&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>PYTHON – FUNCTIONS AND ARGUMENTS</title>
      <dc:creator>Raj</dc:creator>
      <pubDate>Tue, 10 Nov 2026 09:05:48 +0000</pubDate>
      <link>https://dev.to/rajasekar1998/python-functions-and-arguments-32cj</link>
      <guid>https://dev.to/rajasekar1998/python-functions-and-arguments-32cj</guid>
      <description>&lt;p&gt;&lt;strong&gt;What is a Variable?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A variable is a name used to store data in Python.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Raj"&lt;/span&gt;
&lt;span class="n"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;age&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nc"&gt;Output&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;

&lt;span class="nc"&gt;Raj&lt;/span&gt;
&lt;span class="mi"&gt;25&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation:&lt;/p&gt;

&lt;p&gt;Here, "name" and "age" are variables. They store different types of data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is a Function?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A function is a block of reusable code that performs a specific task.&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;p&gt;`def greet():&lt;br&gt;
    print("Hello World")&lt;/p&gt;

&lt;p&gt;greet()&lt;/p&gt;

&lt;p&gt;Output:&lt;/p&gt;

&lt;p&gt;Hello World`&lt;/p&gt;

&lt;p&gt;Explanation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;"def" is a keyword used to define a function.&lt;/li&gt;
&lt;li&gt;"greet" is the function name.&lt;/li&gt;
&lt;li&gt;"greet()" is used to call the function.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Functions help us reuse code and avoid writing the same code again and again.&lt;/p&gt;

&lt;p&gt;**&lt;br&gt;
What is a User-Defined Function?**&lt;/p&gt;

&lt;p&gt;A user-defined function is a function created by the programmer to perform a specific task.&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;p&gt;`def addition():&lt;br&gt;
    a = 10&lt;br&gt;
    b = 20&lt;br&gt;
    print(a + b)&lt;/p&gt;

&lt;p&gt;addition()&lt;/p&gt;

&lt;p&gt;Output:&lt;/p&gt;

&lt;p&gt;30&lt;br&gt;
`&lt;br&gt;
Explanation:&lt;/p&gt;

&lt;p&gt;we create our own function using the "def" keyword.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is a Parameter?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A parameter is a variable that is written inside the function definition to receive data.&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;p&gt;`def addition(a, b):&lt;br&gt;
    print(a + b)&lt;/p&gt;

&lt;p&gt;addition(10, 20)&lt;/p&gt;

&lt;p&gt;Output:&lt;/p&gt;

&lt;p&gt;30`&lt;/p&gt;

&lt;p&gt;Explanation:&lt;/p&gt;

&lt;p&gt;Here, "a" and "b" are parameters. They receive values when the function is called.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is an Argument?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;An argument is a value passed to a function when calling it.&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;p&gt;`def greet(name):&lt;br&gt;
    print("Hello", name)&lt;/p&gt;

&lt;p&gt;greet("Raj")&lt;/p&gt;

&lt;p&gt;Output:&lt;/p&gt;

&lt;p&gt;Hello Raj`&lt;/p&gt;

&lt;p&gt;Explanation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;"name" is a parameter.&lt;/li&gt;
&lt;li&gt;""Raj"" is an argument.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Important Difference:&lt;/p&gt;

&lt;p&gt;Parameter = Variable in function definition.&lt;/p&gt;

&lt;p&gt;Argument = Actual value passed during function call.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is a Positional Argument?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A positional argument is an argument passed to a function based on its position or order.&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;p&gt;`def student(name, age):&lt;br&gt;
    print(name)&lt;br&gt;
    print(age)&lt;/p&gt;

&lt;p&gt;student("Raj", 25)&lt;/p&gt;

&lt;p&gt;Output:&lt;/p&gt;

&lt;p&gt;Raj&lt;br&gt;
25`&lt;/p&gt;

&lt;p&gt;Explanation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;First argument ""Raj"" goes to "name".&lt;/li&gt;
&lt;li&gt;Second argument "25" goes to "age".&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Positional arguments are used when we pass values according to the parameter order.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is a Keyword Argument?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A keyword argument is an argument passed using the parameter name.&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;p&gt;`def student(name, age):&lt;br&gt;
    print(name)&lt;br&gt;
    print(age)&lt;/p&gt;

&lt;p&gt;student(age=25, name="Raj")&lt;/p&gt;

&lt;p&gt;Output:&lt;/p&gt;

&lt;p&gt;Raj&lt;br&gt;
25`&lt;/p&gt;

&lt;p&gt;Explanation:&lt;/p&gt;

&lt;p&gt;we pass values using parameter names.&lt;br&gt;
The order does not matter because we specify the parameter names.&lt;br&gt;
Keyword arguments make code more readable and flexible.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is a Default Argument?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A default argument is a parameter that has a default value.&lt;br&gt;
If we do not pass a value, Python uses the default value.&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;p&gt;`def greet(name="Student"):&lt;br&gt;
    print("Hello", name)&lt;/p&gt;

&lt;p&gt;greet()&lt;br&gt;
greet("Raj")&lt;/p&gt;

&lt;p&gt;Output:&lt;/p&gt;

&lt;p&gt;Hello Student&lt;br&gt;
Hello Raj`&lt;/p&gt;

&lt;p&gt;Explanation:&lt;/p&gt;

&lt;p&gt;If we do not provide a name, Python uses ""Student"" automatically.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is a Function?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A function is a reusable block of code that performs a specific task.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
`&lt;br&gt;
def square(number):&lt;br&gt;
    return number * number&lt;/p&gt;

&lt;p&gt;print(square(5))&lt;/p&gt;

&lt;p&gt;Output:&lt;/p&gt;

&lt;p&gt;25`&lt;/p&gt;

&lt;p&gt;Explanation:&lt;/p&gt;

&lt;p&gt;The function calculates the square of a number and returns the result.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is a Method?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A method is a function that belongs to an object or a class.&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;p&gt;`name = "python"&lt;/p&gt;

&lt;p&gt;print(name.upper())&lt;/p&gt;

&lt;p&gt;Output:&lt;/p&gt;

&lt;p&gt;PYTHON`&lt;/p&gt;

&lt;p&gt;Explanation:&lt;/p&gt;

&lt;p&gt;the "upper()" is a string method. It converts lowercase letters into uppercase letters.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is the Difference Between Function and Method?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Function:&lt;/p&gt;

&lt;p&gt;A function can be called independently.&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;p&gt;print("Hello")&lt;/p&gt;

&lt;p&gt;Method:&lt;br&gt;
A method is called using an object or class.&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;name = "python"&lt;br&gt;
print(name.upper())&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Difference:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Function is called directly by its name.&lt;/li&gt;
&lt;li&gt;Method is called through an object or class.&lt;/li&gt;
&lt;li&gt;Every method is a function-like callable, but not every function is a method.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;What is Mutable?&lt;/p&gt;

&lt;p&gt;Mutable means an object can be changed after it is created.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
`&lt;br&gt;
numbers = [10, 20, 30]&lt;/p&gt;

&lt;p&gt;numbers.append(40)&lt;/p&gt;

&lt;p&gt;print(numbers)&lt;/p&gt;

&lt;p&gt;Output:&lt;/p&gt;

&lt;p&gt;[10, 20, 30, 40]`&lt;/p&gt;

&lt;p&gt;Explanation:&lt;/p&gt;

&lt;p&gt;A list is mutable because we can add, remove, or change its values after creating it.&lt;/p&gt;

&lt;p&gt;Other Mutable Data Types:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;List&lt;/li&gt;
&lt;li&gt;Dictionary&lt;/li&gt;
&lt;li&gt;Set&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;What is Immutable?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Immutable means an object cannot be changed after it is created.&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;p&gt;`name = "Python"&lt;/p&gt;

&lt;p&gt;name = name + " Programming"&lt;/p&gt;

&lt;p&gt;print(name)&lt;/p&gt;

&lt;p&gt;Output:&lt;/p&gt;

&lt;p&gt;Python Programming`&lt;/p&gt;

&lt;p&gt;Explanation:&lt;/p&gt;

&lt;p&gt;Strings are immutable. The original string is not modified; a new string is created and assigned to the variable.&lt;/p&gt;

&lt;p&gt;Other Immutable Data Types:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;String&lt;/li&gt;
&lt;li&gt;Integer&lt;/li&gt;
&lt;li&gt;Float&lt;/li&gt;
&lt;li&gt;Tuple&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;What is a Pure Function?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A pure function always returns the same output for the same input and does not modify external data or produce side effects.&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;p&gt;`def addition(a, b):&lt;br&gt;
    return a + b&lt;/p&gt;

&lt;p&gt;print(addition(10, 20))&lt;br&gt;
print(addition(10, 20))&lt;/p&gt;

&lt;p&gt;Output:&lt;/p&gt;

&lt;p&gt;30&lt;br&gt;
30`&lt;/p&gt;

&lt;p&gt;Explanation:&lt;/p&gt;

&lt;p&gt;The same inputs always produce the same output. The function does not change external data.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Java – Class and Object</title>
      <dc:creator>Raj</dc:creator>
      <pubDate>Tue, 10 Nov 2026 06:59:39 +0000</pubDate>
      <link>https://dev.to/rajasekar1998/java-class-and-object-32fb</link>
      <guid>https://dev.to/rajasekar1998/java-class-and-object-32fb</guid>
      <description>&lt;p&gt;&lt;strong&gt;INTRODUCTION&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Java is an object-oriented programming language. It uses classes and objects to organize data and perform operations.&lt;/p&gt;

&lt;p&gt;Class and Object are the fundamental building blocks of Object-Oriented Programming (OOP).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;WHAT IS A CLASS IN JAVA?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A Class is a blueprint or template used to create objects. It defines the properties (variables) and behaviours (methods) that an object can have.&lt;/p&gt;

&lt;p&gt;Explanation:&lt;/p&gt;

&lt;p&gt;A class is a logical structure that groups related variables and methods together. It describes what data an object can store and what operations it can perform.&lt;/p&gt;

&lt;p&gt;A class is a definition, not an individual object. We use a class as a common structure to create multiple objects.&lt;/p&gt;

&lt;p&gt;Main Components of a Class:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Variables – Used to store data.&lt;/li&gt;
&lt;li&gt;Methods – Used to perform specific operations.&lt;/li&gt;
&lt;li&gt;Constructors – Used to initialize objects.&lt;/li&gt;
&lt;li&gt;Blocks – Used to execute a group of statements.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Syntax:&lt;/p&gt;

&lt;p&gt;`class ClassName {&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Variables

// Constructors

// Methods
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;br&gt;
`&lt;br&gt;
Example Program:&lt;/p&gt;

&lt;p&gt;`class Student {&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;String name;
int age;

void study() {
    System.out.println("Student is studying");
}

void display() {
    System.out.println(name);
    System.out.println(age);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}`&lt;/p&gt;

&lt;p&gt;Explanation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;"class" is the keyword used to declare a class.&lt;/li&gt;
&lt;li&gt;"Student" is the class name.&lt;/li&gt;
&lt;li&gt;"name" is a variable used to store a name.&lt;/li&gt;
&lt;li&gt;"age" is a variable used to store an age.&lt;/li&gt;
&lt;li&gt;"study()" is a method that performs a specific action.&lt;/li&gt;
&lt;li&gt;"display()" is a method used to display student information.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;WHAT IS AN OBJECT IN JAVA?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;An Object is an instance of a class. It is created using the class structure and contains its own data.&lt;/p&gt;

&lt;p&gt;Explanation:&lt;/p&gt;

&lt;p&gt;An object is an individual instance created from a class. It represents a specific entity in a Java program.&lt;/p&gt;

&lt;p&gt;When an object is created, memory is allocated for its instance variables. Each object can store different values and use the methods defined in its class.&lt;/p&gt;

&lt;p&gt;Multiple objects can be created from a single class.&lt;/p&gt;

&lt;p&gt;Syntax:&lt;br&gt;
`&lt;br&gt;
ClassName objectName = new ClassName();&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;p&gt;Student s1 = new Student();`&lt;/p&gt;

&lt;p&gt;Explanation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;"Student" – Name of the class.&lt;/li&gt;
&lt;li&gt;"s1" – Reference variable.&lt;/li&gt;
&lt;li&gt;"new" – Keyword used to create an object.&lt;/li&gt;
&lt;li&gt;"Student()" – Constructor call.
**
HOW TO CREATE AND USE AN OBJECT?**&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Objects are created using the "new" keyword. After creating an object, we can access its instance variables and instance methods using the dot (".") operator.&lt;/p&gt;

&lt;p&gt;Example Program:&lt;/p&gt;

&lt;p&gt;`class Student {&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;String name;
int age;

void display() {
    System.out.println("Name: " + name);
    System.out.println("Age: " + age);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;public class Main {&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public static void main(String[] args) {

    Student s1 = new Student();

    s1.name = "Raj";
    s1.age = 25;

    s1.display();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;Output:&lt;/p&gt;

&lt;p&gt;Name: Raj&lt;br&gt;
Age: 25`&lt;/p&gt;

&lt;p&gt;Explanation:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;First, we create a class named "Student".&lt;/li&gt;
&lt;li&gt;We declare two instance variables: "name" and "age".&lt;/li&gt;
&lt;li&gt;We define a method named "display()".&lt;/li&gt;
&lt;li&gt;Inside the main method, we create an object named "s1".&lt;/li&gt;
&lt;li&gt;We assign values to the object's variables.&lt;/li&gt;
&lt;li&gt;Finally, we call the "display()" method using the object.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;MULTIPLE OBJECTS IN JAVA&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A single class can be used to create multiple objects. Each object has its own instance variables and can store different values.&lt;/p&gt;

&lt;p&gt;Example Program:&lt;/p&gt;

&lt;p&gt;`class Student {&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;String name;
int age;

void display() {

    System.out.println(name);
    System.out.println(age);

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;public class Main {&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public static void main(String[] args) {

    Student s1 = new Student();

    s1.name = "Raj";
    s1.age = 25;

    Student s2 = new Student();

    s2.name = "Kumar";
    s2.age = 22;

    s1.display();
    s2.display();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;Output:&lt;/p&gt;

&lt;p&gt;Raj&lt;br&gt;
25&lt;br&gt;
Kumar&lt;br&gt;
22&lt;br&gt;
`&lt;br&gt;
Explanation:&lt;/p&gt;

&lt;p&gt;we create two objects, "s1" and "s2", from the same Student class.&lt;br&gt;
Both objects use the same class structure, but they maintain different values.&lt;br&gt;
This allows us to manage multiple records using a single class.&lt;/p&gt;

&lt;p&gt;**&lt;br&gt;
TYPES OF VARIABLES IN JAVA**&lt;/p&gt;

&lt;p&gt;Java has three main types of variables based on their declaration and usage.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Instance Variable&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;An instance variable is declared inside a class but outside methods, constructors, and blocks.&lt;/p&gt;

&lt;p&gt;Each object gets its own separate copy of instance variables.&lt;br&gt;
`&lt;br&gt;
class Student {&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;String name;
int age;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}`&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Static Variable&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A static variable is declared using the "static" keyword. It belongs to the class and is shared by all objects of that class.&lt;/p&gt;

&lt;p&gt;`class Student {&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;static String college = "ABC College";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}`&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Local Variable&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A local variable is declared inside a method constructor or block. It can only be accessed within its declared scope.&lt;br&gt;
`&lt;br&gt;
class Student {&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;void display() {

    int marks = 90;

    System.out.println(marks);

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}`&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;WHAT IS A METHOD IN JAVA?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A Method is a block of code that performs a specific task. It executes when it is called.&lt;/p&gt;

&lt;p&gt;Methods help divide a program into smaller and reusable sections.&lt;/p&gt;

&lt;p&gt;Syntax:&lt;/p&gt;

&lt;p&gt;`returnType methodName(parameters) {&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Statements
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}`&lt;/p&gt;

&lt;p&gt;Types of Methods:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Void Method&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A void method performs an operation but does not return a value.&lt;/p&gt;

&lt;p&gt;`void display() {&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;System.out.println("Hello Java");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}`&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Return Type Method&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A return type method sends a value back to the calling statement.&lt;/p&gt;

&lt;p&gt;`int add() {&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;return 10 + 20;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}`&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Parameterized Method&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A parameterized method accepts values as input.&lt;/p&gt;

&lt;p&gt;`void displayName(String name) {&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;System.out.println(name);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}`&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Static Method&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A static method belongs to the class and can be called using the class name without creating an object.&lt;/p&gt;

&lt;p&gt;`class Test {&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;static void display() {

    System.out.println("Hello Java");

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}`&lt;/p&gt;

&lt;p&gt;Method calling:&lt;/p&gt;

&lt;p&gt;Test.display();&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Instance Method&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;An instance method belongs to an object and is generally called using an object reference.&lt;/p&gt;

&lt;p&gt;`class Test {&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;void display() {

    System.out.println("Instance Method");

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}`&lt;/p&gt;

&lt;p&gt;Method calling:&lt;/p&gt;

&lt;p&gt;Test t1 = new Test();&lt;/p&gt;

&lt;p&gt;t1.display();&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;WHAT IS A CONSTRUCTOR IN JAVA?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A Constructor is a special member of a class that is automatically called when an object is created.&lt;/p&gt;

&lt;p&gt;It is mainly used to initialize the object's data.&lt;/p&gt;

&lt;p&gt;Characteristics of a Constructor:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A constructor has the same name as the class.&lt;/li&gt;
&lt;li&gt;A constructor does not have a return type.&lt;/li&gt;
&lt;li&gt;It is called during object creation.&lt;/li&gt;
&lt;li&gt;It can be overloaded.&lt;/li&gt;
&lt;li&gt;Java provides a default constructor if no constructor is explicitly declared.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Example Program:&lt;/p&gt;

&lt;p&gt;`class Student {&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;String name;

Student() {

    name = "Raj";

}

void display() {

    System.out.println(name);

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;public class Main {&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public static void main(String[] args) {

    Student s1 = new Student();

    s1.display();

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;Output:&lt;/p&gt;

&lt;p&gt;Raj`&lt;/p&gt;

&lt;p&gt;Types of Constructors:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Default Constructor&lt;/li&gt;
&lt;li&gt;No-Argument Constructor&lt;/li&gt;
&lt;li&gt;Parameterized Constructor&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;WHY DO WE USE CLASS AND OBJECT?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Uses of Class:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;To organize related variables and methods.&lt;/li&gt;
&lt;li&gt;To define a common structure for multiple objects.&lt;/li&gt;
&lt;li&gt;To improve code readability.&lt;/li&gt;
&lt;li&gt;To support code reusability.&lt;/li&gt;
&lt;li&gt;To make applications easier to maintain.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Uses of Object:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;To store individual data.&lt;/li&gt;
&lt;li&gt;To access instance variables.&lt;/li&gt;
&lt;li&gt;To call instance methods.&lt;/li&gt;
&lt;li&gt;To create multiple instances from one class.&lt;/li&gt;
&lt;li&gt;To represent real-world entities in a program.&lt;/li&gt;
&lt;/ol&gt;

</description>
    </item>
    <item>
      <title>Java</title>
      <dc:creator>Raj</dc:creator>
      <pubDate>Fri, 30 Oct 2026 06:35:24 +0000</pubDate>
      <link>https://dev.to/rajasekar1998/java-42o0</link>
      <guid>https://dev.to/rajasekar1998/java-42o0</guid>
      <description>&lt;p&gt;&lt;strong&gt;what is java?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Java is a high level programming language for building web ,desktop,mobile and enteriprise applications.java is platform independenat because it runs on the java virtual machine(jvm).java supports object oriented programming concepts link classes ,object,inheritance and polymorphism.secure and robust with strong memory management &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;core components&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;JDK java development kit contains the tools libraries and compiler needed to applications&lt;/li&gt;
&lt;li&gt;JRM java runtime evironment provides the libreries and the jvm required to run compiled java programs&lt;/li&gt;
&lt;li&gt;JVM java virtual machine translates bytecode into native machine instructions for the underlying operating system&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;types of data types&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;java define data a varible can hold and memory required to store it they are broadly divided into two categories&lt;/p&gt;

&lt;p&gt;1.Primitive Data type Store simple values directly in memory.&lt;/p&gt;

&lt;p&gt;2.Non Primitive (Reference) Data types Store memory references to objects.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Primitive Dta types&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Primitive data types are the basic built-in data types in Java. They are used to store simple values such as numbers, characters, and true or false values.Java has 8 primitive data types.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. byte&lt;/strong&gt;&lt;br&gt;
The byte data type is used to store small integer values. It takes 1 byte of memory(Range: -128 to 127).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. short&lt;/strong&gt;&lt;br&gt;
The short data type is used to store integer values that are larger than byte. It takes 2 bytes of memory(Range: -32,768 to 32,767).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. int&lt;/strong&gt;&lt;br&gt;
The int data type is used to store whole numbers. It is commonly used for storing integer values. It takes 4 bytes of memory.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. long&lt;/strong&gt;&lt;br&gt;
The long data type is used to store very large whole numbers. It takes 8 bytes of memory.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. float&lt;/strong&gt;&lt;br&gt;
The float data type is used to store decimal numbers. It takes 4 bytes of memory.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. double&lt;/strong&gt;&lt;br&gt;
The double data type is used to store decimal numbers with more precision than float. It takes 8 bytes of memory.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;7. char&lt;/strong&gt;&lt;br&gt;
The char data type is used to store a single character. It takes 2 bytes of memory in Java.&lt;br&gt;
**&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;boolean**
The boolean data type is used to store only two values: true or false.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;*&lt;em&gt;Non-Primitive (Reference) Data Types *&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Non-primitive data types, also called Reference Data Types, are used to store and work with more complex data in Java.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. String&lt;/strong&gt;&lt;br&gt;
String is used to store a sequence of characters (text). We use double quotes to create a String.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Array&lt;/strong&gt;&lt;br&gt;
An Array is used to store multiple values of the same data type in a single variable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Class&lt;/strong&gt;&lt;br&gt;
A Class is a blueprint for creating objects. It defines variables and methods that describe the properties and behaviours of objects.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Object&lt;/strong&gt;&lt;br&gt;
An Object is an instance of a class. It represents a real-world entity and contains data and behaviour.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Interface&lt;/strong&gt;&lt;br&gt;
An Interface is used to define a contract that classes can implement. It contains method declarations that implementing classes provide with their own implementations.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. Enum&lt;/strong&gt;&lt;br&gt;
Enum (Enumeration) is used to define a fixed set of constants.&lt;/p&gt;

</description>
      <category>java</category>
      <category>basic</category>
    </item>
  </channel>
</rss>
