Programming Java: Grade 11

Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

Department of Education

Region V
Division of City Schools
Naga City
DON LEON Q. MERCADO HIGH SCHOOL

PROGRAMMING
JAVA
GRADE 11
Quarter 4 Week 1 Module 1

Learning Competency:
INTRODUCTION TO PROGRAMMING
LESSON 1
FOUR PROGRAMMING FUNDAMENTALS

• Identify the basic parts of a Java program


• Differentiate among Java literals, primitive data types, variable
types ,identifiers
and operators
• Develop a simple valid Java program using the concepts learned
in this chapter
DIVISION OF CITY SCHOOLS – NAGA CITY
DEPARTMENT OF EDUCATION
K TO 12 BASIC EDUCATION CURRICULUM JUNIOR HIGH SCHOOL TECHNICAL LIVELIHOOD
EDUCATION AND SENIOR HIGH SCHOOL - TECHNICAL-VOCATIONAL-LIVELIHOOD TRACK
INFORMATION AND COMMUNICATIONS TECHNOLOGY –PROGRAMMING JAVA NC II

INTRODUCTION TO
PROGRAMMING
SENIOR HIGH SCHOOL
GRADE 11

HOW TO USE THIS MODULE?

Before starting the module, I want you to set aside other tasks that will disturb you while
enjoying the lessons. Read the simple instructions below to successfully enjoy the
objectives of this kit. Have fun!
1. Follow carefully all the contents and instructions indicated in every page of this module
and follow the given instructions for each of the given learning outcome/s.
2. As you read, you can also do the hands-on to check if you were able to follow the
basic programming procedure.
3. Demonstrate what you have learned by doing what the Activity required you to do so.
4. Analyze conceptually the posttest and apply what you have learned.
5. Enjoy studying!

PARTS OF TH MODULE
Before starting the module, I want you to set aside other tasks that will disturb you while
enjoying the lessons. Read the simple instructions below to successfully enjoy the
objectives of this kit. Have fun!
1. Follow carefully all the contents and instructions indicated in every page of this module
and follow the given instructions for each of the given learning outcome/s.
2. As you read, you can also do the hands-on to check if you were able to follow the
basic programming procedure.
3. Demonstrate what you have learned by doing what the Activity required you to do so.
4. Analyze conceptually the posttest and apply what you have learned.
5. Enjoy studying!
• Expectations - These are what you will be able to know after completing the lessons in
the module..
• Technical terms - A word that has a specific meaning within a specific field of
expertise.
• Looking Back to your Lesson - This section will measure what learnings and skills did
you understand from the previous lesson.
• Brief Introduction- This section will give you an overview of the lesson.
• Activities - This is a set of activities you will perform with a partner.
• Remember - This section summarizes the concepts and applications of the lessons.
• Check your Understanding- It will verify how you learned from the lesson.

1
INTRODUCTION TO PROGRAMMING

, LESSON 1
OVERVIEW OF COMPUTER PROGRAMMING

EXPECTATIONS:

At the end of the lesson, the student should be able to:

• Identify the basic parts of a Java Program


• Differentiate among Java literals, primitive data types, variable types, identifiers
and operators

 Develop a simple valid Java program using the consepts learned in this
chapter

TECHNICAL TERMS:

, HARDWARE – Tangible part of computer it is composed of electronic and mechanical


Parts.
SOFTWARE - a series of instruction that tells the hardware what task to perform. It consist of data
And the computer program
Compiler - A programming statement may be translated into one or several machine
Instruction
Assembler – Assembly instruction is translated into one machine instruction by an
Assembler program.
Algorithm - is a clear and unambiguous specification of the steps needed to solve
a Problem
Pseudocode - which is a cross between human language and a programming
language.
BRIEF INTRODUCTION
In this section, we will be discussing the basic parts of a Java program. We
will start by trying to explain the basic parts of the Hello.java program introduced in
the previous section. We will also be discussing some coding guidelines or code
conventions along the way to help in effectively writing readable programs.

Dissecting my first Java program


Now, we'll try to the dissect your first Java program:

The first line of the code,

public class Hello

indicates the name of the class which is Hello. In Java, all code should be placed
insidea class declaration. We do this by using the class keyword. In addition, the
class uses anaccess specifier public, which indicates that our class in accessible to
other classes from other packages (packages are a collection of classes). We will be
covering packages and access specifiers later.

