SlideShare a Scribd company logo
1 of 34
CMP-2123-Object Oriented
Programming
Lecture 1.4
By
Abrar Ahmad
Abrar.ahmad14@ce.ceme.edu.pk
Operators
• Operator in java is a symbol that is used to perform operations. There
are many types of operators in java such as unary operator, arithmetic
operator, relational operator, shift operator, bitwise operator, ternary
operator and assignment operator.
2Badar Waseer arbabwaseergmail.com
Operators Precedence
Postfix expr++ expr--
Unary ++expr --expr +expr -expr ~ !
Multiplicative * / %
Additive + -
Shift << >> >>>
Relational < > <= >= instanceof
Equality == !=
Bitwise AND &
Bitwise exclusive OR ^
Bitwise inclusive OR |
Logical AND &&
Logical OR ||
Ternary ? :
Assignment = += -= *= /= %= &= ^= |= <<= >>= >>>=
3Badar Waseer arbabwaseergmail.com
• The Java if statement is used to test the condition. It checks boolean
condition: true or false. There are various types of if statement in
java.
• if statement
• if-else statement
• nested if statement
• if-else-if ladder
Java If-else Statement
4Badar Waseer arbabwaseergmail.com
Java IF Statement
• The Java if statement tests the condition. It executes the if block if
condition is true.
• Syntax:
5Badar Waseer arbabwaseergmail.com
6Badar Waseer arbabwaseergmail.com
7Badar Waseer arbabwaseergmail.com
Java IF-else Statement
• The Java if-else statement also tests the condition. It executes the if
block if condition is true otherwise else block is executed.
• Syntax:
8Badar Waseer arbabwaseergmail.com
9Badar Waseer arbabwaseergmail.com
10Badar Waseer arbabwaseergmail.com
Java IF-else-if ladder Statement
• The if-else-if ladder statement executes one condition from multiple
statements.
• Syntax:
11Badar Waseer arbabwaseergmail.com
12Badar Waseer arbabwaseergmail.com
13Badar Waseer arbabwaseergmail.com
14Badar Waseer arbabwaseergmail.com
Java Switch Statement
• The Java switch statement executes
one statement from multiple
conditions. It is like if-else-if ladder
statement.
• Syntax:
15Badar Waseer arbabwaseergmail.com
16Badar Waseer arbabwaseergmail.com
17Badar Waseer arbabwaseergmail.com
Java Switch Statement is fall-through
• The java switch statement is fall-through. It means it executes all
statement after first match if break statement is not used with switch
cases.
18Badar Waseer arbabwaseergmail.com
19Badar Waseer arbabwaseergmail.com
JAVA Methods
• A Java method is a collection of statements that are grouped together
to perform an operation. When you call the
System.out.println() method, for example, the system actually
executes several statements in order to display a message on the
console.
• Now you will learn how to create your own methods with or without
return values, invoke a method with or without parameters, and
apply method abstraction in the program design.
20Badar Waseer arbabwaseergmail.com
Creating Method
21Badar Waseer arbabwaseergmail.com
• The syntax shown includes −
• modifier − It defines the access type of the method and it is optional
to use.
• returnType − Method may return a value.
• nameOfMethod − This is the method name. The method signature
consists of the method name and the parameter list.
• Parameter List − The list of parameters, it is the type, order, and
number of parameters of a method. These are optional, method may
contain zero parameters.
• method body − The method body defines what the method does with
the statements.
22Badar Waseer arbabwaseergmail.com
• Here,
• public static − modifier
• int − return type
• methodName − name of the method
• a, b − formal parameters
• int a, int b − list of parameters
• Method definition consists of a method header and a method body.
23Badar Waseer arbabwaseergmail.com
24Badar Waseer arbabwaseergmail.com
25
• Here is the source code of the above defined method
called minFunction(). This method takes two parameters n1 and n2 and
returns the minimum between the two −
Badar Waseer arbabwaseergmail.com
Method Calling
• For using a method, it should be called. There are two ways in which a
method is called i.e., method returns a value or returning nothing (no
return value).
• The process of method calling is simple. When a program invokes a
method, the program control gets transferred to the called method.
This called method then returns control to the caller in two
conditions, when −
• the return statement is executed.
• it reaches the method ending closing brace.
26Badar Waseer arbabwaseergmail.com
• The methods returning void is considered as call to a statement. Lets
consider an example −
• The method returning value can be understood by the following
example −
• Following is the example to demonstrate how to define a method and
how to call it −
27
Badar Waseer arbabwaseergmail.com 27
28
• This will produce the
following result −
Badar Waseer arbabwaseergmail.com
The void Keyword
• The void keyword allows us to create methods which do not return a
value. Here, in the following example we're considering a void
method methodRankPoints. This method is a void method, which
does not return any value. Call to a void method must be a statement
i.e. methodRankPoints(255.7);. It is a Java statement which ends with
a semicolon as shown in the following example.
29Badar Waseer arbabwaseergmail.com
30
• This will
produce the
following
result −
Badar Waseer arbabwaseergmail.com
Passing Parameters by Value
• While working under calling process, arguments is to be passed.
These should be in the same order as their respective parameters in
the method specification. Parameters can be passed by value or by
reference.
• Passing Parameters by Value means calling a method with a
parameter. Through this, the argument value is passed to the
parameter.
31Badar Waseer arbabwaseergmail.com
• The following program shows an example of passing parameter by
value. The values of the arguments remains the same even after the
method invocation.
32Badar Waseer arbabwaseergmail.com
in
33Badar Waseer arbabwaseergmail.com
• This will produce the following result −
34Badar Waseer arbabwaseergmail.com

