<?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: Chhavi Joshi</title>
    <description>The latest articles on DEV Community by Chhavi Joshi (@chhavi_joshi_ede276cfcc06).</description>
    <link>https://dev.to/chhavi_joshi_ede276cfcc06</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%2F2628494%2F6b005627-dc68-488d-b1c0-60c0fb75f966.png</url>
      <title>DEV Community: Chhavi Joshi</title>
      <link>https://dev.to/chhavi_joshi_ede276cfcc06</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/chhavi_joshi_ede276cfcc06"/>
    <language>en</language>
    <item>
      <title>Day 2 Java learning: Prime numbers in range</title>
      <dc:creator>Chhavi Joshi</dc:creator>
      <pubDate>Fri, 07 Nov 2025 08:54:46 +0000</pubDate>
      <link>https://dev.to/chhavi_joshi_ede276cfcc06/day-2-java-learning-prime-numbers-in-range-4lpd</link>
      <guid>https://dev.to/chhavi_joshi_ede276cfcc06/day-2-java-learning-prime-numbers-in-range-4lpd</guid>
      <description>&lt;p&gt;Yesterday we studied about functions, so today lets write code to print prime numbers in a range using function.&lt;/p&gt;

&lt;p&gt;Lets start with the first writing a function to print prime numbers:&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%2Fkz5ytdr1n0ijokb2qikh.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%2Fkz5ytdr1n0ijokb2qikh.png" alt=" " width="512" height="356"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What we did in this code was, first we made a function prime with void as return type. We then created a variable count and initialized it to zero. This counter variable was made to count the number of times a number is divisible by any num other than 1 or itself to check if it's prime or not. Every time the number becomes fully divisible by some other num the value of this counter variable increases so at first we initialized it to 0, and then increment it after checking the condition.&lt;br&gt;
For checking this condition we made a for loop which starts from 2 till squareroot of the number (for optimization), we could have also continued the loop until the number, then in the loop we checked the remainder on dividing the number with every num and if it comes as zero, it means the number is completely divisible by that number and hence the number is not prime. &lt;br&gt;
Once we find a single number that can completely divide the number to be checked for prime, we increment the value of count and break the loop.&lt;/p&gt;

&lt;p&gt;Then we check if the value of count still remains zero or not. If count = 0, till the end of loop it means the number wasn't divisible by any other number and therefore it's prime and so we print the number.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;We could have checked if the number is prime or not by another way as well&lt;/em&gt;&lt;/strong&gt; &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%2Fvit74vl4svn5ptytsnr3.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%2Fvit74vl4svn5ptytsnr3.png" alt=" " width="521" height="236"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this we chose the return type as boolean and then repeated the same loop as we did earlier but this time instead of making a variable counter we directly return true or false to the caller (as the returntype is boolean)&lt;/p&gt;

&lt;p&gt;Now so far we wrote the code to check if a number is prime or not, but we need to print all the prime numbers in the mentioned range. So for this let's write another function that would use one of these functions to check if a number is prime or not and then print all the prime numbers that come in the range.&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%2Fljpzlakc3f400fz06kxn.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%2Fljpzlakc3f400fz06kxn.png" alt=" " width="590" height="362"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So in this we wrote function with returntype as void again, which takes two numbers as parameters and then runs a loop from the first number to the second number and inside it, calls the isPrime function and after checking if the number is prime or not it prints them.&lt;/p&gt;

&lt;p&gt;Then in the main method we provide the  variables and call the range method. &lt;/p&gt;

</description>
      <category>beginners</category>
      <category>tutorial</category>
      <category>java</category>
      <category>learning</category>
    </item>
    <item>
      <title>Day 1, part II : Call by value</title>
      <dc:creator>Chhavi Joshi</dc:creator>
      <pubDate>Wed, 05 Nov 2025 16:41:21 +0000</pubDate>
      <link>https://dev.to/chhavi_joshi_ede276cfcc06/day-1-part-ii-call-by-value-348p</link>
      <guid>https://dev.to/chhavi_joshi_ede276cfcc06/day-1-part-ii-call-by-value-348p</guid>
      <description>&lt;p&gt;Earlier we talked about what functions are, how their syntax looks like and how they work, now let us dive a level deeper into it.&lt;/p&gt;

&lt;p&gt;The functions in java are "&lt;strong&gt;call by value&lt;/strong&gt;", which means that the value that we provide as argument is not directly given to the function but a copy of its value is given.&lt;/p&gt;

