SlideShare a Scribd company logo
1 of 34
OBJECT ORIENTED PROGRAMMING OOP
CSC 3315
PRACTICAL
ALQALAM UNIVERSITY KATSINA
BY
UMAR DANJUMA MAIWADA
OPERATORS
Contents
• Assignment
• Arithmetic
• Compound assignment
• Increment and decrement operators
• Relational and equality operators
• Logical operators
• Bitwise operators
• Explicit Type Casting operator
• Lab exercise
• References
Order of Operations in Operators
• Follows standard math rules:
• Parentheses
• Multiplication and division
• Addition and subtraction
ASSIGNMENT (=)
• The assignment operator assigns a value to a variable. a = 5;
• This statement assigns the integer value 5 to the variable a.
• The part at the left of the assignment operator (=) is known as the
lvalue (left value) and the right one as the rvalue (right value).
// assignment operator
Another Example
a = 2 + (b = 5);
is equivalent to:
b = 5;
a = 2 + b;
Another Example
a = b = c = 5;
Is equivalent to:
a=5, b=5, c=5
ARITHMETIC OPERATORS (+, -, *, /, %)
The five arithmetical operations supported by the JAVA language are:
• + Addition
• - Subtraction
• * Multiplication
• / Division
• %Modulo: a = 11 % 3; a =2 that is the remainder after division
class DoMath {
public static void main(String[] arguments){double
score = 1.0 + 2.0 * 3.0;System.out.println(score);score =
score / 2.0;System.out.println(score);
}}
OUTPUT
Score=3.5
// Arithmetic operators
COMPOUND ASSIGNMENT (+=, -=, *=, /=, %=)
EXAMPLE
// compound assignment operators
INCREMENT AND DECREMENT (++, --)
• Shortening even more some expressions, the increment operator (++)
and the decrement operator (--) increase or reduce the value stored
in a variable by one.
• They are equivalent to +=1 and to -=1, respectively. Example z++;
z+=1; z=z+1;
• A characteristic of this operator is that it can be used both as a prefix
and as a suffix. That means that it can be written either before the
variable identifier (++a) or after it (a++).
// Increment and decrement operators
RELATIONAL AND EQUALITY OPERATORS ( ==,
!=, >, <, >=, <= )
• In order to evaluate a comparison between two expressions we can
use the relational and equality operators.
• The result of a relational operation is a Boolean value that can only be
true or false, according to its Boolean result.
• ==Equal to
• != Not equal to
• > Greater than
• < Less than
• >=Greater than or equal to
• <=Less than or equal to
Here there are some examples:
(7 == 5) // evaluates to false.
(5 > 4) // evaluates to true.
(3 != 2) // evaluates to true.
(6 >= 6) // evaluates to true.
(5 < 5) // evaluates to false.
Suppose that a=2, b=3 and c=6,
(a == 5) // evaluates to false since a is not equal to 5.
(a*b >= c) // evaluates to true since (2*3 >= 6) is true.
(b+4 > a*c) // evaluates to false since (3+4 > 2*6) is false.
((b=2) == a) // evaluates to true.
// Relational and equality operators
LOGICAL OPERATORS ( !, &&, || )
• The operator ! is the JAVA operator to perform the Boolean operation
NOT, it has only one operand, located at its right, and the only thing
that it does is to inverse the value of it, producing false if its operand
is true and true if its operand is false.
• !(5 == 5) // evaluates to false because the expression at its right (5 ==
5) is true.
• !(6 <= 4) // evaluates to true because (6 <= 4) would be false.
• !true // evaluates to false
• !false // evaluates to true.
&& Operator
• The logical operators && and || are used when evaluating two
expressions to obtain a single relational result.
• The operator && corresponds with Boolean logical operation AND.
This operation results true if both its two operands are true, and false
otherwise.
|| Operator
• The operator || corresponds with Boolean logical operation OR.
• This operation results true if either one of its two operands is true,
thus being false only when both operands are false themselves.
For example:
( (5 == 5) && (3 > 6) ) // evaluates to false ( true && false ).
( (5 == 5) || (3 > 6) ) // evaluates to true ( true || false ).
// Logical operators
CONDITIONAL OPERATOR ( ? )
• The conditional operator evaluates an expression returning a value if
that expression is true and a different one if the expression is
evaluated as false.
• condition ? result1 : result2
If condition is true the expression will return
result1, if it is not it will return result2.
* 7==5 ? 4 : 3 // returns 3, since 7 is not equal to 5.
* 7==5+2 ? 4 : 3 // returns 4, since 7 is equal to 5+2.
* 5>3 ? a : b // returns the value of a, since 5 is
greater than 3.
* a>b ? a : b // returns whichever is greater, a or b.
// conditional operator
COMMA OPERATOR ( , )
• The comma operator (,) is used to separate two or more expressions
that are included where only one expression is expected.
• When the set of expressions has to be evaluated for a value, only the
rightmost expression is considered.
• For example, the following code:
• a = (b=3, b+2);
BITWISE OPERATORS ( &, |, ^, ~, <<, >> )
EXPLICIT TYPE CASTING OPERATOR
• Type casting operators allow you to convert a data of a given type to
another.
• int i;
• float f = 3.14;
• i = (int) f;
• i = int ( f );
SIZEOF()
• This operator accepts one parameter, which can be either a type or a
variable itself and returns the size in bytes of that type or object:
• a = sizeof (char);
• This will assign the value 1 to a because char is a one-byte long type.
• The value returned by sizeof is a constant, so it is always determined
before program execution.
Exercise
Q1. Store the weights and ages of three people in variables. Print a table, with titles, of the
weights and ages. At the bottom of the table, print the averages.
Q2. Assume that a video store employee works 50 hours. He is paid N4.50 for the first 40
hours, time-and-a-half (1.5 times the regular pay rate) for the first five hours over 40, and
double-time pay for all hours over 45. Assuming a 28 percent tax rate, write a program that
prints his gross pay, taxes, and net pay to the screen. Label each amount with appropriate
titles
(using string literals) and add appropriate comments in the program.
Q3. Convert each of the following formulas into its JAVA assignment equivalents.
a. a = 3 + 3 / 4 + 4
b. x = (a - b)*(a - c)2
References
• MIT lecture note 2016
• JAVA tutorial.com