The next line which contains a curly brace { indicates the start of a block. In this
code,we placed the curly brace at the next line after the class declaration, however,
we can also place this next to the first line of our code. So, we could actually write
our code as:
The next three lines indicates a Java comment. A comment is something used to
document a part of a code. It is not part of the program itself, but used for
documentation purposes. It is good programming practice to add comments to your
code.

/**
* My first java program
*/

A comment is indicated by the delimiters “/*” and “*/”. Anything within these
delimiters are ignored by the Java compiler, and are treated as comments.
The next line,

public static void main(String[] args) {


or can also be written as,
public static void main(String[] args)
{

indicates the name of one method in Hello which is the main method. The main
method is the starting point of a Java program. All programs except Applets written
in Java start with the main method. Make sure to follow the exact signature.
The next line is also a Java comment,

//prints the string "Hello world" on screen

Now, we learned two ways of creating comments. The first one is by placing the
comment inside /* and */, and the other one is by writing // at the start of the
comment.

The next line,

System.out.println("Hello world!");

prints the text “Hello World!” on screen. The command System.out.println(), prints
the text enclosed by quotation on the screen.

The last two lines which contains the two curly braces is used to close the main
method
and class respectively.

Lesson 2 Java Comments


Comments are notes written to a code for documentation purposes. Those text
are not part of the program and does not affect the flow of the program.

Java supports three types of comments: C++-style single line comments, C-style
multiline comments and special javadoc comments.

C++ STYLE COMMENTS

C-style comments or also called multiline comments starts with a /* and ends with
a */.

All text in between the two delimeters are treated as comments. Unlike C++ style
comments, it can span multiple lines. For example,

/* this is an exmaple of a
C style or multiline comments */

Special Javadoc Comments

Special Javadoc comments are used for generating an HTML documentation for
your Java programs. You can create javadoc comments by starting the line with /**
and ending it with */. Like C-style comments, it can also span lines. It can also
contain certain tags to add more information to your comments. For example,

/**
This is an example of special java doc comments used for \n
generating an html documentation. It uses tags like:
@author Florence Balagtas
@version 1.2
*/

JAVA STATEMENTS AND BLOCKS


A statement is one or more lines of code terminated by a semicolon. An example
of a single statement is,

System.out.println(“Hello world”);

A block is one or more statements bounded by an opening and closing curly braces
that groups the statements as one unit. Block statements can be nested
indefinitely. Any amount of white space is allowed. An example of a block is,

public static void main( String[] args ){


System.out.println("Hello");
System.out.println("world");

Java Identifiers
Identifiers are tokens that represent names of variables, methods, classes, etc.
Examples of identifiers are: Hello, main, System, out.

Java identifiers are case-sensitive. This means that the identifier: Hello is not the
same as hello. Identifiers must begin with either a letter, an underscore “_”, or a
dollar sign “$”. Letters may be lower or upper case. Subsequent characters may
use numbers 0 to 9.

Identifiers cannot use Java keywords like class, public, void, etc. We will discuss
more about Java keywords later.

Java Keywords
Keywords are predefined identifiers reserved by Java for a specific purpose. You
cannot use keywords as names for your variables, classes, methods …etc. Here is a
list of the Java Keywords.

Java Literals
Literals are tokens that do not change or are constant. The different types of literals
in Java are: Integer Literals, Floating-Point Literals, Boolean Literals, Character
Literals and String Literals.

Integer Literals
Integer literals come in different formats: decimal (base 10), hexadecimal (base
16),and octal (base 8). In using integer literals in our program, we have to follow
some special notations.

For decimal numbers, we have no special notations. We just write a decimal


number as it is. For hexadecimal numbers, it should be preceeded by “0x” or “0X”.
For octals, they are preceeded by “0”.

For example, consider the number 12. It's decimal representation is 12, while in
hexadecimal, it is 0xC, and in octal, it is equivalent to 014.

Integer literals default to the data type int. An int is a signed 32-bit value. In some
cases, you may wish to force integer literal to the data type long by appending the
“l” or “L” character. A long is a signed 64-bit value. We will cover more on data
types later.

Floating-Point Literals

Floating point literals represent decimals with fractional parts. An example is


3.1415. Floating point literals can be expressed in standard or scientific notations.
For example, 583.45 is in standard notation, while 5.8345e2 is in scientific
notation.

Floating point literals default to the data type double which is a 64-bit value. To
use a smaller precision (32-bit) float, just append the “f” or “F” character.

Boolean Literals

Boolean literals have only two values, true or false.

Character Literals

Character Literals represent single Unicode characters. A Unicode character is a 16-


bit character set that replaces the 8-bit ASCII character set. Unicode allows the
inclusion of symbols and special characters from other languages.

To use a character literal, enclose the character in single quote delimiters. For
example,
the letter a, is represented as „a‟.
To use special characters such as a newline character, a backslash is used followed
By the character code. For example, „\n‟ for the newline character, „\r‟ for the
carriage return, „\b‟ for backspace.

String Literals

String literals represent multiple characters and are enclosed by double quotes. An
example of a string literal is, “Hello World”.

ACTIVITIES

1. Write sample java comments

2. Write sample C++ if you want to comment using Java language

4. Write at least 5 Java Identifiers with its definition


CHECK YOUR UNDERSTANDING

Direction: Write True if the statement is correct and False if its not correct.

1. _____ Character Literals represent single Unicode characters.


2. _____ Floating point literals represent decimals with fractional parts.
3. _____ Identifiers are tokens that represent names of variables, methods,
classes.
4. _____ A comment is indicated by the delimiters “/*” and “*/”. Anything
within these delimiters are not ignored by the Java compiler.
5. ______ A statement is one or more lines of code terminated by a semicolon.
6. ______ A block is one or more statements bounded by an opening and
closing curly braces that groups the statements as one unit.
7. ______ Special Javadoc comments are used for generating an HTML
documentation for your Java programs.
8. ______ C-style comments or also called multiline comments starts with a /* and
ends with a */.
9. ______ The class uses an access specifier public, which indicates that our class
in accessible to other classes from other packages (packages are a collection
of classes).
10. ______ The main method is the starting point of a Java program.

REFERENCES:

Innovative Training Works, Inc. “Computer Programming Volume I” Technical Vocational


Livelihood K to 12 First Edition https://faradars.org/wp-content/uploads/2015/07/Algorithm-
and-Flow-Chart.pdf

https://sielearning.tafensw.edu.au/toolboxes/Database_Administration/software/content/pro
grammingconstructs/control_structures.htm

https://study.com/academy/lesson/what-is-an-algorithm-in-programming-definition-examples-
analysis.html

Java-student-Manual-Programming

PREPARED BY:
HAZEL B. FRANCE
Teacher

You might also like