{"id":76246,"date":"2020-02-11T10:20:18","date_gmt":"2020-02-11T04:50:18","guid":{"rendered":"https:\/\/techvidvan.com\/tutorials\/?p=76246"},"modified":"2020-02-11T10:20:18","modified_gmt":"2020-02-11T04:50:18","slug":"java-operators","status":"publish","type":"post","link":"https:\/\/techvidvan.com\/tutorials\/java-operators\/","title":{"rendered":"Java Operators and its 8 Types that you should know about!"},"content":{"rendered":"<p>Now as you are familiar with the declaration and initialization of <em><strong>variables in Java<\/strong><\/em>, you might be eager to know how to perform with them. In this tutorial, we will learn the various operators in Java which we can further use accordingly for our need\/purpose.<\/p>\n<p>In computer programming, an operator is a special symbol that is used to perform operations on the variables and values. The <strong>operators<\/strong> represent the operations (specific tasks) and the objects\/variables of the operations are known as <strong>operands<\/strong>.<\/p>\n<h3>Types of Operators in Java<\/h3>\n<p>Java comes with a rich set of operators, which comprises of many kinds of operators such as<em> arithmetic, relational, and logical and many other types of operators<\/em>. Let us discuss each of them in detail.<\/p>\n<h4>1. Arithmetic Operators in Java<\/h4>\n<p>Arithmetic operators are used to perform mathematical expressions or arithmetic calculations in the same way we use them in algebra.<\/p>\n<p>Java provides operators for five basic arithmetic calculations: addition, subtraction, multiplication, division, and the remainder which are <strong>+, -, *, \/, and %<\/strong> respectively. Each of these is a <strong>binary<\/strong> operator that is, it requires two values <em>(operands)<\/em> to perform calculations.<\/p>\n<p>We will discuss each type of Arithmetic operators in detail:<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/02\/types-of-arithmetic-operators-.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-76420\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/02\/types-of-arithmetic-operators-.jpg\" alt=\"types of arithmetic operators\" width=\"764\" height=\"368\" \/><\/a><\/p>\n<h5>1.1. Addition Operator (+)<\/h5>\n<p>The arithmetic binary operator (+) adds the values of its operands and the result is the sum of values of its two operands. Its operands can be of integer type <em>(int, short, byte, long, double)<\/em> or float type <em>(float and double)<\/em>.<\/p>\n<p><strong>For example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">4 + 20; results in 24. \/\/adding two values.\n\nnum1 + 5; (where num1 = 5) results in 10. \/\/adding a variable with a value.\nnum1 + num2; (where num1 = 6, num2 = 8) results in 14. \/\/adding two variables<\/pre>\n<h5>1.2. Subtraction Operator (-)<\/h5>\n<p>The &#8211; operator subtracts the second operand from the first. The operators may be of integer or float types.<\/p>\n<p><strong>For example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">10 - 3; \/\/results in 7.\n\nint num1 = 80;\nint num2 = 15;\nint result;\nnum2 - 9; \/\/results in 6.\nresult = num1 - num2; \/\/stores 65 in result variable.<\/pre>\n<h5>1.3. Multiplication Operator (*)<\/h5>\n<p>The multiplication operator (*) multiplies the values of its operands. The values may be of integer or float types.<\/p>\n<p><strong>For example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">2.5 * 1.5; \/\/results in 3.75 \n\nint num1,num2;\nnum1 = 4,num2 = 6; \nnum1 * num2; \/\/results in 24.<\/pre>\n<h5>1.4. Division Operator (\/)<\/h5>\n<p>The division operator \/ divides its first operand by the second. Here, the operands may be of both integer or float types.<\/p>\n<p><strong>For example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">100\/5; \/\/evaluates to 20.\n\nfloat num1 = 16.2;\nnum1 \/ 2; \/\/evaluates to 8.1\n\nfloat num2 = 2.5;\nnum1 \/ num2; \/\/evaluates to 6.4<\/pre>\n<h5>1.5. Modulus Operator (%)<\/h5>\n<p>The modulus operator % finds the modulus of its first operator relative to the second. That is, it produces the remainder of the division of the first operand by the second.<\/p>\n<p><strong>For example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">20 % 3; \/\/evaluates to 2, since 3 * 6 = 18 and remainder is 2\n\n-5 % -2; \/\/evaluates to 1.\n\nfloat num1 = 7.6, num2 = 2.9;\nnum1 % num2; \/\/evaluates to 1.8<\/pre>\n<h5>Operator + with Strings<\/h5>\n<p>We have used the operator \u2018+\u2019 with numbers. When we use + with the number, the result is also a number. In Java, we can also use the + operator for concatenating 2 strings.<\/p>\n<p><strong>For example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">\u201c5\u201d + \u201c6\u201d; \/\/results into \u201c56\u201d\n\n\u201c20\u201d + \u201c ,Sector A\u201d; \/\/results into \u201c20 ,Sector A\u201d\n\n\u201cAbc\u201d + \u201c123\u201d; \/\/results into \u201cAbc 123\u201d\n\n5 + \u201cxyz\u201d; \/\/results into \u201c5xyz\u201d\n(Java would internally convert 5 into \u201c5\u201d first and then concatenate it with \u201cxyz\u201d).<\/pre>\n<p><strong>Code Snippet to illustrate the concept of Arithmetic operators:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.TechVidvan.Operators;\npublic class ArithmeticOperators\n{\n  public static void main(String[] args)\n  {\n    int operand1 = 100, operand2 = 20;\n    String stringName1 = \"TechVidvan\u2019s\", stringName2 = \" Java Tutorial\";\n\n    \/\/ using + operator with strings will concatenate the 2 strings\n    System.out.println(\"Welcome to \" +stringName1 +stringName2);\n\n    \/\/ using addition + operator\n    System.out.println(\"Adding(+) two operands: \"+(operand1 + operand2));\n    \/\/ using subtraction - operator\n    System.out.println(\"Subtracting(-) two operands: \"+(operand1 - operand2));\n    \/\/ using multiplication * operator\n    System.out.println(\"Multiplying(*) two operands: \"+(operand1 * operand2));\n    \/\/ using division \/ operator\n    System.out.println(\"Dividing(\/) two operands: \"+(operand1 \/ operand2));\n    \/\/ using modulus % operator\n    System.out.println(\"Modulus(%) of two operands: \"+(operand1 % operand2));\n  }\n}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">Welcome to TechVidvan&#8217;s Java Tutorial<br \/>\nAdding(+) two operands: 120<br \/>\nSubtracting(-) two operands: 80<br \/>\nMultiplying(*) two operands: 2000<br \/>\nDividing(\/) two operands: 5<br \/>\nModulus(%) of two operands: 0<\/div>\n<h4>2. Unary Operators in Java<\/h4>\n<p>The operators that act on one operand are called Unary Operators. They are of 2 types:<\/p>\n<h5>2.1. Unary +<\/h5>\n<p>The operator unary \u2018+\u2019 precedes an operand. The operand of the unary + operator must have an arithmetic type and the result is the value of the argument itself.<\/p>\n<p><strong>For example:<\/strong><\/p>\n<p>If number1 = 5 then +number1 means 5.<br \/>\nIf number2 = -4 then +number1 means -4.<\/p>\n<h5>2.2. Unary &#8211;<\/h5>\n<p>The operator unary &#8211; precedes an operand. The operand of the unary &#8211; must be of an arithmetic type and the result is the negation of the value of the operand. This operator changes the sign of the operand\u2019s value.<\/p>\n<p><strong>For example:<\/strong><\/p>\n<p>If number1 = 5 then -number1 means -5.<br \/>\nIf number2 = 0 then -number1 means 0.<br \/>\nIf number3 = -7 then -number3 means 7.<\/p>\n<h5>2.3. Increment\/Decrement operators ( ++\/&#8211; )<\/h5>\n<p>Java includes two useful operators which are generally not found in other computer languages (except C and C++). These are the increment (++) and decrement (- -) operators. The ++ operator adds 1 to its operand while &#8211; &#8211; operator subtracts 1. In other words, we can say,<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">num = num + 1;<\/pre>\n<p>is same as<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">++num ; or num++;<\/pre>\n<p>and,<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">num = num - 1;<\/pre>\n<p>is same as<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">--num ; or num-- ;<\/pre>\n<p>However, both the increment and decrement operators come in<strong> two categories\/varieties:<\/strong> They can either <strong>precede<\/strong> or <strong>follow<\/strong> the operand.<\/p>\n<p>The <strong>prefix<\/strong> version, in which the operator comes before the operand, as in-<br \/>\n<strong>Pre-Increment ( ++operand )<\/strong> and <strong>Pre-Decrement ( &#8211; -operand ):<\/strong><\/p>\n<p>When an increment or decrement operator precedes its operand <em>(prefix form)<\/em>, then Java performs the increment or decrement operation before using the value of the operand.<\/p>\n<p><strong>For example:<\/strong><\/p>\n<p>int count = 3,sum=0;<br \/>\nsum = sum + (++count); \/\/will result in the value of sum to 4.<\/p>\n<p><strong>Principal:<\/strong> The pre-increment or pre-decrement operators follow the <strong>change-then-use<\/strong> rule that is, they first change the value of their operand, then use the new value in evaluating an expression.<\/p>\n<p>And, in the <strong>postfix<\/strong> version, the operator comes after the operand, as in-<br \/>\n<strong>Post-Increment ( operand++ )<\/strong> and <strong>Post-Decrement ( operand &#8211; &#8211; ):<\/strong><\/p>\n<p>When an increment or decrement operator follows its operand (prefix form), then Java first uses the value of the operand before performing the increment or decrement operation on the value of the operand.<\/p>\n<p><strong> For example:<\/strong><br \/>\nint count = 3,sum=0;<br \/>\nsum = sum + (count++); \/\/will result in the value of sum to 3.<\/p>\n<p><strong>Principal:<\/strong> The post-increment or post-decrement operators follow the <strong>use-then-change<\/strong> rule that is, they first use the value of their operand in evaluating the expression, then change the value of the operand.<\/p>\n<p><strong>Code Snippet to understand the increment\/decrement operators:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.TechVidvan.Operators;\npublic class UnaryOperators\n{\n  \/\/ Java program to illustrate unary operators\n  public static void main(String[] args)\n  {\n    int num1 = 10, num2 = 20, num3 = 30, num4 = 40, result;\n\n    \/\/using pre-increment operator\n    result = ++num1;\n    System.out.println(\"Value of pre incremented value of num1: \" +result);\n\n    \/\/using post increment operator\n    result = num2++;\n    System.out.println(\"Value of post incremented value of num2: \" +result);\n\n    \/\/using pre-decrement operator\n    result = --num3;\n    System.out.println(\"Value of pre decremented value of num3: \" + result);\n\n    \/\/using post-decrement operator\n    result = num4--;\n    System.out.println(\"Value of post decremented value of num4: \" +result);\n  }\n}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">Value of pre incremented value of num1: 11<br \/>\nValue of post incremented value of num2: 20<br \/>\nValue of pre decremented value of num3: 29<br \/>\nValue of post decremented value of num4: 40<\/div>\n<h4>3. Relational Operators in Java<\/h4>\n<p>The term <em>\u2018relational\u2019<\/em> in the relational operator refers to the relationships that values or operands can have with one another. Thus, the relational operators determine the relation among the operands. Java provides 6 relational operators for comparing numbers and characters.<\/p>\n<p>But, relational operators do not work with strings. After the comparison, they return the result in boolean datatype. If the comparison is true, the relational operator results in true, otherwise false. They are extensively used in looping as well as conditional if-else statements.<\/p>\n<p>The general <strong>syntax<\/strong> of the relational operator is,<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">variable_name relation_operator value;<\/pre>\n<p>The six relational operators are:<a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/02\/types-of-relational-operators.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-76421\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/02\/types-of-relational-operators.jpg\" alt=\"types of relational operators\" width=\"722\" height=\"269\" \/><\/a><\/p>\n<h5>3.1. Equal to (==) Operator<\/h5>\n<p>It returns true if the left-hand side is equal to the right-hand side, otherwise false.<\/p>\n<h5>3.2. Not Equal to (!=) Operator<\/h5>\n<p>It returns true if the left-hand side is not equal to the right-hand side, otherwise false.<\/p>\n<h5>3.3. Less Than (&lt;) Operator<\/h5>\n<p>It returns true if the left-hand side is less than the right-hand side, otherwise false.<\/p>\n<h5>3.4. Less Than or Equal to (&lt;=) Operator<\/h5>\n<p>It returns true if the left-hand side is less than or equal to the right-hand side, otherwise false.<\/p>\n<h5>3.5. Greater Than (&gt;) Operator<\/h5>\n<p>It returns true if the left-hand side is greater than the right-hand side, otherwise false.<\/p>\n<h5>3.6. Greater Than or Equal to (&gt;=) Operator<\/h5>\n<p>It returns true if the left-hand side is greater than or equal to the right-hand side, otherwise false.<\/p>\n<p>The below table illustrates the relational operations on p and q. Here p and q are of the <strong>int<\/strong> data type.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/02\/relational-operators-in-java.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-76423 aligncenter\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/02\/relational-operators-in-java.jpg\" alt=\"relational operators in java\" width=\"552\" height=\"312\" \/><\/a><\/p>\n<h4>4. Logical Operators in Java<\/h4>\n<p>Logical operators are also known as conditional operators. These operators are used for evaluating one or more boolean expression, for complex decision-making. They also return a boolean value (true or false).<\/p>\n<p>There are three types of logical or conditional operators in Java are <strong>&amp;&amp; (Logical-AND), || (Logical-OR)<\/strong> and <strong>! (Logical NOT).<\/strong><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/02\/types-of-logical-or-conditional-operators.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-76425\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/02\/types-of-logical-or-conditional-operators.jpg\" alt=\"types of logical or conditional operators\" width=\"706\" height=\"284\" \/><\/a><\/p>\n<p>In this, <strong>&amp;&amp; (Logical-AND)<\/strong> and <strong>|| (Logical-OR)<\/strong> operators are the <strong>binary<\/strong> logical operators that work on two operands or expressions, while <strong>! (Logical NOT)<\/strong> is a <strong>unary<\/strong> logical operator which works on single operand or expression.<\/p>\n<p>Let\u2019s discuss each of them in detail<\/p>\n<h5>4.1. The Logical AND Operator (&amp;&amp;)<\/h5>\n<p>The logical AND operator (&amp;&amp;) combines two expressions (operands) into one expression. The resulting expression evaluates to true only if both of its expressions (operands) are true. Following are the examples of &amp;&amp; operator &#8211;<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">(5==3) &amp;&amp; (4==4) \/\/results into false because first expression is false.<\/pre>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">(4==4) &amp;&amp; (7==7) \/\/results into true because both expressions are true.<\/pre>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">1 &lt; 8 &amp;&amp; 4 &gt; 2 \/\/results into true because both expressions are true.<\/pre>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">4 &gt; 6 &amp;&amp; 5 &lt; 2 \/\/results into false because both expressions are false.<\/pre>\n<h5>4.2. The Logical OR Operator ( || )<\/h5>\n<p>The logical OR operator (||) also combines two expressions (operands) into one expression. The resulting expression evaluates to true if either of its expressions (operands) evaluates to true.<\/p>\n<p><strong>Following are the examples of || operator:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">(6==3) || (4==4) \/\/results into true because second expression is true.<\/pre>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">(4==4) || (7==7) \/\/results into true because both expressions are true.<\/pre>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">6 &lt; 9 || 4 &lt; 2 \/\/results into false because both expressions are false.<\/pre>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">4 &lt; 6 || 5 &lt; 2 \/\/results into true because first expression is true.<\/pre>\n<h5>4.3. The Logical NOT Operator ( ! )<\/h5>\n<p>The logical NOT operator, which is written as <strong>! <\/strong>, is a unary operator that works on a single operand or expression. The Logical NOT operator (!) negates or reverses the truth value of its operand.<\/p>\n<p>That is if the expression is true, then !expression is false and vice-versa. The following are the examples of ! operator-<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">! (9 != 0) \/\/results into false because 9 is non-zero(i.e., true).<\/pre>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">! (6 &gt; 2) \/\/results into false because the expression 6 &gt; 2 is true.<\/pre>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">! (4 &gt; 10) \/\/results into true because the expression 4 &gt; 10 is false.<\/pre>\n<p><strong>Code Snippet to understand the Logical operators:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.TechVidvan.Operators;\npublic class LogicalOperators\n{\n  \/\/ Java program to illustrate Logical operators\n  public static void main(String[] args)\n  {\n    int age = 19;\n    String nationality = \"Indian\";\n    int country_code = 22;\n\n    \/\/Using Logical AND (&amp;&amp;) operator\n    if(age &gt;=18 &amp;&amp; nationality.equals(\"Indian\"))\n    {\n      System.out.println(\"You are eligible for voting\");\n    }\n\n    \/\/Using Logical OR(||) operator\n    if(age&gt;=18 &amp;&amp; (nationality.equals(\"Indian\") || country_code==1))\n    {\n      System.out.println(\"You are eligible for voting\");\n    }\n\n    \/\/Using Logical NOT(!) operator\n    if(country_code != 1)\n    {\n      System.out.println(\"You are NOT eligible for voting!!\");\n    }\n  }\n}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">You are eligible for voting<br \/>\nYou are eligible for voting<br \/>\nYou are NOT eligible for voting!!<\/div>\n<h4>5. Bitwise Operators in Java<\/h4>\n<p>The Bitwise operators manipulate the individual bits of a number. The bitwise operators work with the integer types that is,<em> byte, short, int, and long types<\/em>. Java provides 4 bitwise operators:<a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/02\/types-of-bitwise-operators.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-76426\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/02\/types-of-bitwise-operators.jpg\" alt=\"types of bitwise operators\" width=\"636\" height=\"346\" \/><\/a><\/p>\n<p><em>The following table shows the 4 operations that Java programming language provides to perform bitwise functions on their operands:<\/em><\/p>\n<table class=\"tv-table-center\">\n<tbody>\n<tr>\n<td style=\"text-align: center\"><b><i>Operator<\/i><\/b><\/td>\n<td style=\"text-align: center\"><b><i>Use<\/i><\/b><\/td>\n<td style=\"text-align: center\"><b><i>Operation<\/i><\/b><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center\">&amp;<\/td>\n<td><span style=\"font-weight: 400\">op1 &amp; op2<\/span><\/td>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">Bitwise AND<\/span><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center\"><b>|<\/b><\/td>\n<td><span style=\"font-weight: 400\">Op1 | op2<\/span><\/td>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">Bitwise OR<\/span><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center\"><b>^<\/b><\/td>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">op1 ^ op2<\/span><\/td>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">Bitwise XOR<\/span><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center\"><b>~<\/b><\/td>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">~op2<\/span><\/td>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">Bitwise Complement<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>The bitwise operations calculate each bit of their results by comparing the corresponding bits of the two operands on the basis of these 3 rules:<\/p>\n<ul>\n<li>For AND operations, 1 AND 1 produce 1. Any other combination produces 0.<\/li>\n<li>For XOR operations, 1 XOR 0 produces 1, similarly, 0 XOR 1 produces 1. Any other combination produces 0.<\/li>\n<li>For OR operations, 0 OR 0 produces 0. Any other combination produces 1.<\/li>\n<li>For complement operations, the operator inverts the value.<\/li>\n<\/ul>\n<h5>5.1. The Bitwise AND Operator (&amp;)<\/h5>\n<p>It returns Bitwise AND operations on each parallel pair of bits of its every operand. The AND function sets the resulting bit to 1 only if the corresponding bits of both operands are 1, otherwise, the resulting bit is 0.<\/p>\n<table class=\"tv-table-center\">\n<tbody>\n<tr>\n<td style=\"text-align: center\"><b><i>op1<\/i><\/b><\/td>\n<td style=\"text-align: center\"><b><i>op2<\/i><\/b><\/td>\n<td style=\"text-align: center\"><b><i>Result (op1 &amp; op2)<\/i><\/b><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">0<\/span><\/td>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">0<\/span><\/td>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">0<\/span><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">0<\/span><\/td>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">1<\/span><\/td>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">0<\/span><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">1<\/span><\/td>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">0<\/span><\/td>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">0<\/span><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">1<\/span><\/td>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">1<\/span><\/td>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">1<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h5>5.2. The Bitwise OR Operator (|) \/ Inclusive OR Operator<\/h5>\n<p>It returns the Bitwise AND operations on each parallel pair of bits of its every operand. Inclusive OR means that if either of the two bits is 1, the resulting bit is 1. In short, at least one of the two bits should be 1 to get a result as 1.<\/p>\n<table class=\"tv-table-center\">\n<tbody>\n<tr>\n<td style=\"text-align: center\"><b><i>op1<\/i><\/b><\/td>\n<td style=\"text-align: center\"><b><i>op2<\/i><\/b><\/td>\n<td style=\"text-align: center\"><b><i>Result (<\/i><\/b><b>op1 | op2<\/b><b><i>)<\/i><\/b><\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: center\"><span style=\"font-weight: 400\">0<\/span><\/p>\n<\/td>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">0<\/span><\/td>\n<td>\n<p style=\"text-align: center\"><span style=\"font-weight: 400\">0<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p style=\"text-align: center\"><span style=\"font-weight: 400\">0<\/span><\/p>\n<\/td>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">1<\/span><\/td>\n<td>\n<p style=\"text-align: center\"><span style=\"font-weight: 400\">1<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">1<\/span><\/td>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">0<\/span><\/td>\n<td>\n<p style=\"text-align: center\"><span style=\"font-weight: 400\">1<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">1<\/span><\/td>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">1<\/span><\/td>\n<td>\n<p style=\"text-align: center\"><span style=\"font-weight: 400\">1<\/span><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h5>5.3. The Bitwise XOR operator (^) \/ exclusive OR Operator<\/h5>\n<p>Inclusive OR means that if the two bits of the operands are different, then the resulting bit is 1, otherwise the result is 0. If both bits are the same, the result is 0.<\/p>\n<table class=\"tv-table-center\">\n<tbody>\n<tr>\n<td style=\"text-align: center\"><b><i>op1<\/i><\/b><\/td>\n<td style=\"text-align: center\"><b><i>op2<\/i><\/b><\/td>\n<td style=\"text-align: center\"><b><i>Result<\/i><\/b> <b><i>(op1 ^ op2)<\/i><\/b><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">0<\/span><\/td>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">0<\/span><\/td>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">0<\/span><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">0<\/span><\/td>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">1<\/span><\/td>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">1<\/span><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">1<\/span><\/td>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">0<\/span><\/td>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">1<\/span><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">1<\/span><\/td>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">1<\/span><\/td>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">0<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h5>5.4. The Bitwise Complement Operator (~)<\/h5>\n<p>The complement operator inverts the value of each bit of the operand; if the operand bit is 1 the result is 0 and if the bit is 0 the result is 1.<\/p>\n<table class=\"tv-table-center\">\n<tbody>\n<tr>\n<td style=\"text-align: center\"><b><i>op1<\/i><\/b><\/td>\n<td style=\"text-align: center\"><b><i>Result<\/i><\/b><b> (~op1)<\/b><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">0<\/span><\/td>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">1<\/span><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">1<\/span><\/td>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">0<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Code Snippet to understand the Bitwise operators:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.TechVidvan.Operators;\npublic class BitwiseOperators\n{\n  public static void main(String args[])\n  {\n      int num1 = 11; \/\/Binary form of 11 = 00001011\n      int num2 = 22; \/\/Binary form of 22 = 00010110\n      int result;\n\n      result = num1 &amp; num2;\n      System.out.println(\"Performing Bitwise AND operation\");\n      System.out.println(\"num1 &amp; num2: \"+result);\n\n      result = num1 | num2;\n      System.out.println(\"\\nPerforming Bitwise OR operation\");\n      System.out.println(\"num1 | num2: \"+result);\n\n      result = num1 ^ num2;\n      System.out.println(\"\\nPerforming Bitwise XOR operation\");\n      System.out.println(\"num1 ^ num2: \"+result);\n\n      result = ~num1;\n      System.out.println(\"\\nPerforming Bitwise complement operation\");\n      System.out.println(\"~num1: \"+result);\n  }\n}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">Performing Bitwise AND operation<br \/>\nnum1 &amp; num2: 2<br \/>\nPerforming Bitwise OR operation<br \/>\nnum1 | num2: 31<br \/>\nPerforming Bitwise XOR operation<br \/>\nnum1 ^ num2: 29<br \/>\nPerforming Bitwise complement operation<br \/>\n~num1: -12<\/div>\n<h4>6. Shift Operators in Java<\/h4>\n<p>A shift operator performs bit manipulation on operands by shifting the bits of its first operand to right or left.<\/p>\n<p><strong>The general syntax of shift operators is &#8211;<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">number shiftOperator numberOfPlacesToShift ;<\/pre>\n<p>There are 3 shift operators available in Java:<a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/02\/types-of-shift-operators.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-76427\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/02\/types-of-shift-operators.jpg\" alt=\"types of shift operators\" width=\"706\" height=\"295\" \/><\/a><\/p>\n<h5>6.1. The Signed Left Shift Operator (&lt;&lt;)<\/h5>\n<p>The signed left shift operator shifts the bits of the number or operand to the left and fills 0 on vacated bits left as a result. Its effect is similar to multiplying the number with some power of two.<\/p>\n<h5>6.2. The Signed Right Shift Operator (&gt;&gt;)<\/h5>\n<p>The signed right shift operator shifts the bits of the number to the right. In a signed left shift operation, the leftmost vacated bits depend on the sign of the leftmost bit or sign bit or <strong>most significant bit (MSB)<\/strong> of the operand.<\/p>\n<p>Its effect is similar to dividing the number with some power of two.<\/p>\n<h5>6.3. The Unsigned Right Shift Operator (&gt;&gt;&gt;)<\/h5>\n<p>The unsigned right shift operator shifts the bits of the number to the right. In an unsigned right shift operation, the leftmost vacated bits are always set to 0, irrespective of the sign of the leftmost bit or sign bit or <strong>most significant bit (MSB).<\/strong><\/p>\n<p><strong>Note:<\/strong><\/p>\n<p><em>In Java, the <strong>signed<\/strong> right shift operation populates the vacated bits with a sign bit, while the left shift and the <strong>unsigned<\/strong> right shift operation populates the vacated bits with zeroes.<\/em><\/p>\n<p><strong>To understand this, consider the example shown in the following figure:<\/strong><\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/02\/shift-operator-example.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-76330\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/02\/shift-operator-example.jpg\" alt=\"shift operator example\" width=\"642\" height=\"512\" \/><\/a><\/p>\n<p><strong>Code Snippet to understand the shift operators:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.TechVidvan.Operators;\npublic class ShiftOperators\n{\n  public static void main(String args[])\n  {\n    int num1 = 16; \/\/Binary form of 11 = 00010000\n    int result;\n\n    result = num1 &lt;&lt; 2;\n    System.out.println(\"Performing Left shift operation\");\n    System.out.println(\"num1 &lt;&lt; 2: \"+result);\n\n    result = num1 &gt;&gt; 2;\n    System.out.println(\"\\nPerforming signed right shift operation\");\n    System.out.println(\"num1 &gt;&gt; 2: \"+result);\n\n    result = num1 &gt;&gt;&gt; 2;\n    System.out.println(\"\\nPerforming unsigned right shift operation\");\n    System.out.println(\"num1 &gt;&gt;&gt; 2: \"+result);\n  }\n}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">Performing Left shift operation<br \/>\nnum1 &lt;&lt; 2: 64<br \/>\nPerforming signed right shift operation<br \/>\nnum1 &gt;&gt; 2: 4<br \/>\nPerforming unsigned right shift operation<br \/>\nnum1 &gt;&gt;&gt; 2: 4<\/div>\n<h4>7. Assignment Operator in Java (=)<\/h4>\n<p>Like other programming languages, Java offers an assignment operator = for assigning one value to another value or a variable.<\/p>\n<p>Assignment Operator follows the right to left associativity, that is a value given on the right-hand side of the operator is assigned to the variable on the left-hand side and therefore we should declare the value of the right-hand side before using it or it should be a constant.<\/p>\n<p>The general format of the assignment operator is,<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">variable = value;<\/pre>\n<p><strong>For Example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">int x, y, z;\nx = 9;\ny = 7;\nz = x + y;\nz = z * 2;<\/pre>\n<h5>Java Shorthand Assignment Operators<\/h5>\n<p>Java provides some special shorthand operators that simplify the coding of a certain type of assignment operations.<\/p>\n<p>Using these shorthand operators, we can combine the assignment operator with other operators to build a shorter version of the statement, which is called a <strong>Compound Statement.<\/strong><\/p>\n<p><strong>For example:<\/strong><\/p>\n<p>Instead of writing num = num + 5; we can write num += 5;.<br \/>\nThe operator pair += tells the compiler to assign to num the value of <strong>num + 5<\/strong>. This shorthand works on all the binary operators in Java.<\/p>\n<p>The general form of the Java shorthand assignment is:<br \/>\n<strong>var<\/strong> = <strong>var<\/strong> operator <strong>expression<\/strong>;<br \/>\nis same as<br \/>\n<strong>var<\/strong> operator = <strong>expression<\/strong>;<\/p>\n<p><strong>Following are some examples of Java shorthands:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">x -= 10;\tis equivalent to \tx = x - 10;\nx *= 22;\tis equivalent to \tx = x * 22;\nx \/= 3;\t\tis equivalent to \tx = x \/ 3;\nx %= y;\t\tis equivalent to \tx = x % y;<\/pre>\n<p>Thus, we can say =, *=, \/=, %=, +=, -= are assignment operators in Java. The operators *=, \/=, %=, +=, -= are called arithmetic assignment operators.<\/p>\n<p>The following table lists the shorthand assignment operators with their equivalents:<\/p>\n<table class=\"tv-table-center\">\n<tbody>\n<tr>\n<td style=\"text-align: center\"><b><i>Shorthand Operator<\/i><\/b><\/td>\n<td style=\"text-align: center\"><b><i>Use<\/i><\/b><\/td>\n<td style=\"text-align: center\"><b><i>Equivalent to<\/i><\/b><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">+=<\/span><\/td>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">op1 += op2<\/span><\/td>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">op1 = op1 + op2<\/span><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">-=<\/span><\/td>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">op1 -= op2<\/span><\/td>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">op1 = op1 &#8211; op2<\/span><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">*=<\/span><\/td>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">op1 *= op2<\/span><\/td>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">op1 = op1 * op2<\/span><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">\/=<\/span><\/td>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">op1 \/= op2<\/span><\/td>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">op1 = op1 \/ op2<\/span><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">%=<\/span><\/td>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">op1 %= op2<\/span><\/td>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">op1 = op1 % op2<\/span><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">&amp;=<\/span><\/td>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">op1 &amp;= op2<\/span><\/td>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">op1 = op1 &amp; op2<\/span><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">|=<\/span><\/td>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">op1 |= op2<\/span><\/td>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">op1 = op1 | op2<\/span><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">^=<\/span><\/td>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">op1 ^= op2<\/span><\/td>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">op1 = op1 ^ op2<\/span><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">&lt;&lt;=<\/span><\/td>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">op1 &lt;&lt;= op2<\/span><\/td>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">op1 = op1 &lt;&lt; op2<\/span><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">&gt;&gt;=<\/span><\/td>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">op1 &gt;&gt;= op2<\/span><\/td>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">op1 = op1 &gt;&gt; op2<\/span><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">&gt;&gt;&gt;=<\/span><\/td>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">op1 &gt;&gt;&gt;= op2<\/span><\/td>\n<td style=\"text-align: center\"><span style=\"font-weight: 400\">op1 = op1 &gt;&gt;&gt; op2<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Code Snippet to understand the Assignment operators:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.TechVidvan.Operators;\npublic class AssignmentOperators\n{\n  public static void main(String args[])\n  {\n    int num1 = 76;\n    int num2 = 10;\n\n    num2 += num1;\n    System.out.println(\"+= Output: \"+num2);\n\n    num2 -= num1;\n    System.out.println(\"-= Output: \"+num2);\n\n    num2 *= num1;\n    System.out.println(\"*= Output: \"+num2);\n\n    num2 \/= num1;\n    System.out.println(\"\/= Output: \"+num2);\n\n    num2 %= num1;\n    System.out.println(\"%= Output: \"+num2);\n  }\n}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">+= Output: 86<br \/>\n-= Output: 10<br \/>\n*= Output: 760<br \/>\n\/= Output: 10<br \/>\n%= Output: 10<\/div>\n<h4>8. Other Operators in Java<\/h4>\n<p>Java supports some other operators which are &#8211;<\/p>\n<h5>8.1. Ternary Operator ( ?: )<\/h5>\n<p>Java offers a shortcut conditional operator (?:) that stores a value according to the condition. This operator is a ternary operator that is it requires three operands.<\/p>\n<p>The general form of the conditional\/ternary operator is as follows:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">expression1 ? expression2 : expression3 ;<\/pre>\n<p>The result of the whole expression depends on the value of expression1. If expression1 evaluates to true that is 1, then the value of expression2 is evaluated, otherwise, the value of expression3 is evaluated. For instance,<br \/>\nresult = marks &gt;= 50 ? \u201cPass\u201d : \u201cFail\u201d ;<\/p>\n<p>The value of the variable result will be \u201cPass\u201d if the test expression &gt;= 50 evaluates to true (1), otherwise, the value of the result will be \u201cFail\u201d.<\/p>\n<p><strong>Following are some more examples of ternary operator:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">6 &gt; 4 ? 9 : 7 evaluates to 9 because test expression 6 &gt; 4 is true.<\/pre>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">4 == 10 ? 10 :25 evaluates to 25 because test expression 4 == 10 is false.<\/pre>\n<h5>8.2. The Dot . Operator<\/h5>\n<p>The dot operator (.) is used to access the instance members of an object or class members of a class.<\/p>\n<p><strong>For example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">class MyClass\n{\nint num1=10;\npublic static void main(String args[]){\nMyClass object1 = new MyClass();\nobject1.num1 = 10; \/\/using dot operator\n}<\/pre>\n<h5>8.3. The () Operator<\/h5>\n<p>This operator is used when we declare or call the methods or functions. We can list the method\u2019s arguments between parenthesis (and) or we can specify an empty argument list by using () with nothing between them.<\/p>\n<p>For example:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">void display();\nInt addNumbers(int x, int y);<\/pre>\n<h5>8.4. The instanceof Operator<\/h5>\n<p>The instanceof operator is used for type checking. It tests whether its first operand is an instance of its second operand. It can be used to test whether an object is an instance of a class, a subclass or an interface. The general syntax is:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">op1 instanceof op2;<\/pre>\n<p>It returns <em>true<\/em> or <em>false<\/em> in the result.<\/p>\n<p><strong>Code Snippet to understand the instanceof operator:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.TechVidvan.Operators;\npublic class InstanceofOperator\n{\n  public static void main(String[] args)\n  {\n      InstanceofOperator object1 = new \t\t\t\t\t\t\t\t\t\t\t\tInstanceofOperator();\n      InstanceofOperator object2 = null;\n\n      \/\/ As object1 is of type InstanceofOperator,it returns true\n      System.out.println(\"object1 is instance of: InstanceOfOperator: \"\n          + (object1 instanceof InstanceofOperator));\n\n      \/\/ As object2 is not instantiated, it returns false\n      System.out.println(\"object2 is instanceof InstanceOfOperator: \"\n          + (object2 instanceof InstanceofOperator));\n\n    }\n}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">object1 is instance of: InstanceOfOperator: true<br \/>\nobject2 is instanceof InstanceOfOperator: false<\/div>\n<h3>Summary<\/h3>\n<p>Operators in Java are one of the most important and fundamental concepts. Operators help programmers to perform a few specific operations like Arithmetic, Unary, Assignment, Relational, Logical, Ternary, Bitwise, and Shift operation and get the valuable results out of them.<\/p>\n<p>We can not get valuable results or information until and unless we use any of these operators in our program.By this article, we have learned each type of operator in Java along with their sub-categories.<\/p>\n<p>Also, we understood the use of operators with the help of code snippets and examples given with each type of operator. Until and unless the basic knowledge and practical usage of operators are clear, one can not master the language.<\/p>\n<p>Thank you for reading our article. If you have any queries, do let us know through the comment section below.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Now as you are familiar with the declaration and initialization of variables in Java, you might be eager to know how to perform with them. In this tutorial, we will learn the various operators&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":76331,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[183],"tags":[1624,1625,1626,1627,1628,1629,1630,1631,1632,1633,1634],"class_list":["post-76246","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java","tag-java-arithmetic-operators","tag-java-bitwise-operators","tag-java-instanceof-operator","tag-java-operators","tag-java-operators-list","tag-java-operators-with-example","tag-java-ternary-operators","tag-java-unary-operators","tag-operators-in-java","tag-types-of-java-operators","tag-what-is-java-operator"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Java Operators and its 8 Types that you should know about! - TechVidvan<\/title>\n<meta name=\"description\" content=\"Operators in Java are the most fundamental concepts. By this article, learn the 8 types of Java Operators along with their sub categories, syntax &amp; examples.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/techvidvan.com\/tutorials\/java-operators\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Java Operators and its 8 Types that you should know about! - TechVidvan\" \/>\n<meta property=\"og:description\" content=\"Operators in Java are the most fundamental concepts. By this article, learn the 8 types of Java Operators along with their sub categories, syntax &amp; examples.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/techvidvan.com\/tutorials\/java-operators\/\" \/>\n<meta property=\"og:site_name\" content=\"TechVidvan\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/TechVidvan\/\" \/>\n<meta property=\"article:published_time\" content=\"2020-02-11T04:50:18+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/02\/types-of-java-operators.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"802\" \/>\n\t<meta property=\"og:image:height\" content=\"420\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"TechVidvan Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:site\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"TechVidvan Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"19 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Java Operators and its 8 Types that you should know about! - TechVidvan","description":"Operators in Java are the most fundamental concepts. By this article, learn the 8 types of Java Operators along with their sub categories, syntax & examples.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/techvidvan.com\/tutorials\/java-operators\/","og_locale":"en_US","og_type":"article","og_title":"Java Operators and its 8 Types that you should know about! - TechVidvan","og_description":"Operators in Java are the most fundamental concepts. By this article, learn the 8 types of Java Operators along with their sub categories, syntax & examples.","og_url":"https:\/\/techvidvan.com\/tutorials\/java-operators\/","og_site_name":"TechVidvan","article_publisher":"https:\/\/www.facebook.com\/TechVidvan\/","article_published_time":"2020-02-11T04:50:18+00:00","og_image":[{"width":802,"height":420,"url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/02\/types-of-java-operators.jpg","type":"image\/jpeg"}],"author":"TechVidvan Team","twitter_card":"summary_large_image","twitter_creator":"@vidvantech","twitter_site":"@vidvantech","twitter_misc":{"Written by":"TechVidvan Team","Est. reading time":"19 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/techvidvan.com\/tutorials\/java-operators\/#article","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-operators\/"},"author":{"name":"TechVidvan Team","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22"},"headline":"Java Operators and its 8 Types that you should know about!","datePublished":"2020-02-11T04:50:18+00:00","mainEntityOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-operators\/"},"wordCount":2700,"commentCount":0,"publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-operators\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/02\/types-of-java-operators.jpg","keywords":["Java Arithmetic Operators","Java Bitwise Operators","Java instanceof Operator","java operators","Java operators list","Java operators with Example","Java Ternary Operators","Java Unary Operators","operators in java","Types of Java Operators","What is Java Operator"],"articleSection":["Java Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/techvidvan.com\/tutorials\/java-operators\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/techvidvan.com\/tutorials\/java-operators\/","url":"https:\/\/techvidvan.com\/tutorials\/java-operators\/","name":"Java Operators and its 8 Types that you should know about! - TechVidvan","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-operators\/#primaryimage"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-operators\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/02\/types-of-java-operators.jpg","datePublished":"2020-02-11T04:50:18+00:00","description":"Operators in Java are the most fundamental concepts. By this article, learn the 8 types of Java Operators along with their sub categories, syntax & examples.","breadcrumb":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-operators\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/techvidvan.com\/tutorials\/java-operators\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/java-operators\/#primaryimage","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/02\/types-of-java-operators.jpg","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/02\/types-of-java-operators.jpg","width":802,"height":420,"caption":"types of java operators"},{"@type":"BreadcrumbList","@id":"https:\/\/techvidvan.com\/tutorials\/java-operators\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/techvidvan.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"Java Operators and its 8 Types that you should know about!"}]},{"@type":"WebSite","@id":"https:\/\/techvidvan.com\/tutorials\/#website","url":"https:\/\/techvidvan.com\/tutorials\/","name":"TechVidvan Blogs","description":"","publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/techvidvan.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/techvidvan.com\/tutorials\/#organization","name":"TechVidvan","url":"https:\/\/techvidvan.com\/tutorials\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","width":200,"height":50,"caption":"TechVidvan"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/TechVidvan\/","https:\/\/x.com\/vidvantech"]},{"@type":"Person","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22","name":"TechVidvan Team","description":"The TechVidvan Team delivers practical, beginner-friendly tutorials on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our experts are here to help you upskill and excel in today\u2019s tech industry."}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/76246","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/comments?post=76246"}],"version-history":[{"count":0,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/76246\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media\/76331"}],"wp:attachment":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media?parent=76246"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/categories?post=76246"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/tags?post=76246"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}