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

What's hot (20)

PPT
Java-java virtual machine
Surbhi Panhalkar
 
PPTX
oops concept in java | object oriented programming in java
CPD INDIA
 
PPTX
Operators in java presentation
kunal kishore
 
PPTX
Data types in java
HarshitaAshwani
 
PPTX
Interface in java
PhD Research Scholar
 
PPTX
Methods in java
chauhankapil
 
PPTX
Java Tokens
Madishetty Prathibha
 
PPTX
Strings in Java
Abhilash Nair
 
PPTX
Classes objects in java
Madishetty Prathibha
 
PPSX
Break and continue
Frijo Francis
 
PPT
Introduction to method overloading &amp; method overriding in java hdm
Harshal Misalkar
 
PPTX
JAVA AWT
shanmuga rajan
 
PPT
Java interfaces
Raja Sekhar
 
PDF
Java variable types
Soba Arjun
 
PPTX
Constructor in java
SIVASHANKARIRAJAN
 
PPTX
Arrays in c
Jeeva Nanthini
 
PPTX
Static Data Members and Member Functions
MOHIT AGARWAL
 
PPT
Class and object in C++
rprajat007
 
PPTX
Java string handling
Salman Khan
 
Java-java virtual machine
Surbhi Panhalkar
 
oops concept in java | object oriented programming in java
CPD INDIA
 
Operators in java presentation
kunal kishore
 
Data types in java
HarshitaAshwani
 
Interface in java
PhD Research Scholar
 
Methods in java
chauhankapil
 
Strings in Java
Abhilash Nair
 
Classes objects in java
Madishetty Prathibha
 
Break and continue
Frijo Francis
 
Introduction to method overloading &amp; method overriding in java hdm
Harshal Misalkar
 
JAVA AWT
shanmuga rajan
 
Java interfaces
Raja Sekhar
 
Java variable types
Soba Arjun
 
Constructor in java
SIVASHANKARIRAJAN
 
Arrays in c
Jeeva Nanthini
 
Static Data Members and Member Functions
MOHIT AGARWAL
 
Class and object in C++
rprajat007
 
Java string handling
Salman Khan
 

Viewers also liked (20)

PPTX
Operators and Expressions in Java
Abhilash Nair
 
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 in JAVA PPT
Pooja Jaiswal
 
PPTX
Inheritance
Sapna Sharma
 
PPT
Java packages
Raja Sekhar
 
PPTX
Operator in c programming
Manoj Tyagi
 
PPT
Java tutorial PPT
Intelligo Technologies
 
Operators and Expressions in Java
Abhilash Nair
 
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 in JAVA PPT
Pooja Jaiswal
 
Inheritance
Sapna Sharma
 
Java packages
Raja Sekhar
 
Operator in c programming
Manoj Tyagi
 
Java tutorial PPT
Intelligo Technologies
 
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
 
Ad

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
 
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
 
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
 
Bluetooth profile
Then Murugeshwari
 
Thread priorities
Then Murugeshwari
 
Identifiers
Then Murugeshwari
 
Virtual ground
Then Murugeshwari
 

Recently uploaded (20)

PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PDF
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PDF
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PDF
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PDF
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 

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.
  • 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: