Professional Documents
Culture Documents
MODULE 1
Computer Programming (Java) – Grade 12
Quarter 3 – Module 1 : Java Instances of Operator
First Edition, 2020
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 material hopes to engage the learners in guided and independent
learning activities at their own pace and time. Further, this also aims to help learners
acquire the needed 21st century skills especially the 5 Cs, namely: Communication,
Collaboration, Creativity, Critical Thinking, and Character while taking into
consideration their needs and circumstances.
In addition to the material in the main text, you will also see this box in the
body of the module:
As a facilitator you are expected to orient the learners on how to use this
module. You also need to keep track of the learners' progress while allowing them to
manage their own learning. Moreover, you are expected to encourage and assist the
learners as they do the tasks included in the module.
For the Learner:
This module was designed to provide you with fun and meaningful
opportunities for guided and independent learning at your own pace and time. You
will be enabled to process the contents of the learning material while being an active
learner.
Posttest - This measure how much you have learned from the
entire module.
EXPECTATION
At the end of this module the students will be able to:
1. Understand the basic concept of instance in Java operator
2. Differentiate the types of Java operators
3. Applying the use of instance operator in Java.
PRE–TEST
Directions: Select the correct answer and write the letter on the space
provided before each number.
____1. It is a sets of accessibility in Java program structure.
a. Public b. Default c. Private d. Protected
____2. Which of the following declaration is within the package of Java?
a. Public b. Default c. Private d. Protected
____3. The Java declaration found within the class only?
a. Public b. Default c. Private d. Protected
____4. The declaration on Java where it represents character (1-Z and 0-9).
a. string b. int c. char d. var
____5. Which of the following Java operator compare values in class, subclass and interface?
a. greater than b. less than c. instanceof d. protected
RECAP
1. Describe the difference between Java basic commands System.Out and
println.
______________________________________________________________
______________________________________________________________
______________________________________________________________
2. Describe the JAVA Access Modifiers (Publlic, Protected, Default and Private).
______________________________________________________________
______________________________________________________________
______________________________________________________________
______________________________________________________________
LESSON
INSTANCEOF OPERATOR IN JAVA
There are types of operator in Java, arithmetic,
relational, bitwise, assignment and logical
operators. The instanceof of operator is used to
test whether the value of an object in specified
type such as class, subclass or interface. It is
also known as comparison operator because it
compares the instance with type. The values
returns either true or false. Figure 1 http://instanceof/3a35V24
Program Example#1 of instanceof:
Class Main{
Public static void main(String[ ] args {
//check a variable of string type
String name = “Programmers”;
boolean result1 = name intanceof String;
System.out.println(“name is an instance of String:”+result1);
//create an object of Main
Main obj = new Main();
//checks if obj is an instance of Main
Boolean result2 = obj instanceof Main;
System.out.println(“obj is an instance of Main:”+result2);
}
}
3. Bitwise operators are used to compare between two binary values 0’s and 1’s.
These operators are bitwise and(&), bitwise or(|), bitwise XOR(^), bitwise
compliment(~), left shift(<<) , right shift(>>) and zero fill right(>>>)
4. Assignment operators are used to assign to integer or number. These are equal
sign(=), add equal sign (+=), subtract equal sign(-=), multiple equal sign(*=), divide
equal sign(/=), modulus equal sign(%=), left shift and assignment (<<=), right shift
and assignment(>>=), bitwise and assignment(&=), bitwise exclusive or and
assignment(^=) and bitwise inclusive or and assignment(|=).
Example :
// Java code to illustrate "="
import java.io.*;
Class Assignment {
public static void main(String[] args)
{
// Declaring variables and Values
int num=10;
String name=”Rizalians”;
// Displaying the assigned values
System.out.println("num is assigned: " + num);
System.out.println("name is assigned: " + name);
}
}
Output: num is assigned: 10
name is assigned: Rizalians
5. Logical operators are used to compare values of variables. This can be true or
false value. These operators are logical and(&&), logical or(||) and logical not(!).
Example :
class Logical {
public static void main(String[] args)
{
// initializing variables
int a = 10, b = 20, c = 20, d = 0;
// Displaying a, b, c
System.out.println("Var1 = " + a);
System.out.println("Var2 = " + b);
System.out.println("Var3 = " + c);
// using logical AND to verify
if ((a < b) && (b == c)) {
d = a + b + c;
System.out.println("The sum is: " + d);
}
else
System.out.println("False conditions");
}
}
Output : Var1 = 10
Var2 = 20
Var3 = 20
The sum is: 50
ACTIVITY
Directions: Write True in the space provided if the given program statement is true;
otherwise write False.
WRAP–UP
1. Compare and contrast the difference between Relational and Logical operator.
________________________________________________________________
________________________________________________________________
________________________________________________________________
________________________________________________________________
VALUING
Discuss the significance of using instanceof operator in Java programming.
POST TEST
Directions: Read carefully. Select the correct answer and write the letter on the space
provided before each number.
______1. Which of the Java operator compares two or more variables?
a. assignment b. arithmetic c. logical d. bitwise
______2. The Java operator dedicated only for numeric value.
a. assignment b. arithmetic c. logical d. bitwise
______3. It is an operator use to evaluate values of object in class and subclass.
a. Logical b. instanceof c. arithmetic d. relational
______4. Declare b >= 75; or c <= 74; Which operator is apply?
a. Logical b. instanceof c. arithmetic d. relational
______5. What does the sign semicolon ( ; ) means?
a. connector b. separator c. return d. none
a. KEY TO CORRECTION
5. False
4. True
3. False
2. True
1. True
Activity :
5. C B 5.
4. A D 4.
3. D B 3.
2. A A 2.
1. B 1.
C
Pre-Test: Post-Test
REFERENCES
Website:
Instanceof operator in Java January 5, 2021 4:00pm Access from http://bit.ly/3j1c2HH,
http://bit.ly/3r5pjBI, http://bit.ly/39xwE6Z
Photo:
January 5, 2021 3:00pm Access from http://bit.ly/2YtRFZY