&lt;p&gt;Lets understand it by example of swap function:&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%2F1q1v9scciw7m8kfi2vop.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%2F1q1v9scciw7m8kfi2vop.png" alt=" " width="800" height="151"&gt;&lt;/a&gt;&lt;br&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%2Fu02yxf0i7sz3ce10tbkq.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%2Fu02yxf0i7sz3ce10tbkq.png" alt=" " width="293" height="74"&gt;&lt;/a&gt;&lt;br&gt;
In this code we wrote the print statement inside the function itself so we got out desired result, but if we remove the print statement from the function and write&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;in the main function instead, the code would show different behaviour, i.e. its original value would be displayed. Because what we sent in the function was a copy of actual variables and their scope lies inside the function only. So if we wrote the print statement outside the swap function the original value would be printed and not what we did to their copy&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>tutorial</category>
      <category>java</category>
      <category>coding</category>
    </item>
    <item>
      <title>Day 1 of daily coding: Functions is java</title>
      <dc:creator>Chhavi Joshi</dc:creator>
      <pubDate>Wed, 05 Nov 2025 16:11:32 +0000</pubDate>
      <link>https://dev.to/chhavi_joshi_ede276cfcc06/day-1-of-daily-coding-functions-is-java-2ka5</link>
      <guid>https://dev.to/chhavi_joshi_ede276cfcc06/day-1-of-daily-coding-functions-is-java-2ka5</guid>
      <description>&lt;p&gt;We know that functions in java are block of code written to perform a specific task. For example if we need to add two numbers multiple times in same code, it would be very tedious to rewrite the same code again and again, so instead we create a function or a method (a function inside a class is called method) in java. So that instead of writing the whole code we can just call that function.&lt;/p&gt;

