SlideShare a Scribd company logo
Operators in JAVA
OperatorAn operator is a symbol that operates on one or more arguments to produce a result. Java provides a rich set of operators to manipulate variables.
OperandsAn operands are the values on which the operators act upon.An operand can be:A numeric variable - integer, floating point or character
Any primitive type variable - numeric and boolean
Reference variable to an object
A literal - numeric value, boolean value, or string.
An array element, "a[2]“
char primitive, which in numeric operations is treated as an unsigned two byte integerTypes of OperatorsAssignment OperatorsIncrement Decrement OperatorsArithmetic OperatorsBitwise OperatorsRelational OperatorsLogical OperatorsTernary OperatorsComma OperatorsInstanceof Operators
Assignment OperatorsThe assignment statements has the following syntax:<variable> = <expression>
Assigning values Example
Increment and Decrement operators++ and --The increment and decrement operators add an integer variable by one.increment operator: two successive plus signs, ++decrement operator: --
Increment and Decrement operators++ and --Common Shorthanda = a + 1;		a++; or ++a;a = a - 1;		a--; or --a;
Example of ++ and -- operatorspublic class Example {	public static void main(String[] args)   {	 }}int j, p, q, r, s;j = 5;p = ++j;  //  j = j + 1;  p = j;System.out.println("p = " + p);q = j++;  //  q = j;      j = j + 1;System.out.println("q = " + q);System.out.println("j = " + j);r = --j;  //  j = j -1;   r = j;System.out.println("r = " + r);s = j--;  //  s = j;      j = j - 1;System.out.println("s = " + s);> java examplep = 6q = 6j = 7r = 6s = 6>
Arithmetic OperatorsThe arithmetic operators are used to construct mathematical expressions as in algebra. Their operands are of numeric type.
Arithmetic Operators
Simple Arithmeticpublic class Example {	public static void main(String[] args) {		int j, k, p, q, r, s, t;		j = 5;		k = 2;		p = j + k;		q = j - k;		r = j * k;		s = j / k;		t = j % k;		System.out.println("p = " + p);		System.out.println("q = " + q);		System.out.println("r = " + r);		System.out.println("s = " + s);		System.out.println("t = " + t);	}} > java Example p = 7 q = 3 r = 10 s = 2 t = 1 >
Bitwise OperatorsJava's bitwise operators operate on individual bits of integer (int and long) values. If an operand is shorter than an int, it is promoted to int before doing the operations.
Bitwise Operators
Example of Bitwise Operatorsclass Test { public static void main(String args[]) { int a = 60; /* 60 = 0011 1100 */ int b = 13; /* 13 = 0000 1101 */ int c = 0; c = a & b; /* 12 = 0000 1100 */ System.out.println("a & b = " + c ); c = a | b; /* 61 = 0011 1101 */ System.out.println("a | b = " + c );
Example Cont.,	c = a ^ b; /* 49 = 0011 0001 */ 	System.out.println("a ^ b = " + c ); 	c = ~a; /*-61 = 1100 0011 */ 	System.out.println("~a = " + c ); c = a << 2; /* 240 = 1111 0000 */ 	System.out.println("a << 2 = " + c ); c = a >> 2; /* 215 = 1111 */ System.out.println("a >> 2 = " + c ); c = a >>> 2; /* 215 = 0000 1111 */ System.out.println("a >>> 2 = " + c ); } }
Relational OperatorsA relational operator compares two values and determines the relationship between them. For example, != returns true if its two operands are unequal. Relational operators are used to test whether two values are equal, whether one value is greater than another, and so forth. 
Relational Operators
Relational Operators
Example of Relational Operatorspublic LessThanExample {publicstatic void main(String args[]) {	int a = 5; int b = 10;   	if(a < b) 	{System.out.println("a is less than b"); 	}	}	 }
Logical OperatorsThese logical operators work only on boolean operands. Their return values are always boolean.
Logical Operators
Example of Logical OperatorspublicclassANDOperatorExample{	publicstatic void main(String[] args){   	char ans = 'y'; 	int count = 1;   	if(ans == 'y' & count == 0){ 		System.out.println("Count is Zero.");}	if(ans == 'y' & count == 1) { System.out.println("Count is One."); }   	if(ans == 'y' & count == 2) { System.out.println("Count is Two."); } } }
Ternary OperatorsJava has a short hand way by using ?: the ternary aka conditional operator for doing  ifs that compute a value. Unlike the if statement, the conditional operator is an expression which can be used for
Example of Ternary Operator// longhand with if:int answer; if ( a > b ){answer = 1; }else{answer = -1; 	}// can be written more tersely with the ternary operator as:int answer = a > b ? 1 : -1;
Comma OperatorsJava has an often look past feature within it’s for loop and this is the comma operator. Usually when people think about commas in the java language they think of a way to split up arguments within a functions parameters

