<?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: Saravanan B</title>
    <description>The latest articles on DEV Community by Saravanan B (@saravananb15).</description>
    <link>https://dev.to/saravananb15</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.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F822755%2Fd4ef8d38-ee31-43c2-89c1-5a3f0544edaa.jpeg</url>
      <title>DEV Community: Saravanan B</title>
      <link>https://dev.to/saravananb15</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/saravananb15"/>
    <language>en</language>
    <item>
      <title>Core Java - Executer Framework.</title>
      <dc:creator>Saravanan B</dc:creator>
      <pubDate>Mon, 06 Mar 2023 09:54:39 +0000</pubDate>
      <link>https://dev.to/saravananb15/core-java-executer-framework-3c2e</link>
      <guid>https://dev.to/saravananb15/core-java-executer-framework-3c2e</guid>
      <description>&lt;p&gt;If we follow traditional approach to create a thread or implement a runnable interface, then we have certain limitations.&lt;/p&gt;

&lt;p&gt;Time Consuming - every time we need to create a thread its time and resource consuming.&lt;br&gt;
Poor Resource Management - Lets take a example of our application creates 1000 threads and only 500 threads is used remaining thread lies as not used.&lt;br&gt;
Robust - if a million threads access came our application stops.&lt;/p&gt;

&lt;p&gt;To overcome this Executer framework was introduced to overcome this. It overcomes the limitations of thread.&lt;/p&gt;

&lt;p&gt;It will have a pool of thread whenever needed a thread perform a task and again moved to pool.&lt;/p&gt;

&lt;p&gt;Callable and future - using runnable we cannot return a value. To overcome this callable is introduced. Call method is&lt;/p&gt;