More Related Content

What's hot

Operators in python
Operators in pythonOperators in python
Operators in pythoneShikshak
 
Python operators
Python operatorsPython operators
Python operatorsnuripatidar
 
OCA JAVA - 3 Programming with Java Operators
 OCA JAVA - 3 Programming with Java Operators OCA JAVA - 3 Programming with Java Operators
OCA JAVA - 3 Programming with Java OperatorsFernando Gil
 
itft-Operators in java
itft-Operators in javaitft-Operators in java
itft-Operators in javaAtul Sehdev
 
Operators and Expressions in C++
Operators and Expressions in C++Operators and Expressions in C++
Operators and Expressions in C++Praveen M Jigajinni
 
C Prog. - Operators and Expressions
C Prog. - Operators and ExpressionsC Prog. - Operators and Expressions
C Prog. - Operators and Expressionsvinay arora
 
Operator & Expression in c++
Operator & Expression in c++Operator & Expression in c++
Operator & Expression in c++bajiajugal
 
Operators in Python
Operators in PythonOperators in Python
Operators in PythonAnusuya123
 
Arithmetic operator
Arithmetic operatorArithmetic operator
Arithmetic operatorJordan Delacruz
 
Chapter 5 - Operators in C++
Chapter 5 - Operators in C++Chapter 5 - Operators in C++
Chapter 5 - Operators in C++Deepak Singh
 

What's hot (18)

Java 2
Java 2Java 2
Java 2
 
Operator.ppt
Operator.pptOperator.ppt
Operator.ppt
 
Operators in python
Operators in pythonOperators in python
Operators in python
 
Java basic operators
Java basic operatorsJava basic operators
Java basic operators
 
Python operators
Python operatorsPython operators
Python operators
 
OCA JAVA - 3 Programming with Java Operators
 OCA JAVA - 3 Programming with Java Operators OCA JAVA - 3 Programming with Java Operators
OCA JAVA - 3 Programming with Java Operators
 
Operators in C & C++ Language
Operators in C & C++ LanguageOperators in C & C++ Language
Operators in C & C++ Language
 
itft-Operators in java
itft-Operators in javaitft-Operators in java
itft-Operators in java
 
Operators and Expressions in C++
Operators and Expressions in C++Operators and Expressions in C++
Operators and Expressions in C++
 
operator
operatoroperator
operator
 
C Prog. - Operators and Expressions
C Prog. - Operators and ExpressionsC Prog. - Operators and Expressions
C Prog. - Operators and Expressions
 
Operator & Expression in c++
Operator & Expression in c++Operator & Expression in c++
Operator & Expression in c++
 
Operators in Python
Operators in PythonOperators in Python
Operators in Python
 
