lOMoARcPSD|41072676
TVL Comprog 12 Q3 M1
Information Technology (Colegio de Dagupan)
                       Scan to open on Studocu
    Studocu is not sponsored or endorsed by any college or university
   Downloaded by John Harvey Demonteverde (jhndmtvd@gmail.com)
                            lOMoARcPSD|41072676
          QUARTER 3
 MODULE 1
Downloaded by John Harvey Demonteverde (jhndmtvd@gmail.com)
                                                 lOMoARcPSD|41072676
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.
       Borrowed materials (i.e., songs, stories, poems, pictures, photos, brand
names, trademarks, etc.) included in this module are owned by their respective
copyright holders. Every effort has been exerted to locate and seek permission to use
these materials from their respective copyright owners. The publisher and authors
do not represent nor claim ownership over them.
      Published by the Department of Education - Schools Division of Pasig City
                  Development Team of the Self-Learning Module
 Writer           : Jose Alvin P. Tagara
 Editor           : Mrs. Lerma I. Cantanero
 Reviewer         : Mrs. Rowena O. Dimagiba
 Illustrator:
 Layout Artist:
 Management Team:               Ma. Evalou Concepcion A. Agustin
                                OIC-Schools Division Superintendent
                                Aurelio G. Alfonso EdD
                                OIC-Assistant Schools Division Superintendent
                                Victor M. Javeña EdD
                                Chief, School Governance and Operations Division and
                                OIC-Chief, Curriculum Implementation Division
                Education Program Supervisors
                       Librada L. Agon EdD (EPP/TLE/TVL/TVE)
                       Liza A. Alvarez (Science/STEM/SSP)
                       Bernard R. Balitao (AP/HUMSS)
                       Joselito E. Calios (English/SPFL/GAS)
                       Norlyn D. Conde EdD (MAPEH/SPA/SPS/HOPE/A&D/Sports)
                       Wilma Q. Del Rosario (LRMS/ADM)
                       Ma. Teresita E. Herrera EdD (Filipino/GAS/Piling Larang)
                       Perlita M. Ignacio PhD (EsP)
                       Dulce O. Santos PhD (Kindergarten/MTB-MLE)
                       Teresita P. Tagulao EdD (Mathematics/ABM)
       Printed in the Philippines by Department of Education – Schools Division of
Pasig City
                     Downloaded by John Harvey Demonteverde (jhndmtvd@gmail.com)
                                          lOMoARcPSD|41072676
         Computer
       Programming
QUARTER 3
   +
 MODULE
  1         Instance of Operator in Java
   Writer                       : Jose Alvin P. Tagara
   Editor                       : Mrs. Lerma I. Cantanero
   Validator/Reviewer           : Mrs. Rowena O. Dimagiba
              Downloaded by John Harvey Demonteverde (jhndmtvd@gmail.com)
                                                lOMoARcPSD|41072676
Introductory Message
       For the Facilitator:
      Welcome to the Computer Programming (Java) 12 Self-Learning Module on
Use Case Diagram!
       This Self-Learning Module was collaboratively designed, developed and
reviewed by educators from the Schools Division Office of Pasig City headed by its
Officer-in-Charge Schools Division Superintendent, Ma. Evalou Concepcion A.
Agustin, in partnership with the City Government of Pasig through its mayor,
Honorable Victor Ma. Regis N. Sotto. The writers utilized the standards set by the K
to 12 Curriculum using the Most Essential Learning Competencies (MELC) in
developing this instructional resource.
       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:
                                 Notes to the Teacher
                    This contains helpful tips or strategies that
                    will help you in guiding the learners.
       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.
                    Downloaded by John Harvey Demonteverde (jhndmtvd@gmail.com)
                                               lOMoARcPSD|41072676
      For the Learner:
      Welcome to the Computer Programming (Java) 12 Self-Learning Module on