&lt;p&gt;The syntax of a function appears as follow:&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;Access specifier&amp;gt;   &amp;lt;returntype&amp;gt;   &amp;lt;name of finction&amp;gt; (parameter){
...body of function
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example:&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%2Fxm6ggdkgwdbak0q789a2.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%2Fxm6ggdkgwdbak0q789a2.png" alt=" " width="510" height="160"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Above is code for function that would print Hello World three times, we can see that at first we mentioned the access specifier then the type of function, as I wrote it in the main class that would contain the main function later in the code, i wrote static. Then comes the return type of this function, which here is void as it would not return anything, then is the name of function and  inside it, is its &lt;br&gt;
body.&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%2Fnbzb4zebwfk2thr5hac0.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%2Fnbzb4zebwfk2thr5hac0.png" alt=" " width="476" height="170"&gt;&lt;/a&gt;&lt;br&gt;
If instead of void i would have mentioned int as the return type then, at the end of code i would've to return some value, so here i decided to return the number of times Hello World would be printed. Note that this return value is what the function caller gets back and is not displayed or printed.&lt;/p&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%2Fr3vqv055xxj5k970wlok.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%2Fr3vqv055xxj5k970wlok.png" alt=" " width="202" height="83"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Another example would help us understand better:&lt;br&gt;
Sum calculation function:&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%2Fzkr0b2mxlj9jpdfmheuv.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%2Fzkr0b2mxlj9jpdfmheuv.png" alt=" " width="545" height="102"&gt;&lt;/a&gt;&lt;br&gt;
Here we wrote int as the return type and passed two parameters in the parenthesis. We can see two numbers in the parameter block this means that when we call the function we would need to provide two numbers to it as argument and the function would perform whatever task is mentioned in the body on those values. Then at the end the function returns some value to the caller.&lt;br&gt;
Main method:&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%2F8oiuau393jgjr1hymxke.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%2F8oiuau393jgjr1hymxke.png" alt=" " width="470" height="171"&gt;&lt;/a&gt;&lt;br&gt;
Here in the main method I asked for two numbers as input and then passed them as arguments to the function. You can notice that here the value of function call is assigned to a variable sum as:&lt;br&gt;
&lt;em&gt;int sum = calculateSum(a,b)&lt;/em&gt;&lt;br&gt;
which means that sum would contain the value that the calculateSum function would return when a and b are passed as arguments in it.&lt;br&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%2Fvdicnynfrr7i24s4267b.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%2Fvdicnynfrr7i24s4267b.png" alt=" " width="239" height="120"&gt;&lt;/a&gt;&lt;br&gt;
And this is how the final output would look like.&lt;/p&gt;

</description>
      <category>productivity</category>
      <category>tutorial</category>
      <category>java</category>
      <category>learning</category>
    </item>
    <item>
      <title>Code optimization (Prime no.)</title>
      <dc:creator>Chhavi Joshi</dc:creator>
      <pubDate>Sat, 06 Sep 2025 15:08:32 +0000</pubDate>
      <link>https://dev.to/chhavi_joshi_ede276cfcc06/code-optimization-prime-no-5gg5</link>
      <guid>https://dev.to/chhavi_joshi_ede276cfcc06/code-optimization-prime-no-5gg5</guid>
      <description>&lt;h2&gt;
  
  
  Question:
&lt;/h2&gt;

&lt;p&gt;To take 'n' inputs from user and tell if the number is prime or not.&lt;/p&gt;

&lt;p&gt;Let's solve this step by step and analyze how we can reduce it's time complexity.&lt;br&gt;
We know that prime numbers are the numbers which are divisible by only 1 and the number itself.&lt;br&gt;
So the main concept that would be used here is that, we need to check the remainder when we divide the number by each number, if the remainder is 0, the number is completely divisible by that number and then we will increase the value of count, which would be a counter variable initialzed to count the number of times the input num got completely divided. On the basis of which we will tell if the num is prime or not.&lt;/p&gt;

&lt;p&gt;So the first code that i wrote for this was:&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%2Fwae1qievyteova6hqw2z.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%2Fwae1qievyteova6hqw2z.png" alt=" " width="765" height="742"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Output of which appears as:&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%2F03kjwp0a85vv1d4kj2p7.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%2F03kjwp0a85vv1d4kj2p7.png" alt=" " width="793" height="355"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This code is technically correct but the number of time it iterates makes its time complexity very high.&lt;/p&gt;

&lt;p&gt;So the first and most basic change I did was to decrease the number of iterations in the for loop of div.&lt;/p&gt;

&lt;p&gt;I changed it from:&lt;br&gt;
&lt;code&gt;for(int div = 1; div &amp;lt;= n; div++ ){&lt;br&gt;
     if(n % div == 0){&lt;br&gt;
        count++;&lt;br&gt;
     }&lt;br&gt;
if(count == 2){&lt;br&gt;
System.out.println("Prime");&lt;br&gt;
}&lt;br&gt;
 }&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;to:&lt;br&gt;
&lt;code&gt;for(int div = 2; div &amp;lt; n; div++ ){&lt;br&gt;
  if(n % div == 0){&lt;br&gt;
  count++;&lt;br&gt;
 }&lt;br&gt;
}&lt;br&gt;
if(count == 0){&lt;br&gt;
System.out.println("Prime");&lt;br&gt;
}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;which reduces two iterations, we know that the prime nums are divisible by 1 and the num itself so we can exclude these two cases and check if any other num completely divides the num, if it does then the num is not prime and if it doesn't the num is prime. &lt;br&gt;
So this reduces two iterations yet it does not help us significantly.&lt;/p&gt;

&lt;p&gt;There's a pattern we need to analyze in the divisors of a number, take an example:&lt;br&gt;
24, it's divisors can be written as:&lt;br&gt;
1 x 24&lt;br&gt;
2 x 12&lt;br&gt;
3 x 8&lt;/p&gt;

&lt;h2&gt;
  
  
  4 x 6
&lt;/h2&gt;

&lt;p&gt;6 x 4&lt;br&gt;
8 x 3&lt;br&gt;
12 x 2&lt;br&gt;
24 x 1&lt;/p&gt;

&lt;p&gt;We know that square root of 24 is 4.89, so did you notice some pattern in the divisors of the number around it's sqrt, it is clear that the number of times a num can be completely divided before it's sqrt is same as the no. of diviors it would have after the sqrt. &lt;/p&gt;

&lt;p&gt;So instead of iterating the second loop till n we can iterate it till sqrt of n which would reduce the iterations to almost half.&lt;/p&gt;

&lt;p&gt;So the code would now look as follows:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;for(int div = 2; div * div &amp;lt; n; div++ ){&lt;br&gt;
                if(n % div == 0){&lt;br&gt;
                    count++;&lt;br&gt;
                }&lt;br&gt;
            }&lt;br&gt;
            if(count == 0){&lt;br&gt;
                System.out.println("Prime");&lt;br&gt;
            }&lt;/code&gt;&lt;br&gt;
 we cannot write sqrt n directly so instead I wrote it as &lt;em&gt;div * div &amp;lt; n&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;But there's one more optimization that we could do in this, i.e. if a number is divisible by any other number instead of 1 and the num itself then it is called prime, even if there's only one num other then these two, so what we can do is &lt;strong&gt;break&lt;/strong&gt; the loop as soon as we find the very first number that is divisor of the num except 1 and itself.&lt;/p&gt;

&lt;p&gt;So the final code would look as follows:&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%2Fivyry73k7tac92ya5kjw.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%2Fivyry73k7tac92ya5kjw.png" alt=" " width="800" height="681"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>tutorial</category>
      <category>java</category>
    </item>
    <item>
      <title>Exception Handling in java</title>
      <dc:creator>Chhavi Joshi</dc:creator>
      <pubDate>Thu, 28 Aug 2025 16:10:10 +0000</pubDate>
      <link>https://dev.to/chhavi_joshi_ede276cfcc06/exception-handling-in-java-2hf</link>
      <guid>https://dev.to/chhavi_joshi_ede276cfcc06/exception-handling-in-java-2hf</guid>
      <description>&lt;p&gt;We know that there are various types of error which we might come across in coding, they are broadly classified as following types:&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Syntax Error
&lt;/h2&gt;

&lt;p&gt;Error in the syntax such as initializing value without declaration, absence of semicolon etc are considered syntax error.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Logical Error
&lt;/h2&gt;

&lt;p&gt;When wrong logic is applied to the code, it is called logical error. This type of error do not cause any problem in compilation or execution but they perform the wrong task, i.e. the code doesn't behave in the expected manner.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Runtime Error
&lt;/h2&gt;

&lt;p&gt;These are the errors that we do not realize until the code is run, i. e. we cannot view them at compile time as they occur at runtime. These errors can usually be treated and these are then called exceptions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Exception:
&lt;/h2&gt;

&lt;p&gt;So exception in java is basically a resolvable event the disrupts the normal flow of program.&lt;/p&gt;

&lt;p&gt;common exceptions that we come across are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;NullPointerException&lt;/li&gt;
&lt;li&gt;ArithmeticException&lt;/li&gt;
&lt;li&gt;ArrayIndexOutOfBoundException&lt;/li&gt;
&lt;li&gt;-IllegalArgumentException&lt;/li&gt;
&lt;li&gt;-NumberFormatException&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Try catch and finally block:
&lt;/h2&gt;

&lt;p&gt;So assume following code, in this I've declared an array, and its asking the user to enter an index to be retrived. As the length of array is 5 so entering index til 4 is valid and if index greater than 4 is entered in normal circumstances it would give error.&lt;/p&gt;

&lt;p&gt;But we do not want our program to crash over such pity things such as invalid input so we perform exception handling, where we make two blocks a &lt;strong&gt;Try&lt;/strong&gt; block that contains the code that might cause error, by this we tell the compiler to try doing that part of code, and if it throws an error it is given to the &lt;strong&gt;Catch&lt;/strong&gt; block which catches the error by its type mentioned in the parentheses and then does the action that shows us that the error has been dealt.&lt;br&gt;
And then we have &lt;strong&gt;Finally&lt;/strong&gt; block that is executed whether any error arise or not, the only time it is not executed is when there's an error in the finally block as well, or when it contains a dead thread or when we use &lt;strong&gt;System.exit()&lt;/strong&gt;.&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%2Fow6o1i2tysbqo4jxdyl7.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%2Fow6o1i2tysbqo4jxdyl7.png" alt=" " width="800" height="608"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>java</category>
      <category>learning</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Constructors in thread and Thread priority</title>
      <dc:creator>Chhavi Joshi</dc:creator>
      <pubDate>Wed, 27 Aug 2025 04:04:33 +0000</pubDate>
      <link>https://dev.to/chhavi_joshi_ede276cfcc06/constructors-in-thread-and-thread-priority-30a</link>
      <guid>https://dev.to/chhavi_joshi_ede276cfcc06/constructors-in-thread-and-thread-priority-30a</guid>
      <description>&lt;p&gt;There are 8 constructors in Thread class.&lt;/p&gt;

&lt;p&gt;1) Thread():&lt;br&gt;
It's the one we usually use for creating objects of Thread.&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%2Fhuanibqeyjofzkor9z55.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%2Fhuanibqeyjofzkor9z55.png" alt=" " width="601" height="120"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;2) Thread(Runnable):&lt;br&gt;
We use this constructor when we use the Runnable interface for thread creation.&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%2Fymicme3sbxwferx8iy99.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%2Fymicme3sbxwferx8iy99.png" alt=" " width="683" height="244"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;3) Thread(name):&lt;br&gt;
It is used to name a thread, so it's easy for debugging.&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%2Fi0zr30n9adq5y9aeygi3.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%2Fi0zr30n9adq5y9aeygi3.png" alt=" " width="788" height="606"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Main class:&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%2Fl3qsgsorompzz43vu9cd.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%2Fl3qsgsorompzz43vu9cd.png" alt=" " width="533" height="182"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;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%2Fozwxkcuymeao3gqve369.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%2Fozwxkcuymeao3gqve369.png" alt=" " width="166" height="82"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;3) Thread(Runnable, name)&lt;br&gt;
When we create an object for thread using runnable interface, it is done in two step, first where we write obj using the name of class and second step where we use thread class and pass the onj name as argument of it, for example:&lt;br&gt;
&lt;strong&gt;Class obj = new Class();&lt;br&gt;
Thread ob = new Thread(obj);&lt;/strong&gt;&lt;br&gt;
but using this constructor we can directly make the object in one step.&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%2Fzhx356pqw60s4won8cmo.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%2Fzhx356pqw60s4won8cmo.png" alt=" " width="784" height="257"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Main class:&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%2Ftkszl37m1ey1x7uwy62p.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%2Ftkszl37m1ey1x7uwy62p.png" alt=" " width="656" height="81"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Priority
&lt;/h2&gt;

