You are on page 1of 20

Y T

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

INFORMATION INDUSTRIAL ARTS TECHNOLOGY


AND COMMUNICATIONS
PROGRAMMING NC III (JAVA TECHNOLOGY)
ENGLISH
WORKING AT METRIC
WITH JAVA DATA TYPES
DALAWANG SISTEMA
WITH JAVA NG PANUKAT
FRAMEWORK

WRITER/LAYOUT ARTIST: LOUIEGENE T. DONATO


EVALUATORS: MARY ANN S. VALDEZ
EMELITA G. PAGUIO
GRADE11-12
GRADE 4
Book Record
School: _____________________________________________________________
District: _____________________________________________________________
Division: ____________________________________________________________
Region: _____________________________________________________________
Date received by school: _______________________________________________

Issued to Date Date


(Name of Teacher) Issued Condition Returned Condition

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

ROMEO M. ALIP, PhD, CESO V


Schools Division Superintendent

ROLAND M. FRONDA, EdD, CESE


Assistant Schools Division Superintendent

MILAGROS M. PEÑAFLOR, PhD


Chief Education Supervisor, CID

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

MARLON Q. DIEGO OMAR S. MANALANSAN KENNETH G. DOCTOLERO JOVANNI B. BELMONTE


Lead Illustrator Lead Book Designer Lead Book Designer Lead Illustrator
Learning Resource Evaluators
EMELITA G. PAGUIO
ANNE MARIE R. SEÑORA-BONIFACIO, EdD
DONNA T. SANTOS-VILLANUEVA, MAEd
CATHREN DANICA E. RICAPLAZA
MARIO E. DOJILLO JR.
MARY ANN S. VALDEZ

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.

PRINTING AND REPRODUCTION MADE POSSIBLE THROUGH THE


SPECIAL EDUCATION FUND (SEF) OF THE PROVINCIAL GOVERNMENT OF BATAAN
AND THE DEDICATED LEADERSHIP OF
HON. GOVERNOR ALBERT RAYMOND S. GARCIA
Working With Java Data Types With Java Framework

PREFACE

Computer programming plays a crucial role in people’s lives nowadays. It provides


the necessary tools in order for one to use and it makes the work much easier than before.
To achieve the Learning Outcome 1 (Apply basics of Java language) in Computer
Programming NC III Java, this Self-Learning Kit mainly focuses on the different Java data
types that a student can use in Java programming language.

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

1. LO1 Apply basics of Java language


2. Familiarize oneself with java data types in accordance with java framework.
TLE_ICTJAVA11-12POAD-IIf-i-29

WHAT DO YOU KNOW?

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.

Excellent! You did a great job!

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

WHAT YOU NEED TO KNOW?

JAVA DATA TYPES

THE PRIMITIVE TYPES


There are eight primitive data types supported by Java. Primitive data types are
predefined by the language and named by a keyword. Let us now look into details about
the eight-primitive data types.

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.

4. Boolean represents “true” or “false” values.

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

int myAge = 18;


String message = “Hello World”;
Data Type boolean isAMovie = true;
float maxItemCost = 17.98;
Therefore, the value of variable myAge is now 18.
8
Working With Java Data Types With Java Framework

Identifier names must start with a letter of the alphabet, an underscore (_), or a $.
Other characters may include digits.

a item_Cost item#Cost item-Cost


itemCost _itemCost item*Cost abstract
item$Cost itemCost2 2itemCost

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:

int x,y,z //declares three ints, x,y,z


//declares three more ints, //
int a = 3, b, c = 5;
initializing a and c.
byte e = 22; //initializes e.
short s = 10000;
//initializes s and r.
short r = -20000;
double pi = 3.14159; //declares an approximation of pi.
char f = ‘f’; //the variable f has the value ‘f’.
boolean isFinished = false; // The two Boolean variables
isFinished and isAlmostFinished
boolean isAlmostFinished = true; are declared with initial values of
false and true respectively.
//String variable welcomeMessage is
String welcomeMessage = “Hello!!!”;
assigned the String value of “Hello!”

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

WHAT HAVE YOU LEARNED?

Hello! Have you learned something today?

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.

1. What is a data type?


a. The part of the CPU that does arithmetic.
b. A part of main memory used to store data.
c. A particular scheme for representing values with bit patterns.
d. The collection of variables that a program uses.
2. What is a Java primitive data type?
a. A method for representing values that is so useful that it is a fundamental part
of the language.
b. A crude form of representing numbers.
c. The part of Java that is the same as in older languages.
d. A data type that cannot be used as part of an object.
3. Does every Java variable use a data type?
a. No---only numeric variables use data types.
b. No---data types are optional.
c. Yes---all variables are of the same data type.
d. Yes---each variable must be declared along with its data type.
4. Which of the following is NOT the name of a Java primitive data type?
a. int
b. float
c. double
d. String
5. Say that a particular item of data does NOT use a primitive data type. What must
it be?
a. An object.
b. A number.
c. A literal.
d. A boolean.
6. Can character data be stored in computer memory?
a. No---computers can only store numbers.
b. No---computer memory can only store patterns.
c. Yes---characters are stored in special memory.
d. Yes---a primitive data type is used to store characters.

