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

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Recently uploaded (20)

A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
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...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 

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)