You are on page 1of 18

J/SHS

TLE/TVL-ICT (Computer Programming-


Java)
Activity Sheet Quarter 2 – LO 6
Apply Basics of Java Language

REGION VI – WESTERN VISAYAS


TLE/TVL- ICT (Computer Programming - Java)
Activity Sheet No. 7
First Edition, 2020

Published in the Philippines


By the Department of Education
Region 6 – Western Visayas

Republic Act 8293, section 176 states that: No copyright 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.

This Learning Activity Sheet is developed by DepEd Region 6 –


Western Visayas.

ALL RIGHTS RESERVED. No part of this learning resource may be


reproduced or transmitted in any form or by any means electronic or
mechanical without written permission from the DepEd Regional Office 6 –
Western Visayas.

Development Team of TLE/TVL- ICT (Computer Programming - Java)


Activity Sheet
Writer: Ma. Louella B. Gavan
Reviewer/Editor:Edward E. Baña
Layout Artist:
Schools Division Quality Assurance Team:
Schubert Anthony C. Sialongo
Edward E. Baña
Allan B. Montenegto
Michelle P. Jordan
Division of Antique Management Team:
Felisa B. Beriong, CESO VI
Corazon C. Tingson
Gaudencio C. Riego, PhD
Schubert Anthony C. Sialongo
Edward E. Baña
Regional Management Team
Ma. Gemma M. Ledesma
Josilyn S. Solana
Elena P. Gonzaga
Donald T. Genine
April C. Velez
Abraham P. Imas
Introductory Message
Welcome to TLE/TVL- ICT (Computer Programming - Java)!

The Learning Activity Sheet is a product of the collaborative efforts


of the Schools Division of Antique and DepEd Regional Office VI - Western
Visayas through the Curriculum and Learning Management Division
(CLMD). This is developed to guide the learning facilitators (teachers,
parents and responsible adults) in helping the learners meet the standards
set by the K to 12 Basic Education Curriculum.

The Learning Activity Sheet is self-directed instructional materials


aimed to guide the learners in accomplishing activities at their own pace and
time using the contextualized resources in the community. This will also
assist the learners in acquiring the lifelong learning skills, knowledge and
attitudes for productivity and employment.

For learning facilitator:

The TLE/TVL- ICT (Computer Programming - Java) Activity Sheet


will help you facilitate the leaching-learning activities specified in each Most
Essential Learning Competency (MELC) with minimal or no face-to-face
encounter between you and learner. This will be made available to the
learners with the references/links to ease the independent learning.

For the learner:

The TLE/TVL- ICT (Computer Programming - Java) Activity Sheet


is developed to help you continue learning even if you are not in school. This
learning material provides you with meaningful and engaging activities for
independent learning. Being an active learner, carefully read and
understand the instructions then perform the activities and answer the
assessments. This will be returned to your facilitator on the agreed
schedule.
Quarter 2, Week 7
Learning Activity Sheets (LAS) No. 7

Name of Learner:_____________________________________________________
Grade and Section:_________________________________Date: ______________

TLE/TVL- ICT (COMPUTER PROGRAMMING - JAVA) ACTIVITY SHEET


Apply Basics of Java Language

I. Learning Competency with Code


Apply Basics of Java Language-TLE_ICTJAVA1 1-12POAD-IIfi-29

a. Import Java packages to make them accessible in the code


b. Demonstrate working with Java Data types in accordance with
Java framework
II. Background Information for Learners
With almost every task being done digitally using applications or
websites from shopping online, watching movies, to communicating other
people to the different parts of the world, the demand also increases for
many developers and programmers. And so, learning to code is a skill that
has become very popular nowadays.
As a future developer or programmer, how can you learn fast a
programming language and develop your skills in programming? To
understand a programming language and be able to create programs
yourself, you must practice doing them. Remember, programming is learned
best by doing it.
There are two familiar ways to do this: using an Integrated
Development Environment (IDE) or using a console and a text editor. In this
module, you will learn the basics on how to write, compile and run a Java
program using IDE.
A Brief Background
What is Integrated Development Environment (IDE)? An integrated
development environment (IDE) is an application that enables development
of an application. They are designed to include all programming tasks in
one application. Thus, IDEs gives all the tools you need in programming.
An example of a free, open source, integrated development
environment that enables you to develop desktop, mobile and web
applications is NetBeans IDE. The IDE supports application development in
various languages, including Java, HTML5, PHP and C++. The IDE provides
integrated support for the complete development cycle, from project creation
through debugging, profiling and deployment. The IDE runs on Windows,
Linux, Mac OS X, and other UNIX-based systems.
The IDE provides comprehensive support for JDK 8 technologies and
the most recent Java enhancements. It is the first IDE that provides support
for JDK 8, Java EE 7, and JavaFX 2. The IDE fully supports Java EE using
the latest standards for Java, XML, Web services, and SQL and fully
supports the GlassFish Server, the reference implementation of Java EE.

