SlideShare a Scribd company logo
1 of 30
Operators in JAVA
Operator An 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.
Operands An operands are the values on which the operators act upon. An operand can be: ,[object Object]
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 integer,[object Object]
Assignment Operators The 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 Shorthand a = a + 1;		a++; or ++a; a = a - 1;		a--; or --a;
Example of ++ and -- operators public 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 example p = 6 q = 6 j = 7 r = 6 s = 6 >
Arithmetic Operators The arithmetic operators are used to construct mathematical expressions as in algebra.  Their operands are of numeric type.
Arithmetic Operators
Simple Arithmetic public 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 Operators Java'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 Operators class 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 Operators A 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 Operators public LessThanExample  { publicstatic void main(String args[])  { 	int a = 5; int b = 10;    	if(a < b)  	{ System.out.println("a is less than b");  	} 	}	  }
Logical Operators These logical operators work only on boolean operands. Their return values are always boolean.
Logical Operators
Example of Logical Operators publicclassANDOperatorExample{ 	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 Operators Java 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 Operators Java 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)

JVM
JVMJVM
JVM
 
Data Types & Variables in JAVA
Data Types & Variables in JAVAData Types & Variables in JAVA
Data Types & Variables in JAVA
 
Control statements in c
Control statements in cControl statements in c
Control statements in c
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++
 
Features of java
Features of javaFeatures of java
Features of java
 
The Loops
The LoopsThe Loops
The Loops
 
Introduction to method overloading &amp; method overriding in java hdm
Introduction to method overloading &amp; method overriding  in java  hdmIntroduction to method overloading &amp; method overriding  in java  hdm
Introduction to method overloading &amp; method overriding in java hdm
 
Java interfaces
Java interfacesJava interfaces
Java interfaces
 
Stream classes in C++
Stream classes in C++Stream classes in C++
Stream classes in C++
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Control Flow Statements
Control Flow Statements Control Flow Statements
Control Flow Statements
 
Control Statements in Java
Control Statements in JavaControl Statements in Java
Control Statements in Java
 
Java program structure
Java program structureJava program structure
Java program structure
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
 
Basic Input and Output
Basic Input and OutputBasic Input and Output
Basic Input and Output
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
 
Php string function
Php string function Php string function
Php string function
 
Control statements
Control statementsControl statements
Control statements
 
Basics of C programming
Basics of C programmingBasics of C programming
Basics of C programming
 
Looping statements in Java
Looping statements in JavaLooping statements in Java
Looping statements in Java
 

Viewers also liked

Operators and Expressions in Java
Operators and Expressions in JavaOperators and Expressions in Java
Operators and Expressions in JavaAbhilash Nair
 
Data types, Variables, Expressions & Arithmetic Operators in java
Data types, Variables, Expressions & Arithmetic Operators in javaData types, Variables, Expressions & Arithmetic Operators in java
Data types, Variables, Expressions & Arithmetic Operators in javaJaved Rashid
 
Control structures in Java
Control structures in JavaControl structures in Java
Control structures in JavaRavi_Kant_Sahu
 
Control statements in Java
Control statements  in JavaControl statements  in Java
Control statements in JavaJin Castor
 
Constants, Variables and Data Types in Java
Constants, Variables and Data Types in JavaConstants, Variables and Data Types in Java
Constants, Variables and Data Types in JavaAbhilash Nair
 
Operators and expressions
Operators and expressionsOperators and expressions
Operators and expressionsvishaljot_kaur
 
Control structures i
Control structures i Control structures i
Control structures i Ahmad Idrees
 
Control Structures
Control StructuresControl Structures
Control StructuresGhaffar Khan
 
Inheritance in JAVA PPT
Inheritance  in JAVA PPTInheritance  in JAVA PPT
Inheritance in JAVA PPTPooja Jaiswal
 
Operator in c programming
Operator in c programmingOperator in c programming
Operator in c programmingManoj Tyagi
 

Viewers also liked (20)