Use Case Diagram!
       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.
      This module has the following parts and corresponding icons:
                    Expectations - This points to the set of knowledge and skills
                    that you will learn after completing the module.
                    Pretest - This measures your prior knowledge about the lesson
                    at hand.
                    Recap - This part of the module provides a review of concepts
                    and skills that you already know about a previous lesson.
                    Lesson - This section discusses the topic in the module.
                    Activities - This is a set of activities that you need to perform.
                    Wrap-Up - This section summarizes the concepts and
                    application of the lesson.
                    Valuing - This part integrates a desirable moral value in the
                    lesson.
                    Posttest - This measure how much you have learned from the
                    entire module.
                   Downloaded by John Harvey Demonteverde (jhndmtvd@gmail.com)
                                                  lOMoARcPSD|41072676
                       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).
      ______________________________________________________________
      ______________________________________________________________
      ______________________________________________________________
      ______________________________________________________________
                      Downloaded by John Harvey Demonteverde (jhndmtvd@gmail.com)
                                                  lOMoARcPSD|41072676
                       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);
                }
       }
       Output Program Example#1:
       name is an instance of String: true
       obj is an instance of Main: true
       Program Example#2 of instanceof iheritance:
       //Java program to check if an object of the subclass is also an instance of the superclass
       //superclass
       Class Animal{
       }
       //subclass
       Class Dog extends Animal{
       }
       Class Main {
               Public static void main(String [ ] args {
               //create an object of the subclass
               Dog dg1 = new Dog();
               //checks if dg1 is an instance of the subclass
               System.out.println(dg1 instanceof Dog:); //print true
               //checks if dg1 is an instance of the subclass
               System.out.println(dg1 instanceof Animal:); //print true
               }
       }
       Note: The subclass Dog inherit from superclass Animal.
                      Downloaded by John Harvey Demonteverde (jhndmtvd@gmail.com)
                                           lOMoARcPSD|41072676
      dg1 instanceof Animal return to True
Output Program Exampl#2
   dg1 instanceof Dog : true
   dg1 instanceof Animal : true
TYPES OF OPERATORS IN JAVA
1. Arithmetic operators are used in mathematical expression in the same way they
   are use in computation. These operators are Addition(+), subtraction(-),
   multiplication(*), division(/), modulus(%),increment(++) and decrement(- -).
   Example : class OperatorExample{
                   public static void main(String args[]){
                   int a=10;
                   int b=5;
                   System.out.println(a+b);//15
                   System.out.println(a-b);//5
                   System.out.println(a*b);//50
                   System.out.println(a/b);//2
                   System.out.println(a%b);//0
                   }
               }
  Output : 15 5 50 2 0
2. Relational operators are used to compare between two values of numbers or
   integers. The following relational operators are equal to(==), not equal to(!=),
   greater than (>), less than(<), greater than or equal to(>=), less than of equal to
   (<=).
   class Main {
     public static void main(String[] args) {
       int a = 7, b = 11;
       System.out.println("a is " + a + " and b is " + b);
       System.out.println(a == b); // false
       System.out.println(a != b); // true
       System.out.println(a > b); // false
       System.out.println(a < b); // true
       System.out.println(a >= b); // false
       System.out.println(a <= b); // true
     }
   }
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 "="
               Downloaded by John Harvey Demonteverde (jhndmtvd@gmail.com)
                                          lOMoARcPSD|41072676
   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
              Downloaded by John Harvey Demonteverde (jhndmtvd@gmail.com)
                                                 lOMoARcPSD|41072676
                      ACTIVITY
Directions: Write True in the space provided if the given program statement is true;
           otherwise write False.
_______1. The Java declaration for String msg=”Hello World!”;
_______2. The Java declaration
           int a=80; b=85; c=90; int grade;                    grade = (a+b+c)/3;
           System.out.println(“The Final Grade:”+grade);
______3. The Java language has no compiler.
______4. The library import java.io.* : io means input output.
______5. The value a=73; b=75; g=(a+b)/2; If g >75; remarks =”True” else remarks
=”False”.
               WRAP–UP
       1. Compare and contrast the difference between Relational and Logical operator.
          ________________________________________________________________
          ________________________________________________________________
          ________________________________________________________________
          ________________________________________________________________
       2. Discuss the difference between Arithmetic and Assignment operator. Give an
          example program code.
          ________________________________________________________________
          ________________________________________________________________
          ________________________________________________________________
          ________________________________________________________________
                   VALUING
                     Downloaded by John Harvey Demonteverde (jhndmtvd@gmail.com)
                                                   lOMoARcPSD|41072676
        Discuss the significance of using instanceof operator in Java programming.
     Place your answer here:
                       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
                       Downloaded by John Harvey Demonteverde (jhndmtvd@gmail.com)
                                                 lOMoARcPSD|41072676
                         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
                     Downloaded by John Harvey Demonteverde (jhndmtvd@gmail.com)