User Interface Specification: Window System, Final Draft


The window system is a visual framework of the IDE. It displays
windows and allows to manage them to suit the user needs while performing
a concrete task.
Attributes of the new design:
1. document centric– documents are the center of windowing system
2. simple– provides only necessary features
3. open– open to the user customization; allows an easy module
integration to the default layout
4. keyboard accessible– all features are fully keyboard accessible

The following are key terms that you should get familiar with in learning
IDE. These are the following:
● Window System – a framework controlling behavior of windows and
document windows. Window system doesn't control behavior of dialog
boxes, which are native windows controlled by native window
manager.
● Main Window – the main NetBeans window containing main menu,
toolbars, status line and in MDI mode also windows and document
windows. In SDI the main window doesn't contain windows, neither
document windows.
● Window– basic window system element, also called "IDE Window" in
SDI. Note: Some images below use the old terminology and refer to
Window as View.
● Document Window– a special type of window with different behavior
and characteristics than regular window. Document Window is part of
the window system. Some images below use the old terminology and
refer to Document Window as Editor.
● Dialog Box – a special native window controlled by native window
manager. Dialog boxes are not part on NetBeans window system, and
are not covered by this spec.
● Window Area – area inside the main window used for laying out
Windows. Some images below use the old terminology and refer to
Window Area as View Area.
● Document Area – area inside the main window (surrounded by
Window Area) used for laying out Document Windows. Some images
below use the old terminology and refer to Document Area as Editor
Area.
● Status Line – a component displaying status of an action performed
in IDE. This is not the status line of editor window or explorer
windows. Those status lines are part of those components and this
specification doesn't define their behavior. The status line is also
called "Status bar".

SDI specific terminology:


● IDE window – another term used for referring to window in SDI. As in
SDI also native windows exist, the term "IDE window" refers to a
window.
● Native Window – a window used in SDI for displaying windows and
document windows.
Source: https://ui.netbeans.org/docs/ui/ws/ws_spec.html

Detailed Descriptions
● Main Window
Main window is a container for application menu, toolbars, status line
and windows which are provided and controlled by the window system.
All of the windows are always displayed inside the main window, neither
user can separate them out of the main window. The windows are shown
in two areas depending on a type of displayed window. The areas are a
document area and window area. The document area is used for
document windows, and the window area lays out all of the other
windows.
Figure 3.1 Main Window of Netbeans

The main windows characteristics are following:


o title - title of main window contains the application name and
might contain current project name if the project module is part
of IDE distribution. The title pattern is following:
"<application_name> - <project_name>"
o icon - icon of main window is the application icon

● Netbeanslayout
NetBeans layout is distributed in 4 main areas identified by its
numbers in the graphic:
o Control area
o Reference area
o Working area
o Status area
Figure 3.2 Netbean Layout

a. Control Area Elements:


Main menu –NetBeans main menu is located in the top of the NetBeans
windows. You can access to it either by mouse or keyboard pressing F10
or Alt key, whatever of both. In any case notice as, when the main menu
is activated, only one of its items is selected at the same time but all item
words became with one letter underlined.
Main menu offers always the same items and they are always active.
When a main menu item is activated its associated submenu is unfolded.
Submenu items are almost the same with very few changes but its state
depends of the context. If an item can be applied in a certain context
then it will appear enabled, if not it will be disabled, appearing in grey.
This rule is the same for all submenus.

Figure 3.3 Main Menu of Netbeans

Quick launch bar-Few of the most common used actions are available
through quick launch bar icons. It is located between main menu and the
other working areas. It is integrated by smaller and thematic quick
launch bars called Toolbars. 
Figure 3.4 Quick Launch Bar

Search tool- This tool let you find topic inside NetBeans topics. For
source code or project searches there are other tools. You can find more
information out here.

