SlideShare a Scribd company logo
1 of 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)

More Related Content

What's hot

Ap Power Point Chpt5
Ap Power Point Chpt5Ap Power Point Chpt5
Ap Power Point Chpt5
dplunkett
 

What's hot (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
 

Viewers also liked (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
 

Similar to Chapter 04

Reportgroup4 111016004939-phpapp01
Reportgroup4 111016004939-phpapp01Reportgroup4 111016004939-phpapp01
Reportgroup4 111016004939-phpapp01
Nurhidayah Mahmud
 
FP 201 Unit 2 - Part 3
FP 201 Unit 2 - Part 3FP 201 Unit 2 - Part 3
FP 201 Unit 2 - Part 3
rohassanie
 

Similar to Chapter 04 (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
 
C++ problem solving operators ( conditional operators,logical operators, swit...
C++ problem solving operators ( conditional operators,logical operators, swit...C++ problem solving operators ( conditional operators,logical operators, swit...
C++ problem solving operators ( conditional operators,logical operators, swit...
 
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
 

More from 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
 

Recently uploaded

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Recently uploaded (20)

🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
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
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
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...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
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
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 

Chapter 04

  • 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)