EDITED-JAVA-Programming-Module-1-2
EDITED-JAVA-Programming-Module-1-2
Java
Quarter 3 - Module 1
Learner’s Packet
Computer
Programming
(Java)
Grade 12
Quarter 3
Weeks 1 - 4
Schools Division Office Management Team: : Rosemarie C. Blando, August Jamora,
Merle D. Lopez
Writer/s: Jennifer H. Caño
Illustrator: Julius Burdeos
2
Algorithm WEEK
Lesson 1
1
I What I need to know?
At the end of the lesson, you are expected to meet the following:
Content Standard:
The learners demonstrate an understanding of the principles and concepts in
demonstrating knowledge of Java technology and Java programming language,
and performing object-oriented analysis and design.
Performance Standard:
The learners independently and effectively use object oriented technologies and
the use of software modeling, as applied to a software development process, and
present one practical & complete object-oriented analysis and design (OOAD)
roadmap based on TESDA Training Regulations.
Learning Competencies:
1. Demonstrate knowledge of Java technology and Java programming.
2. Create an algorithm to solve a problem.
3. Recognize the importance of an algorithm.
I What is New?
Learning Task 1: Below are the steps in creating an email. Arrange it accordingly
by putting numbers 1 to 8 in the underline.
_______Enter your current email address.
_______Click Next.
_______Verify your email address with the code sent to your existing email address
_______Go to the Account sign in page.
_______Click Use my current email address instead.
_______Enter your Name.
_______Click Verify
_______Click create account
D What I Know?
Pre-Test
Direction: Read each item carefully. Choose the letter that best describes the
statement. Write your answer on a separate sheet.
______1. To determine the outcome of your code, one must know?
a. What is the specific problem you want to solve or the task you want it to
accomplish?
b. What facts will we learn from the process?
c. What formulas are applicable to the issue at hand?
d. What will be added or no longer exist?
3
____2. Finding your starting and ending point are crucial to listing the steps of the process.
To determine a starting point, determine the answer to these questions, except?
a. What data/inputs are available?
b. Where is that data located?
c. What facts will we learn from the process?
d. What formulas are applicable to the issue at hand?
_____3. As with the starting point, you can find the end point of your algorithm by focusing
on these questions, except?
a. What facts will we learn from the process?
b. What changes from the start to the end?
c. What will be added or no longer exist?
d. How do the data values relate to each other?
_____4. To use a real-world example, let’s say your goal is to have lasagna for dinner. You’ve
determined that the starting point is to find a recipe, and that the end result is that you’ll
have a lasagna fully cooked and ready to eat by 7 PM. What will you do?
a. Determine how will you accomplish each step.
b. List the steps from start to finish.
c. Find the ending point of the algorithm.
d. Determine the outcome of your code.
_____5. Now that you’ve written your algorithm, it’s time to evaluate the process by?
a. Review the algorithm.
b. List the steps from start to finish.
c. Find the ending point of the algorithm.
d. Determine how will you accomplish each step.
D What is in?
An example of a real-life situation for creating algorithm. Here is the algorithm for
making a grilled cheese sandwich.
1. Buy a bread.
2. Put butter in a piece of bread.
3. Add cheese to the piece of bread.
4. Cook the bread in a pan.
D What is in?
5
D What is it?
• Clear and Unambiguous: Algorithm should be clear and unambiguous. Each of its
steps should be clear in all aspects and must lead to only one meaning.
• Well-Defined Inputs: If an algorithm says to take inputs, it should be well-defined
inputs.
• Well-Defined Outputs: The algorithm must clearly define what output will be yielded
and it should be well-defined as well.
• Finite-ness: The algorithm must be finite, i.e. it should not end up in an infinite
loops or similar.
• Feasible: The algorithm must be simple, generic and practical, such that it can be
executed upon will the available resources. It must not contain some future technolo-
gy, or anything.
• Language Independent: The Algorithm designed must be language-independent, i.e.
it must be just plain instructions that can be implemented in any language, and yet
the output will be same, as expected.
Advantages of Algorithms:
• It is easy to understand.
• Algorithm is a step-wise representation of a solution to a given problem.
• In Algorithm the problem is broken down into smaller pieces or steps hence, it is eas-
ier for the programmer to convert it into an actual program.
Disadvantages of Algorithms:
• Writing an algorithm takes a long time so it is time-consuming.
• Branching and Looping statements are difficult to show in Algorithms.
Example: Consider the example to add two numbers and print the sum.
Step 1: Fulfilling the pre-requisites
As discussed above, in order to write an algorithm, its pre-requisites must be fulfilled.
The problem that is to be solved by this algorithm: Add 2 numbers and print their
sum.
The constraints of the problem that must be considered while solving the problem:
The numbers must contain only digits and no other characters.
The input to be taken to solve the problem: The two numbers to be added.
The output to be expected when the problem the is solved: The sum of the two num-
bers taken as the input.
The solution to this problem, in the given constraints: The solution consists of adding
the 2 numbers. It can be done with the help of ‘+’ operator.
6
Step 2: Designing the algorithm
Now let’s design the algorithm with the help of above pre-requisites:
Algorithm to add 2 numbers and print their sum:
START
Declare 2 integer variables num1 and num2.
Input num1 and num2.
Computer for the sum
SUM = num1 + num2
5. Print SUM
6. END
Algorithm Examples:
Example 1: Write an algorithm to convert the length in feet to centimeters.
1. START
2. Input length in feet.
3. Compute for the length in centimeters
length in centimeters = Length in feet x 30
4. Print length in centimeters
5. END
Example 2: Write an algorithm that ask the user’s age and displays the age five years
from now.
1. START
2. Declare user’s age.
3. Input user’s age.
4. Compute for user’s age five years from now.
age = age + 5
5. Print user’s age.
6. END
Example 3: Write an algorithm that will compute for the average score of student based on
three quizzes.
1. START
2. Input q1, q2, and q3.
3. Compute for the average
average = (q1 + q2 + q3)/3
4. Print average
5. END
7
What’s more?
E
Learning Task 3:
1. Write an algorithm to print 1 to 10.
Step 1:
____________
Step 2:
____________ variables a,b and c.
Step 3:
____________ variables a,b and c.
Step 4:
if a > b
if a > c
Display a is the _______________.
else
Display c is the largest number.
else
if b > c
Display b is the _______________.
Else
Display c is the largest number.
Step 5: ____________
8
What I have learned?
A
Learning Task 5:
What are the importance of algorithm in programming?
A
Post-test
Write T if the statement is correct, and F if the statement is incorrect.
9
Answers
2)
10
References
Online Sources
11
WEEK
Pseudocode
Lesson 2
2
I What I need to know?
At the end of the lesson, you are expected to meet the following:
Content Standard:
The learners demonstrate an understanding of the principles and concepts in
demonstrating knowledge of Java technology and Java programming language,
and performing object-oriented analysis and design.
Performance Standard:
The learners independently and effectively use object oriented technologies and
the use of software modeling, as applied to a software development process, and
present one practical & complete object-oriented analysis and design (OOAD)
roadmap based on TESDA Training Regulations.
Learning Competencies:
1. Demonstrate knowledge of Java technology and Java programming.
2. Create a pseudocode to solve a problem.
3. Recognize the importance of a pseudocode.
I What is New?
Learning Task 1: Write an algorithm about your everyday activity like riding a
bike, playing a game, going to a mall etc.
D What I Know?
Pre-Test
Direction: Read each item carefully. Choose the letter that best describes the
statement. Write your answer on a separate sheet.
______1. The aim of pseudocode is to make programming easier by using symbols.
A. True B. False
______2. It is a way of expressing an algorithm without conforming to specific syn-
tactic rules.
A. pseudocode C. Data Type
B. algorithm D. flowchart
______3. It is a set of rules on how to use and organize statements in a program-
ming language.
A. variable C. language
B. syntax D. code
______4. Before you write one piece of code, you should what?
A. Conform to a specific syntax C. Know what is the program
B. Create a variable D. Describe an algorithm
12
______5. In writing basic pseudocode is not like writing an actual coding language. It
cannot be compiled or run like a regular program. It can be written on?
A. How you want C. Input and Output device
B. Computer D. Accepted notations
D What is in?
Pseudocode is a term which is often used in programming and algorithm based
fields. It is a methodology that allows the programmer to represent the implementation
of an algorithm. Simply, we can say that it’s the cooked up representation of an algo-
rithm. Often at times, algorithms are represented with the help of pseudo codes as they
can be interpreted by programmers no matter what their programming background or
knowledge is.
Pseudocode, as the name suggests, is a false code or a representation of code
which can be understood by even a layman with some school level programming
knowledge.
Learning Task #3
Based on the definition of pseudocode above, create a pseudocode from your
learning task # 1.
D What is it?
13
D What is it?
Advantages of Pseudocode
• Improves the readability of any approach. It’s one of the best approaches to start
implementation of an algorithm.
• Acts as a bridge between the program and the algorithm or flowchart. Also works as
a rough documentation, so the program of one developer can be understood easily
when a pseudo code is written out. In industries, the approach of documentation is
essential. And that’s where a pseudo-code proves vital.
• The main goal of a pseudo code is to explain what exactly each line of a program
should do, hence making the code construction phase easier for the programmer.
Disadvantages of Pseudocode
• Pseudocode does not provide a visual representation of the logic of programming.
• There are no proper format for writing the for pseudocode.
• In Pseudocode their is extra need of maintain documentation. In Pseudocode their
is no proper standard
Pseudocode Examples:
Example 1: Write a pseudocode that adds two numbers and then displays the result.
• Start program
• Input two numbers, x,y
• Add x and y
• Print sum
• End program
Example 2: Write a pseudocode that will compute for the area of a rectangle and then dis-
plays the result.
• Start program
• Get the length (l) and width (w)
• Compute for the area = l * w
• Print area
• End program
Example 3: Write a pseudocode that will compute for the perimeter of a rectangle and
then displays the result.
• Start program
• Enter length (l) and width (w)
• Compute for the perimeter = 2*l + 2*w
• Print perimeter
• End program
Remember, writing basic pseudocode is not like writing an actual coding language. It
cannot be compiled or run like a regular program. Pseudocode can be written how you
want.
14
Syntax is a set of rules on how to use and organize statements in a programming lan-
guage.
What’s more?
E
Learning Task #3
Write a pseudocode for the following problems:
1. convert the length in feet to centimeter.
15
What I have learned?
A
Learning Task 5:
As a future programmer, why do you think you must create a pseudocode?
A
Post-test
Write T if the statement is correct, and F if the statement is incorrect.
_____1.Pseudocode is algorithm-based.
_____2. Pseudocode is easily understood by programmer not a layman with some
school-level programming knowledge.
_____3. Pseudocode is written in English.
_____4. Pseudocode is standardized.
_____5. Pseudocode makes the life of a programmer easier.
_____6. Visual representations are used in pseudocode.
_____7. There is a format in writing pseudocode.
_____8. Pseudocode is false code.
_____9. Pseudocode works as a rough documentation.
_____10. Syntax is a set of rules on how to use and organize statements in a program
16
Answers
2)
References
Online Sources
17
WEEK
Flowchart
Lesson 3
3
I What I need to know?
At the end of the lesson, you are expected to meet the following:
Content Standard:
The learners demonstrate an understanding of the principles and concepts in
demonstrating knowledge of Java technology and Java programming language,
and performing object-oriented analysis and design.
Performance Standard:
The learners independently and effectively use object oriented technologies and
the use of software modeling, as applied to a software development process, and
present one practical & complete object-oriented analysis and design (OOAD)
roadmap based on TESDA Training Regulations.
Learning Competencies:
1. Demonstrate knowledge of Java technology and Java programming.
2. Identify the basic symbols in flowchart.
3. Create a flowchart to solve a problem.
4. Recognize the importance of a flowchart.
I What is New?
Learning Task 1: Identify the different types of charts.
1 2
3 4
18
D What I Know?
Pre-Test
Direction: Read each item carefully. Choose the letter that best describes the state-
ment. Write your answer on a separate sheet.
1.It indicates the flow of logic by connecting symbols.
A. Decision C. Input/Output
B. Flowline D. Terminal
2. Used for input and output operation.
A. Decision C. Input/Output
B. Flowline D. Terminal
3. Used for decision making between two or more alternatives.
A. Decision C. Input/Output
B. Flowline D. Terminal
4. Represents the start and the end of a flowchart.
A. Decision C. Input/Output
B. Flowline D. Terminal
5. A flowchart is the blueprint of the program.
A. True
B. False
6. The flowchart follows the input-process-output.
A. True
B. False
7. Indicates processes like mathematical operations.
A. Preparation C. Process
B. On page connector D. Off-page connector
8. Variable declaration part and initial values
A. Preparation C. Process
B. On page connector D. Off-page connector
9. Connector to continuation of flowchart on the same page.
A. Preparation C. Process
B. On page connector D. Off-page connector
10. Connector to continuation of flowchart on the separate page.
A. Preparation C. Process
B. On page connector D. Off-page connector
D What is in?
A flowchart is a type of diagram that represents an algorithm, workflow or pro-
cess. The flowchart shows the steps as boxes of various kinds, and their order by con-
necting the boxes with arrows. This diagrammatic representation illustrates a solution
model to a given problem. Flowcharts are used in analyzing, designing, documenting or
managing a process or program in various fields.
A flowchart is also a description of an algorithm or a computer program. It also
serves as the programs blueprint during the Program Development Process. The differ-
ence is that flowchart is a graphical representation of it.
It consists of 8 standard symbols namely: Terminal, Preparation/Initialization,
Process, Decision, On-page Connector, Off-page Connector, Input/Output operation,
and Flow lines (arrow).
19
Learning Task 3:Complete the crossword puzzle.
D What is it?
FLOWCHART SYMBOLS
20
Symbol Name Description
21
Advantages of Flowchart:
• Flowcharts are better way of communicating the logic of system.
• Flowcharts act as a guide for blueprint during program designed.
• Flowcharts helps in debugging process.
• With the help of flowcharts programs can be easily analyzed.
• It provides better documentation.
• Flowcharts serve as a good proper documentation.
Disadvantages of Flowchart:
• It is difficult to draw flowchart for large and complex programs.
• In this their is no standard to determine the amount of detail.
• Difficult to reproduce the flowcharts.
• It is very difficult to modify the Flowchart.
Flowchart Examples:
Example 1:
Create a flowchart that displays the sum of two
numbers.
22
Example 2:
Create a flowchart that converts the length
in feet to centimeter.
Example 3:
Create a flowchart that will display “Even” or
“Odd” depending on the input number of the user.
23
What’s more?
E
Learning Task #4
Create a flowchart for the following problems:
1. Find the area of a circle: Area=3.14*r*r
24
What I have learned?
A
Learning Task 6:
What are the importance of a flowchart in programming?
25
A
Post-Test
Direction: Read each item carefully. Choose the letter that best describes the state-
ment. Write your answer on a separate sheet.
1.It indicates the flow of logic by connecting symbols.
A. Decision C. Input/Output
B. Flowline D. Terminal
2. Used for input and output operation.
A. Decision C. Input/Output
B. Flowline D. Terminal
3. Used for decision making between two or more alternatives.
A. Decision C. Input/Output
B. Flowline D. Terminal
4. Represents the start and the end of a flowchart.
A. Decision C. Input/Output
B. Flowline D. Terminal
5. A flowchart is the blueprint of the program.
A. True
B. False
6. The flowchart follows the input-process-output.
A. True
B. False
7. Indicates processes like mathematical operations.
A. Preparation C. Process
B. On page connector D. Off-page connector
8. Variable declaration part and initial values
A. Preparation C. Process
B. On page connector D. Off-page connector
9. Connector to continuation of flowchart on the same page.
A. Preparation C. Process
B. On page connector D. Off-page connector
10. Connector to continuation of flowchart on the separate page.
A. Preparation C. Process
B. On page connector D. Off-page connector
26
Answers
27
References
Online Sources
28
WEEK
Introduction to Java
Lesson 4 4
I What I need to know?
At the end of the lesson, you are expected to meet the following:
Content Standard:
The learners demonstrate an understanding of the principles and concepts in
demonstrating knowledge of Java technology and Java programming language,
and performing object-oriented analysis and design.
Performance Standard:
The learners independently and effectively use object oriented technologies and
the use of software modeling, as applied to a software development process, and
present one practical & complete object-oriented analysis and design (OOAD)
roadmap based on TESDA Training Regulations.
Learning Competencies:
1. Demonstrate knowledge of Java technology and Java programming.
2. Learn about the history of Java Programming.
3. Familiarize in the structure of Java.
I What is New?
Learning Task 1: Answer the following questions:
1. What can you say about the Java logo?
2. List down all the things you know about Java.
D What I Know?
Pre-Test
Direction: Read each item carefully. Choose the letter that best describes the statement.
Write your answer on a separate sheet.
1.The name of the java file must match the classname.
A. True B. False
2. A method used to print a line of text to the screen
A. comments C. println
B. print D. system.out.println
3. It can be used to explain Java code, and to make it more readable
A. comments C. println
B. print D. system.out.println
4. “MyClass” and “myclass” has the same meaning.
A. True B. False
5. The extension of a java file is .jv
A. True B. False
6. He is the developer of Java.
A. Bill Gates C. James Gosling
B. Bjarne Stroustrup D. Mark Zuckerberg
29
7. It is a software development environment which is used to develop Java applications and applets.
A. JVM C. JDK
B. JRE D. Netbeans
8. What is an example of a method?
A. name C. school
B. age D. code
9. Java is an Object-Oriented programming language
A. True B. False
10. It has states and behaviors.
A. Class C. Methods
B. Instance variables D. Object
D What is in?
Learning Task 3: Word Search: Search for ten (10) words related to Java. List down all
the words in a sheet of paper.
D What is it?
30
Why “Oak”?
The name Oak was used by Gosling after an oak tree that
remained outside his office. Also, Oak is an image of soli-
darity and picked as a national tree of numerous nations
like the U.S.A., France, Germany, Romania, etc. But they
had to later rename it as “JAVA” as it was already a
trademark by Oak Technologies.
“JAVA”
Gosling and his team did a brainstorm session and after
the session, they came up with several names such
as JAVA, DNA, SILK, RUBY, etc.
Java name was decided after much discussion since it was so unique. The name Java
originates from a sort of espresso bean, Java. Gosling came up with this name while
having a coffee near his office.
Java was created on the principles like Robust, Portable, Platform Independent, High
Performance, Multithread, etc. and was called one of the Ten Best Products of 1995 by
the TIME MAGAZINE.
Java Compilers
JVM
JDK is an acronym for Java Development Kit. The Java Development Kit (JDK) is
a software development environment which is used to develop Java applications and
applets. It physically exists. It contains JRE + development tools.
JDK is an implementation of any one of the below given Java Platforms released by Or-
acle Corporation:
• Standard Edition Java Platform
• Enterprise Edition Java Platform
• Micro Edition Java Platform
31
Object − Objects have states and behav-
iors.
Example: A dog has states - color,
name, breed as well as behavior such as
wagging their tail, barking, eating. An
object is an instance of a class.
Class − A class can be defined as a tem-
plate/blueprint that describes the be-
havior/state that the object of its type
supports.
Methods − A method is basically a behav-
ior. A class can contain many methods.
It is in methods where the logics are
written, data is manipulated, and all the actions are executed.
Instance Variables − Each object has its unique set of instance variables. An object's state is created
by the values assigned to these instance variables
Example explained:
Every line of code that runs in Java must be inside a class. In our example, we named the class
MyClass. A class should always start with an uppercase first letter.
The name of the java file must match the classname. When saving the file, save it using the
Class name and add ".java" to the end of the filename.
Any code inside the main() method will be executed. You don't have to understand the keywords
before and after main.
For now, just remember that every Java program has a class name which must match the file-
name, and that every program must contain the main() method.
System.out.println()
Inside the main() method, we can use the println() method to print a line of text to the screen:
32
Note: The curly braces {} marks the beginning and the end of a block of code.
Comments
Comments can be used to explain Java code, and to make it more readable. It can also
be used to prevent execution when testing alternative code.
What’s more?
E
Learning Task #4 Differentiate classes and objects based on the illustration below:
33
What I can do?
E
Learning Task #5 Using system.out.println(), create a Java program that will display
the given output. You may use this online Java compiler: https://www.onlinegdb.com/
A
Post-Test
Direction: Read each item carefully. Choose the letter that best describes the statement.
Write your answer on a separate sheet.
1.The name of the java file must match the classname.
A. True B. False
2. A method used to print a line of text to the screen
A. comments C. println
B. print D. system.out.println
3. It can be used to explain Java code, and to make it more readable
A. comments C. println
B. print D. system.out.println
34
4. “MyClass” and “myclass” has the same meaning.
A. True B. False
5. The extension of a java file is .jv
A. True B. False
6. He is the developer of Java.
A. Bill Gates C. James Gosling
B. Bjarne Stroustrup D. Mark Zuckerberg
7. It is a software development environment which is used to develop Java applications and applets.
A. JVM C. JDK
B. JRE D. Netbeans
8. What is an example of a method?
A. name C. school
B. age D. code
9. Java is an Object-Oriented programming language
A. True B. False
10. It has states and behaviors.
A. Class C. Methods
B. Instance variables D. Object
35
Answers
36
References
Online Sources
37
Para sa mga katanungan o puna, sumulat o tumawag sa:
38