0% found this document useful (0 votes)
4 views14 pages

3.0 Java Variables

The document outlines a lesson on Java variables, detailing the definition, declaration, and initialization of variables, along with the different data types in Java. It includes learning objectives for students and provides examples of primitive and non-primitive data types, as well as a sample program activity for students to practice. The document is prepared by Gwenshane R. Sojor at Metro Dumaguete College, Inc.

Uploaded by

driencaballero
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views14 pages

3.0 Java Variables

The document outlines a lesson on Java variables, detailing the definition, declaration, and initialization of variables, along with the different data types in Java. It includes learning objectives for students and provides examples of primitive and non-primitive data types, as well as a sample program activity for students to practice. The document is prepared by Gwenshane R. Sojor at Metro Dumaguete College, Inc.

Uploaded by

driencaballero
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Fundamentals of 01

Programming 1010
010101
101010101
10101010101
Prepared by: Gwenshane R. Sojor 01010101010101
10101010101010101
01010101010101010101
10101010101010101010101
01010101010101010101010101
0101010101010101010101010101
010101010101010101010101010101
1010101010101010101010101010101
1010101010101010101010101011010
1001010101010101010101010101010
10101010101010101010101010101
Opening prayer
Dear Lord,
We thank You for this new day and for the opportunity to learn together.
Guide our thoughts, our words, and our actions.
Grant us clarity, patience, and understanding as we begin this session.
May You bless every one of us and this learning environment.
May everything we do today bring wisdom, confidence, and purpose.
Amen.

METRO DUMAGUETE COLLEGE, INC


Ej. Blanco Extension Road, Brgy. Daro, Dumaguete city, Philippines 6200
Telephone Nos. (035) 420-9801, 420-9728 or 422-4605
Website: [Link]
01

Java Variables 1010


010101
101010101
10101010101
Prepared by: Gwenshane R. Sojor 01010101010101
10101010101010101
01010101010101010101
10101010101010101010101
01010101010101010101010101
0101010101010101010101010101
010101010101010101010101010101
1010101010101010101010101010101
1010101010101010101010101011010
1001010101010101010101010101010
10101010101010101010101010101
Learning Objectives
At the end of this lesson, the students should be able to:
• Define what variables are in Java.
• Identify the different basic data types used in Java.
• Declare and initialize variables using appropriate data types.
• Display variable values using [Link]().

METRO DUMAGUETE COLLEGE, INC


Ej. Blanco Extension Road, Brgy. Daro, Dumaguete city, Philippines 6200
Telephone Nos. (035) 420-9801, 420-9728 or 422-4605
Website: [Link]
Java Variables
A variable is a container used to store data in a program.

Each variable has:


a data type (what kind of data it can store),
a name (identifier), and
a value.

METRO DUMAGUETE COLLEGE, INC


Ej. Blanco Extension Road, Brgy. Daro, Dumaguete city, Philippines 6200
Telephone Nos. (035) 420-9801, 420-9728 or 422-4605
Website: [Link]
Java Variables

In Java, a variable must be declared before it is used. A variable


declaration involves a data type and a variable name.

METRO DUMAGUETE COLLEGE, INC


Ej. Blanco Extension Road, Brgy. Daro, Dumaguete city, Philippines 6200
Telephone Nos. (035) 420-9801, 420-9728 or 422-4605
Website: [Link]
Java Variables
Example:

•int → data type


•age → variable name
•18 → value

METRO DUMAGUETE COLLEGE, INC


Ej. Blanco Extension Road, Brgy. Daro, Dumaguete city, Philippines 6200
Telephone Nos. (035) 420-9801, 420-9728 or 422-4605
Website: [Link]
Java Data Types
Data types specify the kind of data a variable can hold, as well as its
size and the operations that can be performed on it.

Data types in Java are divided into two groups:


• Primitive data types include byte, short, int, long, float, double,
boolean, and char.

• Non-primitive data types include String, Arrays, and Classes, which


you will learn more about in a later chapter.

METRO DUMAGUETE COLLEGE, INC


Ej. Blanco Extension Road, Brgy. Daro, Dumaguete city, Philippines 6200
Telephone Nos. (035) 420-9801, 420-9728 or 422-4605
Website: [Link]
Common Data Types
Data Type Description Size Example
int Stores whole numbers 4 bytes int score = 90;
double Stores decimal numbers 8 bytes double price = 99.50;
char Stores a single character 2 bytes char grade = 'A';
boolean Stores true or false 1 bit* boolean isPassed = true;
String Stores text (not primitive) Varies String name = "Juan";

METRO DUMAGUETE COLLEGE, INC


Ej. Blanco Extension Road, Brgy. Daro, Dumaguete city, Philippines 6200
Telephone Nos. (035) 420-9801, 420-9728 or 422-4605
Website: [Link]
Sample Program

METRO DUMAGUETE COLLEGE, INC


Ej. Blanco Extension Road, Brgy. Daro, Dumaguete city, Philippines 6200
Telephone Nos. (035) 420-9801, 420-9728 or 422-4605
Website: [Link]
The output of the program will be:

Each [Link]() prints the label and the value of the


variable on a new line.

METRO DUMAGUETE COLLEGE, INC


Ej. Blanco Extension Road, Brgy. Daro, Dumaguete city, Philippines 6200
Telephone Nos. (035) 420-9801, 420-9728 or 422-4605
Website: [Link]
Activity 4: Student Information Program
Instructions:
1. Open OnlineGDB Classroom and locate Activity 4: Student Information
Program.
2. Create a Java program using the Main class.
3. Inside the main method, declare and initialize the following variables:
• String → student name
• int → age
• String → course (DSET)
• char → section
• boolean → currently enrolled status
4. Display each value using [Link]() with proper labels.
5. Run the program and make sure there are no errors.
6. Submit your code in OnlineGDB.

METRO DUMAGUETE COLLEGE, INC


Ej. Blanco Extension Road, Brgy. Daro, Dumaguete city, Philippines 6200
Telephone Nos. (035) 420-9801, 420-9728 or 422-4605
Website: [Link]
Sample output:

METRO DUMAGUETE COLLEGE, INC


Ej. Blanco Extension Road, Brgy. Daro, Dumaguete city, Philippines 6200
Telephone Nos. (035) 420-9801, 420-9728 or 422-4605
Website: [Link]
Thank you!

METRO DUMAGUETE COLLEGE, INC


Ej. Blanco Extension Road, Brgy. Daro, Dumaguete city, Philippines 6200
Telephone Nos. (035) 420-9801, 420-9728 or 422-4605
Website: [Link]

You might also like