Arithmetic operator
Arithmetic operatorArithmetic operator
Arithmetic operator
 
Chapter 5 - Operators in C++
Chapter 5 - Operators in C++Chapter 5 - Operators in C++
Chapter 5 - Operators in C++
 
Operators in java
Operators in javaOperators in java
Operators in java
 
Python basic operators
Python   basic operatorsPython   basic operators
Python basic operators
 
Operators in java
Operators in javaOperators in java
Operators in java
 

Similar to Oop using JAVA

operators and expressions in c++
 operators and expressions in c++ operators and expressions in c++
operators and expressions in c++sanya6900
 
Operators and expressions in C++
Operators and expressions in C++Operators and expressions in C++
Operators and expressions in C++Neeru Mittal
 
C Sharp Jn (2)
C Sharp Jn (2)C Sharp Jn (2)
C Sharp Jn (2)jahanullah
 
C Sharp Jn (2)
C Sharp Jn (2)C Sharp Jn (2)
C Sharp Jn (2)guest58c84c
 
C++ Programming Basics.pptx
C++ Programming Basics.pptxC++ Programming Basics.pptx
C++ Programming Basics.pptxZntalemAbebe
 
Operators
OperatorsOperators
OperatorsKamran
 
IOS Swift Language 3rd tutorial
IOS Swift Language 3rd tutorialIOS Swift Language 3rd tutorial
IOS Swift Language 3rd tutorialHassan A-j
 
OPERATORS OF C++
OPERATORS OF C++OPERATORS OF C++
OPERATORS OF C++ANANT VYAS
 
C++ revision tour
C++ revision tourC++ revision tour
C++ revision tourSwarup Boro
 
Unit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in cUnit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in cSowmya Jyothi
 
L3 operators
L3 operatorsL3 operators
L3 operatorsteach4uin
 
L3 operators
L3 operatorsL3 operators
L3 operatorsteach4uin
 
L3 operators
L3 operatorsL3 operators
L3 operatorsteach4uin
 
Arithmetic Operator in C
Arithmetic Operator in CArithmetic Operator in C
Arithmetic Operator in Cyarkhosh
 
02-01-0-Operators and Operands.pdf
02-01-0-Operators and Operands.pdf02-01-0-Operators and Operands.pdf
02-01-0-Operators and Operands.pdfHomer53
 
chap 2 : Operators and Assignments (scjp/ocjp)
chap 2 : Operators and Assignments (scjp/ocjp)chap 2 : Operators and Assignments (scjp/ocjp)
chap 2 : Operators and Assignments (scjp/ocjp)It Academy
 

Similar to Oop using JAVA (20)

C++
C++ C++
C++
 
operators and expressions in c++
 operators and expressions in c++ operators and expressions in c++
operators and expressions in c++
 
Operators and expressions in C++
Operators and expressions in C++Operators and expressions in C++
Operators and expressions in C++
 
C Sharp Jn (2)
C Sharp Jn (2)C Sharp Jn (2)
C Sharp Jn (2)
 
C Sharp Jn (2)
C Sharp Jn (2)C Sharp Jn (2)
C Sharp Jn (2)
 
C++ Programming Basics.pptx
C++ Programming Basics.pptxC++ Programming Basics.pptx
C++ Programming Basics.pptx
 
Operators
OperatorsOperators
Operators
 
IOS Swift Language 3rd tutorial
IOS Swift Language 3rd tutorialIOS Swift Language 3rd tutorial
IOS Swift Language 3rd tutorial
 
OPERATORS OF C++
OPERATORS OF C++OPERATORS OF C++
OPERATORS OF C++
 
C++ revision tour
C++ revision tourC++ revision tour
C++ revision tour
 
Operator in JAVA
Operator in JAVA Operator in JAVA
Operator in JAVA
 
Unit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in cUnit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in c
 
L3 operators
L3 operatorsL3 operators
L3 operators
 
L3 operators
L3 operatorsL3 operators
L3 operators
 
L3 operators
L3 operatorsL3 operators
L3 operators
 
What are operators?
What are operators? What are operators?
What are operators?
 
SPL 6 | Operators in C
SPL 6 | Operators in CSPL 6 | Operators in C
SPL 6 | Operators in C
 
Arithmetic Operator in C
Arithmetic Operator in CArithmetic Operator in C
Arithmetic Operator in C
 
02-01-0-Operators and Operands.pdf
02-01-0-Operators and Operands.pdf02-01-0-Operators and Operands.pdf
02-01-0-Operators and Operands.pdf
 
