0% found this document useful (0 votes)
8 views

Java Lesson 4 - Data and Variables

This document provides an introduction to data and variables in Java programming. It defines data as information that can be stored, processed, and generated by a computer system. There are 8 fundamental data types in Java - byte, short, int, long, float, double, char, and boolean. A variable is a name assigned to a data container in memory for easier referencing than its actual memory address. Variables must follow certain naming conventions and are declared with a data type and can be initialized with an initial value. The document provides examples of acceptable and unacceptable variable declarations and initializations.

Uploaded by

Rowell Marquina
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Java Lesson 4 - Data and Variables

This document provides an introduction to data and variables in Java programming. It defines data as information that can be stored, processed, and generated by a computer system. There are 8 fundamental data types in Java - byte, short, int, long, float, double, char, and boolean. A variable is a name assigned to a data container in memory for easier referencing than its actual memory address. Variables must follow certain naming conventions and are declared with a data type and can be initialized with an initial value. The document provides examples of acceptable and unacceptable variable declarations and initializations.

Uploaded by

Rowell Marquina
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

TUNASAN NATIONAL HIGH SCHOOL

SDO - Muntinlupa City

Lesson 4 - Java Programming

ROWELL L. MARQUINA
Senior High School Teacher
TUNASAN NATIONAL HIGH SCHOOL
LEARNING OBJECTIVES:
At the end of the session, you will be able to:
1. define data and data type;
2. categorize data according to
classifications;
3. discuss what is a variable and its
importance; and
4. declare and initialize variables and
use it in a Java program.
WHAT IS DATA?
Data in programming refers
to information can be stored,
processed, and generated by
a computer system.
It is characterized by its
capacity to:
▪ be transformed to other
type of information
▪ to be transmitted to other
computer systems.
IMAGE SOURCE:
https://images.datacamp.com/image/upload/v1652357545/shutterstock_1770654182_d43667c1bc.jpg
WHAT IS DATA?
Examples of Data:
▪ Name
▪ Date of Birth
▪ Sex/Gender
▪ Address
▪ Cell Phone Number
▪ Serial Number
▪ Email Address
▪ String of Letters or Numbers
▪ A Yes/No Answer
IMAGE SOURCE:
https://images.datacamp.com/image/upload/v1652357545/shutterstock_1770654182_d43667c1bc.jpg
WHAT IS DATA?
When a data is inputted in
computer system for processing, it
will be entered in the system’s
memory unit for either temporary
or permanent storage.
Depending on its size and data
type, it will be assigned to occupy a
specific space in the storage unit
which are identified using memory
address.

IMAGE SOURCE: https://learningc.org/_images/memory-pieces.png


WHAT IS DATA TYPE?
Data type refers to the classification of data that tells the
program what type of information it is getting and how it
will be processed.

IMAGE SOURCE: https://techvidvan.com/tutorials/wp-content/uploads/sites/2/2020/02/primitive-data-


types-in-java.jpg
WHAT IS DATA TYPE?
There are 8 fundamental data types used in Java.
byte refers to integers that ranges from -128 to 127

short refers to integers that ranges from -32,768 to 32,767

int refers to integers that ranges from -2,147,483,648 to 2,147,483,647

refers to integers that ranges from -9,223,372,036,854,775,808 to


long
9,223,372,036,854,775,807
WHAT IS DATA TYPE?
There are 8 fundamental data types used in Java.
refers to decimal numbers that has a precision of up to 7-digits
float
after the decimal point.

refers to decimal numbers that has a precision of up to 15-digits


double
after the decimal point.

refers to a data type that is used to store a single character. It can


char
be a single letter, number, or symbol.

refers to the data type that can only store any of the two reserved
boolean
values of either true or false.
WHAT IS A VARIABLE?
A variable is a name or label
assigned by a programmer for a
data container located in the
memory unit.
Using variable enables programmers
to label a memory allocation with a
more readable and recognizable
name rather than its actual memory
address for easier referencing.

IMAGE SOURCE: https://www.startertutorials.com/corejava/wp-content/uploads/2014/09/Java-Variable.jpg


NAMING CONVENTIONS:
▪ The length of the variable name
must be at least one character.
▪ It must not be a keyword used by
Java such as print, println, system,
include, int, float, and String to
name a few.
▪ It should start with a either a letter,
dollar sign ($), or underscore (_).
▪ It must not start with a number.

IMAGE SOURCE: https://www.startertutorials.com/corejava/wp-content/uploads/2014/09/Java-Variable.jpg


NAMING CONVENTIONS:
▪ Be mindful of your casing
because Java is case-sensitive.
▪ Must not include a whitespace or
blank instead the user can use
an underscore.

IMAGE SOURCE: https://www.startertutorials.com/corejava/wp-content/uploads/2014/09/Java-Variable.jpg


CHECKPOINT:
Which of these variable names
are acceptable? Why / Why not?
▪ num 1
▪ BirthMonth
▪ 1stnum
▪ $num
▪ systemx
▪ 1st_Year
▪ employee_name
▪ product code
VARIABLE DECLARATION
A variable declaration is a Java statement that
instructs the program to assign a name or label to a
specific memory location in the computer. It also
informs the program what type of data that the
memory location shall contain.
VARIABLE DECLARATION

Data Type Variable Name


Separator
VARIABLE DECLARATION
When declaring variables that are consists of
different data types, each variable must be declared
individually separated by a semicolon.
VARIABLE DECLARATION
When declaring variables that are consists of similar
data types, all the variables can be declared
altogether in one line but are separated by commas.
VARIABLE DECLARATION
Regardless of the similarity or
differences of the data type,
programmers can still opt to
declare their variables in
individually. It is done most likely
for the purpose of readability.
It is important to note that since
variables are declared individually,
each declaration must be
separated by a semicolon.
VARIABLE INITIALIZATION
A variable initialization is a Java statement that
declares a variable with an initial value. It allows the
memory location to start with an initial data.
VARIABLE INITIALIZATION

Variable Name Initial Value


Data Type

Assignment Operator Separator


VARIABLE INITIALIZATION
Important notes when declaring
or initializing a variable:
▪ Only the String data type is
written with its first letter
uppercased, the rest of the
data types are written in
lowercase.
▪ The String value is initiated
by enclosing it value inside
quotation marks (“).
VARIABLE INITIALIZATION
Important notes when
declaring or initializing a
variable:
▪ The integer and
double values are
declared “as is”.
▪ The character is
declared by enclosing
its value with a single
quote (‘).
CHECKPOINT:
Which of these variable
declarations / initializations are
acceptable? Why / Why not?
▪ String sport = ‘basketball’;
▪ int weight = “52”;
▪ double math_grade = 95.39;
▪ String color = blue;
▪ Double gravity = 9.8;
▪ int speed = 8.56;
▪ String dog_breed = Shih Tzu
DATA AND VARIABLES

MR. ROWELL L. MARQUINA


Tunasan National High School
Senior High School Department

Email Address:
[email protected]
[email protected]
[email protected]

You might also like