Java
Java
College of Commerce
Submitted By
Supervised by
Mr. Mahdi Mohammed Younis
1.What is Operator:.................................................................................................2
2.type in operator:..................................................................................................3
3.Bitwise operator:..................................................................................................3
6.Bitwise logical:......................................................................................................5
CONCLUSION...............................................................................................................8
REFERENCES................................................................................................................9
2|Page
Bitwise operator in java
1.What is Operator:
Operators are used for a variety of purposes in Java. Arithmetic operators are used for
performing basic arithmetic operations such as addition, subtraction, multiplication, and
division. Logical operators are used to compare the values of two variables and make
decisions based on the outcome. Relational operators are used to compare two values and
determine their relationship. The bitwise operators are a special type of operator used to
manipulate the individual bits of a given number. They are used to perform bit-level
operations such as AND, OR, XOR, and NOT, which are essential when working with binary
numbers. Bitwise operators are also used to shift bits to the left or right to create a new value.
By using these operators, Java developers can manipulate data more efficiently and
effectively.
2.type in operator:
1. Arithmetic Operators
2. Unary Operators
3. Assignment Operator
4. Relational Operators
5. Logical Operators
6. Ternary Operator
7. Bitwise Operators
8. Shift Operators
3.Bitwise operator:
Bitwise operators are one among those operators which perform their tasks at
binary level directly on binary digits (also known as bits), the smallest form of data
in a computer, or its data types. These bitwise operators are faster and an efficient
3|Page
way to interact with computers to make heavy computation in a linear time
because it works directly within memory rather than through a level of abstraction
of software.
These bitwise operators alter data in constant time complexity and function parallelly by
making it efficient on all systems, and therefore this process of altering data through bitwise
operators is termed Bit Manipulation. Almost all programming languages will have to work
with data abstractions (for eg, objects or variables), rather than the bits they represent.
However, direct bit manipulation is required to optimize the performance of code and
reduce errors in numerous scenarios. (atul, 2022)
Here are few examples of tasks that require bit manipulation or knowledge of Bitwise
Operators:
We shall explore bitwise operators in java throughout this article in detail with its
implementation.
You can see how many steps are reduced with bit manipulation from normal representation.
4|Page
Bit Manipulation is performed using Bitwise Operators, on each and every bit of a number
individually and can be used with any data types such as int, float, short, char, etc.
Bitwise operators work on a binary equivalent of decimal numbers i.e. the operation is
performed on decimal numbers and internally these operators work on individual bits bit by
bit, as per the given operations:
5|Page
6.Bitwise logical:
Sometimes, whether a statement is executed is determined by a
combination of several conditions. you can use logical operators to
combine these conditions. Logical operators are known as Boolean
operators or bitwise logical operators. The boolean operator
operates on boolean values to create a new boolean value. The
bitwise logical operators are “&”, “|”, “^”, and “~” or “!”. The
following table shows the outcome of each operation.
This operator is named as the Logical AND operator. This operator returns true when both
conditions under evaluation are true, otherwise it returns false.
Short-Circuiting Effect: If the first condition cond1 evaluates to false, it doesn't carry out
a check on the second condition. It returns false without evaluating the second condition.
We are going to understand the above-mentioned definition with the help of a table that
shows us the results of the conditions in which this operator has been used. The table
represents the using of AND operator.
6|Page
From the table above, we can see that the AND operator returns true only if both conditions
(under consideration) are true. Even if one of the conditions is false, the AND operator
returns false.
Example
output
7|Page
Explanation:
In the code above, we are finding the maximum number out of p, q, r (taken as inputs).
If p is maximum among p, q, and r variables then both condition p > q and p > r should
be satisfied. Thus we have combined these two conditions using the AND (&&) operator.
Similar logic is employed for q. If p and q are not maximum, the maximum is obviously r.
This operator is named as the Logical OR operator. This operator returns true if any one of
the given conditions is true. OR operator returns false if and only if both conditions under
evaluation are false.
Short-Circuiting Effect: This operator doesn’t check the second condition if the first one
is true. The second condition is checked only and only if the first condition is false.
8|Page
It is clear from the table above that OR operator returns false if and only if both
conditions are false. Otherwise, it returns true.
Example
9|Page
Output
10 | P a g e
From the table above, it is clear that when both the inputs are identical, false is
returned. However, if XOR is performed on opposite operands, true is returned.
example
11 | P a g e
Output
12 | P a g e
CONCLUSION
As a class of operators, logical operators enable us to combine several conditional expressions.
Operator NOT (!
We can manage a program's execution flow with the use of logical operators.
When both conditions being evaluated are true, the AND operator yields true; otherwise, it returns
false.
If any of the predetermined conditions is true, the OR operator returns true. Only when both
conditions being evaluated are false does the OR
The NOT operator takes a single value as input and outputs the value's inverse. Unlike the AND
and OR operators, this one is a unary operator.
In the event that both inputs are identical, XOR returns false.
13 | P a g e
REFERENCES
Difference between Hardware and Software - GeeksforGeeks. (n.d.). Retrieved December 10,
2022, from https://www.geeksforgeeks.org/difference-between-hardware-and-software/
What is Computer Hardware and Software with Examples? (n.d.). Retrieved December 10, 2022,
from https://www.chtips.com/computer-fundamentals/what-is-computer-hardware-and-
software/
What Are the Differences Between Hardware and Software? (n.d.). Retrieved December 10, 2022,
from https://www.computerhope.com/issues/ch000039.htm
Differences between Hardware and Software | Hardware vs Software - javatpoint. (n.d.). Retrieved
December 10, 2022, from https://www.javatpoint.com/hardware-vs-software
CPU vs. RAM: Understanding the Differences - History-Computer. (n.d.). Retrieved December 10,
2022, from https://history-computer.com/cpu-vs-ram/
RAM vs. Processor—Which Is More Important to Your Business? (n.d.). Retrieved December 10,
2022, from https://www.intel.com/content/www/us/en/business/small-business/resources/ram-
vs-processor.html
14 | P a g e