More Related Content

What's hot

Beginners Guide to Object Orientation in PHP
Beginners Guide to Object Orientation in PHPBeginners Guide to Object Orientation in PHP
Beginners Guide to Object Orientation in PHPRick Ogden
 
Scope demystified - AngularJS
Scope demystified - AngularJSScope demystified - AngularJS
Scope demystified - AngularJSSumanth krishna
 
Exercises for ja se
Exercises for ja seExercises for ja se
Exercises for ja sesshhzap
 
(An Extended) Beginners Guide to Object Orientation in PHP
(An Extended) Beginners Guide to Object Orientation in PHP(An Extended) Beginners Guide to Object Orientation in PHP
(An Extended) Beginners Guide to Object Orientation in PHPRick Ogden
 
Let's start with Java- Basic Concepts
Let's start with Java- Basic ConceptsLet's start with Java- Basic Concepts
Let's start with Java- Basic ConceptsAashish Jain
 
Android webinar class_java_review
Android webinar class_java_reviewAndroid webinar class_java_review
Android webinar class_java_reviewEdureka!
 
Super keyword in java
Super keyword in javaSuper keyword in java
Super keyword in javaHitesh Kumar
 
Ch. 3 classes and objects
Ch. 3 classes and objectsCh. 3 classes and objects
Ch. 3 classes and objectsdkohreidze
 
Object Oriented Programming C#
Object Oriented Programming C#Object Oriented Programming C#
Object Oriented Programming C#Muhammad Younis
 
Adobe Flash Actionscript language basics chapter-2
Adobe Flash Actionscript language basics chapter-2Adobe Flash Actionscript language basics chapter-2
Adobe Flash Actionscript language basics chapter-2Nafis Ahmed
 
Ap Power Point Chpt5
Ap Power Point Chpt5Ap Power Point Chpt5
Ap Power Point Chpt5dplunkett
 

What's hot (18)

Chap5java5th
Chap5java5thChap5java5th
Chap5java5th
 
PCSTt11 overview of java
PCSTt11 overview of javaPCSTt11 overview of java
PCSTt11 overview of java
 
Chap1java5th
Chap1java5thChap1java5th
Chap1java5th
 
Beginners Guide to Object Orientation in PHP
Beginners Guide to Object Orientation in PHPBeginners Guide to Object Orientation in PHP
Beginners Guide to Object Orientation in PHP
 
Rails interview questions
Rails interview questionsRails interview questions
Rails interview questions
 
Java Variable Types
Java Variable TypesJava Variable Types
Java Variable Types
 
Scope demystified - AngularJS
Scope demystified - AngularJSScope demystified - AngularJS
Scope demystified - AngularJS
 
Exercises for ja se
Exercises for ja seExercises for ja se
Exercises for ja se
 
(An Extended) Beginners Guide to Object Orientation in PHP
(An Extended) Beginners Guide to Object Orientation in PHP(An Extended) Beginners Guide to Object Orientation in PHP
(An Extended) Beginners Guide to Object Orientation in PHP
 