More Related Content

PPTX
Java Data Types
Spotle.ai
 
PPTX
Data types in java
HarshitaAshwani
 
PPTX
Arrays in Java
Abhilash Nair
 
PPSX
Data Types & Variables in JAVA
Ankita Totala
 
PPTX
Data Types, Variables, and Operators
Marwa Ali Eissa
 
PPTX
Operators in java
AbhishekMondal42
 
PDF
Arrays in Java
Naz Abdalla
 
PPTX
Control Statements in Java
Niloy Saha
 
Java Data Types
Spotle.ai
 
Data types in java
HarshitaAshwani
 
Arrays in Java
Abhilash Nair
 
Data Types & Variables in JAVA
Ankita Totala
 
Data Types, Variables, and Operators
Marwa Ali Eissa
 
Operators in java
AbhishekMondal42
 
Arrays in Java
Naz Abdalla
 
Control Statements in Java
Niloy Saha
 

What's hot (20)

PPS
Java Exception handling
kamal kotecha
 
PPTX
Control structures in java
VINOTH R
 
PPTX
Event Handling in java
Google
 
PPTX
Control statements in java
Madishetty Prathibha
 
PPTX
Presentation on-exception-handling
Nahian Ahmed
 
PPTX
Inheritance in java
Tech_MX
 
PPTX
Operators in java presentation
kunal kishore
 
PPTX
Java string handling
Salman Khan
 
PDF
Java conditional statements
Kuppusamy P
 
PPTX
Java swing
Apurbo Datta
 
PPTX
Operators and Expressions in Java
Abhilash Nair
 
PPTX
Java Tokens
Madishetty Prathibha
 
PPTX
Inheritance in JAVA PPT
Pooja Jaiswal
 
PPTX
Interface in java
PhD Research Scholar
 
PPTX
Basic Concepts of OOPs (Object Oriented Programming in Java)
Michelle Anne Meralpis
 
PPTX
Pointers in c++
Vineeta Garg
 
PPTX
Packages in java
Elizabeth alexander
 
PPTX
Java exception handling
BHUVIJAYAVELU
 
PPTX
Type casting in java
Farooq Baloch
 
Java Exception handling
kamal kotecha
 
Control structures in java
VINOTH R
 
Event Handling in java
Google
 
Control statements in java
Madishetty Prathibha
 
Presentation on-exception-handling
Nahian Ahmed
 
Inheritance in java
Tech_MX
 
Operators in java presentation
kunal kishore
 
Java string handling
Salman Khan
 
Java conditional statements
Kuppusamy P
 
Java swing
Apurbo Datta
 
Operators and Expressions in Java
Abhilash Nair
 
Java Tokens
Madishetty Prathibha
 
Inheritance in JAVA PPT
Pooja Jaiswal
 
Interface in java
PhD Research Scholar
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Michelle Anne Meralpis
 
Pointers in c++
Vineeta Garg
 
Packages in java
Elizabeth alexander
 
Java exception handling
BHUVIJAYAVELU
 
Type casting in java
Farooq Baloch
 
Ad

Viewers also liked (20)

PPSX
Data types, Variables, Expressions & Arithmetic Operators in java
Javed Rashid
 
PDF
Operators in java
Ravi_Kant_Sahu
 
PDF
Control structures in Java
Ravi_Kant_Sahu
 
PPTX
Control statements in Java
Jin Castor
 
PDF
Constants, Variables and Data Types in Java
Abhilash Nair
 
PPTX
Operators and expressions
vishaljot_kaur
 
PPT
Java basic
Sonam Sharma
 
PDF
Operators in java
Muthukumaran Subramanian
 
PPTX
Introduction to java
Veerabadra Badra
 
PPT
Control structures i
Ahmad Idrees
 
PDF
15 bitwise operators
Ravindra Rathore
 
PPT
Packages in java
Abhishek Khune
 
PPT
Control Structures
Ghaffar Khan
 
PPTX
Operators in java
yugandhar vadlamudi
 
PPTX
Inheritance
Sapna Sharma
 
PPT
Java interfaces
Raja Sekhar
 
PPT
Java packages
Raja Sekhar
 
PPTX
Operator in c programming
Manoj Tyagi
 
PPT
Java tutorial PPT
Intelligo Technologies
 
