XOR operator in Java

Avatar ByJayanthi

XOR operator in Java

Reading Time: 1 minute

In the Java programming language, a ‘variable’ is used to store a value. Different kinds of operations can be performed on the variables by means of ‘operators’.  The Java programming language has a number of operators and these are listed below:

  1. Arithmetic operators(+,-,*, /,++,–,%)
  2. Relational operators(<,<=,>,>=,==,!=)
  3. Logical operators(&,|,&&,||,^)
  4. Conditional operators(?:)
  5. instanceof operator
  6. assignment operator(=,+=,-=)

The arithmetic operator deals with the mathematical operations of addition, subtraction, multiplication, division and modulus. The relational operators deals with comparison of the operands(or the variables used) The conditional operator is a ternary operator. The logical operators work only with boolean expressions(like true and false)

XOR operator: (^)

The XOR operator is represented with a ‘^‘. If the two operands are same, then the result is a ‘0’ or false and if the two operands are different then the result is a ‘1’ or true. For example,

Operand 1Operand 2Result

XOR operator works with both boolean values and numerical values. The numerical values will be converted to binary values and the XOR operation will be  done. 

This is the working of the XOR operator. This post is for alphabet ‘X’ for the BlogchatterA2Z challenge… the previous post is here...

About the author


Jayanthi administrator

Jayanthi Manikandan has an undergraduate degree in Computer Science from India and a Master's degree in Information systems with a specialization in Information security from Detroit, MI, USA. She has written blogs for Simplilearn, Whizlabs software, InfoSec institute and Jigsaw academy. She has created e-learning videos for Whizlabs software and Twenty19. She has been passionate about Information security and has several years of experience writing on various technical topics. Additionally, she loves to pen a few personal thoughts here as well! :)

Leave a Reply