Let's start with Java- Basic Concepts
Let's start with Java- Basic ConceptsLet's start with Java- Basic Concepts
Let's start with Java- Basic Concepts
 
Android webinar class_java_review
Android webinar class_java_reviewAndroid webinar class_java_review
Android webinar class_java_review
 
Super keyword in java
Super keyword in javaSuper keyword in java
Super keyword in java
 
Ch. 3 classes and objects
Ch. 3 classes and objectsCh. 3 classes and objects
Ch. 3 classes and objects
 
Java 8
Java 8Java 8
Java 8
 
Object Oriented Programming C#
Object Oriented Programming C#Object Oriented Programming C#
Object Oriented Programming C#
 
Adobe Flash Actionscript language basics chapter-2
Adobe Flash Actionscript language basics chapter-2Adobe Flash Actionscript language basics chapter-2
Adobe Flash Actionscript language basics chapter-2
 
Ap Power Point Chpt5
Ap Power Point Chpt5Ap Power Point Chpt5
Ap Power Point Chpt5
 
JAVA PROGRAMMING- Exception handling - Multithreading
JAVA PROGRAMMING- Exception handling - MultithreadingJAVA PROGRAMMING- Exception handling - Multithreading
JAVA PROGRAMMING- Exception handling - Multithreading
 

Similar to Lec 1.4 Object Oriented Programming

CIS 1403 lab 3 functions and methods in Java
CIS 1403 lab 3 functions and methods in JavaCIS 1403 lab 3 functions and methods in Java
CIS 1403 lab 3 functions and methods in JavaHamad Odhabi
 
METHODS IN JAVA.ppt
METHODS IN  JAVA.pptMETHODS IN  JAVA.ppt
METHODS IN JAVA.pptJayanthiM15
 
Basic elements of java
Basic elements of java Basic elements of java
Basic elements of java Ahmad Idrees
 
Java developer trainee implementation and import
Java developer trainee implementation and importJava developer trainee implementation and import
Java developer trainee implementation and importiamluqman0403
 
Fii Practic Frontend - BeeNear - laborator3
Fii Practic Frontend - BeeNear - laborator3Fii Practic Frontend - BeeNear - laborator3
Fii Practic Frontend - BeeNear - laborator3BeeNear
 
Qat09 presentations dxw07u
Qat09 presentations dxw07uQat09 presentations dxw07u
Qat09 presentations dxw07uShubham Sharma
 
2CPP11 - Method Overloading
2CPP11 - Method Overloading2CPP11 - Method Overloading
2CPP11 - Method OverloadingMichael Heron
 
METHODS OR FUNCTIONS IN C for dotnet.pptx
METHODS OR FUNCTIONS IN C for dotnet.pptxMETHODS OR FUNCTIONS IN C for dotnet.pptx
METHODS OR FUNCTIONS IN C for dotnet.pptxArjunKhanal8
 
Intro to LV in 3 Hours for Control and Sim 8_5.pptx
Intro to LV in 3 Hours for Control and Sim 8_5.pptxIntro to LV in 3 Hours for Control and Sim 8_5.pptx
Intro to LV in 3 Hours for Control and Sim 8_5.pptxDeepakJangid87
 
Java 8 Functional Programming - I
Java 8 Functional Programming - IJava 8 Functional Programming - I
Java 8 Functional Programming - IUgur Yeter
 
Error handling and debugging in vb
Error handling and debugging in vbError handling and debugging in vb
Error handling and debugging in vbSalim M
 

Similar to Lec 1.4 Object Oriented Programming (20)

Java 8 Features
Java 8 FeaturesJava 8 Features
Java 8 Features
 
CIS 1403 lab 3 functions and methods in Java
CIS 1403 lab 3 functions and methods in JavaCIS 1403 lab 3 functions and methods in Java
CIS 1403 lab 3 functions and methods in Java
 
Method overloading
Method overloadingMethod overloading
Method overloading
 
Method overloading
Method overloadingMethod overloading
Method overloading
 
Java method
Java methodJava method
Java method
 
METHODS IN JAVA.ppt
METHODS IN  JAVA.pptMETHODS IN  JAVA.ppt
METHODS IN JAVA.ppt
 