DOCX
JAVA JDK INSTALLATION PROCEDURE
NAGA VENKATESH GAVINI
 
Data types, Variables, Expressions & Arithmetic Operators in java
Javed Rashid
 
Operators in java
Ravi_Kant_Sahu
 
Control structures in Java
Ravi_Kant_Sahu
 
Control statements in Java
Jin Castor
 
Constants, Variables and Data Types in Java
Abhilash Nair
 
Operators and expressions
vishaljot_kaur
 
Java basic
Sonam Sharma
 
Operators in java
Muthukumaran Subramanian
 
Introduction to java
Veerabadra Badra
 
Control structures i
Ahmad Idrees
 
15 bitwise operators
Ravindra Rathore
 
Packages in java
Abhishek Khune
 
Control Structures
Ghaffar Khan
 
Operators in java
yugandhar vadlamudi
 
Inheritance
Sapna Sharma
 
Java interfaces
Raja Sekhar
 
Java packages
Raja Sekhar
 
Operator in c programming
Manoj Tyagi
 
Java tutorial PPT
Intelligo Technologies
 
JAVA JDK INSTALLATION PROCEDURE
NAGA VENKATESH GAVINI
 
Ad

Similar to Operators in java (20)

PPTX
Pj01 4-operators and control flow
SasidharaRaoMarrapu
 
PPTX
05 operators
dhrubo kayal
 
PPT
object oriented programming java lectures
MSohaib24
 
PPTX
Java chapter 3
Munsif Ullah
 
PPT
Operators
Daman Toor
 
PPTX
Operators
VijayaLakshmi506
 
PPTX
Arithmetic Operators ____ java.pptx
gnyanadeepa
 
PPT
Java operators
Shehrevar Davierwala
 
PPTX
Computer programming 2 Lesson 7
MLG College of Learning, Inc
 
PPTX
OOPJ_PPT2,JAVA OPERATORS TPYE WITH EXAMPLES.pptx
SrinivasGopalan2
 
DOCX
Operators
loidasacueza
 
PPT
C Sharp Jn (2)
guest58c84c
 
PPT
C Sharp Jn (2)
jahanullah
 
PDF
Java basic operators
Emmanuel Alimpolos
 
PDF
Java basic operators
Emmanuel Alimpolos
 
PPTX
Lecture-02-JAVA, data type, token, variables.pptx
ChandrashekharSingh859453
 
PPTX
L3 operators
teach4uin
 
PPTX
L3 operators
teach4uin
 
PPTX
L3 operators
teach4uin
 
PPTX
presentation on array java program operators
anushaashraf20
 
Pj01 4-operators and control flow
SasidharaRaoMarrapu
 
05 operators
dhrubo kayal
 
object oriented programming java lectures
MSohaib24
 
Java chapter 3
Munsif Ullah
 
Operators
Daman Toor
 
Operators
VijayaLakshmi506
 
Arithmetic Operators ____ java.pptx
gnyanadeepa
 
Java operators
Shehrevar Davierwala
 
Computer programming 2 Lesson 7
MLG College of Learning, Inc
 
OOPJ_PPT2,JAVA OPERATORS TPYE WITH EXAMPLES.pptx
SrinivasGopalan2
 
Operators
loidasacueza
 
C Sharp Jn (2)
guest58c84c
 
C Sharp Jn (2)
jahanullah
 
Java basic operators
Emmanuel Alimpolos
 
Java basic operators
Emmanuel Alimpolos
 
Lecture-02-JAVA, data type, token, variables.pptx
ChandrashekharSingh859453
 
L3 operators
teach4uin
 
L3 operators
teach4uin
 
L3 operators
teach4uin
 
presentation on array java program operators
anushaashraf20
 

More from Then Murugeshwari (20)

PPT
Traffic safety
Then Murugeshwari
 
PPT
P h indicators
Then Murugeshwari
 
PPT
Avogadro's law
Then Murugeshwari
 
PPT
Resonance
Then Murugeshwari
 
PPT
Microwave remote sensing
Then Murugeshwari
 
PPT
Newton's law
Then Murugeshwari
 
PPT
Surface tension
Then Murugeshwari
 
PPT
Hook's law
Then Murugeshwari
 
PPT
Hook's law
Then Murugeshwari
 
PPTX
ERP components
Then Murugeshwari
 
PPTX
Database fundamentals
Then Murugeshwari
 
PPT
Mosfet
Then Murugeshwari
 
PPTX
Operators
Then Murugeshwari
 
PPTX
Hiperlan
Then Murugeshwari
 
PPTX
Bluetooth profile
Then Murugeshwari
 