Figure 3.5 Search Tool

Reference Area - offers you related information/ resources/actions/


references/settings about the task/project you are working in. Each
one of these items are represented by its own window called Reference
Window. These windows are visible or not depending of circumstances
but visible windows can float or stay docked in the framework. Visibility
and access management of Reference Windows are available through
Windows main menu item.
Working area- it’s the main area of NetBeans IDE. Usually looks like and
code edition area, but it’s also an User Interface visual compositor.
Status area- it is basically a status bar at the bottom of NetBeans
windows. It shows you the insert/overwriting status, cursor coordinates,
upgrading status and some other info.
Java Programming Environment
Java is a recently developed, concurrent, class-based, object-oriented
programming and runtime environment. It is a powerful and an all-purpose
programming environment that is in-demand as programming languages.
With its flexible features to create and run a program, it has been
exceptionally successful in business and enterprise computing.
In this lesson, you will learn how to code your first Java Program in a simple
and step-by-step manner.

Using a Text Editor and Console


We will now use Notepad as our text editor in windows to save the code in
the First Java Program. We will also need to open the command prompt to
compile and run the program.
Take a look at the following codes. This is an example of a very simple
program that you can run on your computer. Do you know how to do this?
My First Java Program
public class MyFirstJavaPrograms
{
public static void main(String[] args)
{
System.out.println (“Welcome to ICT!”);
}
}

Here are the steps to do this:

Step 1: Start the text editor.


To start the text editor or Notepad in Windows, you can follow these
steps:
1. Click “Start”.
2. Click “All Programs”.
3. Go to “Accessories”.
4. Then, click “Notepad”.

Figure 4.1: WindowsNotepad

Step 2: Open the terminal.


To open Command Prompt in Windows, you can follow these steps:
1. Click “Start”.
2. Click “All Programs”.
3. Go to “Accessories”.
4. Then, click “Command Prompt”.
Figure 4.2: Command Prompt Window

Step 3: Write the source code.


In writing the source code, type the code found in
MyFirstJavaPrograms in the Notepad.

Step 4: Save your Java Program.


To open the Save dialog box, follow this:
1. Click “File” which is found on the menu bar.
2. Then, click on “Save”.

Filename: MyFirstJavaProgram.java
Folder Name: MYJAVAPROGRAMS

Note: If the folder MYFIRSTJAVAPROGRAMS does not exist yet, you


will have to create the folder.
Figure 4.3: MyFirstJavaPrograms code written in Notepad

Step 5: Compiling your program.


Go to the Command Prompt window
Go to the folder MYFIRSTJAVAPROGRAMS where you saved the
program
Specify the path for the Java Development Kit
TypePATH C:\Program Files\Java\jdk1.7.0_09\bin

Note: The path may vary for the specified folder in the installation of
Java in your machine.
To compile a Java Program, type in the command: javac[filename]
So, in this case, type in: javac MyFirstJavaPrograms.java during
compilation, javac adds a file to the disk called [filename].class, or in
this case, MyFirstJavaPrograms.class, which is the actual bytecode.

Figure 4.4: Compile MyFirstJavaPrograms in Command Prompt


Step 6: Running the Program
To run the Java Program:
Type java[filename without the extension]
In the case of our example, type in:javaMyFirstJavaPrograms. You can
see on the screen after running the program: “Welcome to ICT!”
Figure 4.5: Run MyFirstJavaPrograms in Command Prompt

Java Errors
In MyFirstJavaPrograms example, we didn’t encounter any problems in
compiling and running the program. However, in programming this is not
always the case. In Java, there are two types of errors: Syntax Errors and
Run-time Errors.

1. Syntax Errors   
Syntax Errors occur after compilation of a Java Program. They are
usually typing errors of the syntax of the Java source code. Java
attempts to isolate the error by displaying the line of code and pointing
to the first incorrect character in that line. However, the problem may
not be at the exact point.
Common syntax errors in Java are misspelled Java commands, or
forgotten semicolon at the end of a statement. Other common mistakes
are capitalization, spelling, use of incorrect special characters, and
omission of correct punctuation.
Example: In our MyFirstJavaProgram.java code, we intentionally omit 
one semicolon at the end of one statement and type a command 
incorrectly. The error messages are then generated after compiling the pr
ogram. 
Figure 4.6: MyFirstJavaPrograms code typed incorrectly 

