SlideShare a Scribd company logo
1 of 8
Versatile Variables
Lesson 23
What Are Variables?
All computer programs work with different
kinds of data such as numbers, texts, dates and
pictures. Although this is typical, compute
programs need places where data can be
stored. These storage places are called
variables. They are called as such because the
data stored in them may vary as the program
runs.
Data Types
Data type refers to the kind of data a
variable can contain. It may either be a
number, letter or a list of characters.
Most common data types:
• int- used to represent whole, non-decimal
numbers. Examples are 1,100 and 1000
• double- used to repesent numbers with
decimal points, examples of which are 1.75,
0.975 and 19.78
Data Types
• char- enclosed in single quotation marks, it is
used to represent a single character;
examples are ‘a’, ‘m’ and ‘c’
• boolean- used to represent a boolean value,
which can be either true or false
A variable may also be classified as a
String, although a String is not a primitive
data type. A String is a class that stores a list
of characters. It is enclosed in double
quotation marks. Examples are “anna” and
“my pet”.
Rules In Naming Variables
Rules in naming variables (in Java):
• Variables can be composed of letters, numbers,
underscores and dollar signs.
• Variables may not start with a number. Below are
some examples of valid and invalid variables.
Valid Variables: Invalid Variables:
○ surname ○ my*name
○ _cost ○ my name
○ score1 ○ 12myName
• You cannot use a word reserved by Java. For
example, you cannot have a variable named if
or while.
Rules In Naming Variables
• The variable names also follow a norm called
camel notation. It is not a must to adhere to the
notation but it is a standard of doing things in
Java. You start a name with a small letter. If it has
two or more words, start all the other words with
capital letters. For example:
myName
firstName
Rules In Naming Variables
• If possible, use variable names that are
meaningful. You should be able to identify the
value stored in a variable by looking at its name.
For example:
myName -to contain my name
myScore -to contain my score
totalScore -to contain my total score
Declaring Variables
Once you have named a variable and
determines what type you want it to be, you must
relay this information to your Java program. So you
need to state in your program that a particular
variable exists. In other words, you need to declare
your variables.
We need a declaration for all variables that we
will use in our Java programs. Proper variable
declaration makes programming easier, minimizes the
possibility of program errors, and makes program
modifications easier later on.

More Related Content

What's hot

What's hot (19)

Chapter 6 java
Chapter 6 javaChapter 6 java
Chapter 6 java
 
Mapping Cardinalities
Mapping CardinalitiesMapping Cardinalities
Mapping Cardinalities
 
String
StringString
String
 
User defined data type
User defined data typeUser defined data type
User defined data type
 
Machine Learning - Accuracy and Confusion Matrix
Machine Learning - Accuracy and Confusion MatrixMachine Learning - Accuracy and Confusion Matrix
Machine Learning - Accuracy and Confusion Matrix
 
Welcome
WelcomeWelcome
Welcome
 
RapidMiner: Data Mining And Rapid Miner
RapidMiner: Data Mining And Rapid MinerRapidMiner: Data Mining And Rapid Miner
RapidMiner: Data Mining And Rapid Miner
 
Array
ArrayArray
Array
 
Swift Generics
Swift GenericsSwift Generics
Swift Generics
 
Computer programming 2 Lesson 5
Computer programming 2  Lesson 5Computer programming 2  Lesson 5
Computer programming 2 Lesson 5
 
Concept Of C++ Data Types
Concept Of C++ Data TypesConcept Of C++ Data Types
Concept Of C++ Data Types
 
Arrays in c_language
Arrays in c_language Arrays in c_language
Arrays in c_language
 
OOPs with java
OOPs with javaOOPs with java
OOPs with java
 
1 1 5 Clases
1 1 5 Clases1 1 5 Clases
1 1 5 Clases
 
Python decision making part4
Python decision making part4Python decision making part4
Python decision making part4
 
Accelerating the Random Forest algorithm for commodity parallel- Mark Seligman
Accelerating the Random Forest algorithm for commodity parallel- Mark SeligmanAccelerating the Random Forest algorithm for commodity parallel- Mark Seligman
Accelerating the Random Forest algorithm for commodity parallel- Mark Seligman
 
C PROGRAMMING LANGUAGE
C  PROGRAMMING  LANGUAGEC  PROGRAMMING  LANGUAGE
C PROGRAMMING LANGUAGE
 
Lect5
Lect5Lect5
Lect5
 
Preparing Data
Preparing DataPreparing Data
Preparing Data
 

Similar to Versatile Variables

PF 2- Data Types and Veriables (1).pptx
PF 2- Data Types and Veriables (1).pptxPF 2- Data Types and Veriables (1).pptx
PF 2- Data Types and Veriables (1).pptxMuhammadMuzaib1
 
Variables & Data Types.pptx
Variables & Data Types.pptxVariables & Data Types.pptx
Variables & Data Types.pptxAbdisamedAdam
 
L1(variables n datatypes).pptx
L1(variables n datatypes).pptxL1(variables n datatypes).pptx
L1(variables n datatypes).pptxshalinitripathi56
 
L2 C# Programming Comments, Keywords, Identifiers, Variables.pdf
L2 C# Programming Comments, Keywords, Identifiers, Variables.pdfL2 C# Programming Comments, Keywords, Identifiers, Variables.pdf
L2 C# Programming Comments, Keywords, Identifiers, Variables.pdfMMRF2
 
