<?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: Nihal Islam</title>
    <description>The latest articles on DEV Community by Nihal Islam (@nihalislam01).</description>
    <link>https://dev.to/nihalislam01</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%2F1052172%2F2cf54e10-0c16-4f89-a1b3-f19d673f2fb7.jpg</url>
      <title>DEV Community: Nihal Islam</title>
      <link>https://dev.to/nihalislam01</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nihalislam01"/>
    <language>en</language>
    <item>
      <title>Java Programming Language (Array)</title>
      <dc:creator>Nihal Islam</dc:creator>
      <pubDate>Mon, 26 Feb 2024 06:48:32 +0000</pubDate>
      <link>https://dev.to/nihalislam01/java-programming-language-array-1kki</link>
      <guid>https://dev.to/nihalislam01/java-programming-language-array-1kki</guid>
      <description>&lt;h2&gt;
  
  
  Array
&lt;/h2&gt;

&lt;p&gt;Array is a set of elements. Instead of using multiple variables for multiple data, we can store SIMILAR types of data in an &lt;code&gt;array&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;datatype[] array = {element1, element2, ....};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Same as declaring a variable for a single data, we need to declare the data type of the elements inside an &lt;code&gt;array&lt;/code&gt;. After declaring the data type, we need to add square brackets &lt;code&gt;[]&lt;/code&gt; to let the compile know that we are assigning an &lt;code&gt;array&lt;/code&gt; to a variable. After that we need to give the variable a name, same as before and lastly to store elements in an array, java use curly braces &lt;code&gt;{}&lt;/code&gt; and inside the braces we can put the values separating by &lt;code&gt;,&lt;/code&gt;. For example,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int[] numbers = {10, 20, 30};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let us see what will happen if we try to print this array in the console.&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 Array {
    public static void main(String[] args) {
        int[] numbers = {10, 20, 30};
        System.out.println(numbers);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[I@2a84aee7
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output will be something like this. But this is not what we wanted to print. &lt;/p&gt;

&lt;p&gt;When we create an array, it stores the location (ram location) of values instead of the actual values. However, we can fetch the actual values using the location and indexing.&lt;/p&gt;

&lt;h2&gt;
  
  
  Indexing
&lt;/h2&gt;

&lt;p&gt;Every element inside an array has an unique index value. Index starts from 0 to n-1 where &lt;code&gt;n&lt;/code&gt; is the number of elements inside an array. So, the first element of an array has index of 0 and second element has 1 and so on.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int[] numbers = {10, 20, 30};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Indexing of this array&lt;/strong&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Index&lt;/th&gt;
&lt;th&gt;0&lt;/th&gt;
&lt;th&gt;1&lt;/th&gt;
&lt;th&gt;2&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Elements&lt;/td&gt;
&lt;td&gt;10&lt;/td&gt;
&lt;td&gt;20&lt;/td&gt;
&lt;td&gt;30&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;To fetch the values we can write the following code,&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 Array {
    public static void main(String[] args) {
        int[] numbers = {10, 20, 30};
        System.out.println(numbers[0]);
        System.out.println(numbers[1]);
        System.out.println(numbers[2]);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So first we need to write the variable where the array location has been stored in this case the variable name is &lt;code&gt;numbers&lt;/code&gt;, then inside square brackets &lt;code&gt;[]&lt;/code&gt; we will pass the index of the values. If the index number exceeds the array, it will give an error.&lt;br&gt;
&lt;strong&gt;Output&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;We can use &lt;a href="https://dev.to/nihalislam01/java-programming-language-loops-for-loop-58o2"&gt;Loops&lt;/a&gt; as well to iterate through the whole array.&lt;/p&gt;

&lt;h2&gt;
  
  
  Appendix
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Arrays can be formed of any data types but the data type of all the elements inside an array must be the same. For example,
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;String[] names = {"Alvin", "Simon", "Theodore"};
&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;double[] gpa = {3.70, 3.30};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Elements inside an array can be changed by using index.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gpa[1] = 4.00;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;We can create an array of a certain size before assigning the values inside it. Then we can add elements using indexes.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int[] numbers = new int[10];
numbers[0] = 50;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;We cannot add elements exceeding the length of the array.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Happy Coding&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>programming</category>
      <category>tutorial</category>
      <category>java</category>
    </item>
    <item>
      <title>Java Programming Language (Loops: Nested loop)</title>
      <dc:creator>Nihal Islam</dc:creator>
      <pubDate>Mon, 26 Feb 2024 06:47:39 +0000</pubDate>
      <link>https://dev.to/nihalislam01/java-programming-language-loops-nested-loop-12p1</link>
      <guid>https://dev.to/nihalislam01/java-programming-language-loops-nested-loop-12p1</guid>
      <description>&lt;h2&gt;
  
  
  Nested loop
&lt;/h2&gt;

&lt;p&gt;Same as conditions, we can use a loop inside another loop. For example,&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 Loops {
    public static void main(String[] args) {
        for (int person = 1; person &amp;lt;= 2; person ++) {
            for (int task = 1; task &amp;lt;= 3; task ++) {
                System.out.println("Person " + person + " completed task " + task);
            }
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Person 1 completed task 1
Person 1 completed task 2
Person 1 completed task 3
Person 2 completed task 1
Person 2 completed task 2
Person 2 completed task 3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Code always executes from top to bottom. If we think about this manner, The compiler first goes inside the outer &lt;code&gt;for&lt;/code&gt; loop. Then it will execute the code inside the block until the loop condition is &lt;code&gt;false&lt;/code&gt;. However, inside the loop block compiler found another &lt;code&gt;for&lt;/code&gt; loop. Now the compiler will execute the code inside this inner &lt;code&gt;for&lt;/code&gt; loop block until it terminates. Then the outer loop will go to the next iteration.&lt;/p&gt;

&lt;p&gt;In this case, the outer loop will iterate two times and the inner loop will iterate three times. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;First, while the outer loop is in it's first iteration the inner loop will iterate three times. &lt;/li&gt;
&lt;li&gt;Once the inner loop terminates the outer loop will move on to it's second iteration. &lt;/li&gt;
&lt;li&gt;In the second iteration the inner loop will reinitialise itself. As a result, while the outer loop is in it's second iteration the inner loop will again iterate over three times.&lt;/li&gt;
&lt;li&gt;After the inner loop terminates itself, the outer loop will also terminate as it does not meet the condition of outer loop.&lt;/li&gt;
&lt;li&gt;Then the compiler will execute the code from the next line.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There can be multiple nested loops and it can be performed with &lt;code&gt;while&lt;/code&gt; loops as well. &lt;/p&gt;

&lt;h2&gt;
  
  
  break statement
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;break&lt;/code&gt; statement is generally used to terminate a block of code. Earlier we used &lt;code&gt;break&lt;/code&gt; inside the &lt;code&gt;switch&lt;/code&gt; statement in the &lt;a href="https://dev.to/nihalislam01/java-programming-language-conditions-50i9"&gt;Conditions&lt;/a&gt; section to terminate the subsequent cases. In loops we can use &lt;code&gt;break&lt;/code&gt; as well to terminate the iterations.&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 Loops {
    public static void main(String[] args) {
        int count = 1;
        System.out.println("Counting to 3");
        while (true) {
            System.out.println("Count: " + count);
            if (count == 3) {
                break;
            }
            count++;
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, on every iteration I am incrementing the &lt;code&gt;count&lt;/code&gt; variable by 1. When the &lt;code&gt;count&lt;/code&gt; becomes 3, the condition becomes &lt;code&gt;true&lt;/code&gt; inside the &lt;code&gt;if&lt;/code&gt; statement. As the compiler executes the &lt;code&gt;break&lt;/code&gt; statement, it terminates the loop and goes to the next line after the loop.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Counting to 3
Count: 1
Count: 2
Count: 3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  continue statement
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;continue&lt;/code&gt; statement is used to skip a particular iteration. Suppose, I want to print number 1 to 5 except number 3.&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 Loops {
    public static void main(String[] args) {
        for (int i = 1; i &amp;lt;= 5; i++) {
            if (i == 3) {
                continue;
            }
            System.out.println(i);
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When the code executes &lt;code&gt;continue&lt;/code&gt; statement, it skips the current iteration and move on to the next iteration.&lt;br&gt;
&lt;strong&gt;Output&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1
2
4
5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Appendix
&lt;/h2&gt;

&lt;p&gt;while using nested loop, &lt;code&gt;break&lt;/code&gt; or &lt;code&gt;continue&lt;/code&gt; statement becomes ambiguous as it cannot figure out which loop it wants to terminate or skip. In these cases, we can use &lt;code&gt;label&lt;/code&gt; to identify the loops.&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 Loops {
    public static void main(String[] args) {
        // label
        outer:
        for (int i = 1; i &amp;lt;= 2; i++) {
            // label
            inner:
            for (int j = 1; j &amp;lt;= 3; j++) {
                if (j == 2) {
                    continue outer;
                }
                System.out.println("i = " + i + ", j = " + j);
            }
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, we are labelling the loops before initialising so that we can specify the particular loop later. In the &lt;code&gt;continue&lt;/code&gt; statement I am specifying which loop I want to skip when the condition meets.&lt;br&gt;
&lt;strong&gt;Output&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;i = 1, j = 1
i = 2, j = 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Find out what would happed if we skipped the inner loop instead of the outer loop here.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;label&lt;/code&gt; can be used in &lt;code&gt;break&lt;/code&gt; statements as well to terminate a certain loop.&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 Loops {
    public static void main(String[] args) {
        outer:
        for (int i = 1; i &amp;lt;= 2; i++) {
            inner:
            for (int j = 1; j &amp;lt;= 3; j++) {
                if (j == 2) {
                    break inner;
                }
                System.out.println("i = " + i + ", j = " + j);
            }
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;i = 1, j = 1
i = 2, j = 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Did you get the idea? Let me know in the comment section. &lt;/p&gt;

&lt;p&gt;Happy coding&lt;/p&gt;

</description>
      <category>java</category>
      <category>tutorial</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Java Programming Language (Loops: for loop)</title>
      <dc:creator>Nihal Islam</dc:creator>
      <pubDate>Mon, 26 Feb 2024 06:47:00 +0000</pubDate>
      <link>https://dev.to/nihalislam01/java-programming-language-loops-for-loop-58o2</link>
      <guid>https://dev.to/nihalislam01/java-programming-language-loops-for-loop-58o2</guid>
      <description>&lt;h2&gt;
  
  
  for loop
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for (initialExpression; testExpression; updateExpression) {...}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;for&lt;/code&gt; loop has the same concept of general loop. In &lt;a href="https://dev.to/nihalislam01/java-programming-language-loops-while-loop-4cf7"&gt;while&lt;/a&gt; loop we needed to manually update the iteration inside the code block. However, in &lt;code&gt;for&lt;/code&gt; loop, it automatically iterates through the loop. &lt;/p&gt;

&lt;p&gt;For example, I want to find the sum of the numbers 1 to 100.&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 Loops {
    public static void main(String[] args) {
        int sum = 0;
        for (int i = 1; i &amp;lt;= 100; i++) {
            sum += i;
        }
        System.out.println(sum);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step01: Using &lt;code&gt;for&lt;/code&gt; we initialise a loop&lt;/p&gt;

&lt;p&gt;Step02: Inside the loop parenthesis, &lt;code&gt;initialExpression&lt;/code&gt; is &lt;code&gt;int i = 1&lt;/code&gt;, declaring the iteration variable&lt;/p&gt;

&lt;p&gt;Step03: &lt;code&gt;testExpression&lt;/code&gt; is &lt;code&gt;i &amp;lt;= 100&lt;/code&gt;, returns a &lt;code&gt;boolean&lt;/code&gt; value to check whether it is &lt;code&gt;true&lt;/code&gt; or &lt;code&gt;false&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Step04: &lt;code&gt;updateExpression&lt;/code&gt; is &lt;code&gt;i++&lt;/code&gt;, updating the iteration variable every time the loop repeats&lt;/p&gt;

&lt;p&gt;Step05: Code inside the loop block will execute until the loop terminates&lt;/p&gt;

&lt;p&gt;Step06: Once the iteration variable &lt;code&gt;i&lt;/code&gt; becomes &lt;code&gt;101&lt;/code&gt;, the &lt;code&gt;testExpression&lt;/code&gt; becomes &lt;code&gt;false&lt;/code&gt; and the loop will terminate&lt;br&gt;
&lt;strong&gt;Output&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  for...each loop
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for (dataType item: array) {...}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;for...each&lt;/code&gt; loop is actually performed in an array to iterate through the elements inside it. So, I recommend you to take a look at the &lt;a href="https://dev.to/nihalislam01/java-programming-language-array-1kki"&gt;Arrays&lt;/a&gt; section before learning &lt;code&gt;for...each&lt;/code&gt; loop. &lt;/p&gt;

&lt;p&gt;An example of &lt;code&gt;for...each&lt;/code&gt; loop is given below,&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 Loops {
    public static void main(String[] args) {
        int[] numbers = {98, 92, 98, 85};
        for (int number: numbers) {
            System.out.println(number);
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step01: Using &lt;code&gt;for&lt;/code&gt; we initialise the loop&lt;/p&gt;

&lt;p&gt;Step02: Inside the loop parenthesis, we declare the data type of the elements inside the array. In this case &lt;code&gt;int&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Step03: Then we declare a new variable &lt;code&gt;number&lt;/code&gt; for each elements. In every iteration, the values inside the array will be assigned to this variable one by one. For example in first iteration &lt;code&gt;number = 98&lt;/code&gt;, second iteration &lt;code&gt;number = 92&lt;/code&gt; and so on.&lt;/p&gt;

&lt;p&gt;Step04: Then we pass the array which we want to iterate through separating by &lt;code&gt;:&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Step05: The loop will repeat &lt;code&gt;n&lt;/code&gt; number of times, where &lt;code&gt;n&lt;/code&gt; is the length of the array&lt;br&gt;
&lt;strong&gt;Output&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;98
92
98
85
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Try to iterate through an array of Strings and print the elements by yourself.&lt;/p&gt;

&lt;p&gt;Happy Coding&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>programming</category>
      <category>tutorial</category>
      <category>java</category>
    </item>
    <item>
      <title>Java Programming Language (Loops: while Loop)</title>
      <dc:creator>Nihal Islam</dc:creator>
      <pubDate>Fri, 16 Feb 2024 10:07:36 +0000</pubDate>
      <link>https://dev.to/nihalislam01/java-programming-language-loops-while-loop-4cf7</link>
      <guid>https://dev.to/nihalislam01/java-programming-language-loops-while-loop-4cf7</guid>
      <description>&lt;h1&gt;
  
  
  Loops
&lt;/h1&gt;

&lt;p&gt;The concept of loops arises in need of executing a specific block of code iteratively. &lt;/p&gt;

&lt;p&gt;Suppose I want to print &lt;code&gt;Hello, World!&lt;/code&gt; 5 times. Instead of using print method multiple times we can use a loop to reduce the lines of codes. &lt;/p&gt;

&lt;p&gt;In java there are multiple types of loops.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;while loop&lt;/li&gt;
&lt;li&gt;do...while loop&lt;/li&gt;
&lt;li&gt;for loop&lt;/li&gt;
&lt;li&gt;for...each loop&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  while loop
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;while (condition) {...}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After using &lt;code&gt;while&lt;/code&gt; statement, it takes a &lt;code&gt;boolean&lt;/code&gt; value as condition. As long as the condition is &lt;code&gt;true&lt;/code&gt; the java compiler will repeat the lines of codes inside the code block. For example,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Do not execute this code
public class Loops {
    public static void main(String[] args) {
        //while loop
        while (true) {
            System.out.println("Hello, World!");
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Have you identified the issue that might arise in this code? &lt;/p&gt;

&lt;p&gt;Because we are using &lt;code&gt;true&lt;/code&gt; inside the &lt;code&gt;(condition)&lt;/code&gt; block, the java compiler will repeat the code inside the block infinite amount of times and eventually the code will crash. Can you think of any solution that we can use to solve this issue?&lt;/p&gt;

&lt;p&gt;We can use a variable to store the the &lt;code&gt;boolean&lt;/code&gt; value and once we are done with our repetition, we can simply assign the variable to &lt;code&gt;false&lt;/code&gt; value. Also, to check whether we are done with our repetition, we can use condition statements. &lt;/p&gt;

&lt;p&gt;Now, to print &lt;code&gt;Hello, World!&lt;/code&gt; 5 times we can write the following code.&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 Loops {
    public static void main(String[] args) {
        int iteration = 1;
        boolean flag = true;
        //while loop
        while (flag) {
            System.out.println("Hello, World!");
            iteration++;
            if (iteration &amp;gt; 5) {
                flag = false;
            }
        }
        System.out.println("End");
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, multiple things are happening. First we assigned an &lt;code&gt;int&lt;/code&gt; value to keep track how many times we want to repeat the code. And we stored the &lt;code&gt;boolean&lt;/code&gt; value &lt;code&gt;true&lt;/code&gt; initially. &lt;/p&gt;

&lt;p&gt;Now, in every iteration first we are printing &lt;code&gt;Hello, World!&lt;/code&gt;. Second, we are increasing the iteration value to keep track of the times we want to print &lt;code&gt;Hello, World!&lt;/code&gt;. Third, we are checking whether we are done with our repetition. Once we are done, we are assigning the &lt;code&gt;boolean&lt;/code&gt; value to &lt;code&gt;false&lt;/code&gt;. When while loop condition is &lt;code&gt;false&lt;/code&gt; it will skip the block of code and go to the next line.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Hello, World!
Hello, World!
Hello, World!
Hello, World!
Hello, World!
End
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is how the code is working. We can make this code much more simpler in the following way,&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 Loops {
    public static void main(String[] args) {
        int iteration = 1;
        while (iteration &amp;lt;= 5) {
            System.out.println("Hello, World!");
            iteration++;
        }
        System.out.println("End");
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we don't need to store a &lt;code&gt;boolean&lt;/code&gt; value manually. We know that relational operators give us &lt;code&gt;boolean&lt;/code&gt; value. So here we are checking whether the condition is &lt;code&gt;true&lt;/code&gt; or &lt;code&gt;false&lt;/code&gt;. When the condition is &lt;code&gt;false&lt;/code&gt;, the loop will terminate. This is how the iteration is working,&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Iteration&lt;/th&gt;
&lt;th&gt;variable&lt;/th&gt;
&lt;th&gt;(iteration &amp;lt;= 5)&lt;/th&gt;
&lt;th&gt;Action&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1st&lt;/td&gt;
&lt;td&gt;iteration = 1&lt;/td&gt;
&lt;td&gt;true&lt;/td&gt;
&lt;td&gt;prints &lt;code&gt;Hello, World!&lt;/code&gt; &lt;br&gt; iteration += 1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2nd&lt;/td&gt;
&lt;td&gt;iteration = 2&lt;/td&gt;
&lt;td&gt;true&lt;/td&gt;
&lt;td&gt;prints &lt;code&gt;Hello, World!&lt;/code&gt; &lt;br&gt; iteration += 1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3rd&lt;/td&gt;
&lt;td&gt;iteration = 3&lt;/td&gt;
&lt;td&gt;true&lt;/td&gt;
&lt;td&gt;prints &lt;code&gt;Hello, World!&lt;/code&gt; &lt;br&gt; iteration += 1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4th&lt;/td&gt;
&lt;td&gt;iteration = 4&lt;/td&gt;
&lt;td&gt;true&lt;/td&gt;
&lt;td&gt;prints &lt;code&gt;Hello, World!&lt;/code&gt; &lt;br&gt; iteration += 1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5th&lt;/td&gt;
&lt;td&gt;iteration = 5&lt;/td&gt;
&lt;td&gt;true&lt;/td&gt;
&lt;td&gt;prints &lt;code&gt;Hello, World!&lt;/code&gt; &lt;br&gt; iteration += 1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;6th&lt;/td&gt;
&lt;td&gt;iteration = 6&lt;/td&gt;
&lt;td&gt;false&lt;/td&gt;
&lt;td&gt;goes to the next line &lt;br&gt; prints &lt;code&gt;End&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  do...while loop
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;do {...} while (condition);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This works same as while loop. However, here first the code in the &lt;code&gt;do&lt;/code&gt; block executes, then checks the condition and repeat accordingly. If we want to print numbers 1 to 5 we can write the following code,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int i = 1;
do {
    System.out.println(i);
    i++;
} while (i &amp;lt;= 5);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1
2
3
4
5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Find out the different use cases of &lt;code&gt;while&lt;/code&gt; loop and &lt;code&gt;do...while&lt;/code&gt; loop.&lt;/p&gt;

&lt;p&gt;Happy Coding&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>programming</category>
      <category>tutorial</category>
      <category>java</category>
    </item>
    <item>
      <title>Java Programming Language (Conditions)</title>
      <dc:creator>Nihal Islam</dc:creator>
      <pubDate>Mon, 12 Feb 2024 07:23:31 +0000</pubDate>
      <link>https://dev.to/nihalislam01/java-programming-language-conditions-50i9</link>
      <guid>https://dev.to/nihalislam01/java-programming-language-conditions-50i9</guid>
      <description>&lt;h2&gt;
  
  
  Conditions
&lt;/h2&gt;

&lt;p&gt;Conditions are used in code to determine whether a specific block of code should execute or be skipped. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;if statement&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;if (condition) {...}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;if&lt;/code&gt; statement takes a boolean value as condition. If the value is &lt;code&gt;true&lt;/code&gt; java executes the code between the block &lt;code&gt;{...}&lt;/code&gt;. Otherwise skip it. For example,&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 Conditions {
    public static void main(String[] args) {
        if (true) {
            System.out.println("Inside if statement.");
        }
        System.out.println("Outside if statement.");
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Inside if statement.
Outside if statement.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, if the condition is &lt;code&gt;false&lt;/code&gt;, the line between the blocks will be skipped.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (false) {
    System.out.println("Inside if statement.");
}
System.out.println("Outside if statement.");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Outside if statement.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now here I hardcoded the &lt;code&gt;true&lt;/code&gt; / &lt;code&gt;false&lt;/code&gt; conditions. We can also use relational and logical operators as conditions. For example, I want to print&lt;/p&gt;

&lt;p&gt;&lt;code&gt;if a student gets above 89, the GPA will be 4.00&lt;/code&gt;&lt;br&gt;
&lt;code&gt;if a student gets between 85 to 89, the GPA will be 3.70&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The statement will be like this,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Conditions {
    public static void main(String[] args) {
        int number = 92;
        // Use of Relational Operator
        if (number &amp;gt; 89) {
            System.out.println("GPA: 4.00");
        }
        // Use of Logical Operator
        if (number &amp;gt;= 85 &amp;amp;&amp;amp; number &amp;lt;= 89) {
            System.out.println("GPA: 3.70");
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GPA: 4.00
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;else if statement&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;else if (condition) {...}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Suppose I want to print the grades like this,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int number = 92;
if (number &amp;gt; 89) {
    System.out.println("GPA: 4.00");
}
if (number &amp;gt; 84) {
    System.out.println("GPA: 3.70");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now there's a bug. Here the problem is that, the code is checking both of the conditions and both of them are &lt;code&gt;true&lt;/code&gt;. So the output will execute both the blocks of codes.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GPA: 4.00
GPA: 3.70
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But we don't want that as nobody gets two grades. Instead what we can do is we can use &lt;code&gt;else if&lt;/code&gt; condition. When the code sees an &lt;code&gt;if&lt;/code&gt; statement it checks whether the condition is &lt;code&gt;true&lt;/code&gt; or &lt;code&gt;false&lt;/code&gt;. If the condition is &lt;code&gt;false&lt;/code&gt; only then the code will check the &lt;code&gt;else if&lt;/code&gt; condition. If the &lt;code&gt;if&lt;/code&gt; condition is &lt;code&gt;true&lt;/code&gt;, then all the other &lt;code&gt;else if&lt;/code&gt; conditions will be skipped.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int number = 92;
if (number &amp;gt; 89) {
    System.out.println("GPA: 4.00");
} else if (number &amp;gt; 84) {
    System.out.println("GPA: 3.70");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GPA: 4.00
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can use as many &lt;code&gt;else if&lt;/code&gt; statements as we want according to our needs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;else statement&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;else {...}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;else&lt;/code&gt; statement will execute the block of code only when all the above &lt;code&gt;if&lt;/code&gt; and &lt;code&gt;else if&lt;/code&gt; conditions are &lt;code&gt;false&lt;/code&gt;. &lt;code&gt;else&lt;/code&gt; statement does not have a condition block.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int number = 80;
if (number &amp;gt; 89) {
    System.out.println("GPA: 4.00");
} else if (number &amp;gt; 84) {
    System.out.println("GPA: 3.70");
} else {
    System.out.println("You need to work hard");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;You need to work hard
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;First comes the &lt;code&gt;if&lt;/code&gt; statement, then the &lt;code&gt;else if&lt;/code&gt; statements if needed and then lastly &lt;code&gt;else&lt;/code&gt; statement if needed. &lt;/p&gt;

&lt;h2&gt;
  
  
  Nested Conditions
&lt;/h2&gt;

&lt;p&gt;You can write nested conditions as well. Suppose I want to figure out if I got &lt;code&gt;A+&lt;/code&gt; or &lt;code&gt;A&lt;/code&gt; after getting CGPA 4.00.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int number = 98;
if (number &amp;gt; 89) {
    System.out.print("GPA: 4.00 ");
    //Nested Conditions inside the if block
    if (number &amp;gt; 96) {
        System.out.println("Grade: A+");
    } else {
        System.out.println("Grade: A");
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CGPA: 4.00 Grade: A+
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can write as many nested conditions as needed. Try to figure out if it's possible to write nested conditions inside &lt;code&gt;else if&lt;/code&gt; and &lt;code&gt;else&lt;/code&gt; statements as well.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;switch statement&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Java switch statement is similar to &lt;code&gt;if...else&lt;/code&gt; statements. We can write switch statement in the following way,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;switch (expression) {
    case value1:
        // code
        break;
    case value2:
        //code
        break;

        ...
        ...
    default:
        //code
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;if...else&lt;/code&gt; statement checks whether the condition is &lt;code&gt;true&lt;/code&gt; or &lt;code&gt;false&lt;/code&gt; in the condition block. However, switch statement tries to match the expression from the &lt;code&gt;(expression)&lt;/code&gt; block with the values from the &lt;code&gt;case&lt;/code&gt; statements. If the value matches, the code of that &lt;code&gt;case&lt;/code&gt; will be executed. And if none of the value matches the expression, then the code will execute the default value at the end. For example,&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 Conditions {
    public static void main(String[] args) {
        int number = 8;
        switch (number) {
            case 7:
                System.out.println("Extra small");
                break;
            case 8:
                System.out.println("Small");
                break;
            case 10:
                System.out.println("Large");
                break;
            case 11:
                System.out.println("Extra large");
                break;
            default:
                System.out.println("Medium");
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

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

&lt;/div&gt;



&lt;p&gt;Here the term &lt;code&gt;break&lt;/code&gt; breaks the switch statement. Which means if the expression matches a case, then it will execute the code of that particular case and skip the rest of the cases. If I don't use the term &lt;code&gt;break&lt;/code&gt; after every case, then the rest of the code will execute from the matching state. For example,&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 Conditions {
    public static void main(String[] args) {
        int number = 10;
        switch (number) {
            case 7:
                System.out.println("Extra small");
            case 8:
                System.out.println("Small");
            case 10:
                System.out.println("Large");
            case 11:
                System.out.println("Extra large");
            default:
                System.out.println("Medium");
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Large
Extra large
medium
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Appendix
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;When there's an error or our desired output does not match the generated output because of some particular code, it's code bug. We can trace our code from beginning to find where the problem occurs and debug our code.&lt;/li&gt;
&lt;li&gt;The white space between the curly braces is called code block. &lt;code&gt;{...}&lt;/code&gt;. We use code block after classes, methods, statements, loops etc to execute code for that particular term.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Happy Coding&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>programming</category>
      <category>tutorial</category>
      <category>java</category>
    </item>
    <item>
      <title>Java Programming Language (Input/Output)</title>
      <dc:creator>Nihal Islam</dc:creator>
      <pubDate>Wed, 07 Feb 2024 08:32:36 +0000</pubDate>
      <link>https://dev.to/nihalislam01/java-programming-language-inputoutput-5a9f</link>
      <guid>https://dev.to/nihalislam01/java-programming-language-inputoutput-5a9f</guid>
      <description>&lt;h2&gt;
  
  
  Output
&lt;/h2&gt;

&lt;p&gt;We have already seen java outputs. We can test our code by simply using java built-in print method. This method will print our desired value into the console. One simple example,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class InputOutput {
    public static void main(String[] args) {
        System.out.println("Hello, World!");
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Hello, World!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can also use &lt;code&gt;print&lt;/code&gt; instead of &lt;code&gt;println&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;What &lt;code&gt;println&lt;/code&gt; does is that if I print another value below, it will create a new line. However if I use &lt;code&gt;print&lt;/code&gt;, the next output will start where this output ends. For example,&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("Hello,");
System.out.print("My name is ");
System.out.println("Nihal.");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Hello,
My name is Nihal.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Input
&lt;/h2&gt;

&lt;p&gt;We can take input from user by Scanner class. Earlier we used String class to store String values in a variable. Scanner is also a built-in class. We will learn more about classes and objects later.&lt;/p&gt;

&lt;p&gt;When we were creating object of String class we needed to declare &lt;code&gt;String&lt;/code&gt; before assigning it into a variable. Here we are going to do the same thing.&lt;/p&gt;

&lt;p&gt;Before using a java built-in class, it needs to import its package. The fun thing about IntelliJ Idea is that it automatically imports necessary packages by itself. Inside the main method, if we start writing &lt;code&gt;Scanner&lt;/code&gt;, halfway through it will show if we want to use java built-in package &lt;code&gt;java.util.Scanner&lt;/code&gt;. This is the package where the Scanner class has been created. By simply clicking enter will automatically imports the package.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import java.util.Scanner;

class InputOutput {
    public static void main(String[] args) {
        Scanner
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After successfully importing the package we can use a variable name to store the object of Scanner class. Here I used &lt;code&gt;input&lt;/code&gt; as my variable name. Next, by using &lt;code&gt;=&lt;/code&gt; I am assigning &lt;code&gt;new Scanner(System.in)&lt;/code&gt; to the variable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import java.util.Scanner;

class InputOutput {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;new Scanner(System.in)&lt;/code&gt; creates an object of Scanner class and sets the location of the object into the &lt;code&gt;input&lt;/code&gt; variable. We will call this variable, object. For now, lets just know that we can take input through this object from the console. &lt;/p&gt;

&lt;p&gt;By using &lt;code&gt;input.next()&lt;/code&gt;, we can take String input from the console. Whatever we write on the console will become a String data type.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import java.util.Scanner;

class InputOutput {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        String name = input.next();
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And lastly, after we are done using Scanner object, we have to close the object using &lt;code&gt;input.close()&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import java.util.Scanner;

class InputOutput {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        String name = input.next();
        System.out.print("My name is, ");
        System.out.println(name);
        input.close();
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After running the code, we have to write our input inside the console. Then the code will execute the output accordingly. The input output of the code will be,&lt;br&gt;
&lt;strong&gt;Input&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;Nihal
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;My name is, Nihal
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also we can use &lt;code&gt;nextInt()&lt;/code&gt;, &lt;code&gt;nextLong()&lt;/code&gt;, &lt;code&gt;nextFloat()&lt;/code&gt; and &lt;code&gt;nextDouble()&lt;/code&gt; to take &lt;code&gt;int&lt;/code&gt;, &lt;code&gt;long&lt;/code&gt;, &lt;code&gt;float&lt;/code&gt; and &lt;code&gt;double&lt;/code&gt; inputs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int age = input.nextInt();
long salary = input.nextLong();
float cg = input.nextFloat();
double rate = input.nextDouble();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Imagine having salary of long numbers :D&lt;/p&gt;

&lt;h2&gt;
  
  
  Appendix
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Concatenation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We can use &lt;code&gt;+&lt;/code&gt; operator between two Strings as well two variables to join the two parts into a single String. The possible use cases are given below,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;String name = Nihal;
int age = 10;
System.out.println("Java " + "is a programming language");
System.out.println("My name is " + name);
System.out.println("My age is " + age);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Java is a programming language
My name is Nihal
My age is 10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Happy Coding&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>programming</category>
      <category>tutorial</category>
      <category>java</category>
    </item>
    <item>
      <title>Java Programming Language (Operators)</title>
      <dc:creator>Nihal Islam</dc:creator>
      <pubDate>Sun, 04 Feb 2024 11:27:49 +0000</pubDate>
      <link>https://dev.to/nihalislam01/java-programming-language-operators-2j4l</link>
      <guid>https://dev.to/nihalislam01/java-programming-language-operators-2j4l</guid>
      <description>&lt;h2&gt;
  
  
  Operators
&lt;/h2&gt;

&lt;p&gt;Java programming language has multiple types of operators to operate two values or variables. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Arithmetic Operators&lt;/strong&gt;&lt;br&gt;
in java there are 5 operators &lt;code&gt;+&lt;/code&gt;, &lt;code&gt;-&lt;/code&gt;, &lt;code&gt;*&lt;/code&gt;, &lt;code&gt;/&lt;/code&gt; and &lt;code&gt;%&lt;/code&gt; that can be performed between two numbers.&lt;/p&gt;

&lt;p&gt;First four operators work the same as it does on mathematics.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Operators {
    public static void main(String[] args) {
        int a = 15;
        int b = 3;
        //Addition Operator (+)
        System.out.println(a+b); //prints 18

        //Subtraction Operator (-)
        System.out.println(a-b); //prints 12

        //Multiplication Operator (*)
        System.out.println(a*b);// prints 45

        //Division Operator (/)
        System.out.println(a/b); //prints 5
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In java, division operation between two int numbers gives the floor int value. We can get double values in the following ways.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Floor division
int a = 15;
int b = 2;
System.out.println(a/b); //prints 7

//If any one number is double, the answer will give us double value
int c = 15;
double d = 2;
System.out.println(c/d); //prints 7.5

//Double wrapper (double) will convert the integer value into a double value
double e = (double) a/b;
System.out.println(e); //prints 7.5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;%&lt;/code&gt; operator called modulo operator can be performed between two values that gives us remainder after dividing them.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int a = 15;
int b = 2;
System.out.println(a%b); //prints 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Relational Operators&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Relational operators compare two numbers and generate boolean value checking if the comparison is true or false.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Operators {
    public static void main(String[] args) {
        int a = 39, b = 24;
        //Is Equal To
        System.out.println(a==b); //prints false

        //Not Equal To
        System.out.println(a!=b); //prints true

        //Is Greater Than
        System.out.println(a&amp;gt;b); //prints ture

        //Is Greater Than Or Equals to
        System.out.println(a&amp;gt;=b); //prints true

        //Is Less Than
        System.out.println(a&amp;lt;b); //prints false

        //Is Less Than Or Equals to
        System.out.println(a&amp;lt;=b); //prints false
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Logical Operators&lt;/strong&gt;&lt;br&gt;
These operators are performed on boolean values and generates another boolean value. The logical operators are &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt;, &lt;code&gt;||&lt;/code&gt; and &lt;code&gt;!&lt;/code&gt;. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;AND operator &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; only generates true if both of the boolean values are true. Otherwise gives false.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;System.out.println(true &amp;amp;&amp;amp; true); //prints true

System.out.println(false &amp;amp;&amp;amp; true); //prints false

System.out.println(true &amp;amp;&amp;amp; false); //prints false

System.out.println(false &amp;amp;&amp;amp; false); //prints false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;OR operator &lt;code&gt;||&lt;/code&gt; only generates false if both of the boolean values are false. Otherwise gives true.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;System.out.println(true || true); //prints true

System.out.println(false || true); //prints true

System.out.println(true || false); //prints true

System.out.println(false || false); //prints false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;NOT operator &lt;code&gt;!&lt;/code&gt; is performed on a single boolean value and reverse it.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;System.out.println(!false); //prints true

System.out.println(!true); //prints false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Logical operations can also be performed with relational operators. For example,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int a = 28, b = 7;
System.out.println((a&amp;gt;=b) &amp;amp;&amp;amp; (a==b)); //prints false

System.out.println((a&amp;gt;=b) || (a==b)); //prints true

System.out.println((a&amp;gt;=b) &amp;amp;&amp;amp; !(a==b)); //prints true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Appendix
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;In java we can invert a sign of a number by simply using &lt;code&gt;-&lt;/code&gt; in front of a variable.
&lt;/li&gt;
&lt;/ul&gt;

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;In Java if we want to increment a single variable by some value we can use the following way
&lt;/li&gt;
&lt;/ul&gt;

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

&lt;/div&gt;



&lt;p&gt;Here first we are performing addition operation and then assigning the value in the same variable. We can even make this process short&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;We can perform other arithmetic operations in the same way.&lt;code&gt;a += 10&lt;/code&gt;, &lt;code&gt;a -= 10&lt;/code&gt;, &lt;code&gt;a *= 10&lt;/code&gt;, &lt;code&gt;a /= 10&lt;/code&gt;, &lt;code&gt;a %= 10&lt;/code&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;There are two operators called increment &lt;code&gt;++&lt;/code&gt; and decrement &lt;code&gt;--&lt;/code&gt; operators which increments and decrements a value by 1.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int a = 10;
//Instead of writing this
a += 1;
System.out.println(a); //prints 11
//We can write this
a++;
System.out.println(a); //prints 12
//Both does the same thing.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can use increment and decrement operation in two ways. Prefix increment/decrement &lt;code&gt;++a;&lt;/code&gt; / &lt;code&gt;--a;&lt;/code&gt; or Postfix increment/decrement &lt;code&gt;a++;&lt;/code&gt; / &lt;code&gt;a--;&lt;/code&gt;. Prefix operators first change the value then preview it and Postfix operators first preview the value then change it. For example,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int a = 5;
System.out.println(a++); //prints 5
System.out.println(a); //prints 6
System.out.println(++a); //prints 7
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Happy Coding&lt;/p&gt;

</description>
      <category>java</category>
      <category>beginners</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Java Programming Language (Data Types)</title>
      <dc:creator>Nihal Islam</dc:creator>
      <pubDate>Wed, 31 Jan 2024 14:03:37 +0000</pubDate>
      <link>https://dev.to/nihalislam01/java-programming-language-data-types-282l</link>
      <guid>https://dev.to/nihalislam01/java-programming-language-data-types-282l</guid>
      <description>&lt;h2&gt;
  
  
  Data Types
&lt;/h2&gt;

&lt;p&gt;A large part of computer science is handling data. Working with data, storing, fetching and providing data is major part of computer science field. &lt;/p&gt;

&lt;p&gt;In this section we are going to learn about data types. Learning data types is a bit boring. But bare with me as we are going to learn some use cases and fun stuff we can do with datas.&lt;/p&gt;

&lt;p&gt;Now let us learn about data types. Java has 8 primitive data types which means they are predefined in java.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. boolean data type&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Boolean data type has two possible values. &lt;code&gt;true/false&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Default value &lt;code&gt;true&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;boolean flag = true;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. byte data type&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Byte data type is basically integer values in the range of -128 to 127.&lt;/li&gt;
&lt;li&gt;Default value &lt;code&gt;0&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;byte number1 = 24;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. short data type&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This is also a similar data type which holds integer values between the range of -32768 to 32767.&lt;/li&gt;
&lt;li&gt;Default value &lt;code&gt;0&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;short number2 = 24540;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4. int data type&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;int data type also carries integer values but in range of -2^31 to (2^31)-1 numbers.&lt;/li&gt;
&lt;li&gt;Default value &lt;code&gt;0&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int number3 = -51432187;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;5. long data type&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;long data types holds integer values between -2^63 to (2^63)-1 numbers.&lt;/li&gt;
&lt;li&gt;Need to use L after the number digits&lt;/li&gt;
&lt;li&gt;Default value &lt;code&gt;0&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;long number4 = 514321874325L;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt; - These are all integer number data types. However, different data types are used to save memory. If we are working on small numbers we can use small range data types accordingly. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. double data type&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It holds decimal values of double precision 64 bit floating point in IEEE standard form. &lt;/li&gt;
&lt;li&gt;Default value &lt;code&gt;0.0&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;double decimal1 = 22.3;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;7. float data type&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;float holds decimal values of single precision 32 bit floating point. To know more about single precision and double precision &lt;a href="https://stackoverflow.com/questions/801117/whats-the-difference-between-a-single-precision-and-double-precision-floating-p"&gt;click here&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Default value '0.0f'
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;float decimal2 = 23.3f;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;8. char data type&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It's a 16-bit Unicode character. So, we can use unicode between single quote from '\u0000' to '\uffff'.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;char letter = '\u0051';
System.out.println(letter); //prints Q
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Unicode value of '\u0051' is Q&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;char also carries a single character between single quotes.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;char letter1 = 'C';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;char data type also accepts &lt;a href="https://www.asciitable.com/"&gt;ASCII&lt;/a&gt; values.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;char letter = 65;
System.out.println(letter); //prints A
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Default value &lt;code&gt;'\u0000'&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;String data type&lt;/strong&gt;&lt;br&gt;
There is also another data type called String which we have learned earlier. String data type is not predefined in java. String is an object acts like a data type. Anything written between double quotes is a String data type.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;String greeting = "Hello, World!";&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Let us quickly look into the code that we can execute in a java file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class DataTypes {
    public static void main(String[] args) {
        //boolean data type
        boolean flag = true;
        System.out.println(flag); //prints true

        //byte data type
        byte number1 = 24;
        System.out.println(number1); //prints 24

        //short data type
        short number2 = 24540;
        System.out.println(number2); //prints 24540

        //int data type
        int number3 = -51432187;
        System.out.println(number3); //prints -51432187

        //long data type
        long number4 = 514321874325L;
        System.out.println(number4); //prints 514321874325

        //double data type
        double decimal1 = 22.3;
        System.out.println(decimal1); //prints 22.3

        //float data type
        float decimal2 = 23.3f;
        System.out.println(decimal2); //prints 23.3

        //char data type
        char letter1 = 'C';
        System.out.println(letter1); //prints C

        char letter2 = '\u0051';
        System.out.println(letter2); //prints Q

        char letter3 = 65;
        System.out.println(letter3); //prints A

        //String data type
        String greeting = "Hello, World!";
        System.out.println(greeting); //prints Hello, World!
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Appendix
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Primitive data types starts with lowercase letter and objects like String starts with uppercase letter following lowercase letters.
&lt;/li&gt;
&lt;/ul&gt;

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;In a String data type, if we want to use double quotes inside a String, we can use a back slash before the quotes to count them as a String.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;String work = "I am a \"Java\" developer.";
System.out.println(work); //prints I am a "Java" developer.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Happy Coding&lt;/p&gt;

</description>
      <category>java</category>
      <category>beginners</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Java Programming Language (Variables)</title>
      <dc:creator>Nihal Islam</dc:creator>
      <pubDate>Wed, 31 Jan 2024 08:32:54 +0000</pubDate>
      <link>https://dev.to/nihalislam01/java-programming-language-variables-2o2l</link>
      <guid>https://dev.to/nihalislam01/java-programming-language-variables-2o2l</guid>
      <description>&lt;h2&gt;
  
  
  Variables
&lt;/h2&gt;

&lt;p&gt;To work with data in programming, we need to store the values into a container. Variables work as containers which stores different data types and later helps us to use them into programming.&lt;/p&gt;

&lt;p&gt;Now if we want to print an integer number in the console we can simply write the code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Variables {
    public static void main(String[] args) {
        System.out.println(10);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will simply prints 10 in the console. However, we want to store the number 10 into a variable then print it.&lt;/p&gt;

&lt;p&gt;Before storing a data into a variable in java we must need to declare what kind of data I am storing in that particular variable. Here I want to store the integer number 10 into a variable. So, we will write the code as follows&lt;br&gt;
&lt;code&gt;int number = 10;&lt;/code&gt;&lt;br&gt;
Now let me define the code step by step. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Declaring Data Type&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;'int' is one kind of data types which holds integer values. There are different kinds of data types in java programming language. For now, I am storing integer value in the variable. That is why before writing a variable name I wrote 'int'. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Variable Name&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here 'number' is the name of my variable. As I am storing a number I named my variable 'number'. Variable names can be anything. However, there are some constraints and conventions of writing a variable name. We will look into that.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Assigning a value&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;'=' sign means we are assigning a value that comes after the sign. The value will be assigned to the variable which we have declared. In this case 10 is the value which we have assigned to the variable named 'number'. Now if I want to print the number 10 we can pass the variable name into the print function as follows.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Variables {
    public static void main(String[] args) {
        int number = 10;
        System.out.println(number);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Variable Naming Conventions
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Constraints&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Variable names cannot start with a number such as &lt;code&gt;int 1number = 1&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Variable names cannot have empty space such as &lt;code&gt;int number one = 1&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Conventions&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Give a proper variable name such as &lt;code&gt;int number = 1&lt;/code&gt; rather that using a single letter such as &lt;code&gt;int x = 1&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Use lowercase letters for naming a variable.&lt;/li&gt;
&lt;li&gt;You can find some of the proper naming conventions &lt;a href="https://curc.readthedocs.io/en/latest/programming/coding-best-practices.html"&gt;here&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Appendix
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;You can declare a variable without assigning a value. It will set a default value into the variable. Default value varies for different data types. For example int data type has default value 0.
&lt;/li&gt;
&lt;/ul&gt;

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;You can write comments in java code using double slash like this &lt;code&gt;//comments&lt;/code&gt;. Anything written after &lt;code&gt;//&lt;/code&gt; will not be executed in code.&lt;/li&gt;
&lt;li&gt;You can change the value of a variable. However, new value needs to be of the same data type as declared before. Also you don't need to declare variable type again while assigning a new value into the same variable.
&lt;/li&gt;
&lt;/ul&gt;

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;You cannot change data type of the same variable. Variable name must be unique.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int number = 10;
float number = 10.0; //you cannot do that
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Happy Coding.&lt;/p&gt;

</description>
      <category>java</category>
      <category>beginners</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Java Programming Language (Getting Started with Java)</title>
      <dc:creator>Nihal Islam</dc:creator>
      <pubDate>Sun, 28 Jan 2024 14:05:14 +0000</pubDate>
      <link>https://dev.to/nihalislam01/java-programming-language-getting-started-with-java-3n9p</link>
      <guid>https://dev.to/nihalislam01/java-programming-language-getting-started-with-java-3n9p</guid>
      <description>&lt;h2&gt;
  
  
  Installation Guide
&lt;/h2&gt;

&lt;p&gt;First thing we need to download to write java code is JDK(Java Development kit) which has all the required libraries and development tools.&lt;/p&gt;

&lt;p&gt;So go to browser and search for JDK and download the latest version.&lt;/p&gt;

&lt;p&gt;Then we need an environment to write code in a specific language. Just as we need Microsoft Word to write documents, we need an IDE(Integrated Development Environment) to write java program. My suggestion is to use IntelliJ Idea to write java code as a beginner.&lt;/p&gt;

&lt;p&gt;Go to browser, search for IntelliJ Idea and download the community edition.&lt;/p&gt;

&lt;p&gt;Open IntelliJ Idea and click New project. Give you project a name and leave the other settings as is. Then click create to create a new project. &lt;/p&gt;

&lt;p&gt;Congratulation you are now ready to write some java code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Hello World
&lt;/h2&gt;

&lt;p&gt;If you have created a project in IntelliJ Idea, you will already see a code written like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Main {
    public static void main(String[] args) {
        System.out.println("Hello, World!");
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you see an empty page go write this code and hit run. If you can see a console which prints the sentence 'Hello, World!' then congrats you have executed your first code in java.&lt;/p&gt;

&lt;p&gt;Now let us move on to the code. &lt;/p&gt;

&lt;p&gt;Firstly to execute our java code we need a class definition and inside a class definition we need to create our 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;class Main {
    public static void main(String[] args) {.....}
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here &lt;code&gt;class Main{}&lt;/code&gt; is the class and &lt;code&gt;public static void main(String[] args){}&lt;/code&gt; is the main method. Java compiler always executes the code inside the main method. So it is necessary to always create a class and inside a class create a main method. As this is the beginning of Java code, we will only focus on the code we write inside the main method between the curly braces. We will learn more about classes and methods later on. &lt;/p&gt;

&lt;p&gt;Now the code &lt;code&gt;System.out.println();&lt;/code&gt; is a built in java function which shows us the element in the console which we pass inside the parenthesis. In this case we pass a String &lt;code&gt;"Hello, World!"&lt;/code&gt; inside the function like this &lt;code&gt;System.out.println("Hello, World!");&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;String is a Data Type defined inside double quotation mark. We write anything inside double quotes is a string. If we write &lt;code&gt;"My Name is Nihal"&lt;/code&gt;, this will also be a string. And if we pass the string inside the print function, it will print the exact sentence in the console. Try to write your name as a string and print it in your console.&lt;/p&gt;

&lt;p&gt;We will learn more about Data Types in the chapter (Data Types).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Things to Remember&lt;/strong&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Always create a class and a main method before writing your code. &lt;/li&gt;
&lt;li&gt;Always put a semi colon after writing a line of code. We need semi colon to let the compiler know that we have ended our line of code.&lt;/li&gt;
&lt;li&gt;class name can be anything but it needs to match the filename. &lt;code&gt;class Main{}&lt;/code&gt; Here the class name is Main and the filename should also be Main.java.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>java</category>
      <category>beginners</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Quick Interview Crack (Unordered map)</title>
      <dc:creator>Nihal Islam</dc:creator>
      <pubDate>Fri, 16 Jun 2023 17:52:46 +0000</pubDate>
      <link>https://dev.to/nihalislam01/quick-interview-crack-unordered-map-2l84</link>
      <guid>https://dev.to/nihalislam01/quick-interview-crack-unordered-map-2l84</guid>
      <description>&lt;p&gt;Unordered map is a data structure in C++, which contains key value pairs. It can contain any type of pairs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Unordered set is implemented as hash table. It creates indices through hash table. As a result, the element inside the map is unordered where in map the keys are inserted in increasing order. And for searching an element in map takes O(logn) time where in unordered map the time complexity of searching an element is O(1). &lt;/p&gt;

&lt;h2&gt;
  
  
  Why is it different than unordered set?
&lt;/h2&gt;

&lt;p&gt;We can use unordered set when we only work with integers because unordered map contains value by indexes but we can set key value pair of any type in unordered map which is quite helpful to solve code problems in less time. Some of the common methods of unordered map are insert, delete, search etc.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to use unordered map?
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#include&amp;lt;unordered_map&amp;gt;

unordered_map&amp;lt;string, string&amp;gt; umap;

//inserting an element
umap["Fruit"] = "Apple";
umap["Flower"] = "Lily";

cout &amp;lt;&amp;lt; umap["Flower"] &amp;lt;&amp;lt; endl;
//Output Lily
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>Bit Manipulation (Part 2)</title>
      <dc:creator>Nihal Islam</dc:creator>
      <pubDate>Thu, 01 Jun 2023 12:39:33 +0000</pubDate>
      <link>https://dev.to/nihalislam01/bit-manipulation-part-2-463l</link>
      <guid>https://dev.to/nihalislam01/bit-manipulation-part-2-463l</guid>
      <description>&lt;p&gt;There are certain things we can do with bitwise operators. These operations are useful for coding interviews. I am just quickly showing an example of how we can use these bitwise operators.&lt;/p&gt;

&lt;h2&gt;
  
  
  Check ith Bit
&lt;/h2&gt;

&lt;p&gt;Checking the ith bit means to check whether the ith bit of a value is 0 or 1. For instance, if a value is &lt;code&gt;001010101&lt;/code&gt; and we want to know the 3rd bit, then the answer would be 0 and 0th bit would be 1. Remember i starts from 0 and it starts from right side.&lt;/p&gt;

&lt;p&gt;By using Left shift and AND operator, we can find the ith bit of a value. An example is given below,&lt;/p&gt;

&lt;p&gt;&lt;code&gt;(1 &amp;lt;&amp;lt; 0) &amp;amp; 13 = 1&lt;/code&gt;&lt;br&gt;
&lt;code&gt;(1 &amp;lt;&amp;lt; 1) &amp;amp; 13 = 0&lt;/code&gt;&lt;br&gt;
&lt;code&gt;(1 &amp;lt;&amp;lt; 2) &amp;amp; 13 = 4&lt;/code&gt;&lt;br&gt;
&lt;code&gt;(1 &amp;lt;&amp;lt; 3) &amp;amp; 13 = 8&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Here, 13 in binary is &lt;code&gt;1101&lt;/code&gt; and 1 in binary is &lt;code&gt;0001&lt;/code&gt;. Left shifting 1 by ith position will give us a value where the bit 1 is on the ith position and all the other bits are 0. For example if we left shift &lt;code&gt;0001&lt;/code&gt; by 2 position, it will look like this &lt;code&gt;0001 &amp;lt;&amp;lt; 2 = 0100&lt;/code&gt;. So, performing AND operation between (1 &amp;lt;&amp;lt; i) and and 13 will give us either 0 or some other number. If it is 0 then we can say the ith bit is 0, otherwise 1. &lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (((1 &amp;lt;&amp;lt; i) &amp;amp; value) &amp;gt; 0) {
    ith bit is 1;
} else {
    ith bit is 0;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You get the idea. There are many things we can do such as update ith bit, clear ith bit, check whether a number is power of 2 or not, etc. &lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
