SlideShare uma empresa Scribd logo
1 de 11
Inside Class Methods
Chapter 4
4
What are variables?
Variables store values within methods
and may change value as the method
processes data.
4
Variables
The scope of a variable determines
how long it holds its value.
Local variables maintain their scope
within the block of code in which they are
declared.
Local variables are not fields of the class.
4
Declaring and Initializing Variables
Declare a variable by identifying its
type and the identifier (name):
double averageSpeed;
Initialization is when you declare a
variable and assign it a value at the
same time:
double averageSpeed = 21.6;
4
What are operators?
Operators are symbols that take action
within a program.
Assignment operator (=) assigns a value
to a field or variable:
averageSpeed = 21.6;
Mathematical operators include:
+, -, *, and /
Relational operators include:
<, >, ==, and !=
4
A Self-Assignment Operator
Manipulates a variable and assigns the
results back to itself.
Self-assignment operators include +=, -=,
*=, and %=
int x = 5;
int y = 6;
x += y;
x has the value (5 + 6) = 11
4
Precedence
Java follows mathematical rules of
precedence.
Multiplication and division are handled
first, followed by addition and subtraction
Use parentheses to force evaluation
4
Increment and Decrement Operators
The increment operator (++) means
increment (add) by one.
++x;
The decrement operator (--) means
decrement (subtract) by one.
--x;
4
Prefix vs. Postfix
Prefix notation increments, then fetches:
int x = 5;
int y = ++x;
Value of y is 6 (1 + 5), value of x is 6
Postfix notation fetches, then increments:
int x = 5;
int y = x++;
Value of y is 5, value of x is 6
4
What is a constant?
A constant is a variable with a fixed
value (cannot be changed).
Use the keyword final to designate a
constant.
Constant identifiers are typically
UPPER_CASE notation to distinguish
them from other variables.
4
Relational Operators
Evaluate the equality or inequality of
two intrinsic types.
Return a boolean value (true or false)
Equality: ==
Inequality: <, >, <=, >=, != (not equal)

Mais conteúdo relacionado

Mais procurados (19)

Operators in java presentation
Operators in java presentationOperators in java presentation
Operators in java presentation
 
Operators
OperatorsOperators
Operators
 
Type Conversion, Precedence and Associativity
Type Conversion, Precedence and AssociativityType Conversion, Precedence and Associativity
Type Conversion, Precedence and Associativity
 
Operators
OperatorsOperators
Operators
 
Cprogrammingoperator
CprogrammingoperatorCprogrammingoperator
Cprogrammingoperator
 
Relational operators
Relational operatorsRelational operators
Relational operators
 
conditional statements and operators
conditional statements and operatorsconditional statements and operators
conditional statements and operators
 
SPL 6 | Operators in C
SPL 6 | Operators in CSPL 6 | Operators in C
SPL 6 | Operators in C
 
05 operators
05   operators05   operators
05 operators
 
Type conversion, precedence, associativity in c programming
Type conversion, precedence, associativity in c programmingType conversion, precedence, associativity in c programming
Type conversion, precedence, associativity in c programming
 
Java 2
Java 2Java 2
Java 2
 
Oop using JAVA
Oop using JAVAOop using JAVA
Oop using JAVA
 
itft-Operators in java
itft-Operators in javaitft-Operators in java
itft-Operators in java
 
C++
C++ C++
C++
 
operator
operatoroperator
operator
 
L3 operators
L3 operatorsL3 operators
L3 operators
 
Operators in java
Operators in javaOperators in java
Operators in java
 
Ap Power Point Chpt5
Ap Power Point Chpt5Ap Power Point Chpt5
Ap Power Point Chpt5
 
Operators
OperatorsOperators
Operators
 

Destaque

Destaque (6)

Chapter 09
Chapter 09Chapter 09
Chapter 09
 
Challenges
ChallengesChallenges
Challenges
 
Chapter 01
Chapter 01Chapter 01
Chapter 01
 
Chapter 10
Chapter 10Chapter 10
Chapter 10
 
Idea's1 only
Idea's1 onlyIdea's1 only
Idea's1 only
 
Managing A Start Up And Ethics M5
Managing A Start Up And Ethics M5Managing A Start Up And Ethics M5
Managing A Start Up And Ethics M5
 