&lt;p&gt;We can also prioritioze which thread to run first using setPriority() method&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%2Fmxeefrjryhq003op3fs4.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%2Fmxeefrjryhq003op3fs4.png" alt=" " width="475" height="201"&gt;&lt;/a&gt;&lt;br&gt;
In the code above I used MAX, MIN priorities but we can also give specified priority as &lt;strong&gt;obj.setPriority(7);&lt;/strong&gt;&lt;br&gt;
and also return the priority of an object by printing &lt;strong&gt;obj.getPriority()&lt;/strong&gt;&lt;/p&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%2Fkptpab75c15cy6px9fn2.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%2Fkptpab75c15cy6px9fn2.png" alt=" " width="177" height="122"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>learning</category>
      <category>java</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Multithreading with Runnable Interface</title>
      <dc:creator>Chhavi Joshi</dc:creator>
      <pubDate>Tue, 26 Aug 2025 15:58:12 +0000</pubDate>
      <link>https://dev.to/chhavi_joshi_ede276cfcc06/multithreading-with-runnable-interfac-3fe1</link>
      <guid>https://dev.to/chhavi_joshi_ede276cfcc06/multithreading-with-runnable-interfac-3fe1</guid>
      <description>&lt;p&gt;Earlier we studied how to perform multithreading using the class &lt;strong&gt;Thread&lt;/strong&gt;, but we know that in java multiple inheritance is not possible so if we want to perform multithreading in a derived class we would not be able to extend the Thread class. So to resolve this issue we can also perform multithreading by using interface!&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;Runnable&lt;/strong&gt; interface performs the same functions as that of the Thread class but we know that we can implement multiple interfaces together and even in a derived class, so they resolve this issue and so are generally preferred more.&lt;/p&gt;