Operators and Expressions in Java
Operators and Expressions in JavaOperators and Expressions in Java
Operators and Expressions in Java
 
Data types, Variables, Expressions & Arithmetic Operators in java
Data types, Variables, Expressions & Arithmetic Operators in javaData types, Variables, Expressions & Arithmetic Operators in java
Data types, Variables, Expressions & Arithmetic Operators in java
 
Operators in java
Operators in javaOperators in java
Operators in java
 
Control structures in Java
Control structures in JavaControl structures in Java
Control structures in Java
 
Control statements in Java
Control statements  in JavaControl statements  in Java
Control statements in Java
 
Constants, Variables and Data Types in Java
Constants, Variables and Data Types in JavaConstants, Variables and Data Types in Java
Constants, Variables and Data Types in Java
 
Operators and expressions
Operators and expressionsOperators and expressions
Operators and expressions
 
Java basic
Java basicJava basic
Java basic
 
Operators in java
Operators in javaOperators in java
Operators in java
 
Control structures i
Control structures i Control structures i
Control structures i
 
15 bitwise operators
15 bitwise operators15 bitwise operators
15 bitwise operators
 
Packages in java
Packages in javaPackages in java
Packages in java
 
Control Structures
Control StructuresControl Structures
Control Structures
 
Operators in java
Operators in javaOperators in java
Operators in java
 
Inheritance in JAVA PPT
Inheritance  in JAVA PPTInheritance  in JAVA PPT
Inheritance in JAVA PPT
 
Inheritance
InheritanceInheritance
Inheritance
 
Java packages
Java packagesJava packages
Java packages
 
Operator in c programming
Operator in c programmingOperator in c programming
Operator in c programming
 
Java tutorial PPT
Java tutorial PPTJava tutorial PPT
Java tutorial PPT
 
JAVA JDK INSTALLATION PROCEDURE
JAVA JDK INSTALLATION PROCEDUREJAVA JDK INSTALLATION PROCEDURE
JAVA JDK INSTALLATION PROCEDURE
 

Similar to Operators in java

object oriented programming java lectures
object oriented programming java lecturesobject oriented programming java lectures
object oriented programming java lecturesMSohaib24
 
Pj01 4-operators and control flow
Pj01 4-operators and control flowPj01 4-operators and control flow
Pj01 4-operators and control flowSasidharaRaoMarrapu
 
Effective Java - Still Effective After All These Years
Effective Java - Still Effective After All These YearsEffective Java - Still Effective After All These Years
Effective Java - Still Effective After All These YearsMarakana Inc.
 
ppt on logical/arthimatical/conditional operators
ppt on logical/arthimatical/conditional operatorsppt on logical/arthimatical/conditional operators
ppt on logical/arthimatical/conditional operatorsAmrinder Sidhu
 
Fundamentals of computer programming by Dr. A. Charan Kumari
Fundamentals of computer programming by Dr. A. Charan KumariFundamentals of computer programming by Dr. A. Charan Kumari
Fundamentals of computer programming by Dr. A. Charan KumariTHE NORTHCAP UNIVERSITY
 
Chapter 2&3 (java fundamentals and Control Structures).ppt
Chapter 2&3 (java fundamentals and Control Structures).pptChapter 2&3 (java fundamentals and Control Structures).ppt
Chapter 2&3 (java fundamentals and Control Structures).ppthenokmetaferia1
 
Operator & Expression in c++
Operator & Expression in c++Operator & Expression in c++
Operator & Expression in c++bajiajugal
 

Similar to Operators in java (20)

object oriented programming java lectures
object oriented programming java lecturesobject oriented programming java lectures
object oriented programming java lectures
 
Pj01 4-operators and control flow
Pj01 4-operators and control flowPj01 4-operators and control flow
Pj01 4-operators and control flow
 
Java operators
Java operatorsJava operators
Java operators
 
Operators
OperatorsOperators
Operators
 
05 operators
05   operators05   operators
05 operators
 
Lecture 3
Lecture 3Lecture 3
Lecture 3
 
