Professional Documents
Culture Documents
ITec121 BSIT
ITec121 BSIT
ITec121 BSIT
Object
Oriented
Programming
Department of
Information Technology
ii
Page ii of xlvii
Vision: A globally competitive university for science, technology, and environmental conservation.
Mission: Development of a highly competitive human resource, cutting-edge scientific knowledge TP-IMD-02
V0 07-15-2020
and innovative technologies for sustainable communities and environment.
No.
For Instructional Purposes only ITec121 : Object Oriented Programming
1st Semester SY 2021-2022
Vision
Mission
Quality Policy
Learning Guide in
Foreword
The year 2020 has been challenging, not just here in the Philippines but in the
whole world. In an instant, the methods of teaching shifted dramatically to flexible
learning, and the word modules and online classes become part of our daily language.
From elementary to tertiary, both private and public institutions, these words are
often the major topic of discussion. As one of the higher institutions in the region,
Visayas State University took the challenge of adapting flexible learning instead of
having face-to-face classes for the first semester this school year.
The Faculties of the Department of Industrial Engineering of the Visayas
State University – Isabel took the challenge of producing learning guides, which will
help you learn at your own pace and time. Inside this guide are notes and discussions
of the courses, greatly designed to grasp the ideas, theories, and technical ability
needed in your respective fields.
As you experience learning your courses thru these learning guides, we are
extremely hopeful that you will enjoy learning and gain the knowledge and skills
necessary in your chosen field. As all of these are still very new to all of us, rest
assured that we, all of your instructors, are very much willing to help and guide you
in navigating this new normal education.
RICHARD C. ABALLE
College Dean
For Instructional Purposes only ITec121 : Object Oriented Programming
1st Semester SY 2021-2022
Acknowledgment
Table of Contents
Contents
Vision.......................................................................................................................i
Mission.....................................................................................................................i
Quality Policy..........................................................................................................i
Title Page.................................................................................................................i
Foreword................................................................................................................ii
Acknowledgment..................................................................................................iii
About the Compiler/s............................................................................................iv
Table of Contents...................................................................................................v
Motivation Question
Module Pretest
IDENTIFICATION: Write your answers before each number
_______________ 1. general-purpose, class-based, object-oriented
programming language designed for having lesser implementation
dependencies.
_______________ 2. Java variables must be identified with unique names.
Page 1 of 47
Vision: A globally competitive university for science, technology, and environmental conservation.
Mission: Development of a highly competitive human resource, cutting-edge scientific knowledge TP-IMD-02
V0 07-15-2020
and innovative technologies for sustainable communities and environment.
No.
For Instructional Purposes only ITec121 : Object Oriented Programming
1st Semester SY 2021-2022
________________ 7. Java variable that stores single characters, such as 'a' or 'B'.
Char values are surrounded by single quotes
________________ 8. defined as specifiers that allocate different sizes and
types of values that can be stored in the variable or an identifier.
________________ 9. Data type that includes integer, character, boolean, and
float
________________ 10. Data type that includes classes, arrays and interfaces.
Learning Outcomes
At the end of the lesson, you are expected to:
1. Define what is java and what it is used for.
2. Install and set-up java.
3. Print “Hello world” in java.
Discussion
One reason people love Java is the Java Virtual Machine, which ensures the
same Java code can be run on different operating systems and platforms. Sun
Microsystems’ slogan for Java was “write once, run everywhere”.
For Instructional Purposes only ITec121 : Object Oriented Programming
1st Semester SY 2021-2022
It is used for:
Java Syntax
The main Method
For now, just remember that every Java program has a class name which must
match the filename, and that every program must contain the main() method.
System.out.println()
System.out.println("Hello World");
}
For Instructional Purposes only ITec121 : Object Oriented Programming
1st Semester SY 2021-2022
Assessment
1. Print “Hello I’m ________(your name)” in java.
Learning Outcomes
At the end of this lesson, you are expected to:
1. Identify and apply the different type of variables and identifiers.
Motivation Question
For Instructional Purposes only ITec121 : Object Oriented Programming
1st Semester SY 2021-2022
Discussion
1. Variable Declaration
2. Variable Initialization
Variable Declaration
To declare a variable, you must specify the data type & give
the variable a unique name.
For Instructional Purposes only ITec121 : Object Oriented Programming
1st Semester SY 2021-2022
float pi;
double d;
char a;
Variable Initialization:
To initialize a variable, you must assign it a valid value.
do =20.22d;
a=’v’;
For Instructional Purposes only ITec121 : Object Oriented Programming
1st Semester SY 2021-2022
Example :
int a=2,b=4,c=6;
float pi=3.14f;
double do=20.22d;
char a=’v’;
Display Variables
Example
String firstName = "John ";
System.out.println(fullName);
For Instructional Purposes only ITec121 : Object Oriented Programming
1st Semester SY 2021-2022
Example
int x = 5;
int y = 6;
Example
int x = 5, y = 6, z = 50;
System.out.println(x + y + z);
Java Identifiers
Identifiers can be short names (like x and y) or more descriptive names (age, sum,
totalVolume).
Example
For Instructional Purposes only ITec121 : Object Oriented Programming
1st Semester SY 2021-2022
// Good
int m = 60;
The general rules for constructing names for variables (unique identifiers) are:
Assessment
1. Create Variable “carName” and assign “Volvo” to it.
2. Create and add three (3) integer type variables.
Instruction on how to submit student output
For Instructional Purposes only ITec121 : Object Oriented Programming
1st Semester SY 2021-2022
Discussion
A primitive data type specifies the size and type of variable values, and it has
no additional methods.
Numbers
Integer Types
Byte
The byte data type can store whole numbers from -128 to 127. This can be
used instead of int or other integer types to save memory when you are certain
that the value will be within -128 and 127:
System.out.println(myNum);
Short
Example
System.out.println(myNum);
Int
Example
System.out.println(myNum);
For Instructional Purposes only ITec121 : Object Oriented Programming
1st Semester SY 2021-2022
Long
Example
System.out.println(myNum);
You should use a floating point type whenever you need a number with a
decimal, such as 9.99 or 3.14515.
Float
Example
System.out.println(myNum);
Double
Example
System.out.println(myNum);
Scientific Numbers
A floating point number can also be a scientific number with an "e" to indicate
the power of 10:
Example
float f1 = 35e3f;
For Instructional Purposes only ITec121 : Object Oriented Programming
1st Semester SY 2021-2022
double d1 = 12E4d;
System.out.println(f1);
System.out.println(d1);
Booleans
A boolean data type is declared with the boolean keyword and can only take
the values true or false:
Example
Characters
Example
System.out.println(myGrade);
Strings
Example
System.out.println(greeting);
Widening Casting
Example
public class Main {
int myInt = 9;
System.out.println(myInt); // Outputs 9
Narrowing Casting
Narrowing casting must be done manually by placing the type in parentheses in front of the
value:
Example
System.out.println(myInt); // Outputs 9
Learning Task/Activities
Directions: Fill in the Box the correct data type for the following
variables:
myNum = 9;
myFloatNum = 8.99f;
myLetter = 'A';
myBool = false;
myText = "Hello World";
Fname = “Dela Cruz”;
myAge = 22;
For Instructional Purposes only ITec121 : Object Oriented Programming
1st Semester SY 2021-2022
MyGrade = 'A+’;
javaIsfun = true;
myNum = 20.05D;
Assessment
Learning Outcomes
Example
int x = 100 + 50;
Although the + operator is often used to add together two values, like in the
example above, it can also be used to add together a variable and a value, or a
variable and another variable:
Example
int sum1 = 100 + 50; // 150 (100 + 50)
int sum2 = sum1 + 250; // 400 (150 + 250)
int sum3 = sum2 + sum2; // 800 (400 + 400)
Arithmetic Operators
Example
int x = 10;
Example
int x = 10;
x += 5;
Logical operators are used to determine the logic between variables or values:
Assessment
1. Write a Java program to print the result of the following
operations.
a. 5 + 8 * 6
b. 20 + 3*5 / 8
Module Posttest
To be posted
For Instructional Purposes only ITec121 : Object Oriented Programming
1st Semester SY 2021-2022
Module Pretest
Learning Outcomes
Motivation Question
if (condition) {
Discussion
https://www.w3schools.com/java/java_conditions.asp
You can use these conditions to perform different actions for different decisions.
For Instructional Purposes only ITec121 : Object Oriented Programming
1st Semester SY 2021-2022
The if Statement
Syntax
if (condition) {
Note that if is in lowercase letters. Uppercase letters (If or IF) will generate an
error.
the example below, we test two values to find out if 20 is greater than 18. If the
condition is true, print some text:
Example
int x = 20;
int y = 18;
if (x > y) {
For Instructional Purposes only ITec121 : Object Oriented Programming
1st Semester SY 2021-2022
Example explained
System.out.println("Good day.");
} else {
System.out.println("Good evening.");
Example explained
For Instructional Purposes only ITec121 : Object Oriented Programming
1st Semester SY 2021-2022
In the example above, time (20) is greater than 18, so the condition is false.
Because of this, we move on to the else condition and print to the screen "Good
evening". If the time was less than 18, the program would print "Good day".
Example explained
In the example above, time (22) is greater than 10, so the first condition is false.
The next condition, in the else if statement, is also false, so we move on to
the else condition since condition1 and condition2 is both false - and print to the
screen "Good evening".
However, if the time was 14, our program would print "Good day."
Learning Tasks/Activities
1. Write a Java program to get a number from the user and print
whether it is positive or negative.
Assessment
1. To be given in our laboratory session
For Instructional Purposes only ITec121 : Object Oriented Programming
1st Semester SY 2021-2022
For Instructional Purposes only ITec121 : Object Oriented Programming
1st Semester SY 2021-2022
Learning Outcomes
1. Apply the switch statement to executes all statements matching the
corresponding case
Motivation Question
Discussion
Syntax
switch(expression) {
case x:
// code block
break;
case y:
// code block
break;
For Instructional Purposes only ITec121 : Object Oriented Programming
1st Semester SY 2021-2022
default:
// code block
The example below uses the weekday number to calculate the weekday name:
int day = 4;
switch (day) {
case 1:
System.out.println("Monday");
break;
case 2:
System.out.println("Tuesday");
break;
case 3:
System.out.println("Wednesday");
break;
case 4:
System.out.println("Thursday");
break;
case 5:
System.out.println("Friday");
break;
For Instructional Purposes only ITec121 : Object Oriented Programming
1st Semester SY 2021-2022
case 6:
System.out.println("Saturday");
break;
case 7:
System.out.println("Sunday");
break;
int day = 4;
switch (day) {
case 6:
System.out.println("Today is Saturday");
break;
For Instructional Purposes only ITec121 : Object Oriented Programming
1st Semester SY 2021-2022
case 7:
System.out.println("Today is Sunday");
break;
default:
Learning Task/Activities
1. Write a Java program that takes the user to provide a
single character from the alphabet. Print Vowel or
Consonant, depending on the input. If the input is not a
letter (between a and z or A and Z), or is a string of length
> 1, print an error message.
Assessment
1. To be given in out laboratory session.
Module Posttest