CSC111-Chap_02.pdf
CSC111-Chap_02.pdfCSC111-Chap_02.pdf
CSC111-Chap_02.pdf2b75fd3051
 
cassignmentii-170424105623.pdf
cassignmentii-170424105623.pdfcassignmentii-170424105623.pdf
cassignmentii-170424105623.pdfYRABHI
 
data types in C programming
data types in C programmingdata types in C programming
data types in C programmingHarshita Yadav
 
python presentation.pptx
python presentation.pptxpython presentation.pptx
python presentation.pptxNightTune44
 
L2 datatypes and variables
L2 datatypes and variablesL2 datatypes and variables
L2 datatypes and variablesteach4uin
 

Similar to Versatile Variables (20)

12.6-12.9.pptx
12.6-12.9.pptx12.6-12.9.pptx
12.6-12.9.pptx
 
PF 2- Data Types and Veriables (1).pptx
PF 2- Data Types and Veriables (1).pptxPF 2- Data Types and Veriables (1).pptx
PF 2- Data Types and Veriables (1).pptx
 
Variables
VariablesVariables
Variables
 
Variables & Data Types.pptx
Variables & Data Types.pptxVariables & Data Types.pptx
Variables & Data Types.pptx
 
L1(variables n datatypes).pptx
L1(variables n datatypes).pptxL1(variables n datatypes).pptx
L1(variables n datatypes).pptx
 
1.3 variables
1.3   variables1.3   variables
1.3 variables
 
JAVA LESSON-01.pptx
JAVA LESSON-01.pptxJAVA LESSON-01.pptx
JAVA LESSON-01.pptx
 
7-Java Language Basics Part1
7-Java Language Basics Part17-Java Language Basics Part1
7-Java Language Basics Part1
 
Typescript-7 (1).pptx
Typescript-7 (1).pptxTypescript-7 (1).pptx
Typescript-7 (1).pptx
 
L2 C# Programming Comments, Keywords, Identifiers, Variables.pdf
L2 C# Programming Comments, Keywords, Identifiers, Variables.pdfL2 C# Programming Comments, Keywords, Identifiers, Variables.pdf
L2 C# Programming Comments, Keywords, Identifiers, Variables.pdf
 
Variables&DataTypes.pptx
Variables&DataTypes.pptxVariables&DataTypes.pptx
Variables&DataTypes.pptx
 
CSC111-Chap_02.pdf
CSC111-Chap_02.pdfCSC111-Chap_02.pdf
CSC111-Chap_02.pdf
 
cassignmentii-170424105623.pdf
cassignmentii-170424105623.pdfcassignmentii-170424105623.pdf
cassignmentii-170424105623.pdf
 
data types in C programming
data types in C programmingdata types in C programming
data types in C programming
 
python presentation.pptx
python presentation.pptxpython presentation.pptx
python presentation.pptx
 
Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentals
 
Variable
VariableVariable
Variable
 
Data types vbnet
Data types vbnetData types vbnet
Data types vbnet
 
Data types vbnet
Data types vbnetData types vbnet
Data types vbnet
 
L2 datatypes and variables
L2 datatypes and variablesL2 datatypes and variables
L2 datatypes and variables
 

Recently uploaded

Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxabhijeetpadhi001
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
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
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
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
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.arsicmarija21
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
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
 
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
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
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
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 

Recently uploaded (20)

Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptx
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.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
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
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
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).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
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
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
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
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
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 

Versatile Variables

  • 2. What Are Variables? All computer programs work with different kinds of data such as numbers, texts, dates and pictures. Although this is typical, compute programs need places where data can be stored. These storage places are called variables. They are called as such because the data stored in them may vary as the program runs.
  • 3. Data Types Data type refers to the kind of data a variable can contain. It may either be a number, letter or a list of characters. Most common data types: • int- used to represent whole, non-decimal numbers. Examples are 1,100 and 1000 • double- used to repesent numbers with decimal points, examples of which are 1.75, 0.975 and 19.78
  • 4. Data Types • char- enclosed in single quotation marks, it is used to represent a single character; examples are ‘a’, ‘m’ and ‘c’ • boolean- used to represent a boolean value, which can be either true or false A variable may also be classified as a String, although a String is not a primitive data type. A String is a class that stores a list of characters. It is enclosed in double quotation marks. Examples are “anna” and “my pet”.
  • 5. Rules In Naming Variables Rules in naming variables (in Java): • Variables can be composed of letters, numbers, underscores and dollar signs. • Variables may not start with a number. Below are some examples of valid and invalid variables. Valid Variables: Invalid Variables: ○ surname ○ my*name ○ _cost ○ my name ○ score1 ○ 12myName • You cannot use a word reserved by Java. For example, you cannot have a variable named if or while.
  • 6. Rules In Naming Variables • The variable names also follow a norm called camel notation. It is not a must to adhere to the notation but it is a standard of doing things in Java. You start a name with a small letter. If it has two or more words, start all the other words with capital letters. For example: myName firstName
  • 7. Rules In Naming Variables • If possible, use variable names that are meaningful. You should be able to identify the value stored in a variable by looking at its name. For example: myName -to contain my name myScore -to contain my score totalScore -to contain my total score
  • 8. Declaring Variables Once you have named a variable and determines what type you want it to be, you must relay this information to your Java program. So you need to state in your program that a particular variable exists. In other words, you need to declare your variables. We need a declaration for all variables that we will use in our Java programs. Proper variable declaration makes programming easier, minimizes the possibility of program errors, and makes program modifications easier later on.