&lt;h2&gt;
  
  
  Code:
&lt;/h2&gt;

&lt;p&gt;Below is the code for the same.&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%2Fheyd9npxj0t2ir6filxl.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%2Fheyd9npxj0t2ir6filxl.png" alt=" " width="590" height="446"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The normal classes appear exactly same to that of implementing multithreading through Thread class. But the only difference lies in the object formation in the main class shown below.&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%2Fua7xnsgvd0r8tp9rwrtk.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%2Fua7xnsgvd0r8tp9rwrtk.png" alt=" " width="435" height="348"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can see that first we need to make objects of the classes like we usually do but then we also need to make objects of the class Thread which would contain the objects &lt;em&gt;m1&lt;/em&gt; and &lt;em&gt;m2&lt;/em&gt; of the normal classes. And at the end we call &lt;em&gt;t1&lt;/em&gt; and &lt;em&gt;t2&lt;/em&gt; the objects of Thread class.&lt;/p&gt;

&lt;h2&gt;
  
  
  Output:
&lt;/h2&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%2Fnr2lseccx09t0j49pult.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%2Fnr2lseccx09t0j49pult.png" alt=" " width="473" height="412"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can see how the statement of thread3 was executed before thread2 and that too the thread was switched before compelete execution as after printing the statement of thread3 6 times only instead of 50 times as mentioned in the code the statements of thread2 were printed.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>tutorial</category>
      <category>java</category>
      <category>learning</category>
    </item>
    <item>
      <title>Multithreading and creating a thread</title>
      <dc:creator>Chhavi Joshi</dc:creator>
      <pubDate>Tue, 26 Aug 2025 05:24:17 +0000</pubDate>
      <link>https://dev.to/chhavi_joshi_ede276cfcc06/multithreading-and-creating-a-thread-4obg</link>
      <guid>https://dev.to/chhavi_joshi_ede276cfcc06/multithreading-and-creating-a-thread-4obg</guid>
      <description>&lt;p&gt;Multithreading is a concept in java that offers concurrency (even parallellism if working on quad-core processor).&lt;br&gt;
Thread can be thought as the smallest unit of code and with the help of multithreading we can work on multiple threads concurrently.&lt;/p&gt;

&lt;p&gt;Think of a shop for instance that has only one person for assistance, if multiple customers come to a shop then instead of fullfilling their needs one by one i.e. listening to their needs, then waiting for the processing of the product and then giving it to customer and later going to another customer its better to get the requests from other customers while the processing takes place.&lt;/p&gt;