chap 2 : Operators and Assignments (scjp/ocjp)
chap 2 : Operators and Assignments (scjp/ocjp)chap 2 : Operators and Assignments (scjp/ocjp)
chap 2 : Operators and Assignments (scjp/ocjp)
 

More from umardanjumamaiwada

More from umardanjumamaiwada (20)

Seminar Information Protection & Computer Security (Cryptography).pptx
Seminar Information Protection & Computer Security  (Cryptography).pptxSeminar Information Protection & Computer Security  (Cryptography).pptx
Seminar Information Protection & Computer Security (Cryptography).pptx
 
Computer hardware
Computer hardware Computer hardware
Computer hardware
 
2javascript web programming with JAVA script
2javascript web programming with JAVA script2javascript web programming with JAVA script
2javascript web programming with JAVA script
 
1 web programming
1 web programming1 web programming
1 web programming
 
0 csc 3311 slide internet programming
0 csc 3311 slide internet programming0 csc 3311 slide internet programming
0 csc 3311 slide internet programming
 
0 lecture 6 wp wireless protocol
0 lecture 6 wp wireless protocol0 lecture 6 wp wireless protocol
0 lecture 6 wp wireless protocol
 
0 lecture 5 wp wireless protocol
0 lecture 5 wp wireless protocol0 lecture 5 wp wireless protocol
0 lecture 5 wp wireless protocol
 
0 lecture 4 wp wireless protocol
0 lecture 4 wp wireless protocol0 lecture 4 wp wireless protocol
0 lecture 4 wp wireless protocol
 
0 lecture 3 wp wireless protocol
0 lecture 3 wp wireless protocol0 lecture 3 wp wireless protocol
0 lecture 3 wp wireless protocol
 
0 lecture 2 wp wireless protocol
0 lecture 2 wp wireless protocol0 lecture 2 wp wireless protocol
0 lecture 2 wp wireless protocol
 
0 lecture 1 wp wireless protocol
0 lecture 1 wp wireless protocol0 lecture 1 wp wireless protocol
0 lecture 1 wp wireless protocol
 
lecture 5
 lecture 5 lecture 5
lecture 5
 
lecture 4
 lecture 4 lecture 4
lecture 4
 
lecture 3
 lecture 3  lecture 3
lecture 3
 
lecture 2
 lecture 2 lecture 2
lecture 2
 
lecture 1
 lecture 1 lecture 1
lecture 1
 
lecture 6
 lecture 6 lecture 6
lecture 6
 
lecture 5
 lecture 5 lecture 5
lecture 5
 
lecture 4
 lecture 4 lecture 4
lecture 4
 
lecture 3
 lecture 3 lecture 3
lecture 3
 

Recently uploaded

POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 

Recently uploaded (20)

POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 