</description>
      <category>watercooler</category>
    </item>
    <item>
      <title>Core Java - Multithreading - 2.</title>
      <dc:creator>Saravanan B</dc:creator>
      <pubDate>Wed, 01 Mar 2023 06:12:36 +0000</pubDate>
      <link>https://dev.to/saravananb15/core-java-multithreading-2-5967</link>
      <guid>https://dev.to/saravananb15/core-java-multithreading-2-5967</guid>
      <description>&lt;p&gt;Using Runnable interface --&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class RunImpl implements Runnable {

    @Override
    public void run() {
        System.out.println("Processed the checks");
    }

    public static void main(String[] args) {
        RunImpl ri = new RunImpl();

        Thread t = new Thread(ri);
        t.start();
    }

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

&lt;/div&gt;



&lt;p&gt;By using the runnable interface, we can extend the other class if need no need for implementation of thread class.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yield Method&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;public class ThreadYield extends Thread {
    @Override
    public void run() {
        for (int i = 0; i &amp;lt; 10; i++) {
            System.out.println("Child Thread");
            Thread.yield();
        }
    }
}
&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;public class ThreadYieldImpl {
    public static void main(String[] args) {
        ThreadYield ty = new ThreadYield();
        ty.start();

        for (int i = 0; i &amp;lt; 10; i++) {
            System.out.println("Main Thread");
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It will wait for main thread to executed and execute the thread.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Thread Intrrupt&lt;/strong&gt; -- It will intrrupt the thread.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Interuppted extends Thread {
    @Override
    public void run() {
        try {
            for (int i = 0; i &amp;lt; 10; i++) {
                System.out.println("I am a lazy Thread");
                Thread.sleep(2000);
            }
        } catch (InterruptedException e) {
            System.out.println("Got Interupted");
        }
    }
}
&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;public class InteruptedImpl {
    public static void main(String[] args) {
        Interuppted ip = new Interuppted();
        ip.start();

        ip.interrupt();

        System.out.println("End of main method");
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;output --&lt;/p&gt;

&lt;p&gt;&lt;code&gt;End of main method&lt;br&gt;
I am a lazy Thread&lt;br&gt;
Got Interupted&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;We can only interrupt the thread in a sleep mode.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Synchronization&lt;/strong&gt; - If two thread is trying to access same object there might be a chance of data getting corrupted.&lt;/p&gt;

&lt;p&gt;In Synchronization the thread trying to access first thread will get access, second thread has to wait till the first thread completes the task.&lt;/p&gt;

&lt;p&gt;Class level lock - If we mark a synchronized block as static and the block is class level locked.&lt;/p&gt;

&lt;p&gt;Interthread Communications - wait () notify () notify all (). &lt;/p&gt;

&lt;p&gt;T1 invokes wait method it will wait and t2 starts work on thread and notify once work done and again t1 completes its work.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class ThreadInter extends Thread {
    int total;

    @Override
    public void run() {
        System.out.println("Child thread is calculating sum");

        synchronized (this) {
            for (int i = 0; i &amp;lt; 10; i++) {
                total += i;
            }
            this.notify();
        }
    }
}
&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;public class InterImpl {
    public static void main(String[] args) throws InterruptedException {
        ThreadInter ti = new ThreadInter();
        ti.start();

        synchronized (ti) {
            System.out.println("Main Thread is waiting");
            ti.wait();
            System.out.println("Main Thread notified");
            System.out.println(ti.total);
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Thread group is something we can set values and do operation on parent thread and child will get the values.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Threadgroup {
    public static void main(String[] args) {
        System.out.println(Thread.currentThread().getName());
        System.out.println(Thread.currentThread().getThreadGroup().getParent().getName());

        ThreadGroup parent = new ThreadGroup("Parent");
        System.out.println(parent.getName());
        ThreadGroup child = new ThreadGroup(parent, "child");
        System.out.println(child.getParent().getName());
        System.out.println(child.getName());
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output --&lt;br&gt;
&lt;code&gt;main&lt;br&gt;
system&lt;br&gt;
Parent&lt;br&gt;
Parent&lt;br&gt;
child&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Here in this example, we are going to set child priority as 4 and the class which inherits child as get priority 4.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ThreadGroup parent = new ThreadGroup("Parent");
        System.out.println(parent.getName());
        ThreadGroup child = new ThreadGroup(parent, "child");
        System.out.println(child.getParent().getName());
        System.out.println(child.getName());

        Thread thread1 = new Thread(child, "Thread1");
        child.setMaxPriority(4);
        Thread thread2 = new Thread(child,"Thread2");
        System.out.println(thread1.getThreadGroup().getName());
        System.out.println(thread1.getPriority());
        System.out.println(thread2.getPriority());
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here the child thread priority is set to 4 after thread1 creation so the thread1 still have the default priority and thread2 will have the updated priority.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Daemon Thread&lt;/strong&gt; -- Runs in background and assists other thread example garbage collector runs in background and cleanup the objects its not using.&lt;/p&gt;

&lt;p&gt;isDeamon method is used to check and returns true if true.&lt;br&gt;
setDeamon is used to set thread as deamon.&lt;br&gt;
main thread cannot be set as deamon thread.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Deadlock&lt;/strong&gt; -- Multiple thread waiting on each other resources. Example method1 access and do task same time method2 access and do task in method 1 both methods are synchornized.&lt;/p&gt;

</description>
      <category>java</category>
    </item>
    <item>
      <title>Core Java - MultiThreading - 1</title>
      <dc:creator>Saravanan B</dc:creator>
      <pubDate>Mon, 27 Feb 2023 03:55:50 +0000</pubDate>
      <link>https://dev.to/saravananb15/core-java-multithreading-p7f</link>
      <guid>https://dev.to/saravananb15/core-java-multithreading-p7f</guid>
      <description>&lt;p&gt;&lt;strong&gt;Single Thread&lt;/strong&gt; -- In this example the program executes by order.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class SingleThread {
    public static void main(String[] args) {
        SingleThread st = new SingleThread();
        st.printNumbers();
        for (int j = 0; j &amp;lt; 2; j++) {
            System.out.print("j: " + j + "\t");
        }
    }

    void printNumbers() {
        for (int i = 0; i &amp;lt; 2; i++) {
            System.out.print("i: " + i + "\t");
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output -- i: 0  i: 1    j: 0    j: 1    &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MultiThread&lt;/strong&gt; -- we can implement multithreading by extending Thread class or using runnable interface.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class MultiThreaded extends Thread {
    public static void main(String[] args) {
        MultiThreaded mt = new MultiThreaded();
        mt.start();

        for (int j = 0; j &amp;lt; 5; j++) {
            System.out.print("j: " + j + "\t");
        }
    }

    public void run() {
        for (int i = 0; i &amp;lt; 5; i++) {
            System.out.print("i: " + i + "\t");
        }
    }
}

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

&lt;/div&gt;



&lt;p&gt;Output -- &lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2mar3fihnbiz4e43g3gx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2mar3fihnbiz4e43g3gx.png" alt=" " width="800" height="44"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;2nd time output--&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsvcv8d3m1yujrez5bphx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsvcv8d3m1yujrez5bphx.png" alt=" " width="800" height="52"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Sleep Method --  Thread.sleep(1000); If we use this in thread it will print the output taking the time mentioned in mille seconds. Above i mentioned 1000 which is equal to 1second.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Joiner&lt;/strong&gt; -- wait for run method to execute first and then process the next line.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Joiner extends Thread {
    static int n;
    static int sum = 0;

    public static void main(String[] args) throws InterruptedException {
        System.out.println("Sum of first 'N' numbers");
        System.out.println("Enter a vale");
        Scanner sc = new Scanner(System.in);
        Joiner.n = sc.nextInt();

        Joiner joiner = new Joiner();
        joiner.start();
        joiner.join();

        System.out.println("Sum of first "+Joiner.n+"  n numbers  is "+Joiner.sum);
    }

    public void run() {
        for(int i=1;i&amp;lt;= Joiner.n;i++) {
            Joiner.sum +=i;
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output&lt;br&gt;&lt;br&gt;
&lt;code&gt;Sum of first 'N' numbers&lt;br&gt;
Enter a vale&lt;br&gt;
2&lt;br&gt;
Sum of first2  n numbers  is 3&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Output without Joiner -- &lt;br&gt;
&lt;code&gt;Sum of first 'N' numbers&lt;br&gt;
Enter a vale&lt;br&gt;
2&lt;br&gt;
Sum of first 2  n numbers  is 0&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Calculating Time taken for a thread.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;long start = System.currentTimeMillis();
long end = System.currentTimeMillis();
        System.out.println("total time taken "+(end-start)/1000+" seconds");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Thread Identity - Assigne a name to Thread.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class ThreadName extends Thread{
    public static void main(String[] args) {
        ThreadName t = new ThreadName();
        t.start();

        Thread current = Thread.currentThread();
        System.out.println("Current Thread name : "+current.getName());
    }

    public void run() {
        Thread t = Thread.currentThread();
        t.setName("Now Thread name is set to this");
        System.out.println("Thread name : "+t.getName());
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Current Thread name : main&lt;br&gt;
Thread name : Now Thread name is changed to this&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;thread priority&lt;/strong&gt; -- In certain situation we need to set the tread to executed first. &lt;/p&gt;

&lt;p&gt;Minimum is 1 and the maximum is 10.&lt;br&gt;
&lt;/p&gt;

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

        ThreadName t1 = new ThreadName();
        t1.setPriority(MIN_PRIORITY);
        t1.setName("Minimun priortiy Thread");
        t1.start();

        ThreadName t = new ThreadName();
        t.setPriority(MAX_PRIORITY);
        t.setName("Maximum priority Thread");
        t.start();
    }

    public void run() {
        System.out.println("Thread name : " + Thread.currentThread().getName());
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output -- &lt;/p&gt;

&lt;p&gt;&lt;code&gt;Thread name: Maximum priority Thread&lt;br&gt;
Thread name: Minimum priority Thread&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Here maximum priority thread is executed first and then minimum priority thread.&lt;/p&gt;

&lt;p&gt;Its always up to JVM to which thread to get executed first even though if we set the priority.&lt;/p&gt;

</description>
      <category>tooling</category>
      <category>developer</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Core Java - Exception Handling.</title>
      <dc:creator>Saravanan B</dc:creator>
      <pubDate>Wed, 22 Feb 2023 10:40:47 +0000</pubDate>
      <link>https://dev.to/saravananb15/core-java-exception-handling-11ch</link>
      <guid>https://dev.to/saravananb15/core-java-exception-handling-11ch</guid>
      <description>&lt;p&gt;Runtime error are exception and we need to handle it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Test {
    public static void main(String[] args) {
        int a=12/8;
        System.out.println("Result : "+a);
        System.out.println("Before Exception");
        int b = a/0; //Exception code
        System.out.println("Result : "+b);
        System.out.println("After exception");
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9ml2uzvnb2x6ivk28oy8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9ml2uzvnb2x6ivk28oy8.png" alt=" " width="773" height="122"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Arithmetic Exception&lt;/strong&gt; - it happens when we try to do calculations like divide by zero.&lt;br&gt;
&lt;strong&gt;Number format Exception&lt;/strong&gt; - it happens when we try to parse a string into integer.&lt;br&gt;
&lt;strong&gt;ArrayIndexOutOfBound&lt;/strong&gt; - trying to access the element with the index out of bounds means array size is 4 and trying to access element at 5 is out of bound.&lt;br&gt;
&lt;strong&gt;NullPointerException&lt;/strong&gt; - It happens when we call the method of object without creating instance of it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class ArrayIndexOutOfBound {
    public static void main(String[] args) {
        int a[] = {1,2,3};
        System.out.println("Trying to get element at 4 : "+ a[4]);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output - java.lang.ArrayIndexOutOfBoundsException&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class ArrayIndexOutOfBound {
    public static void main(String[] args) {
        int a[] = {1,2,3};
        System.out.println("Trying to get element at 4 : "+ a[4]);
    }
    void method1() {
        System.out.println("null");
    }
}
&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;public class NullPointer {
    static ArrayIndexOutOfBound a;

    public static void main(String[] args) {
        NullPointer.a.method1();
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output -  java.lang.NullPointerException&lt;/p&gt;

&lt;p&gt;We can handle a exception using try catch throw finally and throws.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;try{&lt;br&gt;
code that cause exception&lt;br&gt;
}catch(Exception e){&lt;br&gt;
Exception&lt;br&gt;
}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Handling Arithmetic Exception.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Arithmatic {
    public static void main(String[] args) {
        try {int b = 12 / 0; // Exception code
        } catch (Exception e) { System.out.println(e+ ": can't divide by zero");}
        System.out.println("After exception");
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output -- java.lang.ArithmeticException: / by zero: can't divide by zero&lt;br&gt;
After exception&lt;/p&gt;

&lt;p&gt;Handling ArrayIndexOutbound&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class ArrayIndexOutOfBound {
    public static void main(String[] args) {
        int a[] = { 1, 2, 3 };

        try {
            System.out.println("Trying to get element at 4 : " + a[4]);
        } catch (Exception e) {
            System.out.println(e);
        }

        System.out.println("After exception Code");
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output -- java.lang.ArrayIndexOutOfBoundsException: Index 4 out of bounds for length 3&lt;br&gt;
After exception Code&lt;/p&gt;

&lt;p&gt;Handling NullPointerException.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class NullPointer {
    static ArrayIndexOutOfBound a;
    public static void main(String[] args) {
        try {
            NullPointer.a.method1();
        } catch (Exception e) {
            System.out.println(e);
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output -- java.lang.NullPointerException: Cannot invoke "com.exception.ArrayIndexOutOfBound.method1()" because "com.exception.NullPointer.a" is null&lt;/p&gt;

&lt;p&gt;Once we handled an exception using parent class like Exception and then we try to handle specific exceptions after parent exception it will throw an error.&lt;/p&gt;

&lt;p&gt;Checked Exception needs to be handled unlike unchecked Exception otherwise compiler won't compile the program.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Finally&lt;/strong&gt; -- even if there is exception or not this block will gets executed always.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;throws&lt;/strong&gt; -- We don't want to write catch for a method and we want the method to handle the exception we use throws keyword.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class tryingThrows {
    public static void main(String[] args) throws FileNotFoundException{
        tryingThrows ty = new tryingThrows();
        ty.fis();
        System.out.println("After Exception");
    }
    void fis() throws FileNotFoundException {
        FileInputStream fis = new FileInputStream("");
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It will throw a exception and not execute the code after the exception throws keyword is used to just to declare that the method not gonna handle exception but whichever implements needs to handle.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Throw&lt;/strong&gt; -- Explicitly throw exception or throw our own exception.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Throw {
    public static void main(String[] args) {
        throw new RuntimeException("Trying throw");
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fepm1381pqr4n5aflqj2j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fepm1381pqr4n5aflqj2j.png" alt=" " width="760" height="80"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In checked Exception we need to handle the with try catch for throw.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;custom Exception&lt;/strong&gt; --&lt;/p&gt;

&lt;p&gt;Unchecked Custom Exception -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class UncheckedCustomException extends RuntimeException {
    UncheckedCustomException(String message){
        super(message);
    }
}
&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;public class Test {
public static void main(String[] args) {
    throw new UncheckedCustomException("Business Exception");
}
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output - &lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flbalqd9jedn2isddtkr2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flbalqd9jedn2isddtkr2.png" alt=" " width="800" height="66"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Checked Exception-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class CheckedCustomException extends Exception{
    CheckedCustomException(String message){
        super(message);
    }
}
&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;public class TestChecked {
    public static void main(String[] args) throws CheckedCustomException {
        throw new CheckedCustomException("Checked Custom Exception");
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3g7vgq1iw9ecir276bow.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3g7vgq1iw9ecir276bow.png" alt=" " width="800" height="50"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Assertions&lt;/strong&gt; - Testing and debugging.&lt;/p&gt;

&lt;p&gt;Assert expression;&lt;br&gt;
Used for testing in junit and spring..&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Assert {
public static void main(String[] args) {
    int a=10;
    int b=20;
    assert(a&amp;gt;b):"Condtion not satisfied";
}
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F84bjc4b9sgad5myp870c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F84bjc4b9sgad5myp870c.png" alt=" " width="800" height="94"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If the condition passed return nothing else throws exception.&lt;/p&gt;

</description>
      <category>welcome</category>
    </item>
    <item>
      <title>Core Java - Encapsulation.</title>
      <dc:creator>Saravanan B</dc:creator>
      <pubDate>Thu, 16 Feb 2023 02:44:11 +0000</pubDate>
      <link>https://dev.to/saravananb15/core-java-encapsulation-4e1j</link>
      <guid>https://dev.to/saravananb15/core-java-encapsulation-4e1j</guid>
      <description>&lt;p&gt;&lt;strong&gt;Encapsulation&lt;/strong&gt;  is a process of binding data and code together. 2 Major advantage of encapsulation is security and easy enhancement.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Customer {
    private String firstName;
    private String lastName;
    private String debitCard;

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getDebitCard() {
        return debitCard;
    }

    public void setDebitCard(String debitCard) {
        this.debitCard = debitCard;
    }
}
&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;public class Test {
    public static void main(String[] args) {
        Customer c = new Customer();
        c.setFirstName("dev");
        c.setLastName(".to");
        c.setDebitCard("1234");
        System.out.println(c.getFirstName()+" "+c.getLastName()+" "+c.getDebitCard());
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output - dev .to 1234&lt;/p&gt;

</description>
      <category>java</category>
    </item>
    <item>
      <title>Core Java - Polymorphism</title>
      <dc:creator>Saravanan B</dc:creator>
      <pubDate>Wed, 15 Feb 2023 16:34:12 +0000</pubDate>
      <link>https://dev.to/saravananb15/core-java-polymorphism-p2i</link>
      <guid>https://dev.to/saravananb15/core-java-polymorphism-p2i</guid>
      <description>&lt;p&gt;&lt;strong&gt;Polymorphism&lt;/strong&gt; Poly means many.&lt;br&gt;
Morphic means Shapes.&lt;/p&gt;

&lt;p&gt;It means a object can behave differently while communicating with different objects.&lt;/p&gt;

&lt;p&gt;Two types of polymorphism &lt;br&gt;
   Compile time or static binding&lt;br&gt;
   Runtime or dynamic binding&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Compile time&lt;/strong&gt; which is also static binding we can achieve compile time polymorphism by method overloading.&lt;br&gt;
Method overloading means same method name with different signature arguments or different number of arguments.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
public class CompileTime {
    void add(int a, int b) {
        int result = a + b;
        System.out.println("Result is : " + result);
    }

    void add(float a, float b) {
        float result = a + b;
        System.out.println("Result is : " + result);
    }

    void add(int a, int b, int c) {
        int result = a + b + c;
        System.out.println("Result is : " + result);
    }

    public static void main(String[] args) {
        CompileTime ct = new CompileTime();
        ct.add(10, 20);
        ct.add(10.1f, 20.5f);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output :&lt;/strong&gt;&lt;br&gt;
Result is : 30&lt;br&gt;
Result is : 30.6&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Runtime Polymorphism&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;public interface Runtime {
        void start();
        void shutDown();
}
&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;public class MacBook implements Runtime {
    @Override
    public void start() {
        System.out.println("Inside macbook start");
    }
    @Override
    public void shutDown() {
        System.out.println("Inside macbook shutdown");
    }
}
&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;public class MacBookAir implements Runtime{
    @Override
    public void start() {
        System.out.println("Inside MacbookAir Start");
    }
    @Override
    public void shutDown() {
        System.out.println("Inside MacBookAir shut down");
    }
}
&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;public class RuntimePoly {
    public static void main(String[] args) {
            Runtime mac = new MacBook();
            Runtime air = new MacBookAir();
            mac.start();
            air.start();
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt; &lt;br&gt;
  Inside macbook start&lt;br&gt;
  Inside MacbookAir Start&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Object Casting&lt;/strong&gt;&lt;br&gt;
We can convert child class object to parent vise versa.&lt;/p&gt;

&lt;p&gt;Upcasting is when we create a object for child from parent.&lt;br&gt;
  Runtime mac = new MacBook();&lt;/p&gt;

&lt;p&gt;DownCasting is when we create a object for parent from child.&lt;br&gt;
MacBook m1 = (MacBook)mac;&lt;/p&gt;

&lt;p&gt;AutoTypeCasting -- The compiler will automatically promote to next available type if the exact type not found.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class CompileTime {
    void add(float a) {
        System.out.println("Result is : " + a);
    }

    public static void main(String[] args) {
        CompileTime ct = new CompileTime();
        ct.add(10);
        ct.add(10.1f);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output -  Result is : 10.0&lt;br&gt;
Result is : 10.1&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Overriding&lt;/strong&gt; -- The static method in the parent cannot be override as non static methods. Vise versa non static method cannot be converted to static method in child.&lt;/p&gt;

&lt;p&gt;If we use parent class to create a object for child and call the variable it will call the parent variable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public interface Runtime {
        String s ="Hello";
}
&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;public class MacBook implements Runtime {
    String s = "Hello MacBook";
}
&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;public class RuntimePoly {
    public static void main(String[] args) {
                Runtime mac = new MacBook();
        System.out.println(mac.s);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;  Hello&lt;/p&gt;

&lt;p&gt;Overloading of main method.&lt;br&gt;
&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) {
        System.out.println("String[] args");
        main(10);
    }
    public static void main(int args) {
        System.out.println("int args overloaded main method");
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Even though we overload main method JVM will take method with String[] args. We need to call the method with overloaded method in main method then only jvm will print the output of the method.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Core Java - Final &amp; Marker Interface</title>
      <dc:creator>Saravanan B</dc:creator>
      <pubDate>Tue, 14 Feb 2023 14:40:22 +0000</pubDate>
      <link>https://dev.to/saravananb15/core-java-final-marker-interface-48b3</link>
      <guid>https://dev.to/saravananb15/core-java-final-marker-interface-48b3</guid>
      <description>&lt;p&gt;&lt;strong&gt;Final&lt;/strong&gt;&lt;br&gt;
If a class is marked as final, we cannot extend the class.&lt;br&gt;
If a variable is marked as final, we cannot change the value of it.&lt;br&gt;
If a method is marked as final, we cannot override it.&lt;/p&gt;

&lt;p&gt;An a marker interface is interface which has no method by using we are telling jvm to perform some actions.&lt;br&gt;
Serializable cloneable. &lt;/p&gt;

</description>
      <category>java</category>
    </item>
    <item>
      <title>Core Java - Interface</title>
      <dc:creator>Saravanan B</dc:creator>
      <pubDate>Tue, 14 Feb 2023 14:05:39 +0000</pubDate>
      <link>https://dev.to/saravananb15/core-java-interface-5b87</link>
      <guid>https://dev.to/saravananb15/core-java-interface-5b87</guid>
      <description>&lt;p&gt;&lt;strong&gt;Interface&lt;/strong&gt;   Fully Abstract methods.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public interface Car {
    void go();
    void stop();
}
&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;public class Honda implements Car{

    @Override
    public void go() {
        System.out.println("Implemented go method");
    }

    @Override
    public void stop() {
        System.out.println("Implemented stop method");
    }

}
&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;public class Test {
    public static void main(String[] args) {
        Honda h = new Honda();
        h.go();
        h.stop();
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;An interface is a contract whereas Abstract method contains partial implementation.&lt;/p&gt;

&lt;p&gt;An interface is by default public abstract method.&lt;/p&gt;

&lt;p&gt;Variable in interface is public static final and should be initialized.&lt;/p&gt;

&lt;p&gt;cannot define blocks and constructor.&lt;/p&gt;

</description>
      <category>java</category>
    </item>
    <item>
      <title>Core Java - Abstraction</title>
      <dc:creator>Saravanan B</dc:creator>
      <pubDate>Tue, 14 Feb 2023 13:26:45 +0000</pubDate>
      <link>https://dev.to/saravananb15/core-java-abstraction-2860</link>
      <guid>https://dev.to/saravananb15/core-java-abstraction-2860</guid>
      <description>&lt;p&gt;&lt;strong&gt;Abstraction&lt;/strong&gt;&lt;br&gt;
Abstract means theoretical not practical or not implemented.&lt;br&gt;
If we need to watch TV we need not to know how TV works we just switch channels using remote.&lt;/p&gt;

&lt;p&gt;Abstract class can be fully and partially implemented Abstract class.&lt;/p&gt;

&lt;p&gt;Abstraction means hiding the internal details of implementation.&lt;/p&gt;

&lt;p&gt;We cannot create a instance of abstract class&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public abstract class BMV {
    void commonFunctionality() {
        System.out.println("Inside common fun");
    }
    abstract void acclerate();
}
&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;public class ThreeSeries extends BMV {
    @Override
    void acclerate() {
        System.out.println("Inside 3 series can go upto 120");
    }
}
&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;public abstract class FiveSeries extends BMV{
    abstract void acclerate();
}
&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;public class Test {
    public static void main(String[] args) {
        ThreeSeries three = new ThreeSeries();
        three.acclerate();
        three.commonFunctionality();
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output -&lt;/strong&gt;  Inside 3 series can go upto 120&lt;br&gt;
Inside common fun&lt;/p&gt;

&lt;p&gt;Access modifiers --&lt;/p&gt;

&lt;p&gt;we can't mark abstract class as final.&lt;br&gt;
we can't mark abstract method as static.&lt;/p&gt;

</description>
      <category>java</category>
    </item>
    <item>
      <title>DSA - Binary Search</title>
      <dc:creator>Saravanan B</dc:creator>
      <pubDate>Tue, 14 Feb 2023 06:54:15 +0000</pubDate>
      <link>https://dev.to/saravananb15/dsa-binary-search-1g57</link>
      <guid>https://dev.to/saravananb15/dsa-binary-search-1g57</guid>
      <description>&lt;p&gt;&lt;strong&gt;Binary search&lt;/strong&gt;&lt;br&gt;
It's an algorithm which is optimized way to find a element in array.&lt;br&gt;
let's take an example array which is sorted.&lt;br&gt;
&lt;code&gt;arr[] = {1,2,3,4,5,6};&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Here target is to find 5.&lt;/p&gt;

&lt;p&gt;first it will take no of index here 5 after it will take half of the index = 2 the element in 2 index is 3. 3 is lesser then 5 again from index 3 to 5 it will take the half. If the element 4 is greater than target it will search from index 0 to 2. Now index is 4 and element is 5. and 5 is equal to target and it prints the output.&lt;/p&gt;

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

&lt;p&gt;&lt;code&gt;arr[] = {1,5,7,9,10,15};  target = 10;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;1st - index = 5 &lt;br&gt;
Start = 0 end= 5&lt;br&gt;
binary search = 0+5/2 -&amp;gt; 2(index)&lt;/p&gt;

&lt;p&gt;Value in index 2 is 7 and 7 is lesser than target.&lt;/p&gt;

&lt;p&gt;2nd - &lt;code&gt;{9,10,15}&lt;/code&gt;&lt;br&gt;
Start = 3 end = 5&lt;br&gt;
binary = 3+5/2 -&amp;gt; 4(index)&lt;/p&gt;

&lt;p&gt;Value in index 4 is 10 and its equal to target.&lt;/p&gt;

&lt;p&gt;Now output is index 4.&lt;/p&gt;

&lt;p&gt;Time complexity -&lt;/p&gt;

&lt;p&gt;Best case - O(1)  //size does not matter if element is found in first index &lt;br&gt;
Worst Case - logN.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class BinarySearch {
    public static void main(String[] args) {
        int arr[] = {1,2,3,5,6,7,9,10};
        int target = 6;
        int ans =binarySearch(arr,target);
        System.out.println(ans);
    }

    static int binarySearch(int[] arr, int target) {
        int start =0;
        int end = arr.length-1;
        while(start &amp;lt;= end) {
            int mid = start+(end-start)/2;
        if(target &amp;lt; arr[mid]) {
            end = mid-1;
        }else if(target &amp;gt; arr[mid]) {
            start = mid+1;
        }else {
            return mid;
        }
        }
        return -1;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output - 4&lt;/p&gt;

</description>
      <category>java</category>
      <category>algorithms</category>
    </item>
    <item>
      <title>DSA- Linear Search</title>
      <dc:creator>Saravanan B</dc:creator>
      <pubDate>Mon, 13 Feb 2023 15:40:06 +0000</pubDate>
      <link>https://dev.to/saravananb15/dsa-linear-search-4ocf</link>
      <guid>https://dev.to/saravananb15/dsa-linear-search-4ocf</guid>
      <description>&lt;p&gt;&lt;strong&gt;linear Search&lt;/strong&gt; - is algorithm which starts searching from index 0 till the element finds.&lt;/p&gt;

&lt;p&gt;This algorithm also worst-case algorithm. If element not available, it iterates through the elements till end.&lt;/p&gt;

&lt;p&gt;Best Case - O(1)&lt;br&gt;
Worst case - O(n) where n is the size of the array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class LinearSearch {
    public static void main(String[] args) {
        int[] arr = new int[5];
        for(int i=0;i&amp;lt;arr.length;i++) {
            arr[i]=i;
        }
        int target = 2;
        System.out.println("element found in the array at index " +linearSearch(arr, target));
        int targetNotInArray = 100; // to prove worst case
        System.out.println("This will iterate through the array and element "
                + "is not found in array and return false" +
        linearSearch(arr, targetNotInArray));
    }

    static int linearSearch(int[] arr, int target) {
        if (arr.length == 0) { // if the array has no element
            return -1;
        }
        // looping through the array to find element
        for (int i = 0; i &amp;lt; arr.length; i++) {
            if (arr[i] == target) {
                return i;
            }
        }

        return -1;
    }
}

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

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wg1LsrXm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l6sog0k8i1hqwmiz0jva.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wg1LsrXm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l6sog0k8i1hqwmiz0jva.png" alt="Image description" width="800" height="114"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>java</category>
      <category>algorithms</category>
    </item>
    <item>
      <title>Core Java - Inheritance</title>
      <dc:creator>Saravanan B</dc:creator>
      <pubDate>Mon, 13 Feb 2023 08:31:22 +0000</pubDate>
      <link>https://dev.to/saravananb15/core-java-inheritance-3h06</link>
      <guid>https://dev.to/saravananb15/core-java-inheritance-3h06</guid>
      <description>&lt;p&gt;&lt;strong&gt;Single Inheritance&lt;/strong&gt; &lt;br&gt;
Implicitly every class inherits the java.lang.object class.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--sWksmDXS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/diwo7h8c2rnoxadqpf2u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--sWksmDXS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/diwo7h8c2rnoxadqpf2u.png" alt="Image description" width="800" height="241"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Multilevel Inheritance&lt;/strong&gt;&lt;br&gt;
In this we have a parent class and child class extending parent class.&lt;/p&gt;

&lt;p&gt;while creating object for child class using that object we can call the parent class methods.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--47SZoe5J--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0lvvfmw1ts67xgus34y7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--47SZoe5J--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0lvvfmw1ts67xgus34y7.png" alt="Image description" width="498" height="171"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If we create a object for child class and object address is same for parent class and child class.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hierarchical inheritance&lt;/strong&gt;&lt;br&gt;
A vehicle class has a fuel method a bus and car class extend vehicle class.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Method Overriding&lt;/strong&gt;&lt;br&gt;
The fuel method return diesal for bus and petrol for car this is method overriding. Still the method name and signature is same.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Class Vehicle{
public String fuel(){
return "null";
}
}
&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;Class bike extends Vehicle{
@override 
public String fuel(){
return "petrol";
}
}
&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;class bus extends Vehicle{
@override 
public String fuel(){
return "diesal";
}
}
&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;class Main{
public static void main(String[] args){
 Bike b = new Bike();
 System.out.println(b.fuel());
 Bus b1 = new Bus();
 System.out.println(b1.fuel());
}
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Super keyword&lt;/strong&gt;&lt;br&gt;
Super keyword is used to point out parent class.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Parent {
    void f1() {
        System.out.println("inside parent f1");
    }
}

&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;public class Child extends Parent{
    void f1() {
        super.f1();
        System.out.println("inside child f1");
    }
}
&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;public class Test {
    public static void main(String[] args) {
        Child c = new Child();
        c.f1();
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4wzpLWXp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dlyl4k6hzfdjxpbt6ilv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4wzpLWXp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dlyl4k6hzfdjxpbt6ilv.png" alt="Image description" width="206" height="150"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Constructor Chaining&lt;/strong&gt;&lt;br&gt;
Is a feature we can access parent and child constructor in single object creation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class SuperClass {
    int x;

    public SuperClass() {
        System.out.println("No args constructor");
    }

    public SuperClass(int x) {
        this();
        this.x = x;
        System.out.println("All args Constructor");
    }

}
&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;public class ChildClass extends SuperClass{
    ChildClass(){
        this(10);
        System.out.println("No args child class constrctor");
    }
    ChildClass(int x){
        super(x);
        System.out.println("No args child class constrctor");
    }
    public static void main(String[] args) {
        ChildClass c = new ChildClass();

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

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--I01vHitm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u4y0t0a4k7wbrrlbzyo4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--I01vHitm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u4y0t0a4k7wbrrlbzyo4.png" alt="Image description" width="528" height="194"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>java</category>
    </item>
  </channel>
</rss>