12
Working With Java Data Types With Java Framework

7. What is the range of data type short in Java?


a. -128 to 127
b. -32768 to 32767
c. -2147483648 to 2147483647
d. None of the mentioned
8. Which of these literals can be contained in a data type float variable?
a. 1.7e-308
b. 3.4e-038
c. 1.7e+308
d. 3.4e-050
9. Which data type value is returned numbers with fractional/decimal parts?
a. int
b. short
c. double
d. long
10. Which of these values can a boolean variable contain declaration of a boolean?
a. boolean b1 = 1;Z
b. boolean b2 = ‘false’;
c. boolean b3 = false;
d. boolean b4 = ‘true’
12. Which is NOT an integer data type?
a. int
b. long
c. short
d. double
13. Choose appropriate data type for storing the number of Facebook users?
a. byte
b. int
c. short
d. long
14. What is the size in bits for an ‘int’ variable?
a. 32
b. 16
c. 64
d. 8
15. If the range of the values for a certain information is 91,345 to 121,887, which
data type should we use.
a. byte
b. int
c. short
d. long

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.

A. public class Receipt


{
public 1. _______ ReceiptId = “456765648956”;
public 2. _______ CustomerId = 112895;
public 3. _______ IsCancelled = false;
public 4. _______ VAT = 10.00;
}
public class SquareGrid
{
private int rowCount;
private 5. _______ columnCount;
private 6. _______ length;
private 7. _______ perimeter;
private 8. _______ totalSquares;
public SquareGrid (9. _______ rowCount,
10. _______ columnCount, double length) {
this.rowCount = rowCount;
this.columnCount = columnCount;
this.length = length;
this.perimeter = (rowCount + columnCount) * 2 * length;
this.totalSquares = rowCount * columnCount;
}
}

B. public class DataTypes {


public static void main (String [] args) {
//declared variables and assigned data
11.__________ eName=”Louiegene Donato”, eDept=”ICT”;
12.__________ eStatus=’R’;
13.__________ eNumber=122800, DailyWork=22;
14.__________ Rate=400.43, GrossPay, Tax=250.30, SSS=750.00,
15.__________ Philhealth=120.65, Netpay;
//computation
GrossPay=DailyWork*Rate;
Netpay=GrossPay-(Tax+SSS+Philhealth);
//display
System.out.println(“Employee Name: “+eName);
System.out.println(“Employee Number: “+eNumber);

15
Self-Learning Kit in Information and Communications Technology

System.out.println(“Employee Status: “+eStatus);


System.out.println(“Employee Department: “+eDept);
System.out.println();
System.out.println(“Days Worked: “+DailyWork);
System.out.println(“Daily Rate: “+Rate);
System.out.println(“Gross Pay: %.2f”+GrossPay);
System.out.println();
System.out.println(“Tax: “+Tax);
System.out.println(“SSS: “+SSS);
System.out.println(“Philhealth: “+Philhealth);
System.out.println();
System.out.format(“Net Pay: %.2f”, Netpay);
}
}

Sample Output:

Employee Name: Louiegene Donato


Employee Number: 122800
Employee Status: R
Employee Department: Accounting

Days Worked: 22
Daily Rate: 400.43
Gross Pay: 8809.46

Tax: 250.3
SSS: 750.0
Philhealth: 120.65

Net Pay: 7688.51

16
Working With Java Data Types With Java Framework

Activity 1 ANSWER KEY

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

1. Compile Error. It must be double.


2. Complie Error. Boolean data type does not accept large numbers only 1 and 0.
3. Compile Error. Because the sizeof variable is a byte, and can therefore only hold
numbers in the range -128 to +127.
4. Compile Error. Because char variables can only hold a single character. Declare
a String object instead:
5. No Error

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

4-5 14 -15 Excellent!

3 10 - 13 Good

2 6-9 Fair

1 1-5 Start Again

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.

EVALUATOR: MARY ANN S. VALDEZ She is a graduate of Bachelor in Secondary Education


major in Mathematics from Bataan Polytechnic State College, year 2002. She earned
her units in Master of Arts in Education major in Mathematics at Bataan Peninsula State
University Institute of Graduate Studies. Serves as a Teacher at Nagbalayong National
High School from 2003 up to present. Currently taking up Master of Arts in Education,
major in Educational Management at Gordon College – Institute of Graduate Studies in
Olongapo City. At present, she is a Learning Resource Evaluator for Learning Resource
Management and Development Section (LRMDS) Bataan

EVALUATOR: EMELITA G. PAGUIO Graduated with the degree Bachelor of Secondary


Education, major in English at Tomas del Rosario College. She has 33 units in MAEd-
Educational Management and complete academic requirements in MAEd-Language
Education. She taught for three years in private schools in Balanga City and 13 years
in Nagbalayong NHS in Morong. Presently, she serves as Assistant School Principal II of
Senior High School in E.C. Bernabe NHS, Bagac, Bataan.

SCHOOLS DIVISION OF BATAAN


LEARNING RESOURCES MANAGEMENT AND DEVELOPMENT SECTION (LRMDS)
Bataan Provincial Capitol Compound, Balanga City 2100

You might also like