PPTX
Router
Then Murugeshwari
 
PPTX
Thread priorities
Then Murugeshwari
 
PPTX
Threads
Then Murugeshwari
 
PPTX
Identifiers
Then Murugeshwari
 
PPT
Virtual ground
Then Murugeshwari
 
Traffic safety
Then Murugeshwari
 
P h indicators
Then Murugeshwari
 
Avogadro's law
Then Murugeshwari
 
Resonance
Then Murugeshwari
 
Microwave remote sensing
Then Murugeshwari
 
Newton's law
Then Murugeshwari
 
Surface tension
Then Murugeshwari
 
Hook's law
Then Murugeshwari
 
Hook's law
Then Murugeshwari
 
ERP components
Then Murugeshwari
 
Database fundamentals
Then Murugeshwari
 
Operators
Then Murugeshwari
 
Hiperlan
Then Murugeshwari
 
Bluetooth profile
Then Murugeshwari
 
Thread priorities
Then Murugeshwari
 
Identifiers
Then Murugeshwari
 
Virtual ground
Then Murugeshwari
 

Recently uploaded (20)

PDF
Revolutionize Operations with Intelligent IoT Monitoring and Control
Rejig Digital
 
PDF
Chapter 2 Digital Image Fundamentals.pdf
Getnet Tigabie Askale -(GM)
 
PDF
CIFDAQ'S Market Insight: BTC to ETH money in motion
CIFDAQ
 
PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
PDF
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
codernjn73
 
PDF
Enable Enterprise-Ready Security on IBM i Systems.pdf
Precisely
 
PDF
REPORT: Heating appliances market in Poland 2024
SPIUG
 
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
AVTRON Technologies LLC
 
PPTX
Comunidade Salesforce SĂŁo Paulo - Desmistificando o Omnistudio (Vlocity)
Francisco Vieira JĂşnior
 
DOCX
Top AI API Alternatives to OpenAI: A Side-by-Side Breakdown
vilush
 
PDF
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
PDF
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
PDF
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
PPTX
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
PDF
madgavkar20181017ppt McKinsey Presentation.pdf
georgschmitzdoerner
 
PPTX
How to Build a Scalable Micro-Investing Platform in 2025 - A Founder’s Guide ...
Third Rock Techkno
 
PPTX
Smart Infrastructure and Automation through IoT Sensors
Rejig Digital
 
PDF
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
PDF
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
PDF
agentic-ai-and-the-future-of-autonomous-systems.pdf
siddharthnetsavvies
 
Revolutionize Operations with Intelligent IoT Monitoring and Control
Rejig Digital
 
Chapter 2 Digital Image Fundamentals.pdf
Getnet Tigabie Askale -(GM)
 
CIFDAQ'S Market Insight: BTC to ETH money in motion
CIFDAQ
 
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
codernjn73
 
Enable Enterprise-Ready Security on IBM i Systems.pdf
Precisely
 
REPORT: Heating appliances market in Poland 2024
SPIUG
 
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
AVTRON Technologies LLC
 
Comunidade Salesforce SĂŁo Paulo - Desmistificando o Omnistudio (Vlocity)
Francisco Vieira JĂşnior
 
Top AI API Alternatives to OpenAI: A Side-by-Side Breakdown
vilush
 
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
madgavkar20181017ppt McKinsey Presentation.pdf
georgschmitzdoerner
 
How to Build a Scalable Micro-Investing Platform in 2025 - A Founder’s Guide ...
Third Rock Techkno
 
Smart Infrastructure and Automation through IoT Sensors
Rejig Digital
 
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
agentic-ai-and-the-future-of-autonomous-systems.pdf
siddharthnetsavvies
 

