[Go to site: main page, start]

0% found this document useful (0 votes)
2 views3 pages

Java Operators and DataTypes Notes

The document provides an overview of Java operators and data types, detailing various operator types such as arithmetic, relational, logical, assignment, unary, bitwise, ternary, and shift operators along with their definitions. It also outlines primitive data types including byte, short, int, long, float, double, char, and boolean, as well as non-primitive data types like String, Array, Class, Object, and Interface, with examples for each. This serves as a foundational reference for understanding how to manipulate data and perform operations in Java programming.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

Java Operators and DataTypes Notes

The document provides an overview of Java operators and data types, detailing various operator types such as arithmetic, relational, logical, assignment, unary, bitwise, ternary, and shift operators along with their definitions. It also outlines primitive data types including byte, short, int, long, float, double, char, and boolean, as well as non-primitive data types like String, Array, Class, Object, and Interface, with examples for each. This serves as a foundational reference for understanding how to manipulate data and perform operations in Java programming.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Java Operators and Data Types –

Definitions and Examples


1. Java Operators – With Definitions
Operator Type Operator Definition
Arithmetic + Adds two numbers
- Subtracts the right
operand from the left
operand
* Multiplies two numbers
/ Divides the left operand
by the right operand
% Returns the remainder
after division
Relational == Checks if two values are
equal
!= Checks if two values are
not equal
> Checks if the left value is
greater than the right
< Checks if the left value is
less than the right
>= Checks if the left value is
greater than or equal to
the right
<= Checks if the left value is
less than or equal to the
right
Logical && Returns true if both
conditions are true
|| Returns true if at least
one condition is true
! Reverses the result of a
condition
Assignment = Assigns the right value to
the left variable
+= Adds right operand to left
and assigns the result
-= Subtracts right operand
from left and assigns the
result
*= Multiplies and assigns the
result
/= Divides and assigns the
result
%= Finds remainder and
assigns to the variable
Unary + Unary plus – represents a
positive value
- Unary minus – changes
the sign of the value
++ Increments value by 1
(prefix or postfix)
-- Decrements value by 1
(prefix or postfix)
! Logical NOT – reverses
the Boolean value
Bitwise & Bitwise AND – compares
each bit
| Bitwise OR – compares
each bit
^ Bitwise XOR – returns 1 if
bits are different
~ Bitwise NOT – inverts all
the bits
Ternary ?: Short-hand if-else:
condition ? true : false
Shift << Left shift – shifts bits left
>> Right shift – shifts bits
right with sign
>>> Unsigned right shift –
shifts bits right and fills
with 0

2. Java Data Types – With Definitions and Examples


Primitive Data Types
Data Type Category Definition Example
byte Primitive 8-bit integer, used byte a = 100;
to save memory in
large arrays
short Primitive 16-bit integer, short s = 30000;
larger than byte
int Primitive 32-bit integer, int x = 100000;
default type for
integers
long Primitive 64-bit integer, long l =
used for large 123456789L;
values
float Primitive 32-bit decimal float f = 10.5f;
number with single
precision
double Primitive 64-bit decimal double d = 99.99;
number with
double precision
char Primitive 16-bit Unicode char ch = 'A';
character
boolean Primitive Stores only true or boolean flag =
false true;
Non-Primitive (Reference) Data Types
Data Type Definition Example
String A sequence of characters String name = "Vaibhav";
(object of String class)
Array A collection of elements int[] marks = {90, 80, 85};
of the same type
Class A blueprint for objects class Student { ... }
Object An instance of a class Student s1 = new
Student();
Interface A reference type with interface Animal { void
abstract methods sound(); }

You might also like