Semelhante a Inside Class Methods: Understanding Variables and Operators

Day1, session iv - spss
Day1, session iv - spssDay1, session iv - spss
Day1, session iv - spssabir hossain
 
OCA Java SE 8 Exam Chapter 2 Operators & Statements
OCA Java SE 8 Exam Chapter 2 Operators & StatementsOCA Java SE 8 Exam Chapter 2 Operators & Statements
OCA Java SE 8 Exam Chapter 2 Operators & Statementsİbrahim Kürce
 
Linear equation class 8 by siddhartha kumar panda
Linear equation class 8 by siddhartha kumar pandaLinear equation class 8 by siddhartha kumar panda
Linear equation class 8 by siddhartha kumar pandaSUSANTA KUMAR PANDA
 
Polymath For Chemical Engineers
Polymath For Chemical EngineersPolymath For Chemical Engineers
Polymath For Chemical EngineersHashim Khan
 
Reportgroup4 111016004939-phpapp01
Reportgroup4 111016004939-phpapp01Reportgroup4 111016004939-phpapp01
Reportgroup4 111016004939-phpapp01Nurhidayah Mahmud
 
Operators in java script
Operators   in  java scriptOperators   in  java script
Operators in java scriptAbhinav Somani
 
Operators and expressions in C++
Operators and expressions in C++Operators and expressions in C++
Operators and expressions in C++Neeru Mittal
 
FP 201 Unit 2 - Part 3
FP 201 Unit 2 - Part 3FP 201 Unit 2 - Part 3
FP 201 Unit 2 - Part 3rohassanie
 
Lecture - 3 Variables-data type_operators_oops concept
Lecture - 3 Variables-data type_operators_oops conceptLecture - 3 Variables-data type_operators_oops concept
Lecture - 3 Variables-data type_operators_oops conceptmanish kumar
 
Shubhrat operator &amp; expression
Shubhrat operator &amp; expressionShubhrat operator &amp; expression
Shubhrat operator &amp; expressionShubhrat Mishra
 

Semelhante a Inside Class Methods: Understanding Variables and Operators (20)

SPSS
SPSSSPSS
SPSS
 
Day1, session iv - spss
Day1, session iv - spssDay1, session iv - spss
Day1, session iv - spss
 
SPSS
SPSSSPSS
SPSS
 
OCA Java SE 8 Exam Chapter 2 Operators & Statements
OCA Java SE 8 Exam Chapter 2 Operators & StatementsOCA Java SE 8 Exam Chapter 2 Operators & Statements
OCA Java SE 8 Exam Chapter 2 Operators & Statements
 
Chapter3
Chapter3Chapter3
Chapter3
 
Operator
OperatorOperator
Operator
 
Linear equation class 8 by siddhartha kumar panda
Linear equation class 8 by siddhartha kumar pandaLinear equation class 8 by siddhartha kumar panda
Linear equation class 8 by siddhartha kumar panda
 
c programming2.pptx
c programming2.pptxc programming2.pptx
c programming2.pptx
 
Operators in C Programming
Operators in C ProgrammingOperators in C Programming
Operators in C Programming
 
Polymath For Chemical Engineers
Polymath For Chemical EngineersPolymath For Chemical Engineers
Polymath For Chemical Engineers
 
Operators in java By cheena
Operators in java By cheenaOperators in java By cheena
Operators in java By cheena
 
Guide to Java.pptx
Guide to Java.pptxGuide to Java.pptx
Guide to Java.pptx
 
Reportgroup4 111016004939-phpapp01
Reportgroup4 111016004939-phpapp01Reportgroup4 111016004939-phpapp01
Reportgroup4 111016004939-phpapp01
 
Operators in java script
Operators   in  java scriptOperators   in  java script
Operators in java script
 
Operators and expressions in C++
Operators and expressions in C++Operators and expressions in C++
Operators and expressions in C++
 
FP 201 Unit 2 - Part 3
FP 201 Unit 2 - Part 3FP 201 Unit 2 - Part 3
FP 201 Unit 2 - Part 3
 
Lecture - 3 Variables-data type_operators_oops concept
Lecture - 3 Variables-data type_operators_oops conceptLecture - 3 Variables-data type_operators_oops concept
Lecture - 3 Variables-data type_operators_oops concept
 