Basic elements of java
Basic elements of java Basic elements of java
Basic elements of java
 
Guide to Java.pptx
Guide to Java.pptxGuide to Java.pptx
Guide to Java.pptx
 
Java developer trainee implementation and import
Java developer trainee implementation and importJava developer trainee implementation and import
Java developer trainee implementation and import
 
Fii Practic Frontend - BeeNear - laborator3
Fii Practic Frontend - BeeNear - laborator3Fii Practic Frontend - BeeNear - laborator3
Fii Practic Frontend - BeeNear - laborator3
 
java.pptx
java.pptxjava.pptx
java.pptx
 
Qat09 presentations dxw07u
Qat09 presentations dxw07uQat09 presentations dxw07u
Qat09 presentations dxw07u
 
Smart Testing-Test Less, Cover More, Benefit Manifold- STeP-IN Summit 2014 Sp...
Smart Testing-Test Less, Cover More, Benefit Manifold- STeP-IN Summit 2014 Sp...Smart Testing-Test Less, Cover More, Benefit Manifold- STeP-IN Summit 2014 Sp...
Smart Testing-Test Less, Cover More, Benefit Manifold- STeP-IN Summit 2014 Sp...
 
Day 6.pptx
Day 6.pptxDay 6.pptx
Day 6.pptx
 
2CPP11 - Method Overloading
2CPP11 - Method Overloading2CPP11 - Method Overloading
2CPP11 - Method Overloading
 
METHODS OR FUNCTIONS IN C for dotnet.pptx
METHODS OR FUNCTIONS IN C for dotnet.pptxMETHODS OR FUNCTIONS IN C for dotnet.pptx
METHODS OR FUNCTIONS IN C for dotnet.pptx
 
Intro to LV in 3 Hours for Control and Sim 8_5.pptx
Intro to LV in 3 Hours for Control and Sim 8_5.pptxIntro to LV in 3 Hours for Control and Sim 8_5.pptx
Intro to LV in 3 Hours for Control and Sim 8_5.pptx
 
Lambdas in Java 8
Lambdas in Java 8Lambdas in Java 8
Lambdas in Java 8
 
Java 8 Functional Programming - I
Java 8 Functional Programming - IJava 8 Functional Programming - I
Java 8 Functional Programming - I
 
Error handling and debugging in vb
Error handling and debugging in vbError handling and debugging in vb
Error handling and debugging in vb
 

More from Badar Waseer

Ch 03 s.e agile development
Ch 03 s.e agile developmentCh 03 s.e agile development
Ch 03 s.e agile developmentBadar Waseer
 
Ch 02 s.e software process models 1
Ch 02 s.e software process models   1Ch 02 s.e software process models   1
Ch 02 s.e software process models 1Badar Waseer
 
Ch 01 s.e introduction
Ch 01 s.e introductionCh 01 s.e introduction
Ch 01 s.e introductionBadar Waseer
 
Ch 14 s.e use case diagrams
Ch 14 s.e use case diagramsCh 14 s.e use case diagrams
Ch 14 s.e use case diagramsBadar Waseer
 
Lec 1.1 Object Oriented Programming
Lec 1.1 Object Oriented ProgrammingLec 1.1 Object Oriented Programming
Lec 1.1 Object Oriented ProgrammingBadar Waseer
 
Lec 1.10 Object Oriented Programming
Lec 1.10 Object Oriented ProgrammingLec 1.10 Object Oriented Programming
Lec 1.10 Object Oriented ProgrammingBadar Waseer
 
Multimedia System & Design Ch 7 multimedia skills
Multimedia System & Design Ch 7 multimedia skillsMultimedia System & Design Ch 7 multimedia skills
Multimedia System & Design Ch 7 multimedia skillsBadar Waseer
 
Multimedia System & Design Ch 6 animation
Multimedia System & Design Ch 6 animationMultimedia System & Design Ch 6 animation
Multimedia System & Design Ch 6 animationBadar Waseer
 
Multimedia System & Design Ch 5 video
Multimedia System & Design Ch 5 videoMultimedia System & Design Ch 5 video
Multimedia System & Design Ch 5 videoBadar Waseer
 
Multimedia System & Design Ch 4 Audio
Multimedia System & Design Ch 4 AudioMultimedia System & Design Ch 4 Audio
Multimedia System & Design Ch 4 AudioBadar Waseer
 