Figure 4.7: Run MyFirstJavaPrograms with errors


The first and second error message suggests that there is an error on the
declaration of an identifier of the main method. The third error message
suggests that there is a missing semicolon by the end of a Java
statement.
As a rule of thumb, if you encounter a lot of error messages, try to
connect the first mistake in a long list, and try to compile the program
again. Doing so may reduce the total number of errors dramatically.
In the example, correcting the spelling of static deletes the second and
third errors.

2. Run-time Errors
Run-time Errors are errors that will not display until you run or execute
the program. Even programs that compile successfully may display
wrong answers if the programmer has not thought the logical processes
and structures of the program.
++ ++op Increments op by 1;
evaluates to the value
of op after it was
incremented
-- op-- Decrements op by 1;
Evaluates to the value
of op before it was
decremented
-- --op Decrements op by 1;
Evaluates to the value
of op after it was
decremented
Table 1. Increment and Decrement Operators

The increment and decrement operators can be placed before or after an


operand.

Example:
public class MySecondJavaProgram
{
public static void main (String[] args)
{
int a= 2;
int b= 5;
System.out.println (“Variable value:”);
System.out.println (“a=” + a);
System.out.println (“b=” + b);
}
}
III. Accompanying DepEd Textbook and Educational Sites (With
Possible Materials for experiments/activities)
NetBeans Developing Applications with NetBeans IDE. (n.d.). Retrieved July 5, 2020,
from Oracle.com:
https://docs.oracle.com/netbeans/nb81/netbeans/develop/gs_nbea
ns.htm#NBDAG111
Paon, J. (2013, June 6). Java programming with NetBeans – NetBeans layout.
Retrieved July 5, 2020, from Wordpress.com:
https://joanpaon.wordpress.com/2013/06/28/java-programming-with-
netbeans-netbeans-layout/

Rojcek, J., & Tichy, G. (n.d.). User Interface Specification: Window System, Final
Draft. Retrieved July 5, 2020, from netbeans.org:
https://ui.netbeans.org/docs/ui/ws/ws_spec.html

IV. Activity Proper


1. Exercises / Activities
1.1. Multiple Choice. Direction. Select the letter of the correct
answer. Write your answers on a separate sheet of paper.
1. I What are the elements of Netbeans’ control area?
a. main menu bar, quick launch bar, search tool
b. reference area, main menu bar
c. working area, search tool
d. status area, working area

2. It refers to errors that will not display until you run or executes the
program.
a. Syntax error c. Run-time error
b. Timing Error d. Program Error

3. It shows you the insert/overwriting status, cursor coordinates,


upgrading status and some other info.
a. Reference area c. Status Area
b. Working Area d. Main Menu

4. What do you call an error that occurs after compilation of a java


program?
a. Syntax error c. Run-time error
b. Timing Error d. Program Error

5. It refers to a free, open source, integrated development environment


(IDE) that enables you to develop desktop, mobile and web
applications.
a. Syntax Error c. Menu
b. Netbeans d. Area

1.2. Answer the following questions:


1. When does syntax error occur?
2. What is Java Programming Environment?
1.3. Show what you have learned in this module. Create a program
that would display your name, grade level and address. Make
sure to do it correctly. Your work will be graded according to the
following scoring rubric.
Rubric:

Output 5 4 3 2

Specification The program The program The program The program


works and works and produces produces
meets all the meets most of correct results incorrect
specification the other but does not results
specifications display
correctly

For further reference regarding the topic on programming, please visit


the following websites:

https://www.w3schools.com/
1.4.
Rubric for Scoring
Criteria Score
Completeness (5 points) Does
your response directly answer 5 4 3 2 1
each part of the question(s)?
Knowledge (10 points) Does
your response clearly show you
have read and understand the
lesson content by correctly 10-9 8-7 6-5 4-3 2-1
defining key terms, key persons
and summarizing concepts?
Have you made inferences based
on this knowledge to personal or
modern-day applications?
Writing Skills (5 points) Does
you write clearly, in complete 5 4 3 2 1
sentences, with minimal errors
in grammar and spelling

V. Reflection (Provide reflection guide question)


1. What insights have you gained from the activity?
____________________________________________________________________
____________________________________________________________________
__________________________________________________
2. After compilation and there are errors occur, how would you fix it?

VI. Answer Key

You might also like