Shubhrat operator &amp; expression
Shubhrat operator &amp; expressionShubhrat operator &amp; expression
Shubhrat operator &amp; expression
 
Programming in c by pkv
Programming in c by pkvProgramming in c by pkv
Programming in c by pkv
 
MODULE_2_Operators.pptx
MODULE_2_Operators.pptxMODULE_2_Operators.pptx
MODULE_2_Operators.pptx
 

Mais de Graham Royce (20)

Chapter 18
Chapter 18Chapter 18
Chapter 18
 
Chapter 17
Chapter 17Chapter 17
Chapter 17
 
Chapter 16
Chapter 16Chapter 16
Chapter 16
 
Chapter 15
Chapter 15Chapter 15
Chapter 15
 
Chapter 14
Chapter 14Chapter 14
Chapter 14
 
Chapter 13
Chapter 13Chapter 13
Chapter 13
 
Chapter 12
Chapter 12Chapter 12
Chapter 12
 
Chapter 11
Chapter 11Chapter 11
Chapter 11
 
Chapter 08
Chapter 08Chapter 08
Chapter 08
 
Chapter 07
Chapter 07Chapter 07
Chapter 07
 
Chapter 06
Chapter 06Chapter 06
Chapter 06
 
Chapter 05
Chapter 05Chapter 05
Chapter 05
 
Chapter 03
Chapter 03Chapter 03
Chapter 03
 
Chapter 02
Chapter 02Chapter 02
Chapter 02
 
13 java in oracle
13 java in oracle13 java in oracle
13 java in oracle
 
Java tut1 Coderdojo Cahersiveen
Java tut1 Coderdojo CahersiveenJava tut1 Coderdojo Cahersiveen
Java tut1 Coderdojo Cahersiveen
 
My 3 min pitch pack
My 3 min pitch packMy 3 min pitch pack
My 3 min pitch pack
 
Things to do
Things to doThings to do
Things to do
 
House in order
House in orderHouse in order
House in order
 
Blank 10 all you need
Blank 10 all you needBlank 10 all you need
Blank 10 all you need
 

Último

How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Kaya Weers
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...itnewsafrica
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesManik S Magar
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkPixlogix Infotech
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 

Último (20)

How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App Framework
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 

Inside Class Methods: Understanding Variables and Operators

  • 2. 4 What are variables? Variables store values within methods and may change value as the method processes data.
  • 3. 4 Variables The scope of a variable determines how long it holds its value. Local variables maintain their scope within the block of code in which they are declared. Local variables are not fields of the class.
  • 4. 4 Declaring and Initializing Variables Declare a variable by identifying its type and the identifier (name): double averageSpeed; Initialization is when you declare a variable and assign it a value at the same time: double averageSpeed = 21.6;
  • 5. 4 What are operators? Operators are symbols that take action within a program. Assignment operator (=) assigns a value to a field or variable: averageSpeed = 21.6; Mathematical operators include: +, -, *, and / Relational operators include: <, >, ==, and !=
  • 6. 4 A Self-Assignment Operator Manipulates a variable and assigns the results back to itself. Self-assignment operators include +=, -=, *=, and %= int x = 5; int y = 6; x += y; x has the value (5 + 6) = 11
  • 7. 4 Precedence Java follows mathematical rules of precedence. Multiplication and division are handled first, followed by addition and subtraction Use parentheses to force evaluation
  • 8. 4 Increment and Decrement Operators The increment operator (++) means increment (add) by one. ++x; The decrement operator (--) means decrement (subtract) by one. --x;
  • 9. 4 Prefix vs. Postfix Prefix notation increments, then fetches: int x = 5; int y = ++x; Value of y is 6 (1 + 5), value of x is 6 Postfix notation fetches, then increments: int x = 5; int y = x++; Value of y is 5, value of x is 6
  • 10. 4 What is a constant? A constant is a variable with a fixed value (cannot be changed). Use the keyword final to designate a constant. Constant identifiers are typically UPPER_CASE notation to distinguish them from other variables.
  • 11. 4 Relational Operators Evaluate the equality or inequality of two intrinsic types. Return a boolean value (true or false) Equality: == Inequality: <, >, <=, >=, != (not equal)