&lt;p&gt;This is what we can achieve by multithreading, executing multiple threads concurrently, and switching between threads while one is stuck in a process.&lt;/p&gt;

&lt;h2&gt;
  
  
  Code:
&lt;/h2&gt;

&lt;p&gt;Firstly when we make a class such that we want to perform multithreading we extend the class &lt;strong&gt;Thread&lt;/strong&gt; which is a built in class in java.&lt;/p&gt;

&lt;p&gt;To perform multithreading we use the method &lt;strong&gt;run()&lt;/strong&gt; which again is a method of class Thread that we override in our classes.&lt;/p&gt;

&lt;p&gt;Even if we create other methods in the class, to perform them in multithreaded manner we must declare them inside the &lt;em&gt;run()&lt;/em&gt; method.&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%2Fo0y2zxfch085cxuzn1ev.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%2Fo0y2zxfch085cxuzn1ev.png" alt=" " width="647" height="692"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;At the time of creating objects of the class and calling the methods we use &lt;strong&gt;obj.start()&lt;/strong&gt;. The &lt;em&gt;start()&lt;/em&gt; method is the basis of multithreading and it calls the &lt;em&gt;run()&lt;/em&gt; method.&lt;/p&gt;

&lt;p&gt;The &lt;em&gt;start()&lt;/em&gt; method creates a new thread that can be concurrently run. If we do not call the start method and directly call any other method (even &lt;em&gt;run()&lt;/em&gt; ) then the code is executed in sequential manner.&lt;/p&gt;

&lt;h2&gt;
  
  
  Output:
&lt;/h2&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%2Fwl2effzfspm28xgrcre2.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%2Fwl2effzfspm28xgrcre2.png" alt=" " width="222" height="321"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is a part of output, where we can clearly see that instead of running the first line for 50 times and then executing the other statement both the statements are being executed concurrently.&lt;/p&gt;

&lt;p&gt;I used the for loop for 50 statements as the processing happens so quickly that if the statements were to be printed only a few number of times they might have appeared almost sequential.&lt;/p&gt;

&lt;h2&gt;
  
  
  Doubts:
&lt;/h2&gt;

&lt;p&gt;Now lets discuss some doubts that might come in our mind as a beginner.&lt;/p&gt;

&lt;p&gt;First:Does start() only calls run() method?&lt;br&gt;
Answer: Yes it only calls run() so if any other method is to be made it needs to be either declared inside of run() or called separately. But calling it separately in main thread (main class) makes it sequential.&lt;/p&gt;

&lt;p&gt;Second: what if we create a method apart form run().&lt;br&gt;
Answer: In that case we will have to declare the method in the run() method as well, so that when we call start(), all the part of run() of run() is executed including the other methods mentioned in it&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%2F3is8bcqtri01k1o22qis.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%2F3is8bcqtri01k1o22qis.png" alt=" " width="510" height="340"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;in this manner doWork() would also be executed along with run().&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>tutorial</category>
      <category>java</category>
      <category>learning</category>
    </item>
    <item>
      <title>Default and Private methods in interface</title>
      <dc:creator>Chhavi Joshi</dc:creator>
      <pubDate>Tue, 26 Aug 2025 03:19:32 +0000</pubDate>
      <link>https://dev.to/chhavi_joshi_ede276cfcc06/default-and-private-methods-in-interface-50dp</link>
      <guid>https://dev.to/chhavi_joshi_ede276cfcc06/default-and-private-methods-in-interface-50dp</guid>
      <description>&lt;p&gt;We know that interface is like a blueprint class that gives us a hollow structure or scaffold that needs to be used in other classes, by just declaring the methods and not implementing it in the interface. This gives freedom for every class to implement the same method in its own manner, whenever we &lt;strong&gt;implement&lt;/strong&gt; the inteface.&lt;/p&gt;

&lt;p&gt;But one thing must be kept in mind that when we derive a class from an interface by implementing it we must either define all the methods present in the interface or we must make the class abstract. This is because when we implement an interace in a class all the methods that were a part of interface earlier are now indirectly present in the class as well, and so if a method is not defined among the existing methods it is present as an abstract method in the class and we already know that even if a class contains a single abstract method it must be abstract itself.&lt;/p&gt;

