Professional Documents
Culture Documents
Shs - SLK - Ict Prog Creating Methods According To Java Framework
Shs - SLK - Ict Prog Creating Methods According To Java Framework
Shs - SLK - Ict Prog Creating Methods According To Java Framework
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
INDUSTRIAL
INFORMATION AND ARTS TECHNOLOGY
COMMUNICATIONS
PROGRAMMING NC III (JAVA TECHNOLOGY)
ENGLISH AT METRIC
CREATING METHODS ACCORDING
DALAWANG SISTEMA NG PANUKAT
TO JAVA FRAMEWORK
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
Creating Methods According to Java Framework
SELF-LEARNING KIT
INFORMATION AND COMMUNICATIONS TECHNOLOGY
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 assist you to strengthen your knowledge in
creating and invoking methods, as well as passing parameters to methods and
returning values from methods. This learning material is designed for grade 11 and
grade 12 students who are willing to learn on self-paced mode. This learning material
includes several challenges that will test your learning. It is best to read the content
of this learning material to achieve the objectives and conquer these challenges.
As impossible as it might seem to you, the principle of writing program has not
changed all that as years past. Programming languages changes, technologies get
modernized, integrated development environment get more and more advanced but
the creating and invoking of the methods remain the same. With the help of this SLK,
you can make your first step in advance programming. This learning material focuses
about methods which is one of the most significant components of programming.
In addition, remember the following tips to keep this learning material neat and
clean; do not write anything on its pages; use separate paper as your answer sheet;
read, understand and follow the instruction carefully; answer the given task after
reading the lesson; try to achieve at least an 80% level of proficiency in every activity.
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 the different elements of a method by naming the elements based on its
description;
2. express understanding in the correct syntax of method by re-arranging the parts of a
code to form a correct method; and
3. demonstrate proficiency in creating and invoking methods by completing the given
codes to create a program.
LEARNING COMPETENCIES
Create methods with arguments and return values in accordance with Java
framework. TLE_ICTJAVA11-12POAD-Id-g-36
Welcome! Are you ready to go on a journey? Are you ready for some fun while
learning? Alright then, let’s start this awsome ride with a warm up activity.
WHAT IS METHOD?
• When you call the System.out.println() method, for example, the system actually
executes several statements in order to display a message on the console
(Tutorialpoint,2019).
ELEMENTS OF A METHOD,(TUTORIALPOINT,2019)
• Access Specifier – This determine the visibility of a variable or a method from another
class.
• Return Type – A method may return a value. The return type is the data type of the value
the method returns. If the method is not returning any value, then the return type is void.
• Method Name – Method name is a unique identifier and it is case sensitive. It cannot be
same as any other identifier declared in the class.
• Parameter List – Enclosed between parentheses, the parameters are used to pass and
receive data from a method. The parameter list refers to the type, order and number of
the parameters of a method. Parameters are optional; that is, a method may contain
no parameters.
• Method Body - This contains the set of instruction needed to complete the required
activity.
To define Method, basically declare the elements of its structure. The syntax for
defining method in Java is as follows:
In Java, both Methods and Functions are same, there are no difference and
these are a just different terms to do the same thing.
7
Self-Learning Kit in Information and Communications Technology
EXAMPLE
The following code shows a method Addnum that takes two integer values and return
the sum of the two integer. It has Public access specifier, so it can be accessed outside the
CALLING A METHOD
Using the example method below, you can call a method using name of the
8
Creating Methods According to Java Framework
two different variables which are copies of each other. Any changes to one variable don’t
It means that while calling a method, parameters passed to the calling method will
be clones of original parameters. Any modification done in calling method will have no
If you observe above example, the variables a and b are value type and it passed
to the Addnum method. The value of variable a and b copies to the parameter num1 and
num2 respectively and made required modifications in Addnum method but the changes
that made inside of the method have no effect on the original value of the variable.
9
Self-Learning Kit in Information and Communications Technology
The void keyword allows us to create methods which do not return a value.
If we observe the above codes, we have created a method using the void keyword.
When the main method calls the PrintNum method it only executes the code inside it and not
returning anything from the caller method.
10
Creating Methods According to Java Framework
METHOD OVERLOADING
When a class has two or more methods by the same name but different parameters, it
is known as method overloading. It is different from overriding. In overriding, a method has the
Let’s consider the example discussed earlier for finding minimum numbers of integer
type. If, let’s say we want to find the minimum number of double types. Then the concept
of overloading will be introduced to create two or more methods with the same name but
11
Self-Learning Kit in Information and Communications Technology
METHOD OVERLOADING
Overloading methods makes program readable. Here, two methods are given by the
same name but with different parameters. The minimum number from integer and double
2. User-define Methods
for use. These standard libraries come along with the Java Class Library in a Java archive.
For Example:
• print() is a method of java.io.PrintStream. The print(“..”) prints what ever string inside the
quotation marks.
USER-DEFINED METHOD
You can also defined methods inside a class as per your wish. Such methods are
For Example:
12
Creating Methods According to Java Framework
REMEMBER
Awesome! We are almost done, here are some tips to remember with:
• Methods are block of codes that only executes when called by your main method.
• Methods have five elements the Access Specifier, Return Type, Method Name, Parameter
List and last but not the least the Method Body.
• We can pass a value from method to method with the use of pass-by-value were as if
you pass a value from the calling method to the called method, any changes happened
inside the called method will not affect the value in the calling method.
Wonderful! The end of your journey is now nearing. Now it’s time to test what you have
learned from this journey. The are several activities along the way. Do your best to answer
13
Self-Learning Kit in Information and Communications Technology
ACTIVITY # 1
INSTRUCTION: Match column A with column B to identify the elements of a method based
on the given description. Write your answer on a separate sheet of paper as your answer
sheet.
COLUMN A COLUMN B
1. It is the data type of the value the method returns. a. Method Body
receive data from a method. This list refers to the type, order c. Return Type
another class.
required activity.
14
Creating Methods According to Java Framework
ACTIVITY # 2
INSTRUCTION: Rearrange the codes to create a valid and correct syntax method named
“CheckNum” that will display if a number is odd or even. Use numbers 1 to 10 to arrange the
______2. If
______4. Void
______5. (a % 2 == 0 )
______6. Else
______7. {System.out.println(“Even”);}
______9. }
______10. {
15
Self-Learning Kit in Information and Communications Technology
ACTIVITY # 3
INSTRUCTION: Complete the codes below to create a program that will generate the
greatest common divisor and least common multiple of two numbers. Identify the missing
16
17
ACTIVITY # 1 Pg. 14 WHAT DO YOU KNOW Pg. 6
1. C 1. C
2. B 2. B
3. D 3. D
4. E 4. E
5. A 5. A
ACTIVITY # 2 Pg. 15 ACTIVITY # 3 Pg. 16
3 1. CheckNum (int a) 1. hcf
5 2. If 2. Scanner
1 3. Private Static 3. sc
2 4. Void 4. out
5. gcd
6 5. (a % 2 == 0 )
6. hcf
8 6. Else
7. hcf
7 7. { System.out.println (“Even”);}
8. lcm
9 8. { System.out.println (“Odd”);}
9. Private
10 9. }
10. if
4 10. {
ANSWER KEY
Creating Methods According to Java Framework
Self-Learning Kit in Information and Communications Technology
SELF-ASSESSMENT
RUBRICS OF LEARNING
SCORE SCORE SCORE DESCRIPTORS
1-5 1 - 10 1 - 15
18
Creating Methods According to Java Framework
ACKNOWLEDGEMENT
I would like to express my special thanks to LRMDS Bataan for giving me the golden
opportunity to create this Self-Learning Kit. This has been a wonderful experience - to be
a part of this fantastic team that creates learning material for the good of our students.
I wish that this learning material may serve as a tool to achieve greater learning for our
REFERENCES
WEBSITE
“Java - Methods”, Tutorials Point India Limited, July 24, 2019, https://www.tutorialspoint.
com/java/java_methods
19
CREATING METHODS ACCORDING
TO JAVA FRAMEWORK
If you are a senior high school student and you find programming difficult to
learn and to understand, then we have good news for you. We introduce to you this
Self-Learning Kit that will help you to your journey in the world of programming. With
the use this SLK, we made learning programming easy and fun where you are able
to learn at your own pace.
The core topic of this Self-Learning Kit is Methods, one the components of
programming. Using this learning material, you are able to learn how to create and
use method in your programs. Don't miss this chance for a wonderful programming
experience.
C O N T E NT DE VE LO P E RS