Effective Java - Still Effective After All These Years
Effective Java - Still Effective After All These YearsEffective Java - Still Effective After All These Years
Effective Java - Still Effective After All These Years
 
Java chapter 3
Java chapter 3Java chapter 3
Java chapter 3
 
Java unit 3
Java unit 3Java unit 3
Java unit 3
 
ppt on logical/arthimatical/conditional operators
ppt on logical/arthimatical/conditional operatorsppt on logical/arthimatical/conditional operators
ppt on logical/arthimatical/conditional operators
 
Fundamentals of computer programming by Dr. A. Charan Kumari
Fundamentals of computer programming by Dr. A. Charan KumariFundamentals of computer programming by Dr. A. Charan Kumari
Fundamentals of computer programming by Dr. A. Charan Kumari
 
02basics
02basics02basics
02basics
 
C++.pptx
C++.pptxC++.pptx
C++.pptx
 
Chapter 2&3 (java fundamentals and Control Structures).ppt
Chapter 2&3 (java fundamentals and Control Structures).pptChapter 2&3 (java fundamentals and Control Structures).ppt
Chapter 2&3 (java fundamentals and Control Structures).ppt
 
operators.pptx
operators.pptxoperators.pptx
operators.pptx
 
Operators
OperatorsOperators
Operators
 
Strings v.1.1
Strings v.1.1Strings v.1.1
Strings v.1.1
 
C++
C++C++
C++
 
Operator & Expression in c++
Operator & Expression in c++Operator & Expression in c++
Operator & Expression in c++
 
Ch5(loops)
Ch5(loops)Ch5(loops)
Ch5(loops)
 

More from Then Murugeshwari (20)

Traffic safety
Traffic safetyTraffic safety
Traffic safety
 
P h indicators
P h indicatorsP h indicators
P h indicators
 
Avogadro's law
Avogadro's lawAvogadro's law
Avogadro's law
 
Resonance
ResonanceResonance
Resonance
 
Microwave remote sensing
Microwave remote sensingMicrowave remote sensing
Microwave remote sensing
 
Newton's law
Newton's lawNewton's law
Newton's law
 
Surface tension
Surface tensionSurface tension
Surface tension
 
Hook's law
Hook's lawHook's law
Hook's law
 
Hook's law
Hook's lawHook's law
Hook's law
 
ERP components
ERP componentsERP components
ERP components
 
Database fundamentals
Database fundamentalsDatabase fundamentals
Database fundamentals
 
Mosfet
MosfetMosfet
Mosfet
 
Operators
OperatorsOperators
Operators
 
Hiperlan
HiperlanHiperlan
Hiperlan
 
Bluetooth profile
Bluetooth profileBluetooth profile
Bluetooth profile
 
Router
RouterRouter
Router
 
Thread priorities
Thread prioritiesThread priorities
Thread priorities
 
Threads
ThreadsThreads
Threads
 
Identifiers
Identifiers Identifiers
Identifiers
 
Virtual ground
Virtual groundVirtual ground
Virtual ground
 

Recently uploaded

Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024The Digital Insurer
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024SynarionITSolutions
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Principled Technologies
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 

Recently uploaded (20)

Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 

Operators in java

  • 2. Operator An 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.
  • 4. Any primitive type variable - numeric and boolean
  • 6. A literal - numeric value, boolean value, or string.
  • 8.
  • 9. Assignment Operators The 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 Shorthand a = a + 1; a++; or ++a; a = a - 1; a--; or --a;
  • 13. Example of ++ and -- operators public 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 example p = 6 q = 6 j = 7 r = 6 s = 6 >
  • 14. Arithmetic Operators The arithmetic operators are used to construct mathematical expressions as in algebra. Their operands are of numeric type.
  • 16. Simple Arithmetic public 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 Operators Java'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 Operators class 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 Operators A 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 Operators public 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 Operators These logical operators work only on boolean operands. Their return values are always boolean.
  • 27. Example of Logical Operators publicclassANDOperatorExample{ 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 Operators Java 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 Operators Java 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 Operators This 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 …..