Professional Documents
Culture Documents
LE ER
LEARNING RESOURCES MANAGEMENT AND DEVELOPMENT SECTION
SA P
R RO
FO P
T E NT
NO NM
SELF-LEARNING KIT
R
VE
GO
To the Teacher
Write your name clearly under the column “Issued to.” Use the following letters
in recording the condition of the book:
A New Book
B Used Book in Good Condition
C Used Book in Fair Condition
D Used Book in Poor Condition
Working With Java Data Types With Java Framework
SELF-LEARNING KIT
INFORMATION AND COMMUNICATIONS TECHNOLOGY
PROGRAMMING NC III (JAVA TECHNOLOGY)
WORKING WITH JAVA DATA TYPES
WITH JAVA FRAMEWORK
3
This Self-Learning Kit was conceptualized and developed by the
LEARNING RESOURCES MANAGEMENT AND DEVELOPMENT SECTION (LRMDS)
SCHOOLS DIVISION OF BATAAN
EDGAR E. GARCIA
Education Program Supervisor, LRMDS
ROSITA P. SERRANO JOAN T. BRIZ RICHARD M. ALBORO
Librarian II Project Development Officer II Information Technology Officer II
COPYRIGHT NOTICE
Section 9 of Presidential Decree No. 49 provides:
No copy shall subsist in any work of the Government of the Philippines. However, prior approval of the government agency or
office wherein the work is created shall be necessary for exploitation of such work for profit. Such agency or office may, among other
things, impose as a condition the payment of royalties...
A “Work of the Government of the Philippines” is a work created by any officer or employee of the Philippine Government or
any of its subdivisions and instrumentalities, including government owned or controlled corporations as a part of his regularly prescribed
official duties.
Notwithstanding the foregoing provisions, the Government is not precluded from receiving and holding copyright transferred to
it by assignment, bequests or otherwise; nor shall publication or republication by the Government in a public document of any work in
which copyright is subsisting be taken to cause any abridgment or annulment of the copyright or to authorize any use of appropriation
of such work without the consent of the copyright proprietor.
This Self-Learning Kit was conceptualized and developed by the Learning Resources Management and Development Section
of the Department of Education Region III – Schools Division of Bataan. It can be reproduced, used, copied, printed or reprinted for
educational purposes use only, but the source must be clearly acknowledged. This storybook can also be modified for the purpose of
translation into another language or dialect, but the original work must be documented. Derivatives of the work including creating an
edited version, an enhancement or a supplementary work are permitted provided all original works are credited and the copyright is
attributed. No work may be derived from this material for commercial purposes or profit.
PREFACE
This Self-Learning Kit (SLK) will help the learners deepen their knowledge about the
Java Data types in accordance with Java framework. This material is designed for Grade
11 and 12 students who need remediation and who are willing to learn in self-paced mode.
For “you” to start, remember to do the following tips to successfully achieve the
objectives of this Self-Learning Kit (SLK): keep this material in good condition and neat all
the time; do not write any unnecessary things on its pages; use separate paper as your
answer sheet; read and follow all the instructions carefully; answer the given task before
you start the lesson; take note and record points of clarification; try to achieve at least
80% level of proficiency in every activity; work diligently and honestly; answer the activities
thoroughly and find out the given description in the progress chart after having self-check
of the activities.
5
Self-Learning Kit in Information and Communications Technology
OBJECTIVES
At the end of the lesson, with at least 80% level of proficiency, you should be able to:
1. Identify and understand variables and data types based on its description;
2. investigate the usage and function of different data types by giving example
program; and
3. create a java program that will apply java data types in accordance with java
technology.
LEARNING COMPETENCIES
v
Before we proceed further to your Self-Learning Kit proper, answer first the given
items below.
Instruction: Match the word in Column A with the definitions in Column B. Write the
letter of the correct answer on a separate sheet of paper.
A B
_________1. Integer a. It is the presentation of
values.
_________2. Floating-point numbers b. It is used for logical values like true or
false.
_________3. Characters c. It is a data type used to store charac
ters.
_________4. Boolean d. It is used when evaluating expressions
that require fractional parts.
_________5. Literals e. These are signed positive and nega
tive values.
f. It is utilized to access objects.
Do you know the different java data types that you can use to create a java program?
Actually, that’s what you are going to learn in this material. So, let us start!
6
Working With Java Data Types With Java Framework
1. Integers consist of byte, short, int, and long that represent signed whole number.
Name Width in Bits Range
-9,223,372,036,854,775,808 to
long 64
9,223,372,036,854,775,807
int 32 -2,147,483,648 to 2,147,483,647
short 16 -32,768 to 32,767
byte 8 -128 to 127
2. Floating-point numbers include float and double that can be numbers with
fractional/decimal parts.
Name Width in Bits Approximate Range
double 64 4.9E-324 to 1.8E+308
float 32 1.4E-045 to 3.4E+038
3. Characters such as “char” are symbols in a character set that is similar to letters
and numbers.
Name Width Approximate Range
• Minimum value is ‘\u0000’ or 0.
16-bit
char • Maximum value is ‘\uffff’ or 65,535
Unicode Character
inclusive.
JAVA LITERALS
A literal is a source code representation of a fixed value. It is represented directly in
the code without any computation.
Literals can be assigned to any primitive type variable. For example:
class Literals {
public static void main (String args []) {
byte a = 68;
char b = ‘A’;
}
}
Sample Output:
68
A
7
Self-Learning Kit in Information and Communications Technology
String literals in Java are specified like they are in most other languages by enclosing
a sequence of characters between a pair of double quotes. Examples of string literals are:
“Hello World”
“two\nlines”
“\”This is in quotes\””
String and char types of literals can contain any Unicode characters. For example:
char a = ‘ \uFF21’;
String a = “\uFF21”;
Sample Output:
A
A
byte, int, long, and short can be expressed in decimal (base 10), hexadecimal (base 16) or
octal (base 8) number systems as well.
Prefix 0 is used to indicate octal, and prefix 0x indicates hexadecimal when using these
number systems for literals. For example –
int decimal = 100;
int octal = 0144;
int hexa = 0x64;
Sample Output:
100
100
100
REFERENCE DATA TYPES
• Reference variables are created using defined constructors of the classes. They
are used to access objects. These variables are declared to be of a specific type
that cannot be changed. For example, Employee, Puppy etc.
• Class objects, and various types of array variables come under reference data
type.
• Default value of any reference variable is null.
• A reference variable can be used to refer to any object of the declared type or
any compatible type.
Animal animal = new Animal “giraffe”;
DECLARING A VARIABLE
To declare a Java variable, follow this format:
DataType identifier [ = value] [, variable [ = value] ...];
Type is the name of a class or interface (e.g. int, double, boolean) while identifier
is the name of the variable (e.g. num1, num2, a, b). A user can initialize the variable by
specifying an equal sign (=) and a value. The initialization expression must result in a value
of the same (or compatible) use in the comma-separated list.
Identifier
Identifier names must start with a letter of the alphabet, an underscore (_), or a $.
Other characters may include digits.
Correct Wrong
Remember:
1. Use meaningful names for variables, such as customerFirstName, ageNextBirthday.
2. Be aware of using reserved keywords in naming variables.
RESERVED KEYWORDS
Below is the list of some java reserved keywords
boolean abstract break finally class implements
byte final case for extends throws
char native catch if interface
double private continue return instanceof super
float protected default switch new this
int public do else false null
long static throw try true
short synchronized while
void transient import package const goto
volatile
The table below shows some examples of variable declarations of various types:
9
Self-Learning Kit in Information and Communications Technology
The identifiers that the user choose have nothing intrinsic in their names that indicates
their type. Java allows any properly formed identifier to have any declared type.
EXAMPLE #1
10
Working With Java Data Types With Java Framework
OUTPUT:
EXAMPLE #2
In this example, you will notice that there is a plus (+) sign between the text, it is called
concatenation. We merged the text so that we achieved the desired output.
OUTPUT:
11
Self-Learning Kit in Information and Communications Technology
Great! Let us now see if you really understood your lesson today. Are you ready for
the activity? Let’s start!
ACTIVITY 1
Instructions: Choose the letter of the correct answer from the choices given. Write
your answer on your paper.
12
Working With Java Data Types With Java Framework
13
Self-Learning Kit in Information and Communications Technology
ACTIVITY 2
Instructions: Using your knowledge in this lesson, investigate what will be the possible
output of the following program. If you think that the program will not run, write “Compile
Error” or “Error” and explain why. Write your answer on a separate sheet of paper.
1. class Main {
public static void main (String args []) {
int pie = 3.14;
System.out.println(pie);
}
}
Answer:
__________________________
2. class Main {
public static void main (String args []) {
boolean price = 1000;
System.out.println(price);
}
}
Answer:
__________________________
3. class Main {
public static void main (String args []) {
byte sizeof = 200;
System.out.println(sizeof);
}
}
Answer:
__________________________
4. class Main {
public static void main (String args []) {
char maine = “New England state”;
System.out.println(maine);
}
}
Answer:
__________________________
5. class Main {
public static void main (String args []) {
int big = 10;
int bigger = big + big + big; //it will add the 3 big
System.out.println(bigger);
}
}
Answer:
__________________________
14
Working With Java Data Types With Java Framework
ACTIVITY 3
Instructions: Complete the missing codes below to complete the program. Write your
answer on your paper.
15
Self-Learning Kit in Information and Communications Technology
Sample Output:
Days Worked: 22
Daily Rate: 400.43
Gross Pay: 8809.46
Tax: 250.3
SSS: 750.0
Philhealth: 120.65
16
Working With Java Data Types With Java Framework
1. C
2. A
3. C
4. D
5. A
6. D
7. B
8. B
9. C
10. D
11. C
12. D
13. D
14. A
15. B
Activity 2
Activity 3
1. long
2. int
3. boolean
4. double
5. int
6. double
7. double
8. int
9. int
10. int
11. String
12. char
13. int
14. double
15. double
17
Self-Learning Kit in Information and Communications Technology
SELF-ASSESSMENT
RUBRICS OF LEARNING
SCORE SCORE DESCRIPTORS REMARKS
1-5 1 - 15
3 10 - 13 Good
2 6-9 Fair
18
Working With Java Data Types With Java Framework
ACKNOWLEDGEMENT
First and foremost, praises and thanks to God, the Almighty, for His guidance
throughout this Self-Learning Kit project to be completed successfully.
Secondly, I would like to express my deepest gratitude to LRDMS Bataan for giving
me the opportunity to be a part of this wonderful project. Also, I am thankful and fortunate
enough to get constant encouragement, support and guidance from all staff of LRMDS
Bataan who helped us to produce a quality and accessible learning kit. I am also grateful
to my co-trainees (Kenneth Doctolero and Cheyser Charrese Gatchula) who helped
me in making fruitful ideas productively to accomplish this Self-Learning Kit in computer
programming java.
Thirdly, I would like to thank my friends who helped me a lot in finalizing this project
within a limited time frame. Crafting a learning kit as a product of an instructional method is
difficult, to be honest. One requires knowledge, wisdom and enough patience to review all
the contents from the starting point until the end. Professional consultations matter for the
verification and validation of the contents, leading to a more reliable source.
Lastly, I would like to describe my sincerity because I truly learned a lot of things in
making a learning kit for my students. As a teacher, it is my duty to not leave my learners
behind. They deserve not only the good, but the best quality of education that will enable
them to be globally competitive in all endeavors of their future careers. To dream is free,
but a dream must be concretized so that a goal is achieved.
REFERENCES
Books
Pasco, D. Technical Vocational Livelihood Series Programming JAVA. 1st ed. Quezon City:
The Phoenix Publishing House Inc.,13-18.
Website
“Java Basic Datatypes,” Tutorials Point (I) Pvt. Ltd., accessed May 30, 2019, https://www.
tutorialspoint.com/java/java_basic_datatypes.htm.
19
WORKING WITH JAVA DATA TYPES WITH JAVA FRAMEWORK
Java is an object-oriented programming (OOP) language. Object-oriented
(OO) programming has been proven to be one of the most effective and flexible
programming languages nowadays.
Java, unlike some languages before, allows the use of words and commands
instead of just symbols and numbers. Java also allows the creation of advanced data
types which represent real world things like a car or a computer where you can set the
characteristics of these objects and things they do.
Learning Java serves as a good introduction to software development.
As an ICT student and aspiring software engineer/developer, you need to know
and apply the different data types for you to produce an error-free program. To further
understand your lessons, this material is a big help for you to learn more about data
types and other essential topics in Java in order for you to proceed to the next topic.
C O N T E NT DE VE LO P E RS
WRITER/LAYOUT ARTIST: LOUIEGENE T. DONATO A graduate of Bataan Peninsula State
University – Main Campus with the degree of Bachelor of Science in Computer Science
Major in Software Development, year 2016. He earned his Trainer’s Methodology I
(TM I) at Manila International Skills Academy (MISA) Training and Assessment Center.
He studied one year Certificate in Professional Education at Tomas Del Rosario and
eventually passed the Licensure Examination for Teachers last 2018. He is currently
serving as a teacher in Technical-Vocational-Livelihood at Limay Senior High School-
Duale, Limay, Bataan.