<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Gaurav Shah on Medium]]></title>
        <description><![CDATA[Stories by Gaurav Shah on Medium]]></description>
        <link>https://medium.com/@gauravshah97?source=rss-62bc86d4416a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*QPwG6J5aPWQ_Wvei</url>
            <title>Stories by Gaurav Shah on Medium</title>
            <link>https://medium.com/@gauravshah97?source=rss-62bc86d4416a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 03:09:51 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@gauravshah97/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Modifiers in Java]]></title>
            <link>https://medium.com/@gauravshah97/modifiers-in-java-4b2cc8597424?source=rss-62bc86d4416a------2</link>
            <guid isPermaLink="false">https://medium.com/p/4b2cc8597424</guid>
            <category><![CDATA[modifier]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[access-modifier]]></category>
            <category><![CDATA[visibility-modifier]]></category>
            <category><![CDATA[java-certification]]></category>
            <dc:creator><![CDATA[Gaurav Shah]]></dc:creator>
            <pubDate>Sat, 22 Jun 2024 11:32:33 GMT</pubDate>
            <atom:updated>2024-06-22T11:32:33.735Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>In Java, modifiers define the scope, behavior, and properties of classes, methods, and variables. These modifiers are divided into two main categories access modifiers and non-access modifiers. In this blog, we’ll delve into the modifiers available in Java and their usage.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Uy6w83mG5PIBskVtsrK_rw.png" /><figcaption><strong>Modifiers in Java</strong></figcaption></figure><h3>Access Modifier:</h3><p>Access modifiers control the accessibility of a class or an interface, including its members (methods and variables), by other classes and interfaces within the same or separate packages. By using the appropriate access modifiers, you can limit access to your class or interface and its members.<br><strong>i.</strong> A top-level class can only be defined using public or default access modifiers.<br><strong>ii.</strong> Access modifiers can be applied to classes, interfaces, and their members (instance and class variables and methods).<br><strong>iii. </strong>Local variables and method parameters can’t be defined using access modifiers. An attempt to do so will prevent the code from compiling.</p><p>If a Java class, interface, method, or variable isn’t defined using an explicit access modifier, it is said to be defined using the default access, also called package access.</p><h4><strong>Java has four access levels:</strong></h4><p><strong>1. public</strong>: This is the least restrictive access modifier. Classes and interfaces defined using the public access modifier are accessible across all packages, from derived to unrelated classes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/619/0*It2ASKJSkEr32qdA.png" /><figcaption><strong>Scope of public access modifier</strong></figcaption></figure><p><strong>2. protected</strong>: The members of a class defined using the protected access modifier are accessible to<br><strong> — </strong>Classes and interfaces defined in the same package<br><strong> — </strong>All derived classes, even if they’re defined in separate packages</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/557/0*9936bp-Aq0ODZexE.png" /><figcaption><strong>Scope of protected access modifier</strong></figcaption></figure><p><strong>3. default</strong>: The members of a class defined without using any explicit access modifier are defined with package accessibility (also called default accessibility). The members with package access are only accessible to classes and interfaces defined in the same package. The default access is also referred to as package-private.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/569/0*3xdkpTnmUAGl-KrA.png" /><figcaption><strong>Scope of default access modifier</strong></figcaption></figure><p><strong>4. private</strong>: The private access modifier is the most restrictive. The members of a class defined using the private access modifier are accessible only to themselves.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/556/0*fOeBtnOhsWFkIvi5.png" /><figcaption><strong>Scope of private access modifier</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/0*lsTEA8m1OGyXy0Z4.png" /><figcaption><strong>Java entities and the access modifiers that can be applied to them</strong></figcaption></figure><h3>Non-access modifier:</h3><p>Non-access modifiers change the default behavior of a Java class and its members.</p><ol><li><strong>abstract modifier:</strong> When added to the definition of a class, interface, or method, the abstract modifier changes its default behavior.<br>■ <strong><em>Abstract class:</em></strong><em> </em>When the abstract keyword is prefixed to the definition of a concrete class, it changes it to an abstract class, even if the class doesn’t define any abstract methods.<br><strong> — </strong>An abstract class can’t be instantiated.<br><strong> — </strong>An abstract class may or may not define an abstract method. However, a concrete class can’t define an abstract method.<br>■ <strong><em>Abstract interface:</em> </strong>An interface is an abstract entity by default. Thus, adding the keyword abstract to the definition of an interface is redundant.<br>■ <strong><em>Abstract Method:</em></strong> An abstract method doesn’t have a body. Usually, an abstract method is implemented by a derived class.<br>■ <strong><em>Abstract Variables:</em></strong><em> </em>None of the different types of variables (instance, static, local, and method parameters) can be defined as abstract.</li><li><strong>final modifier: </strong>The keyword final can be used to declare a class, variable, or method.<br>It can’t be used with the declaration of an interface.<br>■<strong><em> Final class:</em></strong> A final marked class can’t be extended by another class.<br>■<strong><em> Final interface</em></strong><em>:</em> An interface can’t be marked as final. An interface is abstract by default and marking it with final will prevent your interface from compiling.<br>■<strong><em> Final variable:</em></strong> A final variable can’t be reassigned to a value. It can be assigned a value only once.<br>■<strong><em> Final method:</em></strong> A final method defined in a base class can’t be overridden by a derived class.</li><li><strong>static modifier:</strong> The non-access modifier static can be applied to the declarations of variables, methods, classes, and interfaces.<br>■<strong><em> static variable:</em></strong> static variables belong to a class. They’re common to all instances of a class and aren’t unique to any instance of a class.<br><strong> — </strong>static attributes exist independently of any instances of a class and may be accessed even when no instances of the class have been created.<br><strong> — </strong>A static variable is shared by all the objects of a class. static members belong to a class and not to individual objects.<br><strong> — </strong>The static and final non-access modifiers can be used together to define constants (variables whose value can’t change).<br>■<strong><em> static method:</em></strong> static methods aren’t associated with objects and can’t use any of the instance variables of a class. You can define static methods to access or manipulate static variables.<br><strong> — </strong>You can’t override the static members in a derived class, but you can redefine them.<br><strong> — </strong>Neither static methods nor static variables can access the non-static variables and methods of a class. But the reverse is true.<br><strong> — </strong>non-static variables and methods can access static variables and methods because the static members of a class exist even if no instances of the class exist.<br>■ <strong><em>static class and interface:</em> </strong>You can’t prefix the definition of a top-level class or an interface with the keyword static. But you can define a class and an interface as a static member of another class.</li><li><strong>synchronized:</strong> A synchronized method can’t be accessed by multiple threads concurrently.<br><strong> — </strong>The synchronized modifier can’t be applied to classes, interfaces, or variables with this modifier.</li><li><strong>native: </strong>A native method calls and makes use of libraries and methods implemented in other programming languages such as C or C++.<br><strong> — </strong>The native modifier can’t be applied to classes, interfaces, or variables with this modifier.</li><li><strong>transient:</strong> A transient variable isn’t serialized when the corresponding object is serialized.<br><strong> — </strong>The transient modifier can’t be applied to classes, interfaces, or methods.</li><li><strong>volatile:</strong> A volatile variable’s value can be safely modified by different threads.<br><strong> — </strong>The volatile modifier can’t be applied to Classes, interfaces, and methods.</li><li><strong>strictfp:</strong> classes, interfaces, and methods defined using this keyword ensure that calculations using floating-point numbers are identical on all platforms.<br><strong> — </strong>staticfp modifier can’t be used with variables.</li></ol><h3>Conclusion</h3><p>Understanding and using the modifiers correctly ensures that you control the accessibility and behavior of your classes, methods, and variables effectively in Java.</p><p>Oracle Certified Associate<strong> </strong>(<strong>OCA</strong>) <strong>certification overview</strong>:<br><a href="https://medium.com/@gauravshah97/oracle-certified-associate-java-se-8-programmer-d883ca58d80d"><strong>Oracle Certified Associate: Java SE 8 Programmer</strong></a></p><p>For more <strong>Java and Spring-Boot-related blogs</strong>, check out my profile:<br><a href="https://medium.com/@gauravshah97"><strong>https://medium.com/@gauravshah97</strong></a></p><p>Reach me out at:<br><a href="https://www.linkedin.com/in/gauravshah97/"><strong>https://www.linkedin.com/in/gauravshah97/</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4b2cc8597424" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Decision Constructs in Java]]></title>
            <link>https://medium.com/@gauravshah97/decision-constructs-in-java-3b0e77412160?source=rss-62bc86d4416a------2</link>
            <guid isPermaLink="false">https://medium.com/p/3b0e77412160</guid>
            <category><![CDATA[java-certification]]></category>
            <category><![CDATA[decision-constructs]]></category>
            <category><![CDATA[java-training]]></category>
            <category><![CDATA[oracle-certification]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Gaurav Shah]]></dc:creator>
            <pubDate>Sat, 18 May 2024 12:02:03 GMT</pubDate>
            <atom:updated>2024-05-20T07:45:30.550Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>Decision constructs are fundamental building blocks in programming that allow developers to control the execution flow based on certain conditions. In Java, the decision constructs empower developers to write flexible and efficient code by incorporating conditional statements and control flow structures. In this blog, we’ll delve into the various decision constructs available in Java, their syntax, and examples to illustrate their usage.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RGKqW9rLU8dplip2awJMJw.png" /><figcaption><strong>Decision Constructs</strong></figcaption></figure><h4>The if statement</h4><p>The <strong>if </strong>statement is the most basic decision construct in Java. It allows developers to execute a code block only if a specified condition evaluates to true. Let’s understand it with an example:</p><pre>class IfStatement {<br>    public static void main(String[] args) {<br>        int i = 10;<br>        if (i &gt; 5) {<br>            // code to be executed if the condition (i &gt; 5) is true<br>            System.out.println(&quot;i is greater than 5&quot;);<br>        }<br>        if (i &gt; 15) {<br>            // code to be executed if the condition (i &gt; 15) is true<br>            System.out.println(&quot;i is greater than 15&quot;);<br>        }<br>    }<br>}</pre><h4><strong>Output</strong></h4><blockquote>i is greater than 5</blockquote><h4>The if-else statement</h4><p>The <strong>if-else</strong> statement extends the functionality of the <strong>if </strong>statement by providing an alternative block of code to execute if the condition evaluates to false. Let’s understand it with an example:</p><pre>class IfElseStatement {<br>    public static void main(String[] args) {<br>        int i = 10;<br>        if (i &lt; 5) {<br>            // code to be executed if the condition (i &lt; 5) is true<br>            System.out.println(&quot;i is less than 5&quot;);<br>        } else {<br>            // code to be executed if the condition (i &lt; 5) is false<br>            System.out.println(&quot;i is greater than 5&quot;);<br>        }<br>    }<br>}</pre><h4><strong>Output</strong></h4><blockquote>i is greater than 5</blockquote><h4>The if-else-if statement</h4><p>When dealing with multiple conditions, the <strong>if-else-if</strong> statement allows developers to test various conditions sequentially until one evaluates to true, executing the corresponding code block. Let’s understand it with an example:</p><pre>class IfElseIfStatement {<br>    public static void main(String[] args) {<br>        int i = 15;<br>        if (i &lt; 5) {<br>            // code to be executed if the condition (i &lt; 5) is true<br>            System.out.println(&quot;i is less than 5&quot;);<br>        } else if (i &lt; 10) {<br>            // code to be executed if the condition (i &lt; 10) is true<br>            System.out.println(&quot;i is less than 10&quot;);<br>        } else {<br>             // code to be executed if all conditions are false<br>            System.out.println(&quot;i is greater than 10&quot;);<br>        }<br>    }<br>}</pre><h4>Output</h4><blockquote>i is greater than 10</blockquote><h4>Things to keep in mind while using the if statement</h4><ol><li>One course of action for an if construct (using only if and omitting the else part) is acceptable but you can’t define the else part for an if construct, skipping the if code block. <strong>The code won’t compile</strong>.</li><li>Using if(<em>testValue == true</em>) is the same as using if(<em>testValue</em>). <br>Similarly, if(<em>testValue == false</em>) is the same as if(<strong>!</strong><em>testValue</em>).</li><li>An if block is marked by enclosing one or more statements within a pair of curly braces <strong>{ }</strong>. An if block will execute a single line of code with no braces but will execute an unlimited number of lines if they’re contained within a block (defined using braces). <br>The braces are <strong>optional</strong> if there’s only one line in the if statement.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zTSnAvQAkJRzFUet0gOQ_A.png" /><figcaption><strong>if, if-else, and if-else-if statement</strong></figcaption></figure><h3>Ternary construct</h3><p>The ternary operator is a compact decision-making construct in Java. It allows you to write concise conditional expressions with a compact syntax. Unlike if-else statements, which are statements, the ternary operator is an <strong>expression</strong>, meaning it returns a value.<br>Ternary operators are useful to assign values or make decisions based on simple conditions in a single line, making your code more concise and readable.<br><strong>Syntax</strong> of the ternary operator:</p><blockquote><strong>result = (condition) ? expression1 : expression2</strong></blockquote><p>Here’s how it works:<br>The condition is evaluated first.<br>If it’s true, expression1 is executed. Otherwise, expression2 is executed.<br>The type of the result produced by the ternary operator is determined by the common type of the two expressions. <br>Let’s understand it with an example:</p><pre>class TernaryConstruct {<br>    public static void main(String[] args) { <br>        int age = 25;<br>        String message;<br>        message = (age &gt;= 18) ? &quot;You are an adult&quot; : &quot;You are not an adult&quot;;<br>        System.out.println(message);<br>    }<br>}</pre><h4>Output</h4><blockquote>You are an adult</blockquote><h4>The switch statement</h4><p>The <strong>switch </strong>statement is useful particularly when you have multiple possible execution paths based on the value of a variable. It evaluates the variable and executes the corresponding case block. Let’s understand it with an example:</p><pre>class SwitchStatement {<br>    public static void main(String[] args) { <br>        int dayOfWeek = 3;<br>        String dayName;<br>          switch (dayOfWeek) {<br>            case 1:<br>                // code to be executed if dayOfWeek equals 1<br>                dayName = &quot;Monday&quot;;<br>                break;<br>            case 2:<br>                // code to be executed if dayOfWeek equals 2<br>                dayName = &quot;Tuesday&quot;;<br>                break;<br>            case 3:<br>                // code to be executed if dayOfWeek equals 3<br>                dayName = &quot;Wednesday&quot;;<br>                break;<br>            case 4:<br>                // code to be executed if dayOfWeek equals 4<br>                dayName = &quot;Thursday&quot;;<br>                break;<br>            case 5:<br>                // code to be executed if dayOfWeek equals 5<br>                dayName = &quot;Friday&quot;;<br>                break;<br>            case 6:<br>                // code to be executed if dayOfWeek equals 6<br>                dayName = &quot;Saturday&quot;;<br>                break;<br>            case 7:<br>                // code to be executed if dayOfWeek equals 7<br>                dayName = &quot;Sunday&quot;;<br>                break;<br>            default:<br>                // code to be executed if none of the above cases are true<br>                dayName = &quot;Invalid day&quot;;<br>        }<br>          System.out.println(&quot;Today is &quot; + dayName); <br>    }<br>}</pre><h4>Output</h4><blockquote>Today is Wednesday</blockquote><h4>Things to keep in mind while using the switch statement</h4><ol><li>A switch statement accepts arguments of types char, byte, short, int, and String. It also accepts arguments and expressions of enum, Character, Byte, Integer, and Short type.</li><li>The switch statement <strong>doesn’t accept</strong> arguments of type long, float, double, or any object besides String.</li><li>Apart from passing a variable to a switch statement, you can also pass an <strong>expression </strong>to a switch statement as long as it returns one of the allowed types.</li><li>Values passed to the label case of a switch statement should be <strong>compile-time constants. </strong>That is the value should be known at the time of code compilation. If using an expression in the switch case, the variables must be declared as final so that it’s constant and can’t be manipulated.</li><li>null is not allowed as a case label. Code that compares the variable passed to the switch statement with null <strong>won’t compile</strong>.</li><li>When a break statement is reached, the switch terminates, and the flow control jumps to the next line following the switch statement.</li><li>Not every case needs to contain a break. If <strong>no break</strong> appears, the flow control will fall through to subsequent cases until a break is reached.</li><li>A switch statement can have an <strong>optional</strong> <strong>default case</strong>, which must appear at the end of the switch. The default case can be used for performing a task when none of the cases is true. No break is needed in the default case.</li></ol><h3>Conclusion</h3><p>Decision constructs are essential tools in Java for controlling the flow of your programs. Understanding and effectively utilizing <strong>if</strong>, <strong>if-else</strong>, <strong>if-else-if</strong>, <strong>switch</strong>, and the <strong>ternary operator </strong>allows you to write more flexible and efficient code. You can handle complex decision-making processes and build robust Java applications by mastering these constructs.</p><p>Oracle Certified Associate<strong> </strong>(<strong>OCA</strong>) <strong>certification overview</strong>:<br><a href="https://medium.com/@gauravshah97/oracle-certified-associate-java-se-8-programmer-d883ca58d80d"><strong>Oracle Certified Associate: Java SE 8 Programmer</strong></a></p><p>For more <strong>Java and Spring-Boot-related blogs</strong>, check out my profile:<br><a href="https://medium.com/@gauravshah97"><strong>https://medium.com/@gauravshah97</strong></a></p><p>Reach me out at:<br><a href="https://www.linkedin.com/in/gauravshah97/"><strong>https://www.linkedin.com/in/gauravshah97/</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3b0e77412160" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Operators in Java]]></title>
            <link>https://medium.com/@gauravshah97/operators-in-java-12b85530416f?source=rss-62bc86d4416a------2</link>
            <guid isPermaLink="false">https://medium.com/p/12b85530416f</guid>
            <category><![CDATA[java-operator]]></category>
            <category><![CDATA[java-certification]]></category>
            <category><![CDATA[oracle-certification]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[java-training]]></category>
            <dc:creator><![CDATA[Gaurav Shah]]></dc:creator>
            <pubDate>Sat, 20 Apr 2024 12:02:07 GMT</pubDate>
            <atom:updated>2024-04-26T04:25:42.174Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>In the programming world, operators are indispensable tools that enable developers to perform various operations on data. In this blog post, we’ll delve into the world of operators in Java.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*72Yeu3s_qDICzp7XZUM6LA.png" /><figcaption>Operators in Java</figcaption></figure><h3>Types of Operators</h3><p>Being one of the most popular programming languages, Java offers a rich set of operators that facilitate tasks ranging from simple arithmetic operations to complex logical manipulations. A few of the Operators are:</p><ol><li>Arithmetic Operators</li><li>Assignment Operators</li><li>Bitwise Operators</li><li>Comparison Operators</li><li>Logical Operators</li><li>Unary Operators</li></ol><h4>Arithmetic Operators</h4><p>Arithmetic operators perform mathematical operations such as addition, subtraction, multiplication, and division. In Java, the basic arithmetic operators include addition (+), subtraction (-), multiplication (*), division (/), and modulus (%). Let’s see some examples:</p><pre>class ArithmeticOperators {<br>    public static void main(String[] args) {<br>        int a = 10;<br>        int b = 5;<br>        int sum = a + b; // Addition<br>        int difference = a - b; // Subtraction<br>        int product = a * b; // Multiplication<br>        int quotient = a / b; // Division<br>        int remainder = a % b; // Modulus<br><br>        System.out.println(&quot;a + b = &quot;+sum);<br>        System.out.println(&quot;a - b = &quot;+difference);<br>        System.out.println(&quot;a * b = &quot;+product);<br>        System.out.println(&quot;a / b = &quot;+quotient);<br>        System.out.println(&quot;a % b = &quot;+remainder);<br>    }<br>}</pre><h4>Output</h4><blockquote>a + b = 15<br>a — b = 5<br>a * b = 50<br>a / b = 2<br>a % b = 0</blockquote><h4>Assignment Operators</h4><p>Assignment Operators are used to assign values to variables. They include the simple assignment operator (=) and compound assignment operators like +=, -=, *=, /=, and %=, which combine arithmetic operations with assignment operations.</p><pre>class AssignmentOperators {<br>    public static void main(String[] args) {<br>        int a = 10; // Assignment Operator<br>        int b = 5;<br>        int d = 30;<br>        <br>        d+=a;       // d = d + a;<br>        System.out.println(&quot;d+=a &quot;+ d);<br>        System.out.println(&quot;d = &quot;+ d);<br>        d-=b;       // d = d - b;<br>        System.out.println(&quot;d-=b &quot;+ d);<br>        System.out.println(&quot;d = &quot;+ d);<br>        a*=b;       // a = a * b;<br>        System.out.println(&quot;a*=b &quot;+ a);<br>        System.out.println(&quot;a = &quot;+ a);<br>    }<br>}</pre><h4>Output</h4><blockquote>d+=a 40<br>d = 40<br>d-=b 35<br>d = 35<br>a*=b 50<br>a = 50</blockquote><h4>Bitwise Operators</h4><p>Bitwise operators are used to perform operations on individual bits of integers. They are often used in low-level programming and for manipulating binary data. Java supports bitwise AND (&amp;), bitwise OR (|), bitwise XOR (^), bitwise complement (~), left shift (&lt;&lt;), and right shift (&gt;&gt;).</p><pre>class BitwiseOperators {<br>    public static void main(String[] args) {<br>        int a = 10; // binary: 1010<br>        int b = 5;  // binary: 0101<br>        int c = 3; // binary: 0011<br>        int bitwiseAnd = b &amp; c; // binary: 0001 (1 in decimal)<br>        int bitwiseOr = a | b; // binary: 1111 (15 in decimal)<br>        <br>        System.out.println(&quot;b &amp; c = &quot;+ bitwiseAnd);<br>        System.out.println(&quot;a | b = &quot;+ bitwiseOr);<br>    }<br>}</pre><h4>Output</h4><blockquote>b &amp; c = 1<br>a | b = 15</blockquote><h4>Comparison Operators</h4><p>Comparison operators are used to compare two values. They return a boolean result indicating whether the comparison is true or false. Common comparison operators in Java include == (equal to), != (not equal to), &gt; (greater than), &lt; (less than), &gt;= (greater than or equal to), and &lt;= (less than or equal to).</p><pre>class ComparisonOperators {<br>    public static void main(String[] args) {<br>        int a = 10;<br>        int b = 5;<br>        int c = 10;<br>        boolean isEqual = (a == b);         // false<br>        boolean isGreater = (a &gt; b);        // true<br>        boolean isLess = (a &lt; c);           // false<br>        boolean isLessOrEqual = (a &lt;= c);   // true<br>        <br>        System.out.println(&quot;is a == b : &quot;+ isEqual);<br>        System.out.println(&quot;is a &gt; b : &quot;+ isGreater);<br>        System.out.println(&quot;is a &lt; c : &quot;+ isLess);<br>        System.out.println(&quot;is a &lt;= c : &quot;+ isLessOrEqual);<br>    }<br>}</pre><h4>Output</h4><blockquote>is a == b : false<br>is a &gt; b : true<br>is a &lt; c : false<br>is a &lt;= c : true</blockquote><h4>Logical Operators</h4><p>Logical operators are used to perform logical operations on boolean values. Java provides three logical operators: &amp;&amp; (logical AND), || (logical OR), and ! (logical NOT).</p><pre>class LogicalOperators {<br>    public static void main(String[] args) {<br>        boolean b1 = true;<br>        boolean b2 = false;<br>        boolean andOperation = b1 &amp;&amp; b2; // false<br>        boolean orOperation = b1 || b2; // true<br>        boolean notOperation = !b1;     // false<br><br>        <br>        System.out.println(&quot;b1 &amp;&amp; b2 = &quot;+ andOperation);<br>        System.out.println(&quot;b1 || b2 = &quot;+ orOperation);<br>        System.out.println(&quot;!b1 = &quot;+ notOperation);<br>    }<br>}</pre><h4>Output</h4><blockquote>b1 &amp;&amp; b2 = false<br>b1 || b2 = true<br>!b1 = false</blockquote><h4>Unary Operators</h4><p>Unary Operators are used to perform operations such as negating an expression, incrementing or decrementing a value by one, and inverting the value of a boolean.</p><pre>class UnaryOperators {<br>    public static void main(String[] args) {<br>        int a = 10;<br>        int b = -a;     // b becomes -10<br>        int c = +a;     // c remains 10<br>        int count = 50;<br>        boolean isTrue = true;<br>        boolean isFalse = !isTrue;      // false<br>        <br>        System.out.println(&quot;b = &quot;+ b);<br>        System.out.println(&quot;c = &quot;+ c);<br>        System.out.println(&quot;isFalse = &quot;+ isFalse);<br>        System.out.println(&quot;++count = &quot;+ ++count);  // Prefix increment: count becomes 51<br>        System.out.println(&quot;count++ = &quot;+ count++);  // Postfix increment: count becomes 52<br>        System.out.println(&quot;count = &quot;+ count);<br>        System.out.println(&quot;--count = &quot;+ --count);  // Prefix decrement: count becomes 51<br>        System.out.println(&quot;count-- = &quot;+ count--);  // Postfix decrement: count becomes 50<br>        System.out.println(&quot;count = &quot;+ count);<br>    }<br>}</pre><h4>Output</h4><blockquote>b = -10<br>c = 10<br>isFalse = false<br>++count = 51<br>count++ = 51<br>count = 52<br> — count = 51<br>count — = 51<br>count = 50</blockquote><h3>Operator Precedence</h3><p>Operator precedence defines the order in which operators are evaluated when multiple operators appear in the same expression. Operators with higher precedence are evaluated before operators with lower precedence. Parentheses can be used to override the default precedence and control the order of evaluation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/983/1*RJFHPevlotGDTfnUCg4W8g.png" /><figcaption><strong>Precedence of operators</strong></figcaption></figure><h4>Importance of Understanding Operator Precedence</h4><p><strong>Writing correct expressions:</strong> Understanding precedence ensures that expressions are evaluated as intended, avoiding unexpected results.<br><strong>Improving readability: </strong>Explicitly specifying the order of evaluation using parentheses enhances code readability and makes it easier for others to understand.<br><strong>Enhancing efficiency:</strong> Proper use of precedence can lead to more efficient code execution by reducing unnecessary evaluations.</p><p>Oracle Certified Associate<strong> </strong>(<strong>OCA</strong>) <strong>certification overview</strong>:<br><a href="https://medium.com/@gauravshah97/oracle-certified-associate-java-se-8-programmer-d883ca58d80d"><strong>Oracle Certified Associate: Java SE 8 Programmer</strong></a></p><p>For more <strong>Java and Spring-Boot-related blogs</strong>, check out my profile:<br><a href="https://medium.com/@gauravshah97"><strong>https://medium.com/@gauravshah97</strong></a></p><p>Reach me out at:<br><a href="https://www.linkedin.com/in/gauravshah97/"><strong>https://www.linkedin.com/in/gauravshah97/</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=12b85530416f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Install Maven on Windows]]></title>
            <link>https://medium.com/@gauravshah97/how-to-install-maven-on-windows-39ff317e40cf?source=rss-62bc86d4416a------2</link>
            <guid isPermaLink="false">https://medium.com/p/39ff317e40cf</guid>
            <category><![CDATA[maven-installation]]></category>
            <category><![CDATA[how-to-install-maven]]></category>
            <category><![CDATA[windows-11]]></category>
            <category><![CDATA[install-maven-on-windows]]></category>
            <category><![CDATA[maven]]></category>
            <dc:creator><![CDATA[Gaurav Shah]]></dc:creator>
            <pubDate>Sat, 23 Mar 2024 10:32:23 GMT</pubDate>
            <atom:updated>2024-04-13T10:41:24.559Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>Maven is a popular open-source build tool developed by <a href="https://apache.org/"><strong>The Apache Sofware Foundation</strong></a> to build, publish, and deploy several projects simultaneously for better project management. The tool allows developers to build and document the lifecycle framework.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/848/1*zYumOQBmy6uq99XPGm7OWg.png" /></figure><h4>Pre-requisite</h4><p>Before installing Maven, ensure you have Java installed and ready to use in your machine with the <strong>JAVA_HOME</strong> environment variable set up.<br>(To learn about how to install Java or how to set up the JAVA_HOME environment variable, refer to the <a href="https://medium.com/@gauravshah97/how-to-install-java-on-windows-20fb8c329b74"><strong>Guide to Install Java on Windows</strong></a>)</p><h3>Download and Install Maven</h3><h4>Download the Maven Zip File</h4><p>To download the Maven zip file<br><strong>1.</strong> Open a web browser and go to <a href="https://maven.apache.org/download.cgi"><strong>Maven Download Page</strong></a>.<br><strong>2.</strong> Click on the appropriate link to download the binary zip archive of the latest version of Maven. In this example, the latest available version is <strong>Maven 3.9.6</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eB2bMkoEt55vSfz1LvoVhw.png" /><figcaption>Download Maven</figcaption></figure><p><strong>Note<em>: </em></strong><em>The download page usually contains the latest available version. You can access the earlier version using the archives link in the Previous Releases section.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RsIKABD_sCQR0xpiLOvD-g.png" /><figcaption><strong>Selecting an Older Version</strong></figcaption></figure><p><strong>3.</strong> Maven does not require any installation process. Just extract the Maven archive to a directory of your choice once the download is complete. For this tutorial, we are using <strong><em>C:\Program Files\Maven\apache-maven-3.9.6</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xE5F0sSviwIztibVS237eQ.png" /><figcaption>Maven Folder</figcaption></figure><h3>Set Environment Variables</h3><p>To configure Maven environment variables in Windows, follow the following steps</p><h4>1. Add MAVEN_HOME System Variable</h4><p><strong>1. </strong>Open the Start menu and search for environment variables.<br><strong>2. </strong>Select <strong>Edit the system environment variables</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f0tvTKM64n0Fi4Cw_2VRvQ.png" /><figcaption>Edit Environment Variables</figcaption></figure><p><strong>3. </strong>Select the <strong>Advanced </strong>tab in the System Properties window.<br><strong>4. </strong>Click <strong>Environment Variables</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/607/1*Qv7inxSBNuWvFof6-6OaXA.png" /></figure><p><strong>5.</strong> Click <strong>New </strong>under the <strong>System variables</strong> category to create a new variable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/877/1*hgZwtNn38fX-DNWTogE9fg.png" /></figure><p><strong>5. </strong>Name the variable <strong>MAVEN_HOME</strong>.<br><strong>6.</strong> Enter the path to your Maven Extract directory in the variable value field.<br><strong>7. </strong>Click <strong>OK</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/928/1*6dvZDA3OdIByxSiMNUIwXg.png" /></figure><h4>2. Add Maven to the Path Variable</h4><p><strong>1. </strong>In the Environment Variables wizard, Select the <strong>Path </strong>variable in the System variables category and click <strong>Edit</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/870/1*f6qQrqqhhnTmtPByZ_rpvw.png" /></figure><p>2. Click <strong>New</strong>.<br>3. Enter the path as <strong>%MAVEN_HOME%\bin</strong>.<br>4. Click <strong>OK </strong>to save the changes and exit the variable editing window.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/757/1*igscrGtjLTcJ1oQUa1Qi4Q.png" /></figure><p>Confirm the changes by clicking <strong>OK </strong>in the Environment Variables and System properties windows.</p><h3>Verify Maven Installation</h3><p>Verify that Maven is installed by entering the mvn -version command in the command prompt. If installed correctly, the command outputs the maven version.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Wky-hhQ9uW1Rp9HlIfNkTQ.png" /></figure><p><strong>Installing Java on Windows</strong>: A Beginner’s Guide<br><a href="https://medium.com/@gauravshah97/how-to-install-java-on-windows-20fb8c329b74"><strong>How to install Java on Windows</strong></a></p><p>For more <strong>Java-related blogs</strong>, check out my profile:<br><a href="https://medium.com/@gauravshah97"><strong>https://medium.com/@gauravshah97</strong></a></p><p>Reach me out at:<br><a href="https://www.linkedin.com/in/gauravshah97/"><strong>https://www.linkedin.com/in/gauravshah97/</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=39ff317e40cf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Install Java on Windows]]></title>
            <link>https://medium.com/@gauravshah97/how-to-install-java-on-windows-20fb8c329b74?source=rss-62bc86d4416a------2</link>
            <guid isPermaLink="false">https://medium.com/p/20fb8c329b74</guid>
            <category><![CDATA[how-to-install-java]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[java21]]></category>
            <category><![CDATA[wi̇ndows11]]></category>
            <category><![CDATA[windows]]></category>
            <dc:creator><![CDATA[Gaurav Shah]]></dc:creator>
            <pubDate>Sun, 25 Feb 2024 05:30:01 GMT</pubDate>
            <atom:updated>2024-04-13T10:36:45.992Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>The Java Development Kit (JDK) is a set of software tools for developing Java applications. The toolkit includes a compiler for converting Java code into bytecode, a collection of class libraries, documentation for integrating Java APIs, and the Java Runtime Environment (JDE) for executing Java code. The JDK provides developers with the resources they need to create Java applications and applets in one neat package.</p><figure><img alt="Cover image" src="https://cdn-images-1.medium.com/max/907/1*qfC10jd9pOAtgN31ueFCWQ.png" /></figure><h3>Download and Install Java</h3><h4>Download Java Development Kit (JDK)</h4><p>To download the Java Development Kit installation file <br><strong>1. </strong>Open a web browser and go to the <a href="https://www.oracle.com/java/technologies/downloads/#jdk21-windows"><strong>Oracle Java Downloads page</strong></a>.<br><strong>2. </strong>Select the latest JDK version. In this example, the latest available version is <strong>JDK 21</strong>.<br><strong>3.</strong> Navigate to the <strong>Windows </strong>tab.<br><strong>4.</strong> Click the x64 Installer <strong>download </strong>link.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C-YbwWSYVByhWiQny1bDnw.png" /><figcaption>Java Download</figcaption></figure><p>Wait for the download to complete.</p><h4>Install Java Development Kit</h4><p>To install Java Development Kit on your Windows system:<br><strong>1. </strong>Double-click the downloaded Java file to start the installation.<br><strong>2.</strong> Once the installation wizard welcome screen appears, select <strong>Next </strong>to proceed.</p><figure><img alt="Java Installation Start Wizard" src="https://cdn-images-1.medium.com/max/778/1*u3ORp1TwtcQfl30EZ0VsKw.png" /><figcaption>Java Installation Start Wizard</figcaption></figure><p><strong>3.</strong> Choose the destination folder for the Java installation files, or stick to the default path and click <strong>Next</strong>.</p><figure><img alt="Java Installation Path Selection wizard" src="https://cdn-images-1.medium.com/max/788/1*zS3tcniYj-VWjqf5MFTofg.png" /><figcaption>Java Installation Path Selection wizard</figcaption></figure><p><strong>4.</strong> The installation process is complete when the Successfully Installed message appears. Click <strong>Close </strong>to exit the wizard.</p><figure><img alt="Java Installation Successful wizard" src="https://cdn-images-1.medium.com/max/788/1*QT-pm0uswfTufSZZhhzAIg.png" /><figcaption>Java Installation Successful wizard</figcaption></figure><p>The JDK 21 is successfully installed on your Windows system. To enable program compiling from any directory, you must set up Java environment variables.</p><h3>Set Environment Variables</h3><p>To configure Java environment variables in Windows, follow the following steps</p><h4>1. Add JAVA_HOME System Variable</h4><p>Some applications require the <strong>JAVA_HOME </strong>variable to point to the JDK installation directory. Follow the steps below to create the variable:<br><strong>1. </strong>Open the <strong>Start</strong> menu and search for environment variables.<br><strong>2. </strong>Select <strong>Edit the system environment variables.</strong></p><figure><img alt="Edit environment Variables" src="https://cdn-images-1.medium.com/max/1024/1*sqS_Z4MLBr-pJBG7ZmLP_w.png" /><figcaption>Edit Environment Variables</figcaption></figure><p><strong>3. </strong>Select <strong>Advanced </strong>in the System Properties window.<br><strong>4. </strong>Click <strong>Environment Variables</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/607/1*Qv7inxSBNuWvFof6-6OaXA.png" /></figure><p><strong>5.</strong> Click <strong>New </strong>under the <strong>System variables</strong> category to create a new variable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/877/1*hgZwtNn38fX-DNWTogE9fg.png" /></figure><p><strong>6.</strong> Name the variable <strong>JAVA_HOME</strong>.<br><strong>7. </strong>Enter the path to your Java JDK directory in the variable value field.<br><strong>8.</strong> Click OK.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/929/1*vTwAemHbjr8vjC-zZ2B3-w.png" /></figure><h4>2. Add Java to Path Variables</h4><p>Setting up Java System Variable ensures that Java is accessible from the command line in any directory.<br><strong>1.</strong> In the Environment Variables wizard, Select the <strong>Path </strong>variable in the System variables category and click <strong>Edit</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/870/1*f6qQrqqhhnTmtPByZ_rpvw.png" /></figure><p><strong>2. </strong>Click New.<br><strong>3.</strong> Enter the path as <strong>%JAVA_HOME%\bin</strong>.<br><strong>4. </strong>Click OK to save the changes and exit the variable editing window.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/745/1*j5LxG6wmjPX8kGeqrnLmPA.png" /></figure><p>Confirm the changes by clicking OK in the Environment Variables and System properties windows.</p><h3>Test Java Installation</h3><p>Verify that Java is installed by entering the <strong>java -version</strong> command in the command prompt. If installed correctly, the command outputs the Java version.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_UHrKsPzHwWdSh0CgOKcWg.png" /></figure><p><strong>Installing Maven on Windows</strong>: A Beginner’s Guide<br><a href="https://medium.com/@gauravshah97/how-to-install-maven-on-windows-39ff317e40cf"><strong>How to Install Maven on Windows</strong></a></p><p>For more <strong>Java and Spring-Boot-related blogs</strong>, check out my profile:<br><a href="https://medium.com/@gauravshah97"><strong>https://medium.com/@gauravshah97</strong></a></p><p>Reach me out at:<br><a href="https://www.linkedin.com/in/gauravshah97/"><strong>https://www.linkedin.com/in/gauravshah97/</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=20fb8c329b74" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Wrapper Classes in Java]]></title>
            <link>https://medium.com/@gauravshah97/wrapper-classes-in-java-0c5d9205f3b3?source=rss-62bc86d4416a------2</link>
            <guid isPermaLink="false">https://medium.com/p/0c5d9205f3b3</guid>
            <category><![CDATA[oracle-certification]]></category>
            <category><![CDATA[java-certification]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[oracle-certified-training]]></category>
            <category><![CDATA[wrapper-class]]></category>
            <dc:creator><![CDATA[Gaurav Shah]]></dc:creator>
            <pubDate>Sun, 28 Jan 2024 09:32:01 GMT</pubDate>
            <atom:updated>2024-04-26T04:55:33.887Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>Java defines a wrapper class for each of its primitive data types. A Wrapper class in Java is one whose object wraps or contains primitive data types. Wrapper classes help you write cleaner code, which is easy to read.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D0s9l3ZWgEs4P26UbXoJEQ.png" /><figcaption><strong>Wrapper Classes</strong></figcaption></figure><h3>Need &amp; Advantages of Wrapper Class</h3><ol><li>Java collection framework works with objects only. All classes of the collection framework (ArrayList, LinkedList, HashSet, etc.) deal with objects only.</li><li>Serialization can be achieved via Wrapper classes. Serialization is converting the objects into streams. If we have a primitive value, we can convert it into objects through the wrapper classes.</li><li>If we pass a primitive value as a method parameter, it will not change the original value. But, if we convert the primitive value into an object, we can change its original value.</li><li>The java.util package provides the utility classes to deal with objects.</li><li>Synchronization can be achieved via Wrapper classes as synchronization works with objects in Multithreading.</li></ol><h3>Wrapper Classes and Their Hierarchy</h3><h4>Primitive data types and their corresponding wrapper class</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c662e6cb8242c4910868189b4836ee4c/href">https://medium.com/media/c662e6cb8242c4910868189b4836ee4c/href</a></iframe><h4>Hierarchy of wrapper classes</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/858/1*xzpnylQkUFHCB8F2QYkmRA.png" /><figcaption><strong>Hierarchy of wrapper classes</strong></figcaption></figure><ol><li>All the numeric wrapper classes (Byte, Short, Integer, Long, Float, Double) extend the class java.lang.Number.</li><li>Classes Boolean and Character directly extend the class Object.</li><li>All the wrapper classes implement the interfaces java.io.Serializable and java.lang.Comparable.</li></ol><h3>Autoboxing and Unboxing</h3><h4>Autoboxing</h4><p>Autoboxing is the automatic conversion of a primitive data type to an object of the corresponding wrapper class. <br>For example, boolean to Boolean, char to Character, byte to Byte, short to Short, int to Integer, long to Long, float to Float, and double to Double.</p><pre>class Autoboxing {<br>    public static void main(String[] args) {<br>        Boolean bool = true;<br>        Character ch = &#39;c&#39;;<br>        Byte b = 2;<br>        Short s = 2;<br>        Integer i = 1;<br>        Long l = 4L;<br>        Float f = 1.2f;<br>        Double d = 1.2;<br>    }<br>}</pre><h4>Unboxing</h4><p>Unboxing is just the reverse process of autoboxing. It is the automatic conversion of a wrapper class object to the corresponding primitive data type.</p><h3>Ways to create an object of Wrapper Class</h3><p>You can create objects of all the wrapper classes in multiple ways</p><ol><li><strong>Autoboxing</strong></li><li><strong>Constructor</strong><br>All the wrapper classes define constructors to create an object using a corresponding primitive value.<br>All wrapper classes (<strong><em>except Character</em></strong>) also define a constructor that accepts a String argument representing the primitive value that needs to be wrapped.</li><li><strong>Static Method<br></strong>All wrapper classes (<strong><em>except Character</em></strong>) also define a static method that accepts a String argument representing the primitive value that needs to be wrapped.</li></ol><pre>class WrapperUsingConstructor {<br>    public static void main(String[] args) {<br><br>//      Constructors that accepts primitive Value<br>        Boolean bool1 = new Boolean(true);<br>        Character char1 = new Character(&#39;c&#39;);<br>        Byte byte1 = new Byte((byte) 3);<br>        Short short1 = new Short((short) 2);<br>        Integer int1 = new Integer(1);<br>        Long long1 = new Long(4L);<br>        Float float1 = new Float(1.2f);<br>        Double double1 = new Double(1.5);<br><br>//      Constructors that accepts String Value<br>        Boolean bool2 = new Boolean(&quot;true&quot;);<br>//      Character char2 = new Character(&quot;c&quot;);  -&gt; Won&#39;t compile<br>        Byte byte2 = new Byte(&quot;3&quot;);<br>        Short short2 = new Short(&quot;2&quot;);<br>        Integer int2 = new Integer(&quot;1&quot;);<br>        Long long2 = new Long(&quot;4&quot;);<br>        Float float2 = new Float(&quot;1.2&quot;);<br>        Double double2 = new Double(&quot;1.5&quot;);<br><br>    }<br>}</pre><pre>class WrapperUsingStaticMethod {<br>    public static void main(String[] args) {<br>//      Static methods that accepts primitive Value<br>        Boolean bool1 = Boolean.valueOf(true);<br>        Character char1 = Character.valueOf(&#39;c&#39;);<br>        Byte byte1 = Byte.valueOf((byte) 3);<br>        Short short1 = Short.valueOf((short) 2);<br>        Integer int1 = Integer.valueOf(1);<br>        Long long1 = Long.valueOf(4L);<br>        Float float1 = Float.valueOf(1.2f);<br>        Double double1 = Double.valueOf(1.5);<br><br>//      Static methods that accepts String Value<br>        Boolean bool2 = Boolean.valueOf(&quot;true&quot;);<br>//      Character char2 = Character.valueOf(&quot;c&quot;);  -&gt; Won&#39;t compile<br>        Byte byte2 = Byte.valueOf(&quot;3&quot;);<br>        Short short2 = Short.valueOf(&quot;2&quot;);<br>        Integer int2 = Integer.valueOf(&quot;1&quot;);<br>        Long long2 = Long.valueOf(&quot;4&quot;);<br>        Float float2 = Float.valueOf(&quot;1.2&quot;);<br>        Double double2 = Double.valueOf(&quot;3.5&quot;);<br><br>    }<br>}</pre><h3>Retrieving primitive value from the wrapper object</h3><p>To get a primitive data type value corresponding to a wrapper object, you can use the static utility method <strong><em>dataTypeValue</em></strong>. Each wrapper class defines a method to retrieve the primitive value.</p><pre>class WrapperToPrimitive {<br>    public static void main(String[] args) {<br><br>        Boolean bool2 = Boolean.valueOf(&quot;true&quot;);<br>        Character char2 = Character.valueOf(&#39;c&#39;);<br>        Byte byte2 = Byte.valueOf(&quot;3&quot;);<br>        Short short2 = Short.valueOf(&quot;2&quot;);<br>        Integer int2 = Integer.valueOf(&quot;1&quot;);<br>        Long long2 = Long.valueOf(&quot;4&quot;);<br>        Float float2 = Float.valueOf(&quot;1.2&quot;);<br>        Double double2 = Double.valueOf(&quot;3.5&quot;);<br><br>  //    Retrieve primitive value from the wrapper object<br>        boolean bool = bool2.booleanValue();<br>        char ch = char2.charValue();<br>        byte b = byte2.byteValue();<br>        short s = short2.shortValue();<br>        int i = int2.intValue();<br>        long l = long2.longValue();<br>        float f = float2.floatValue();<br>        double d = double2.doubleValue();<br><br>    }<br>}</pre><h3><strong>Parsing a string value to a primitive type</strong></h3><p>To get a primitive data type value corresponding to a string value, you can use the static utility method <strong><em>parseDataType</em></strong>. Each wrapper class (<strong><em>except Character</em></strong>) defines a method to parse a String to the corresponding primitive value.</p><pre>class StringToPrimitive {<br>    public static void main(String[] args) {<br>//      Retrieve primitive value from string<br>        boolean bool = Boolean.parseBoolean(&quot;true&quot;);<br>        byte b = Byte.parseByte(&quot;2&quot;);<br>        short s = Short.parseShort(&quot;3&quot;);<br>        int i = Integer.parseInt(&quot;4&quot;);<br>        long l = Long.parseLong(&quot;5&quot;);<br>        float f = Float.parseFloat(&quot;6.6&quot;);<br>        double d = Double.parseDouble(&quot;7.7&quot;);<br>    }<br>}</pre><p>Oracle Certified Associate<strong> </strong>(<strong>OCA</strong>) <strong>certification overview</strong>:<br><a href="https://medium.com/@gauravshah97/oracle-certified-associate-java-se-8-programmer-d883ca58d80d"><strong>Oracle Certified Associate: Java SE 8 Programmer</strong></a></p><p>For more <strong>Java and Spring-Boot-related blogs</strong>, check out my profile:<br><a href="https://medium.com/@gauravshah97"><strong>https://medium.com/@gauravshah97</strong></a></p><p>Reach me out at:<br><a href="https://www.linkedin.com/in/gauravshah97/"><strong>https://www.linkedin.com/in/gauravshah97/</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0c5d9205f3b3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Working with Java Datatypes]]></title>
            <link>https://medium.com/@gauravshah97/working-with-java-datatypes-fd8f333fcd24?source=rss-62bc86d4416a------2</link>
            <guid isPermaLink="false">https://medium.com/p/fd8f333fcd24</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[oracle-certified-training]]></category>
            <category><![CDATA[oracle-certification]]></category>
            <category><![CDATA[java-certification]]></category>
            <category><![CDATA[java-datatypes]]></category>
            <dc:creator><![CDATA[Gaurav Shah]]></dc:creator>
            <pubDate>Sun, 17 Dec 2023 04:41:00 GMT</pubDate>
            <atom:updated>2024-04-26T04:31:16.709Z</atom:updated>
            <content:encoded><![CDATA[<h3>Java Datatypes</h3><p>The Java programming language is statically typed, meaning all variables must be declared before being used. This involves stating the variable’s type and name, for example:</p><pre>int id = 1;</pre><p>Doing so tells your program that a field named “id” exists, holds numerical data, and has an initial value of “1”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gJgQcBXvmRI3ibvc4IkSjQ.png" /><figcaption><strong>Java data types</strong></figcaption></figure><p>In Java, the data types are broadly classified into two types.<br><strong>1. </strong>Primitive Data Type<br><strong>2.</strong> Non-Primitive Data Type</p><h3>Primitive Data Type</h3><p>A primitive type is predefined by the language, specifies the size and type of variable values, and is named by a reserved keyword.</p><p>There are eight primitive data types in Java:</p><figure><img alt="Primitive data type hierarchy" src="https://cdn-images-1.medium.com/max/1024/1*03mwl9duGlrLrBPZaF4IZw.png" /><figcaption>Primitive data types</figcaption></figure><h3>1. Integers</h3><p><strong>Byte Data Type</strong><br>The byte data type is an 8-bit signed two’s complement integer. The byte data type is useful for saving memory in large arrays.</p><p><strong>Short Data Type</strong><br>The short data type is a 16-bit signed two’s complement integer. Similar to byte, use a short to save memory in large arrays, in situations where the memory savings matter.</p><p><strong>Integer Data Type</strong><br>It is a 32-bit signed two’s complement integer.</p><p><strong>Long Data Type</strong><br>The long data type is a 64-bit two’s complement integer and is used when an int type is not large enough to hold the desired value. To designate an integer literal value as a long value, add the suffix L or l. The size of the Long Datatype is 8 bytes (64 bits).<br> <strong>— Literal: </strong>A literal is a fixed value that doesn’t need further calculations for it to be assigned to any variable.</p><figure><img alt="Integers size, default value and range" src="https://cdn-images-1.medium.com/max/1024/1*2iojL_9fwwb2YyaGvYErmQ.png" /><figcaption><strong>Integers</strong></figcaption></figure><h4>Integer literal values come in four flavors:</h4><ol><li><strong>Binary number system:</strong> A base-2 system, that uses only 2 digits, 0 &amp; 1.</li><li><strong>Octal number system: </strong>A base-8 system, that uses digits 0 through 7 (a total of 8 digits). Here the decimal number 8 is represented as octal 10, decimal 9 as 11, and so on.</li><li><strong>Decimal number system:</strong> The base-10 number system that you use every day. It’s based on 10 digits, from 0 through 9 (a total of 10 digits).</li><li><strong>Hexadecimal number system: </strong>A base-16 system, that uses digits 0 through 9 and the letters A through F (a total of 16 digits and letters). Here, the number 10 is represented as A or a, 11 as B or b, 12 as C or c, 13 as D or d, 14 as E or e, and 15 as F or f.</li></ol><figure><img alt="Example of how to convert an integer from decimal to octal" src="https://cdn-images-1.medium.com/max/526/1*PWimxTObDYN2FuSHFfKUrw.png" /><figcaption><strong>Converting an integer from decimal to octal</strong></figcaption></figure><figure><img alt="Example of how to convert an integer from decimal to Hexadecimal" src="https://cdn-images-1.medium.com/max/669/1*soKDqol7AROzssUGkeR2IA.png" /><figcaption><strong>Converting an integer from decimal to Hexadecimal</strong></figcaption></figure><p>We can assign integer literals in base decimal, binary, octal, and hexadecimal.<br><strong>1. For octal literals:</strong> use the prefix 0<br><strong> 2.</strong> <strong>For binary:</strong> use the prefix 0B or 0b<br><strong>3.</strong> <strong>For hexadecimal:</strong> use the prefix 0X or 0x.</p><p>We can use underscores as part of the literal values. Grouping individual digits or letters of literal values makes them more readable. The underscores do not affect the values.</p><p><strong>Rules to remember: </strong><br>Here’s a quick list of rules for the usage of underscores in the numeric literal values<br>■ You can place an underscore right after the prefix 0, which is used to define an octal literal value.<br>■ You can’t start or end a literal value with an underscore.<br>■ You can’t place an underscore right after the prefixes 0b, 0B, 0x, and 0X, which are used to define binary and hexadecimal literal values.<br>■ You can’t place an underscore before an L suffix (the L suffix marks a literal value as long).<br>■ You can’t use an underscore in positions where a string of digits is expected</p><h3>2. Floating points</h3><p><strong>Float Data Type</strong><br>The float data type is a single-precision 32-bit IEEE 754 floating-point. Use a float (instead of double) if you need to save memory in large arrays of floating-point numbers. The size of the float data type is 4 bytes (32 bits).</p><p><strong>Double Data Type</strong><br>The double data type is a double-precision 64-bit IEEE 754 floating-point. For decimal values, this data type is generally the default choice. The size of the double data type is 8 bytes or 64 bits.</p><figure><img alt="Floating points size, default value and range" src="https://cdn-images-1.medium.com/max/1024/1*aGaQRekiL0P-WBohob4Yrw.png" /><figcaption>Floating point</figcaption></figure><p>The default type of a decimal literal is double, but by suffixing a decimal literal value with F or f, you tell the compiler that the literal value should be treated like float and not a double.<br>You can also add the suffix D or d to a decimal number value to specify that it’s a double value. Because the default type of a decimal number is double, the use of the suffix D or d is redundant.</p><p><strong><em>The following rules are specific to floating-point literals:</em></strong><br> <strong>—</strong> You can’t place an underscore before a D, d, F, or f suffix (these suffixes are used to mark a floating-point literal as double or float).<br> <strong>— </strong>You can’t place an underscore adjacent to a decimal point.</p><h3>Character</h3><p><strong>Char Data Type</strong><br>A char is an unsigned integer. It can store a single 16-bit Unicode character; that is, it can store characters from virtually all the existing scripts and languages.<br>char stores the value from <strong>\u0000</strong> (or <strong>0</strong>) to a maximum value of <strong>\uffff</strong> (or <strong>65,535</strong>) inclusive.<br>Never use double quotes to assign a letter to a char variable. Double quotes are used to assign a value to a variable of type String.<br>char values are unsigned integer values, so if you try to assign a negative number to one, the code won’t compile but you can forcefully assign a negative number to a char type by casting it to char</p><figure><img alt="Character size, default value and range" src="https://cdn-images-1.medium.com/max/1024/1*I9HMIz7wq1ticXijtWivFQ.png" /><figcaption><strong>Character</strong></figcaption></figure><h3>Boolean</h3><p><strong>Boolean Data Type</strong><br>The simplest primitive data type is boolean. It can contain only one of two values: true or false. It stores its value in a single bit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/921/1*j85_4LBgFDtsqHzMqlLv5A.png" /></figure><h3>Identifiers</h3><p>All Java variables must be identified with unique names. These unique names are called identifiers.<br>Identifiers can be short names (like x and y) or more descriptive names (name, id, address). It is recommended to use descriptive names to create understandable and maintainable code.</p><h4>Properties of valid identifiers</h4><ol><li>Identifiers can be of any length</li><li>Starts with a letter ( a–z, lowercase), a currency sign, or an underscore</li><li>Can use a digit (not at the starting position)</li><li>Can use an underscore (at any position)</li><li>Can use a currency sign (at any position): ¤, $, £, ¢, ¥, and others</li><li>Identifiers are case-sensitive</li></ol><p><strong>Note: </strong>Identifiers can not have the same name as Java keywords or reserved words.</p><figure><img alt="Java keywords or reserved words that can’t be used as names for Java variables" src="https://cdn-images-1.medium.com/max/1024/1*1y8nLx1n8IemTORraay7nA.png" /><figcaption><strong>Java keywords and reserved words</strong></figcaption></figure><p>Oracle Certified Associate<strong> </strong>(<strong>OCA</strong>) <strong>certification overview</strong>:<br><a href="https://medium.com/@gauravshah97/oracle-certified-associate-java-se-8-programmer-d883ca58d80d"><strong>Oracle Certified Associate: Java SE 8 Programmer</strong></a></p><p>For more <strong>Java and Spring-Boot-related blogs</strong>, check out my profile:<br><a href="https://medium.com/@gauravshah97"><strong>https://medium.com/@gauravshah97</strong></a></p><p>Reach me out at:<br><a href="https://www.linkedin.com/in/gauravshah97/"><strong>https://www.linkedin.com/in/gauravshah97/</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fd8f333fcd24" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Java Basics]]></title>
            <link>https://medium.com/@gauravshah97/java-basics-84909a80064a?source=rss-62bc86d4416a------2</link>
            <guid isPermaLink="false">https://medium.com/p/84909a80064a</guid>
            <category><![CDATA[oracle-certification]]></category>
            <category><![CDATA[oracle-certified-training]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[java-certification]]></category>
            <category><![CDATA[java-training]]></category>
            <dc:creator><![CDATA[Gaurav Shah]]></dc:creator>
            <pubDate>Thu, 30 Nov 2023 14:59:07 GMT</pubDate>
            <atom:updated>2024-05-26T06:14:11.745Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>Java is a widely used, high-level, object-oriented programming language designed to be platform-independent and secure. It was developed by Sun Microsystems (now owned by Oracle Corporation) and released in 1995. Java’s design principles focus on simplicity, robustness, portability, and performance. In this blog, we’ll delve into the key concepts, features, and it’s components.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6XC_lMksAJPtch29tC9gQQ.png" /><figcaption>Java Basics</figcaption></figure><h3>Java source code file</h3><p><strong>Java Source Code File</strong><br>A Java source code file defines Java entities such as a class, interface, enum, and annotation.<br>All your Java code should be defined in Java source code files.</p><p><strong>Multiple classes in a Java Source code file</strong><br>The classes and interfaces can be defined in any order of occurrence in a Java source code file.<br>When you define a public class or an interface in a Java source file, the names of the class or interface and the Java source file must match. <br><em>A source code file can’t define more than one public class or interface.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A7Y1Tu9JOvAvlpGjisDIbA.png" /></figure><h3>Structure of Java class</h3><ol><li><strong>Package Statement:</strong> A package statement explicitly defines which package a class is in. <br> <strong>a.</strong> If a class includes a package statement, it must be the first statement in the class definition.<br><strong>b.</strong> The package statement must appear exactly once in a class.</li><li><strong>Import Statement:</strong> Classes and interfaces in the same package can use each other without prefixing their names with the package name. <br>But to use a class or an interface from another package, you must use its fully qualified name, that is, <em>PackageName.anySubpackageName.ClassName </em>. For example, the fully qualified name of class String is <em>java.lang.String</em>. The import statement follows the package statement but precedes the class declaration.</li><li><strong>Comments:</strong> You can also add comments to your Java code. Comments can appear at multiple places in a class. A comment can appear before and after a package statement, before and after the class definition, as well as before and within and after a method definition.</li><li><strong>Javadoc Comments:</strong> Javadoc comments are special comments that start with<strong> /** </strong>and end with<strong> */</strong> in a Java source file. <br>These comments are processed by Javadoc, a JDK tool, to generate API documentation for your Java source code files.</li><li><strong>Class:</strong> A class is a design used to specify the attributes and behavior of an object. A class is a design from which an object can be created.<br>The attributes of an object are implemented using variables, and the behavior is implemented using methods.</li></ol><h3>Components of a class</h3><ol><li><strong>Java Package:</strong> The Package is used to group a related set of classes and interfaces. Packages also provide access protection and namespace management. All classes and interfaces are defined in a package. <br>If you don’t include an explicit package statement in a class or an interface, it’s part of a default package.<br>Important rules about packages:<br>■ As per Java naming conventions, package names should all be in lowercase.<br>■ The package and subpackage names are separated using a dot.<br>■ Package names follow the rules defined for valid identifiers in Java.<br>■ For classes and interfaces defined in a package, the package statement is the first statement in a Java source file (a .java file). The exception is that comments can appear before or after a package statement.<br>■ There can be a maximum of one package statement per Java source code file (.java file).<br>■ All the classes and interfaces in a Java source code file are defined in the same package. They can’t be defined in separate packages.</li></ol><p><strong>2. Import Statements:</strong> The import statement enables us to use simple names instead of fully qualified names for classes and interfaces defined in separate packages.<br>The import statement doesn’t embed the contents of the imported class in your class, which means that importing more classes doesn’t increase the size of your class.<br>You can import an individual static member of a class or all its static members by using a static import statement.<br>■ It’s important to note that you can’t use the import statement to access multiple classes or interfaces with the same names from different packages.<br>■ You can’t import classes from a subpackage using an asterisk in the import statement.<br>■ By using the wildcard character, an asterisk (<strong>*</strong>), you can import all the public members, classes, and interfaces of a package.<br>■ Using an asterisk to import all package members has a drawback. It may be harder to figure out which imported class or interface comes from which package.<br>■ An attempt to use an import statement to import both the classes with the same name in the same class will not compile.<br>For example, the Java API defines class Date in two commonly used packages: java.util and java.sql. <br>To define variables of these classes in a class, use their fully qualified names with the variable declaration</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xXMWLFGuVp51mfxDTRzuuw.png" /><figcaption><strong>Importing classes with the same name</strong></figcaption></figure><p><strong>3. Class:</strong> A class is a design from which an object can be created.</p><ol><li><strong><em>Main Method: </em></strong>The first requirement in creating an executable Java application is to create a class with a method whose signature (name and method arguments) matches the main method.<br>The main method should comply with the following rules:<br>■ The method must be marked as a public method.<br>■ The method must be marked as a static method.<br>■ The name of the method must be main.<br>■ The return type of this method must be void.<br>■ The method must accept a method argument of a String array or a variable argument (varargs) of type String.<br><strong>Note: </strong>The placement of the keywords public and static can be interchanged, Both public static and the static public are the valid order of keywords to declare the main method.</li><li><strong>Constructor: </strong>A class constructor is used to create and initialize the objects of a class.<br>A class can define multiple constructors that accept different sets of method parameters.</li><li><strong>Variables: </strong>The instance variables are defined within a class but outside all methods in a class. <br>A single copy of a class variable or static variable is shared by all the objects of a class.<br>It isn’t compulsory to define all variables of a class before defining its methods.</li><li><strong>Methods:</strong> A class method or static method can be used to manipulate the static variables.</li></ol><p><strong>4. Interface:</strong> An interface specifies a contract for the classes to implement. An interface is a grouping of related methods and constants. An interface can also define static methods.</p><h3>Class Declaration</h3><p>The class declaration marks the start of a class. It can be as simple as the keyword class followed by the name of the class.<br>A class name starts with the keyword class. class (lowercase c) isn’t the same as Class (uppercase C). You can’t use the word Class (uppercase C) to define a class.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fqFTmMS3dsCx7UTrQ_BNZw.png" /><figcaption><strong>Components of a class declaration</strong></figcaption></figure><p><strong>Executable classes versus non-executable classes</strong>:<br>An executable Java class, when handed over to the JVM, starts its execution at a particular point in the class: the main method.<br>The JVM starts executing the code that’s defined in the main method.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GGBhkvukTuEG1slBdmqomQ.png" /><figcaption><strong>Executable Application</strong></figcaption></figure><h3>Java Features</h3><p>Java offers multiple advantages over other languages and platforms.</p><ol><li><strong>Platform Independent:</strong> It’s also referred to as “write once, run anywhere” (<strong><em>WORA</em></strong>). Java code can be executed on multiple systems without recompilation. Java code is compiled into bytecode, to be executed by a virtual machine — the Java Virtual Machine (JVM). Bytecode generated by a Java compiler is supported by all platforms with a JVM.</li><li><strong>Object Orientation:</strong> Java emulates real-life object definition and behavior. All Java code is defined within classes, interfaces, or enums. You need to create their objects to use them.</li><li><strong>Abstraction:</strong> Java lets you abstract objects and include only the required properties and behavior in your code.</li><li><strong>Encapsulation:</strong> With Java classes, you can encapsulate the state and behavior of an object. The state or the fields of a class are protected from unwanted access and manipulation. You can control the level of access and modifications to your objects.</li><li><strong>Inheritance:</strong> Java enables its classes to inherit other classes and implement interfaces. The interfaces can inherit other interfaces. This saves you from redefining common code.</li><li><strong>Polymorphism:</strong> Java enables instances of its classes to exhibit multiple behaviors for the same method calls.</li><li><strong>Type Safety:</strong> In Java, you must declare a variable with its data type before using it. This means that you have compile-time checks that ensure you never assign to a variable a value of the wrong type.</li><li><strong>Automatic Memory Management:</strong> Java uses garbage collectors for automatic memory management. They reclaim memory from objects that are no longer in use. This frees developers from explicitly managing the memory themselves. It also prevents memory leaks.</li><li><strong>Multithreading and Concurrency:</strong> Java has supported multithreading and concurrency.</li><li><strong>Security:</strong> Java includes multiple built-in security features to control access to your resources and execution of your programs.</li></ol><h3>Points to Remember</h3><ol><li>The method parameters that are passed to the main method are also called command-line parameters or command-line values. As the name implies, these values are passed to a method from the command line.</li><li>You don’t need an explicit import statement to use members from java.lang package. Classes and interfaces in this package are automatically imported into all other Java classes, interfaces, or enums.</li><li>Members of a named package can’t access classes and interfaces defined in the default package.</li><li>static methods and variables can’t access the instance members of a class.</li><li>You can access static variables and methods using a null reference.</li><li>A class may define an instance variable before or after the definition of a method and still use it.</li><li>If you explicitly import a class name, it has precedence over any wildcards present.</li><li>To compile and execute the code, execute the following:<br> <strong>Compile </strong>(javac className.java), <strong>Run </strong>(java className)</li></ol><p>Oracle Certified Associate<strong> </strong>(<strong>OCA</strong>) <strong>certification overview</strong>:<br><a href="https://medium.com/@gauravshah97/oracle-certified-associate-java-se-8-programmer-d883ca58d80d"><strong>Oracle Certified Associate: Java SE 8 Programmer</strong></a></p><p>For more <strong>Java and Spring-Boot-related blogs</strong>, check out my profile:<br><a href="https://medium.com/@gauravshah97"><strong>https://medium.com/@gauravshah97</strong></a></p><p>Reach me out at:<br><a href="https://www.linkedin.com/in/gauravshah97/"><strong>https://www.linkedin.com/in/gauravshah97/</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=84909a80064a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Oracle Certified Associate: Java SE 8 Programmer]]></title>
            <link>https://medium.com/@gauravshah97/oracle-certified-associate-java-se-8-programmer-d883ca58d80d?source=rss-62bc86d4416a------2</link>
            <guid isPermaLink="false">https://medium.com/p/d883ca58d80d</guid>
            <category><![CDATA[java-certification]]></category>
            <category><![CDATA[oracle]]></category>
            <category><![CDATA[oracle-certification]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[certification]]></category>
            <dc:creator><![CDATA[Gaurav Shah]]></dc:creator>
            <pubDate>Tue, 24 Oct 2023 10:23:08 GMT</pubDate>
            <atom:updated>2024-05-26T06:01:26.435Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Oracle Certified Associate Badge" src="https://cdn-images-1.medium.com/max/552/1*27FZZjeNhzMI4MYNsHY4PA.jpeg" /></figure><p>The Java SE 8 Programmer I, or the <strong>1Z0–808</strong> exam, is an Oracle Certified Associate (OCA) certification. It’s designed to test your knowledge of the fundamentals of Java.</p><p>The upcoming blog series provides a systematic approach to Java Fundamentals and the Oracle Java 8 1Z0–808 (OCA) Certification exam. It will help you understand the fundamental concepts in Java and prepare for the exam.</p><h3>A brief overview of the topics covered:</h3><h4><a href="https://medium.com/@gauravshah97/java-basics-84909a80064a"><strong>Java Basics</strong></a><strong> </strong>and <a href="https://medium.com/@gauravshah97/4b2cc8597424">Modifiers</a></h4><ul><li>Define the structure of a Java class</li><li>Create executable Java applications with a main method, run a Java program from the command line, and produce console output</li><li>Import other Java packages to make them accessible in your code</li><li>Compare and contrast the features and components of Java such as platform independence, object orientation, encapsulation, etc</li><li>Define the scope of variables</li><li>Access and non-access modifiers in Java</li></ul><h4><strong>Working With </strong><a href="https://medium.com/@gauravshah97/working-with-java-datatypes-fd8f333fcd24"><strong>Java Data Types</strong></a><strong> and </strong><a href="https://medium.com/@gauravshah97/wrapper-classes-in-java-0c5d9205f3b3"><strong>Wrapper Classes</strong></a></h4><ul><li>Declare and initialize variables (including casting of primitive data types)</li><li>Differentiate between object reference variables and primitive variables</li><li>Know how to read or write object fields</li><li>Explain an Object’s Lifecycle (creation, “dereference by reassignment” and garbage collection)</li><li>Develop code that uses wrapper classes such as Boolean, Double, and Integer</li></ul><h4><strong>Using </strong><a href="https://medium.com/@gauravshah97/operators-in-java-12b85530416f"><strong>Operators </strong></a><strong>and </strong><a href="https://medium.com/@gauravshah97/decision-constructs-in-java-3b0e77412160"><strong>Decision Constructs</strong></a></h4><ul><li>Use Java operators; use parentheses to override operator precedence</li><li>Test equality between Strings and other objects using == and equals ()</li><li>Create if and if/else and ternary constructs</li><li>Use a switch statement</li></ul><h4><strong>Creating and Using Arrays</strong></h4><ul><li>Declare, instantiate, initialize, and use a one-dimensional array</li><li>Declare, instantiate, initialize, and use multi-dimensional arrays</li></ul><h4>Using Loop Constructs</h4><ul><li>Create and use while loops</li><li>Create and use for loops including the enhanced for loop</li><li>Create and use do/while loops</li><li>Compare loop constructs</li><li>Use break and continue</li></ul><h4><strong>Working with Methods and Encapsulation</strong></h4><ul><li>Create methods with arguments and return values; including overloaded methods</li><li>Apply the static keyword to methods and fields</li><li>Create and overload constructors; differentiate between default and user-defined constructors</li><li>Apply access modifiers</li><li>Apply encapsulation principles to a class</li><li>Determine the effect upon object references and primitive values when they are passed into methods that change the values</li></ul><h4><strong>Working with Inheritance</strong></h4><ul><li>Describe inheritance and its benefits</li><li>Develop code that makes use of polymorphism; develop code that overrides methods; differentiate between the type of a reference and the type of an object</li><li>Determine when casting is necessary</li><li>Use super and this to access objects and constructors</li><li>Use abstract classes and interfaces</li></ul><h4>Handling Exceptions</h4><ul><li>Differentiate among checked exceptions, unchecked exceptions, and Errors</li><li>Create a try-catch block and determine how exceptions alter normal program flow</li><li>Describe the advantages of Exception handling</li><li>Create and invoke a method that throws an exception</li><li>Recognize common exception classes (such as NullPointerException, ArithmeticException, ArrayIndexOutOfBoundsException, ClassCastException)</li></ul><h4>Working with Selected classes from the Java API</h4><ul><li>Manipulate data using the StringBuilder class and its methods</li><li>Create and manipulate Strings</li><li>Create and manipulate calendar data using classes from java.time.LocalDateTime, java.time.LocalDate, java.time.LocalTime, java.time.format.DateTimeFormatter, java.time.Period</li><li>Declare and use an ArrayList of a given type</li><li>Write a simple Lambda expression that consumes a Lambda Predicate expression</li></ul><p>Oracle Certified Associate<strong> </strong>(<strong>OCA</strong>) <strong>certification blog series<br></strong><a href="https://medium.com/@gauravshah97/list/oca-preparation-6e5a0a48b1f4"><strong>OCA Preparation</strong></a></p><p>For more <strong>Java and Spring-Boot-related projects</strong>, check out my profile:<br><a href="https://medium.com/@gauravshah97"><strong>https://medium.com/@gauravshah97</strong></a></p><p>Reach me out at-<br><a href="https://www.linkedin.com/in/gauravshah97/"><strong>https://www.linkedin.com/in/gauravshah97/</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d883ca58d80d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Custom Queries, Objects in Spring Data JPA]]></title>
            <link>https://medium.com/@gauravshah97/custom-queries-objects-in-spring-data-jpa-8e1711de59f3?source=rss-62bc86d4416a------2</link>
            <guid isPermaLink="false">https://medium.com/p/8e1711de59f3</guid>
            <category><![CDATA[spring-data-jpa]]></category>
            <category><![CDATA[custom-queries]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[mysql]]></category>
            <category><![CDATA[spring-boot]]></category>
            <dc:creator><![CDATA[Gaurav Shah]]></dc:creator>
            <pubDate>Wed, 07 Sep 2022 06:35:32 GMT</pubDate>
            <atom:updated>2024-05-24T06:46:58.167Z</atom:updated>
            <content:encoded><![CDATA[<p>This tutorial helps build a Spring Boot RESTful API using custom queries in Spring Data JPA to interact with the MySQL database.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZQHEjrWGNtGAa69UzwJLpA.png" /></figure><p><strong>Overview:</strong><br><strong>The Spring Framework</strong> provides a comprehensive programming and configuration model for modern Java-based enterprise applications on any deployment platform. Spring Boot is a module of Spring Framework that allows us to build a stand-alone application with minimal or zero configurations.<br> <br><strong>Spring Data JPA</strong><br>The Java Persistence API(JPA) is a specification that facilitates object-relational mapping to manage relational data in Java applications. JPA provides a platform to work directly with the objects.</p><p><strong>Overview of HostpitalManagement RESTful API</strong><br>Each Patient has an id, name, reasonForVisit, and attendingDoctorId.<br>Each Doctor has an id, name, specialization, and experience.<br> <br>The APIs we will be creating are:</p><figure><img alt="HospitalManagement API methods, URL and Actions" src="https://cdn-images-1.medium.com/max/782/1*krPLbMfWckDjOSQyJVtnRA.png" /><figcaption>API Method, URL, and Action</figcaption></figure><p><strong>Project Structure</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/461/1*4UBqEEIqikptpFjanzdUcQ.png" /><figcaption>HospitalManagement API Project Structure</figcaption></figure><p>Brief introduction about these files:</p><ul><li><strong>Patient.java</strong> model class corresponds to entity and table Patient.</li><li><strong>Doctor.java</strong> model class corresponds to the entity and table Doctor.</li><li><strong>PatientRepository.java</strong> is an interface that extends the JPA Repository for CRUD methods of Patient Entity. It will be autowired in PatientController.</li><li><strong>DoctorRepository.java</strong> is an interface that extends the JPA Repository for CRUD methods of Doctor Entity. It will be autowired in DoctorController.</li><li><strong>PatientController.java </strong>is a RestController containing request mapping methods for RESTful requests such as addPatient and getAllPatients.</li><li><strong>DoctorController.java</strong> is a RestController containing request mapping methods for RESTful requests such as addDoctor and getAllDoctors.</li><li><strong>CustomRepository.java </strong>is an interface that extends the JPA Repository for running custom queries on Patient and Doctor Entity. It will be autowired in CustomController.</li><li><strong>CustomController.java</strong> is a RestController containing request mapping methods for RESTful requests such as getPatientsOfDoctor, getDoctorBySpecialization, and updateAttendingDoctorId.</li><li><strong>application.properties</strong> contains configuration for Spring Datasource and JPA Hibernate.</li><li><strong>pom.xml </strong>contains Spring Boot, Spring Data JPA, MySQL, and JSON dependencies.</li></ul><p><strong>Spring Boot Project Creation and Setup</strong><br>Use the <a href="https://start.spring.io/"><strong>Spring Initializr</strong></a> or any IDE such as <a href="https://www.eclipse.org/downloads/"><strong>Eclipse</strong></a>, <a href="https://spring.io/tools"><strong>Spring Tool Suite</strong></a>, or <a href="https://www.jetbrains.com/idea/download/"><strong>IntelliJ</strong></a><strong> </strong>to create a Spring Boot project.<br>Once the project is created, open the <strong>pom.xml</strong> file and add the following dependency:</p><pre>&lt;dependency&gt;<br> &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;<br> &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;<br>&lt;/dependency&gt;<br><br>&lt;dependency&gt;<br> &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;<br> &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;<br>&lt;/dependency&gt;<br><br>&lt;dependency&gt;<br> &lt;groupId&gt;mysql&lt;/groupId&gt;<br> &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;<br> &lt;scope&gt;runtime&lt;/scope&gt;<br>&lt;/dependency&gt;<br><br>&lt;dependency&gt;<br> &lt;groupId&gt;org.json&lt;/groupId&gt;<br> &lt;artifactId&gt;json&lt;/artifactId&gt;<br> &lt;version&gt;20220320&lt;/version&gt;<br>&lt;/dependency&gt;</pre><p><strong>Configure application.properties</strong><br>Under the <strong>src/main/resources</strong> folder, open the <strong>application.properties</strong> and add the following property:</p><pre># A DataSource is a factory for connections to the physical databases. It uses a URL, username, and password to establish the database connection.<br>spring.datasource.url = jdbc:mysql://localhost:3306/hospitalmanagement<br>spring.datasource.username = root<br>spring.datasource.password = admin<br><br># A hibernate dialect gives information to the framework of how to convert hibernate queries(HQL) into native SQL queries.<br>spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect<br><br># Hibernate ddl-auto automatically validates or exports schema DDL to the database when the SessionFactory is created.<br>spring.jpa.hibernate.ddl-auto = update</pre><p><strong>Spring Boot Entry Point</strong><br>The entry point of the HostpitalManagement application is the class containing the main method and the <strong>@SpringBootApplication</strong> annotation.<br>The<strong> HospitalManagementApiApplication.java</strong> looks like this:</p><pre>package com.hospital.management;<br><br>import org.springframework.boot.SpringApplication;<br>import org.springframework.boot.autoconfigure.SpringBootApplication;<br><br>@SpringBootApplication<br>public class HospitalManagementApiApplication {<br><br>public static void main(String[] args) {<br> SpringApplication.run(HospitalManagementApiApplication.class, args);<br> }<br>}</pre><p><strong>The Data Model</strong><br>Our first Data Model <strong>Patient </strong>consists of patientId, patientName, reasonForVisit, and attendingDoctorId.<br>The <strong>Patient.java</strong> looks like this:</p><pre>package com.hospital.management.model;<br><br>import javax.persistence.Column;<br>import javax.persistence.Entity;<br>import javax.persistence.Id;<br>import javax.persistence.Table;<br><br>@Entity<br>@Table(name = &quot;patient&quot;)<br>public class Patient {<br><br> @Id<br> @Column(name = &quot;patient_id&quot;)<br> private String patientId;<br> @Column(name = &quot;patient_name&quot;)<br> private String patientName;<br> @Column(name = &quot;reason_for_visit&quot;)<br> private String reasonForVisit;<br> @Column(name = &quot;attending_doctor_id&quot;)<br> private String attendingDoctorId;<br><br> public Patient() {<br>  super();<br> }<br> public String getPatientId() {<br>  return patientId;<br> }<br> public void setPatientId(String patientId) {<br>  this.patientId = patientId;<br> }<br> public String getPatientName() {<br>  return patientName;<br> }<br> public void setPatientName(String patientName) {<br>  this.patientName = patientName;<br> }<br> public String getReasonForVisit() {<br>  return reasonForVisit;<br> }<br> public void setReasonForVisit(String reasonForVisit) {<br>  this.reasonForVisit = reasonForVisit;<br> }<br> public String getAttendingDoctorId() {<br>  return attendingDoctorId;<br> }<br> public void setAttendingDoctorId(String attendingDoctorId) {<br>  this.attendingDoctorId = attendingDoctorId;<br> }<br><br> @Override<br> public String toString() {<br>  return &quot;Patient Details:\nPatient ID = &quot; + patientId + &quot;, Patient Name = &quot; + patientName + &quot;, Reason for visit = &quot;<br>  + reasonForVisit + &quot;, Attending Doctor ID = &quot; + attendingDoctorId;<br> }<br>}</pre><p>Our second Data Model is <strong>Doctor </strong>consisting of doctorId, doctorName, specialization, and experience.<br>The <strong>Doctor.java</strong> looks like this:</p><pre>package com.hospital.management.model;<br><br>import javax.persistence.Column;<br>import javax.persistence.Entity;<br>import javax.persistence.Id;<br>import javax.persistence.Table;<br><br>@Table<br>@Entity<br>public class Doctor {<br> <br> @Id<br> @Column(name = &quot;doctor_id&quot;)<br> private String doctorId;<br> @Column(name = &quot;doctor_name&quot;)<br> private String doctorName;<br> @Column(name = &quot;specialization&quot;)<br> private String specialization;<br> @Column(name = &quot;experience&quot;)<br> private double experience;<br><br> public Doctor() {<br>  super();<br> }<br> public String getDoctorId() {<br>  return doctorId;<br> }<br> public void setDoctorId(String doctorId) {<br>  this.doctorId = doctorId;<br> }<br> public String getDoctorName() {<br>  return doctorName;<br> }<br> public void setDoctorName(String doctorName) {<br>  this.doctorName = doctorName;<br> }<br> public String getSpecialization() {<br>  return specialization;<br> }<br> public void setSpecialization(String specialization) {<br>  this.specialization = specialization;<br> }<br> public double getExperience() {<br>  return experience;<br> }<br> public void setExperience(double experience) {<br>  this.experience = experience;<br> }<br><br> @Override<br> public String toString() {<br>  return &quot;Doctor Details:\nDoctor ID = &quot; + doctorId + &quot;, Doctor Name = &quot; + doctorName + &quot;, Specialization = &quot;<br>  + specialization + &quot;, Total Experience = &quot; + experience;<br> }<br>}</pre><p><strong>The Data Repository</strong><br>The PatientRepository interface allows us to interact with the Patient table from the database.<br>The <strong>PatientRepository.java</strong> looks like this:</p><pre>package com.hospital.management.repository;<br><br>import org.springframework.data.jpa.repository.JpaRepository;<br>import org.springframework.stereotype.Repository;<br>import com.hospital.management.model.Patient;<br><br>@Repository<br>public interface PatientRepository extends JpaRepository&lt;Patient, String&gt; {<br>}</pre><p>The DoctorRepository interface allows us to interact with the Doctor table from the database.<br>The <strong>DoctorRepository.java</strong> looks like this:</p><pre>package com.hospital.management.repository;<br><br>import org.springframework.data.jpa.repository.JpaRepository;<br>import org.springframework.stereotype.Repository;<br>import com.hospital.management.model.Doctor;<br><br>@Repository<br>public interface DoctorRepository extends JpaRepository&lt;Doctor, String&gt; {<br>}</pre><p>The CustomRepository interface allows us to interact with the Patient and Doctor table from the database.<br>The <strong>CustomRepository.java</strong> looks like this:</p><pre>package com.hospital.management.custom;<br><br>import java.util.List;<br>import javax.transaction.Transactional;<br>import org.springframework.data.jpa.repository.JpaRepository;<br>import org.springframework.data.jpa.repository.Modifying;<br>import org.springframework.data.jpa.repository.Query;<br>import org.springframework.stereotype.Repository;<br>import com.hospital.management.model.Patient;<br><br>@Repository<br>public interface CustomRepository extends JpaRepository&lt;Patient, String&gt; {<br><br> @Query(value = &quot;select p.patient_id, p.patient_name, p.reason_for_visit from patient as p join doctor as d on p.attending_doctor_id = d.doctor_id where d.doctor_id = ?1&quot;, nativeQuery = true)<br> List&lt;String&gt; getPatientsOfDoctor(String doctorId);<br> <br> @Query(value = &quot;select doctor_id, doctor_name from doctor where specialization = ?1&quot;, nativeQuery = true)<br> List&lt;String&gt; getDoctorByDisease(String reasonForVisit);<br> <br> @Transactional<br> @Modifying<br> @Query(value = &quot;update patient set attending_doctor_id = ?1 where patient_id = ?2&quot;, nativeQuery = true)<br> int updateAttendingDoctorId( String doctorId, String patientId);<br>}</pre><p>The<strong> @Repository </strong>annotation indicates that the class provides the mechanism to delete, store, update, and search operations on objects.<br>The <strong>@Query </strong>annotation value attribute contains the JPQL or SQL to execute.<br>The <strong>@Transactional</strong> annotation enables us to apply the default transaction configurations.<br>The <strong>@Modifying</strong> annotation overrides the transaction configuration.</p><p>By default, CRUD methods on repository instances are transactional. For the transaction configuration, the readOnly flag is set to true.<br>The <strong>@Modifying</strong> annotation overrides the transaction’s default configuration and the method runs with the readOnly flag set to false.</p><p><strong>The Rest APIs Controller</strong><br>The <strong>Patient Controller</strong> provides APIs for creating and retrieving Patients.<br>The <strong>PatientController.java</strong> looks like this:</p><pre>package com.hospital.management.controller;<br><br>import java.util.List;<br>import java.util.Optional;<br>import org.springframework.beans.factory.annotation.Autowired;<br>import org.springframework.web.bind.annotation.DeleteMapping;<br>import org.springframework.web.bind.annotation.GetMapping;<br>import org.springframework.web.bind.annotation.PathVariable;<br>import org.springframework.web.bind.annotation.PostMapping;<br>import org.springframework.web.bind.annotation.RequestBody;<br>import org.springframework.web.bind.annotation.RequestMapping;<br>import org.springframework.web.bind.annotation.RestController;<br>import com.hospital.management.model.Patient;<br>import com.hospital.management.repository.PatientRepository;<br><br>@RestController<br>@RequestMapping(&quot;/api/patient&quot;)<br>public class PatientController {<br> <br> @Autowired<br> PatientRepository patientRepository;<br> <br> @GetMapping(&quot;/list&quot;)<br> public List&lt;Patient&gt; getAllPatients(){<br>  return patientRepository.findAll();<br> }<br> @GetMapping(&quot;/{id}&quot;)<br> public Optional&lt;Patient&gt; getPatientById(@PathVariable(value = &quot;id&quot;) String id) {<br>  return patientRepository.findById(id);<br> }<br> @PostMapping<br> public Patient addPatient(@RequestBody Patient patient) {<br>  return patientRepository.save(patient);<br> }<br> @DeleteMapping(&quot;/{id}&quot;)<br> public void deletePatientById(@PathVariable(value = &quot;id&quot;) String id) {<br>  patientRepository.deleteById(id);<br> }<br>}</pre><p>The <strong>Doctor Controller</strong> provides APIs for creating and retrieving Doctors.<br>The <strong>DoctorController.java </strong>looks like this:</p><pre>package com.hospital.management.controller;<br><br>import java.util.List;<br>import java.util.Optional;<br>import org.springframework.beans.factory.annotation.Autowired;<br>import org.springframework.web.bind.annotation.DeleteMapping;<br>import org.springframework.web.bind.annotation.GetMapping;<br>import org.springframework.web.bind.annotation.PathVariable;<br>import org.springframework.web.bind.annotation.PostMapping;<br>import org.springframework.web.bind.annotation.RequestBody;<br>import org.springframework.web.bind.annotation.RequestMapping;<br>import org.springframework.web.bind.annotation.RestController;<br>import com.hospital.management.model.Doctor;<br>import com.hospital.management.repository.DoctorRepository;<br><br>@RestController<br>@RequestMapping(&quot;/api/doctor&quot;)<br>public class DoctorController {<br><br> @Autowired<br> DoctorRepository doctorRepository;<br> <br> @GetMapping(&quot;/list&quot;)<br> public List&lt;Doctor&gt; getAllDoctors() {<br>  return doctorRepository.findAll();<br> }<br> @GetMapping(&quot;/{id}&quot;)<br> public Optional&lt;Doctor&gt; getDoctorById(@PathVariable(value = &quot;id&quot;) String id){<br>  return doctorRepository.findById(id);<br> }<br> @PostMapping<br> public Doctor addDoctor(@RequestBody Doctor doctor) {<br>  return doctorRepository.save(doctor);<br> }<br> @DeleteMapping(&quot;/{id}&quot;)<br> public void deleteDoctor(@PathVariable(value = &quot;id&quot;) String id) {<br>  doctorRepository.deleteById(id);<br> }<br>}</pre><p>The <strong>Custom Controller</strong> provides APIs to</p><ul><li>Retrieve all the Patients under a Doctor using a Doctor ID.</li><li>Retrieve all the Doctors available with a particular Specialization.</li><li>Update Attending Doctor ID for particular Patient.</li></ul><p>The <strong>CustomController.java</strong> looks like this:</p><pre>package com.hospital.management.custom;<br><br>import java.util.ArrayList;<br>import java.util.List;<br>import org.json.JSONObject;<br>import org.springframework.beans.factory.annotation.Autowired;<br>import org.springframework.http.HttpStatus;<br>import org.springframework.http.ResponseEntity;<br>import org.springframework.web.bind.annotation.GetMapping;<br>import org.springframework.web.bind.annotation.PathVariable;<br>import org.springframework.web.bind.annotation.PutMapping;<br>import org.springframework.web.bind.annotation.RequestMapping;<br>import org.springframework.web.bind.annotation.RestController;<br>import com.fasterxml.jackson.core.JsonProcessingException;<br>import com.fasterxml.jackson.databind.JsonMappingException;<br>import com.fasterxml.jackson.databind.ObjectMapper;<br><br>@RestController<br>@RequestMapping(&quot;/api&quot;)<br>public class CustomController {<br><br> @Autowired<br> CustomRepository customRepository;<br> <br> /** Retrieve all the patients under a doctor using Doctor ID */<br> @GetMapping(&quot;/patients/{doctorid}&quot;)<br> public ResponseEntity&lt;List&lt;Object&gt;&gt; getPatientsOfDoctor(@PathVariable(&quot;doctorid&quot;) String doctorId) throws JsonMappingException, JsonProcessingException {<br>  List&lt;String&gt; listFromDb = customRepository.getPatientsOfDoctor(doctorId);<br>  List&lt;Object&gt; patientList = new ArrayList&lt;&gt;();<br><br>  for (String row : listFromDb) {<br>   String[] entries = row.split(&quot;,&quot;);<br>   JSONObject patientDetails = new JSONObject();<br>   patientDetails.put(&quot;patientId&quot;, entries[0]);<br>   patientDetails.put(&quot;patientName&quot;, entries[1]);<br>   patientDetails.put(&quot;reasonForVisit&quot;, entries[2]);<br>   Object object = new ObjectMapper().readValue(patientDetails.toString(), Object.class);<br>   patientList.add(object);<br>  }<br><br>  if (patientList.isEmpty()) {<br>   patientList.add(&quot;No patients are currently under this doctor&quot;);<br>   return new ResponseEntity&lt;List&lt;Object&gt;&gt;(patientList, HttpStatus.OK);<br>  }<br>  return new ResponseEntity&lt;List&lt;Object&gt;&gt;(patientList, HttpStatus.OK);<br> }<br> <br> /** Retrieve all the doctors available with a particular Specialization */<br> @GetMapping(&quot;/doctors/{specialization}&quot;)<br> public ResponseEntity&lt;List&lt;Object&gt;&gt; getDoctorByDisease(@PathVariable(&quot;specialization&quot;) String specialization) throws JsonMappingException, JsonProcessingException {<br>  List&lt;String&gt; listFromDb = customRepository.getDoctorByDisease(specialization);<br>  List&lt;Object&gt; doctorList = new ArrayList&lt;&gt;();<br><br>  for (String row : listFromDb) {<br>   String[] entries = row.split(&quot;,&quot;);<br>   JSONObject doctorDetails = new JSONObject();<br>   doctorDetails.put(&quot;doctorId&quot;, entries[0]);<br>   doctorDetails.put(&quot;doctorName&quot;, entries[1]);<br>   Object object = new ObjectMapper().readValue(doctorDetails.toString(), Object.class);<br>   doctorList.add(object);<br>  }<br><br>  if (doctorList.isEmpty()) {<br>   doctorList.add(&quot;No doctors are currently available for the given specialization&quot;);<br>   return new ResponseEntity&lt;List&lt;Object&gt;&gt;(doctorList, HttpStatus.OK);<br>  }<br>  return new ResponseEntity&lt;List&lt;Object&gt;&gt;(doctorList, HttpStatus.OK);<br> }<br> <br> /** Update Attending Doctor ID for a particular Patient */<br> @PutMapping(&quot;/patient/{patientid}/{doctorid}&quot;)<br> public ResponseEntity&lt;String&gt; updateAttendingDoctorId(@PathVariable(&quot;patientid&quot;) String patientId, @PathVariable(&quot;doctorid&quot;) String doctorId) {<br>  int check = customRepository.updateAttendingDoctorId(doctorId, patientId);<br>  if (check == 1)<br>  return new ResponseEntity&lt;String&gt;(&quot;Patient found and updated successfully&quot;, HttpStatus.OK);<br>  else<br>  return new ResponseEntity&lt;String&gt;(&quot;Unable to update the patient. Please verify the details.&quot;, HttpStatus.NOT_FOUND);<br> }<br>}</pre><p>The <strong>ResponseEntity </strong>represents the complete HTTP response that is status code, headers, and body. We can use it to configure the HTTP response.<br>The <strong>readValue </strong>API of the <strong>ObjectMapper </strong>enables us to parse or deserialize JSON content into a Java object.</p><p><strong>Testing the APIs using Postman</strong><br>Postman is an API platform for building and using APIs. It allows us to manually test our APIs.</p><p>The <strong>Postman Documentation</strong> for the entire project can be found at:<br><a href="https://documenter.getpostman.com/view/22576021/VUjHMTsQ"><strong>https://documenter.getpostman.com/view/22576021/VUjHMTsQ</strong></a></p><p>The <strong>Entire code</strong> of the project can be found at:<br><a href="https://github.com/GauravShah97/HospitalManagementAPI"><strong>https://github.com/GauravShah97/HospitalManagementAPI</strong></a></p><p>For more <strong>Java and Spring-Boot-related projects</strong>, check out my profile:<br><a href="https://medium.com/@gauravshah97"><strong>https://medium.com/@gauravshah97</strong></a></p><p>Reach me out at-<br><a href="https://www.linkedin.com/in/gauravshah97/"><strong>https://www.linkedin.com/in/gauravshah97/</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8e1711de59f3" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>