Operators in java

  • 2. OperatorAn operator is a symbol that operates on one or more arguments to produce a result. Java provides a rich set of operators to manipulate variables.
  • 3. OperandsAn operands are the values on which the operators act upon.An operand can be:A numeric variable - integer, floating point or character
  • 4. Any primitive type variable - numeric and boolean
  • 6. A literal - numeric value, boolean value, or string.
  • 7. An array element, "a[2]“
  • 8. char primitive, which in numeric operations is treated as an unsigned two byte integerTypes of OperatorsAssignment OperatorsIncrement Decrement OperatorsArithmetic OperatorsBitwise OperatorsRelational OperatorsLogical OperatorsTernary OperatorsComma OperatorsInstanceof Operators
  • 9. Assignment OperatorsThe assignment statements has the following syntax:<variable> = <expression>
  • 11. Increment and Decrement operators++ and --The increment and decrement operators add an integer variable by one.increment operator: two successive plus signs, ++decrement operator: --
  • 12. Increment and Decrement operators++ and --Common Shorthanda = a + 1; a++; or ++a;a = a - 1; a--; or --a;
  • 13. Example of ++ and -- operatorspublic class Example { public static void main(String[] args) { }}int j, p, q, r, s;j = 5;p = ++j; // j = j + 1; p = j;System.out.println("p = " + p);q = j++; // q = j; j = j + 1;System.out.println("q = " + q);System.out.println("j = " + j);r = --j; // j = j -1; r = j;System.out.println("r = " + r);s = j--; // s = j; j = j - 1;System.out.println("s = " + s);> java examplep = 6q = 6j = 7r = 6s = 6>
  • 14. Arithmetic OperatorsThe arithmetic operators are used to construct mathematical expressions as in algebra. Their operands are of numeric type.
  • 16. Simple Arithmeticpublic class Example { public static void main(String[] args) { int j, k, p, q, r, s, t; j = 5; k = 2; p = j + k; q = j - k; r = j * k; s = j / k; t = j % k; System.out.println("p = " + p); System.out.println("q = " + q); System.out.println("r = " + r); System.out.println("s = " + s); System.out.println("t = " + t); }} > java Example p = 7 q = 3 r = 10 s = 2 t = 1 >
  • 17. Bitwise OperatorsJava's bitwise operators operate on individual bits of integer (int and long) values. If an operand is shorter than an int, it is promoted to int before doing the operations.
  • 19. Example of Bitwise Operatorsclass Test { public static void main(String args[]) { int a = 60; /* 60 = 0011 1100 */ int b = 13; /* 13 = 0000 1101 */ int c = 0; c = a & b; /* 12 = 0000 1100 */ System.out.println("a & b = " + c ); c = a | b; /* 61 = 0011 1101 */ System.out.println("a | b = " + c );
  • 20. Example Cont., c = a ^ b; /* 49 = 0011 0001 */ System.out.println("a ^ b = " + c ); c = ~a; /*-61 = 1100 0011 */ System.out.println("~a = " + c ); c = a << 2; /* 240 = 1111 0000 */ System.out.println("a << 2 = " + c ); c = a >> 2; /* 215 = 1111 */ System.out.println("a >> 2 = " + c ); c = a >>> 2; /* 215 = 0000 1111 */ System.out.println("a >>> 2 = " + c ); } }
  • 21. Relational OperatorsA relational operator compares two values and determines the relationship between them. For example, != returns true if its two operands are unequal. Relational operators are used to test whether two values are equal, whether one value is greater than another, and so forth. 
  • 24. Example of Relational Operatorspublic LessThanExample {publicstatic void main(String args[]) { int a = 5; int b = 10;   if(a < b) {System.out.println("a is less than b"); } } }
  • 25. Logical OperatorsThese logical operators work only on boolean operands. Their return values are always boolean.
  • 27. Example of Logical OperatorspublicclassANDOperatorExample{ publicstatic void main(String[] args){   char ans = 'y'; int count = 1;   if(ans == 'y' & count == 0){ System.out.println("Count is Zero.");} if(ans == 'y' & count == 1) { System.out.println("Count is One."); }   if(ans == 'y' & count == 2) { System.out.println("Count is Two."); } } }
  • 28. Ternary OperatorsJava has a short hand way by using ?: the ternary aka conditional operator for doing ifs that compute a value. Unlike the if statement, the conditional operator is an expression which can be used for
  • 29. Example of Ternary Operator// longhand with if:int answer; if ( a > b ){answer = 1; }else{answer = -1; }// can be written more tersely with the ternary operator as:int answer = a > b ? 1 : -1;
  • 30. Comma OperatorsJava has an often look past feature within it’s for loop and this is the comma operator. Usually when people think about commas in the java language they think of a way to split up arguments within a functions parameters
  • 31. Example of Comma Operator//: c03:CommaOperator.java// From 'Thinking in Java, 3rd ed.' (c) Bruce Eckel 2002// www.BruceEckel.com. See copyright notice in CopyRight.txt.public class CommaOperator {  public static void main(String[] args) {    for(int i = 1, j = i + 10; i < 5;        i++, j = i * 2) {      System.out.println("i= " + i + " j= " + j);    }  }} ///:~                    
  • 32. Instanceof OperatorsThis operator is used only for object reference variables. The operator checks whether the object is of a particular type(class type or interface type). InstanceOf operator is wriiten as:
  • 34. The End ….. Thank You …..