Multimedia System & Design Ch 1, 2, 3 Multimedia
Multimedia System & Design Ch 1, 2, 3 MultimediaMultimedia System & Design Ch 1, 2, 3 Multimedia
Multimedia System & Design Ch 1, 2, 3 MultimediaBadar Waseer
 
Multimedia System & Design Ch 8 delivering
Multimedia System & Design Ch 8 deliveringMultimedia System & Design Ch 8 delivering
Multimedia System & Design Ch 8 deliveringBadar Waseer
 
Agriculture Information System (AIS)
Agriculture Information System (AIS)Agriculture Information System (AIS)
Agriculture Information System (AIS)Badar Waseer
 
Output Devices UoS Fsd
Output Devices UoS FsdOutput Devices UoS Fsd
Output Devices UoS FsdBadar Waseer
 

More from Badar Waseer (15)

Ch 03 s.e agile development
Ch 03 s.e agile developmentCh 03 s.e agile development
Ch 03 s.e agile development
 
Ch 02 s.e software process models 1
Ch 02 s.e software process models   1Ch 02 s.e software process models   1
Ch 02 s.e software process models 1
 
Ch 01 s.e introduction
Ch 01 s.e introductionCh 01 s.e introduction
Ch 01 s.e introduction
 
Ch 14 s.e use case diagrams
Ch 14 s.e use case diagramsCh 14 s.e use case diagrams
Ch 14 s.e use case diagrams
 
Ch 13 s.e cmmi
Ch 13 s.e cmmiCh 13 s.e cmmi
Ch 13 s.e cmmi
 
Lec 1.1 Object Oriented Programming
Lec 1.1 Object Oriented ProgrammingLec 1.1 Object Oriented Programming
Lec 1.1 Object Oriented Programming
 
Lec 1.10 Object Oriented Programming
Lec 1.10 Object Oriented ProgrammingLec 1.10 Object Oriented Programming
Lec 1.10 Object Oriented Programming
 
Multimedia System & Design Ch 7 multimedia skills
Multimedia System & Design Ch 7 multimedia skillsMultimedia System & Design Ch 7 multimedia skills
Multimedia System & Design Ch 7 multimedia skills
 
Multimedia System & Design Ch 6 animation
Multimedia System & Design Ch 6 animationMultimedia System & Design Ch 6 animation
Multimedia System & Design Ch 6 animation
 
Multimedia System & Design Ch 5 video
Multimedia System & Design Ch 5 videoMultimedia System & Design Ch 5 video
Multimedia System & Design Ch 5 video
 
Multimedia System & Design Ch 4 Audio
Multimedia System & Design Ch 4 AudioMultimedia System & Design Ch 4 Audio
Multimedia System & Design Ch 4 Audio
 
Multimedia System & Design Ch 1, 2, 3 Multimedia
Multimedia System & Design Ch 1, 2, 3 MultimediaMultimedia System & Design Ch 1, 2, 3 Multimedia
Multimedia System & Design Ch 1, 2, 3 Multimedia
 
Multimedia System & Design Ch 8 delivering
Multimedia System & Design Ch 8 deliveringMultimedia System & Design Ch 8 delivering
Multimedia System & Design Ch 8 delivering
 
Agriculture Information System (AIS)
Agriculture Information System (AIS)Agriculture Information System (AIS)
Agriculture Information System (AIS)
 
Output Devices UoS Fsd
Output Devices UoS FsdOutput Devices UoS Fsd
Output Devices UoS Fsd
 

Recently uploaded

Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...RKavithamani
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
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
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 

Recently uploaded (20)

Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
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
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 