&lt;p&gt;So problem arises when we want to update the interface i.e. add a new method in interface. Earlier it was &lt;strong&gt;not possible&lt;/strong&gt; as when we &lt;strong&gt;update&lt;/strong&gt; the interface by adding even a single method to it, every class that implemented the interface must also be updated, so to solve this problem &lt;strong&gt;default&lt;/strong&gt; methods were introduced.&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%2Fvaauk1667i1qtt6qtnpr.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%2Fvaauk1667i1qtt6qtnpr.png" alt=" " width="800" height="331"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In my previous post I had already posted this interface Shape where the methods were &lt;em&gt;dimensions()&lt;/em&gt; and &lt;em&gt;area()&lt;/em&gt;, these were the fields that would be different for every shape but suppose later I thought of adding a method &lt;em&gt;show()&lt;/em&gt; that would print "I'm a shape", so i could make this a default method. You'll understand it further by going through its properties mentioned as follows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;They must be defined in the interface itself.&lt;/li&gt;
&lt;li&gt;It's not necessary to mention a default method for a class to be concrete.&lt;/li&gt;
&lt;li&gt;If we want to use it for other purpose in a class implementing the interface we can simply override the default method.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In this manner default methods are used to add new method without breaking  the old code&lt;/p&gt;

&lt;p&gt;Now talking about private methods, these are like helper methods used for supporting the default method. Or these can be used when the logic of the default method becomes very long so these can be seperately made and then be called inside the default method like I did in the above code.&lt;/p&gt;

&lt;p&gt;properties of private method:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Unlike default methods they can only be used in the interface as they are private.&lt;/li&gt;
&lt;li&gt;These cannot be overridden.&lt;/li&gt;
&lt;li&gt;These are helper methods of the default method.&lt;/li&gt;
&lt;li&gt;Any object cannot call them directly because of private access specifier.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>beginners</category>
      <category>tutorial</category>
      <category>java</category>
      <category>learning</category>
    </item>
    <item>
      <title>Abstract classes and Interface</title>
      <dc:creator>Chhavi Joshi</dc:creator>
      <pubDate>Sat, 23 Aug 2025 12:51:25 +0000</pubDate>
      <link>https://dev.to/chhavi_joshi_ede276cfcc06/abstract-classes-and-interface-4ab5</link>
      <guid>https://dev.to/chhavi_joshi_ede276cfcc06/abstract-classes-and-interface-4ab5</guid>
      <description>&lt;p&gt;&lt;strong&gt;Abstract classes&lt;/strong&gt; in java are the classes that contain &lt;strong&gt;abstract mehtods&lt;/strong&gt;, and abstract methods are the methods which do not contain any implementation.&lt;/p&gt;

&lt;p&gt;We know that the meaning of abstract is something that only exists in thoughts, similarly a method that only has declaration but not implementation are called absract methods.&lt;/p&gt;

&lt;p&gt;Even a single abstract method would make the whole class abstract i.e. an abstract class can contain both normal methods and abstract methods, even if there's a single method that is abstract in any normal class, we have to declare the whole class as abstract.&lt;/p&gt;

&lt;p&gt;See the example below to understand it further.&lt;/p&gt;

&lt;h2&gt;
  
  
  Example:
&lt;/h2&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%2Fz5kfreixavgubvb7munb.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%2Fz5kfreixavgubvb7munb.png" alt=" " width="642" height="778"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here Animal is an abstract class with two abstract methods, &lt;em&gt;sound() _and _feet() _ and a normal method _breathe()&lt;/em&gt;. The working of method breathe would be same for every animal so it was written as a normal class. Whereas animal's make different sounds and have different number of legs, so these properties would differ for every animal and hence they are not initialized in the class animal itself but in the derived classes. So we can say  that basically the abstract methods provide blueprint.&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%2Ftocztpzczv4o730i5n6d.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%2Ftocztpzczv4o730i5n6d.png" alt=" " width="502" height="369"&gt;&lt;/a&gt;&lt;br&gt;
And their working could be understood making object of each class.&lt;/p&gt;

&lt;h2&gt;
  
  
  Output:
&lt;/h2&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%2Fxgg304vg5wzuct2pkc2t.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%2Fxgg304vg5wzuct2pkc2t.png" alt=" " width="406" height="276"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Interface:
&lt;/h2&gt;

&lt;p&gt;Interfaces are similar to abstract classes, as they also contain methods with only declaration and not implementation&lt;br&gt;
This is code for interface, which act as a blueprint for all the shape classes that would be further derived from this.&lt;br&gt;
In interface each method is automatically public and abstract method. So unlike the abstract class which can contain both normal as well as abstract methods, in interface all the methods are automatically abstract.&lt;/p&gt;