Oop using JAVA

  • 1. OBJECT ORIENTED PROGRAMMING OOP CSC 3315 PRACTICAL ALQALAM UNIVERSITY KATSINA BY UMAR DANJUMA MAIWADA
  • 3. Contents • Assignment • Arithmetic • Compound assignment • Increment and decrement operators • Relational and equality operators • Logical operators • Bitwise operators • Explicit Type Casting operator • Lab exercise • References
  • 4. Order of Operations in Operators • Follows standard math rules: • Parentheses • Multiplication and division • Addition and subtraction
  • 5. ASSIGNMENT (=) • The assignment operator assigns a value to a variable. a = 5; • This statement assigns the integer value 5 to the variable a. • The part at the left of the assignment operator (=) is known as the lvalue (left value) and the right one as the rvalue (right value).
  • 7. Another Example a = 2 + (b = 5); is equivalent to: b = 5; a = 2 + b; Another Example a = b = c = 5; Is equivalent to: a=5, b=5, c=5
  • 8. ARITHMETIC OPERATORS (+, -, *, /, %) The five arithmetical operations supported by the JAVA language are: • + Addition • - Subtraction • * Multiplication • / Division • %Modulo: a = 11 % 3; a =2 that is the remainder after division
  • 9. class DoMath { public static void main(String[] arguments){double score = 1.0 + 2.0 * 3.0;System.out.println(score);score = score / 2.0;System.out.println(score); }} OUTPUT Score=3.5
  • 11. COMPOUND ASSIGNMENT (+=, -=, *=, /=, %=)
  • 13. INCREMENT AND DECREMENT (++, --) • Shortening even more some expressions, the increment operator (++) and the decrement operator (--) increase or reduce the value stored in a variable by one. • They are equivalent to +=1 and to -=1, respectively. Example z++; z+=1; z=z+1; • A characteristic of this operator is that it can be used both as a prefix and as a suffix. That means that it can be written either before the variable identifier (++a) or after it (a++).
  • 14.
  • 15. // Increment and decrement operators
  • 16. RELATIONAL AND EQUALITY OPERATORS ( ==, !=, >, <, >=, <= ) • In order to evaluate a comparison between two expressions we can use the relational and equality operators. • The result of a relational operation is a Boolean value that can only be true or false, according to its Boolean result. • ==Equal to • != Not equal to • > Greater than • < Less than • >=Greater than or equal to • <=Less than or equal to
  • 17. Here there are some examples: (7 == 5) // evaluates to false. (5 > 4) // evaluates to true. (3 != 2) // evaluates to true. (6 >= 6) // evaluates to true. (5 < 5) // evaluates to false. Suppose that a=2, b=3 and c=6, (a == 5) // evaluates to false since a is not equal to 5. (a*b >= c) // evaluates to true since (2*3 >= 6) is true. (b+4 > a*c) // evaluates to false since (3+4 > 2*6) is false. ((b=2) == a) // evaluates to true.
  • 18. // Relational and equality operators
  • 19. LOGICAL OPERATORS ( !, &&, || ) • The operator ! is the JAVA operator to perform the Boolean operation NOT, it has only one operand, located at its right, and the only thing that it does is to inverse the value of it, producing false if its operand is true and true if its operand is false. • !(5 == 5) // evaluates to false because the expression at its right (5 == 5) is true. • !(6 <= 4) // evaluates to true because (6 <= 4) would be false. • !true // evaluates to false • !false // evaluates to true.
  • 20. && Operator • The logical operators && and || are used when evaluating two expressions to obtain a single relational result. • The operator && corresponds with Boolean logical operation AND. This operation results true if both its two operands are true, and false otherwise.
  • 21.
  • 22. || Operator • The operator || corresponds with Boolean logical operation OR. • This operation results true if either one of its two operands is true, thus being false only when both operands are false themselves.
  • 23.
  • 24. For example: ( (5 == 5) && (3 > 6) ) // evaluates to false ( true && false ). ( (5 == 5) || (3 > 6) ) // evaluates to true ( true || false ).
  • 26. CONDITIONAL OPERATOR ( ? ) • The conditional operator evaluates an expression returning a value if that expression is true and a different one if the expression is evaluated as false. • condition ? result1 : result2
  • 27. If condition is true the expression will return result1, if it is not it will return result2. * 7==5 ? 4 : 3 // returns 3, since 7 is not equal to 5. * 7==5+2 ? 4 : 3 // returns 4, since 7 is equal to 5+2. * 5>3 ? a : b // returns the value of a, since 5 is greater than 3. * a>b ? a : b // returns whichever is greater, a or b.
  • 29. COMMA OPERATOR ( , ) • The comma operator (,) is used to separate two or more expressions that are included where only one expression is expected. • When the set of expressions has to be evaluated for a value, only the rightmost expression is considered. • For example, the following code: • a = (b=3, b+2);
  • 30. BITWISE OPERATORS ( &, |, ^, ~, <<, >> )
  • 31. EXPLICIT TYPE CASTING OPERATOR • Type casting operators allow you to convert a data of a given type to another. • int i; • float f = 3.14; • i = (int) f; • i = int ( f );
  • 32. SIZEOF() • This operator accepts one parameter, which can be either a type or a variable itself and returns the size in bytes of that type or object: • a = sizeof (char); • This will assign the value 1 to a because char is a one-byte long type. • The value returned by sizeof is a constant, so it is always determined before program execution.
  • 33. Exercise Q1. Store the weights and ages of three people in variables. Print a table, with titles, of the weights and ages. At the bottom of the table, print the averages. Q2. Assume that a video store employee works 50 hours. He is paid N4.50 for the first 40 hours, time-and-a-half (1.5 times the regular pay rate) for the first five hours over 40, and double-time pay for all hours over 45. Assuming a 28 percent tax rate, write a program that prints his gross pay, taxes, and net pay to the screen. Label each amount with appropriate titles (using string literals) and add appropriate comments in the program. Q3. Convert each of the following formulas into its JAVA assignment equivalents. a. a = 3 + 3 / 4 + 4 b. x = (a - b)*(a - c)2
  • 34. References • MIT lecture note 2016 • JAVA tutorial.com