Lec 1.4 Object Oriented Programming

  • 2. Operators • Operator in java is a symbol that is used to perform operations. There are many types of operators in java such as unary operator, arithmetic operator, relational operator, shift operator, bitwise operator, ternary operator and assignment operator. 2Badar Waseer arbabwaseergmail.com
  • 3. Operators Precedence Postfix expr++ expr-- Unary ++expr --expr +expr -expr ~ ! Multiplicative * / % Additive + - Shift << >> >>> Relational < > <= >= instanceof Equality == != Bitwise AND & Bitwise exclusive OR ^ Bitwise inclusive OR | Logical AND && Logical OR || Ternary ? : Assignment = += -= *= /= %= &= ^= |= <<= >>= >>>= 3Badar Waseer arbabwaseergmail.com
  • 4. • The Java if statement is used to test the condition. It checks boolean condition: true or false. There are various types of if statement in java. • if statement • if-else statement • nested if statement • if-else-if ladder Java If-else Statement 4Badar Waseer arbabwaseergmail.com
  • 5. Java IF Statement • The Java if statement tests the condition. It executes the if block if condition is true. • Syntax: 5Badar Waseer arbabwaseergmail.com
  • 8. Java IF-else Statement • The Java if-else statement also tests the condition. It executes the if block if condition is true otherwise else block is executed. • Syntax: 8Badar Waseer arbabwaseergmail.com
  • 11. Java IF-else-if ladder Statement • The if-else-if ladder statement executes one condition from multiple statements. • Syntax: 11Badar Waseer arbabwaseergmail.com
  • 15. Java Switch Statement • The Java switch statement executes one statement from multiple conditions. It is like if-else-if ladder statement. • Syntax: 15Badar Waseer arbabwaseergmail.com
  • 18. Java Switch Statement is fall-through • The java switch statement is fall-through. It means it executes all statement after first match if break statement is not used with switch cases. 18Badar Waseer arbabwaseergmail.com
  • 20. JAVA Methods • A Java method is a collection of statements that are grouped together to perform an operation. When you call the System.out.println() method, for example, the system actually executes several statements in order to display a message on the console. • Now you will learn how to create your own methods with or without return values, invoke a method with or without parameters, and apply method abstraction in the program design. 20Badar Waseer arbabwaseergmail.com
  • 21. Creating Method 21Badar Waseer arbabwaseergmail.com
  • 22. • The syntax shown includes − • modifier − It defines the access type of the method and it is optional to use. • returnType − Method may return a value. • nameOfMethod − This is the method name. The method signature consists of the method name and the parameter list. • Parameter List − The list of parameters, it is the type, order, and number of parameters of a method. These are optional, method may contain zero parameters. • method body − The method body defines what the method does with the statements. 22Badar Waseer arbabwaseergmail.com
  • 23. • Here, • public static − modifier • int − return type • methodName − name of the method • a, b − formal parameters • int a, int b − list of parameters • Method definition consists of a method header and a method body. 23Badar Waseer arbabwaseergmail.com
  • 25. 25 • Here is the source code of the above defined method called minFunction(). This method takes two parameters n1 and n2 and returns the minimum between the two − Badar Waseer arbabwaseergmail.com
  • 26. Method Calling • For using a method, it should be called. There are two ways in which a method is called i.e., method returns a value or returning nothing (no return value). • The process of method calling is simple. When a program invokes a method, the program control gets transferred to the called method. This called method then returns control to the caller in two conditions, when − • the return statement is executed. • it reaches the method ending closing brace. 26Badar Waseer arbabwaseergmail.com
  • 27. • The methods returning void is considered as call to a statement. Lets consider an example − • The method returning value can be understood by the following example − • Following is the example to demonstrate how to define a method and how to call it − 27 Badar Waseer arbabwaseergmail.com 27
  • 28. 28 • This will produce the following result − Badar Waseer arbabwaseergmail.com
  • 29. The void Keyword • The void keyword allows us to create methods which do not return a value. Here, in the following example we're considering a void method methodRankPoints. This method is a void method, which does not return any value. Call to a void method must be a statement i.e. methodRankPoints(255.7);. It is a Java statement which ends with a semicolon as shown in the following example. 29Badar Waseer arbabwaseergmail.com
  • 30. 30 • This will produce the following result − Badar Waseer arbabwaseergmail.com
  • 31. Passing Parameters by Value • While working under calling process, arguments is to be passed. These should be in the same order as their respective parameters in the method specification. Parameters can be passed by value or by reference. • Passing Parameters by Value means calling a method with a parameter. Through this, the argument value is passed to the parameter. 31Badar Waseer arbabwaseergmail.com
  • 32. • The following program shows an example of passing parameter by value. The values of the arguments remains the same even after the method invocation. 32Badar Waseer arbabwaseergmail.com
  • 34. • This will produce the following result − 34Badar Waseer arbabwaseergmail.com