&lt;p&gt;So interfaces are used to create a blueprint of all the methods should be in its derived classes  &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%2Fuehp99osiqzlst5urgmw.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%2Fuehp99osiqzlst5urgmw.png" alt=" " width="579" height="245"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To derive a class from interface we use &lt;strong&gt;implement&lt;/strong&gt; keyword, like we use  &lt;strong&gt;extends&lt;/strong&gt; for normal classes.&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%2Fvca1u7j7q9ap5zsbp750.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%2Fvca1u7j7q9ap5zsbp750.png" alt=" " width="723" height="784"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Output:
&lt;/h2&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%2Flzr53jy0mq7dmv5ja2i5.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%2Flzr53jy0mq7dmv5ja2i5.png" alt=" " width="267" height="192"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>tutorial</category>
      <category>java</category>
    </item>
    <item>
      <title>Overriding</title>
      <dc:creator>Chhavi Joshi</dc:creator>
      <pubDate>Fri, 22 Aug 2025 12:32:08 +0000</pubDate>
      <link>https://dev.to/chhavi_joshi_ede276cfcc06/overriding-494j</link>
      <guid>https://dev.to/chhavi_joshi_ede276cfcc06/overriding-494j</guid>
      <description>&lt;p&gt;Overriding is a concept similar to that of method overloading, its just that method overriding takes place in inheritance and unlike method overloading where at least a parameter or return type must be different in both the methods having same name, in function overriding two functions of same name in different classes can be overridden such that their name, number of parameters, type of parameters and return type is also same.&lt;/p&gt;

&lt;h2&gt;
  
  
  Example:
&lt;/h2&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%2F5y7smzh70v8q1ex8uuos.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%2F5y7smzh70v8q1ex8uuos.png" alt=" " width="718" height="616"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Output:
&lt;/h2&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%2Fn07hpjvnxwavz8julqbu.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%2Fn07hpjvnxwavz8julqbu.png" alt=" " width="338" height="76"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>tutorial</category>
      <category>java</category>
    </item>
    <item>
      <title>Super keyword</title>
      <dc:creator>Chhavi Joshi</dc:creator>
      <pubDate>Fri, 22 Aug 2025 05:04:12 +0000</pubDate>
      <link>https://dev.to/chhavi_joshi_ede276cfcc06/super-keyword-17c2</link>
      <guid>https://dev.to/chhavi_joshi_ede276cfcc06/super-keyword-17c2</guid>
      <description>&lt;p&gt;Super keyword is used to access any variable or method or constructor of the immediate parent class in java. So it is a keyword used in inheriatance whenever we want to call a variable, method or constructor in java.&lt;/p&gt;

&lt;p&gt;Below is an example that shows how super keyword works.&lt;/p&gt;

&lt;h2&gt;
  
  
  Example (comparision with this keyword):
&lt;/h2&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%2F83v2kqnm4m6ofm2aqbiu.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%2F83v2kqnm4m6ofm2aqbiu.png" alt=" " width="800" height="560"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this block of code I've made two classes, a parent class and a child class that extends parent class to perform inheritance.And I made a variable named strength in each class and then I made a method &lt;em&gt;showStrength()&lt;/em&gt; to display strengths of both the class.&lt;/p&gt;

&lt;p&gt;Now both the variables have same name so if I was to  directly call strength the compiler would not know the variable of which of the class is being called, so like we use &lt;strong&gt;this&lt;/strong&gt; keyword to signify that the particular object is being called, we use &lt;strong&gt;super&lt;/strong&gt; keyword to signify that the part of the immediate parent class it to be called.&lt;/p&gt;

&lt;h2&gt;
  
  
  Output:
&lt;/h2&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%2Fxkl841f0rgx4s67k9ubf.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%2Fxkl841f0rgx4s67k9ubf.png" alt=" " width="379" height="100"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So I used this and super keyword together to show the similarity and differences in both of them.&lt;/p&gt;




&lt;p&gt;Now below is an example that shows that every constructor has an inbuilt super keyword that is present though it is not visible. &lt;/p&gt;

&lt;h2&gt;
  
  
  Super in constructor:
&lt;/h2&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%2Fkwgfolutbac1m792i4ls.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%2Fkwgfolutbac1m792i4ls.png" alt=" " width="664" height="542"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this code again I used the parent and child class but this time I also made a default constructor of each class which would be directly called whenever an object of any of the classes is created.&lt;/p&gt;

&lt;p&gt;Then I made an object of the child class only. But when we look at the output the constructor of both the classes have been run. Check the output below for understanding. &lt;/p&gt;

&lt;h2&gt;
  
  
  Output:
&lt;/h2&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%2Fq6kd1t7fqwhv1i3r78i8.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%2Fq6kd1t7fqwhv1i3r78i8.png" alt=" " width="416" height="156"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This happened because each constructor has a default inbuilt super keyword mentioned, that executes the constructor of its immediate parent class automatically.&lt;/p&gt;

&lt;p&gt;To show the working of the super keyword I've commented super for understanding in each constructor, that even though we do not write it in the code it is automatically present there.&lt;/p&gt;

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