TEMPLATE 4: The Lesson Structure
TEMPLATE 4: The Lesson Structure
Analysis 1. Describe the current state and list two or three things you can do
with that object.
______________________________________________________
______________________________________________________
______________________________________________________
______________________________________________________
Abstraction What is Object-Oriented Programming?
In the 1980s, ‘modular’ languages were developed that became the precursor to
modern Object-Oriented languages.
The object-oriented paradigm is based on many of the ideas developed over the
previous 30 years of abstraction, encapsulation, generalization, and
polymorphism. It led to the development of software components where the
operation of the software and the data it operates on are modeled together.
While you can focus your attention on the actual program code you are writing,
whatever development methodology is adopted, it is not the creation of the code
that is generally the source of most problems.
Object-Oriented Principles
The general proponents of the object-oriented approach claim that this model
provides:
● better abstractions (modeling information and behavior together)
● better maintainability (more comprehensible, less fragile)
● better reusability (classes as encapsulated components)
Well done! You have just finished Lesson 1 of this module. Should there be
some parts of the lesson you need clarification, feel free to ask your teacher?
Closure
Module No. Module 1: Basic OOP Concepts
and Title
Lesson No. Lesson 2: Procedural Programming vs. OOP
and Title
The procedural approach to programming was the de facto approach in the early
days of programming. Here, code is modularized based on a system’s
processes.
For instance, in developing a library application system, we would have
considered processes such as checking in and out of books, making reservations
of books, cataloging books, and so on. Problem-solving would involve the
analysis of these processes in terms of the procedural tasks carried out and the
production of a system whose representation is based on the procedural flow of
the processes.
Since objects and their interactions characterize the real-world problem domain,
a software application developed using the object-oriented programming
approach will result in the production of a computer system that has a closer
representation of the real-world problem domain than would be the case if the
procedural programming approach is used.
Let us consider a real-world situation. There are two persons, Benjamin and his
wife, Bambie. They are customers of HomeCare, a company dealing with
luxurious furniture. HomeCare sells a variety of sofa sets. Each sofa set is
labeled with an identification number and a price tag. After viewing the sofa
sets for an hour, Benjamin and Bambie decide to purchase a green leather 5-
seater set. They approach Sean, a salesperson, to place their order.
The message that Benjamin has sent to Sean is a takeOrder message. It contains
information such as the type of sofa set (a green leather, 5-seater set) and the
date of delivery (next Wednesday). This information is known as the
parameters of
the takeOrder message.
The interactions between Benjamin and Sean in the above real-world situation
can be represented in object-oriented programming terms. For instance,
Benjamin and Sean are objects that interact by sending messages. Benjamin is
thus a message-sending object, while Sean is a message-receiving object.
Alternatively, we can label Benjamin as a sender and Sean as a receiver.
On the other hand, an invalid message is one that the receiver cannot respond
to; that is, the receiver does not have a corresponding
method to match the message. For example, if Benjamin had requested a
discount on the price, his request would have been rejected because Sean, being
a salesperson, would not have the capability (or a corresponding method) to
respond to the message.
While Benjamin may know what Sean can do through his methods, he may not
know how Sean does them. This is an important principle of object-oriented
programming known as information hiding: the sender of a message does not
know how a receiver will satisfy the request in the message.
Application Consider the following scenarios and outline the objects and their interactions
in terms of messages and arguments:
a) a driver driving a car;
b) a customer making a cash withdrawal from an automated teller
c) machine (ATM);
d) a customer buying a compact disk player from a vendor;
e) a traffic policeman directing traffic at a junction;
f) a lecturer delivering his/her lecture to a class of students;
g) (f) a tutorial discussion between an instructor and students.
Well done! You have just finished Lesson 2 of this module. Should there be
some parts of the lesson which you need clarification, feel free to ask your
Closure
teacher?
With hundreds of pets, if code had to be created from scratch for each new pet,
there would be way too much code. Here’s a code of creating two dog objects:
var rufus = {
name: "Rufus",
birthday: "2/1/2017",
age: function() {
},
attendance: 0
var fluffy = {
name: "Fluffy",
birthday: "1/12/2019",
age: function() {
},
attendance: 0
What do you notice about the code? There is a lot of duplicated code between
both objects - the age() function appears in each object. If you think about
hundreds of pets, you wouldn’t want to repeat it often. In OOP, programmers
think about how to model things using objects, so code is reusable and
maintainable.
Grouping related information together to form a class structure makes the code
shorter and easier to maintain.
In the pet sitting camp example, here’s how a programmer could think about
organizing an OOP:
The dog is a parent class with generic methods, a blueprint for creating any type
of dog. French Bulldog is a child class of the Dog parent class. The French
Bulldog class adds more specific attributes and methods unique to French
Bulldogs – like a nap. The French Bulldog class also inherits the attributes and
methods of the parent class. Next, the programmer creates instances of the
French Bulldog class – one named Fluffy and Maisel. Fluffy & Maisel can both
bark and nap. However, Rufus is an instance of the generic dog parent class so
that Rufus can bark, but he can’t nap. Nap is a method of the child class, and
Rufus is an object created from the parent class Dog.
Classes
In a nutshell, they’re essentially user-defined data types. Classes are where the
programmer creates a blueprint for the structure of methods and attributes.
Individual objects are instantiated, or created from this blueprint. Classes
contain fields for attributes and methods for behaviors. In our dog class
example, attributes include name & birthday, while methods include bark() and
updateAttendance().
class Dog {
constructor(name, birthday) {
this.name = name;
this.birthday = birthday;
_attendance = 0;
getAge() {
//Getter
return this.calcAge();
}
calcAge() {
bark() {
return console.log("Woof!");
updateAttendance() {
this._attendance++;
Objects
Of course, OOP includes objects! Objects are instances of classes created with
specific data. For example, in the code snippet below, Rufus is an instance of
the dog class.
class Dog {
constructor(name, birthday) {
this.name = name;
this.birthday = birthday;
}
//Declare private variables
_attendance = 0;
getAge() {
//Getter
return this.calcAge();
calcAge() {
bark() {
return console.log("Woof!");
updateAttendance() {
this._attendance++;
//instantiate a new object of the Dog class, and individual dog named Rufus
Attributes are the information that is stored. Attributes are defined in the Class
template. When objects are instantiated, individual objects contain data stored
in the Attributes field.
The state of an object is defined by the data in the object’s attributes fields. For
example, a puppy and a dog might be treated differently at a pet camp. The
birthday could define the state of an object, and allow the software to handle
dogs of different ages differently.
Methods
class Dog {
_attendance = 0;
constructor(name, birthday) {
this.namee = name;
this.birthday = birthday;
getAge() {
//Getter
return this.calcAge();
}
calcAge() {
return this.calcAge();
bark() {
return console.log("Woof!");
updateAttendance() {
this._attendance++;
Methods often modify, update, or delete data. Methods don’t have to update
data through – for example, the bark method doesn’t update any data because
barking doesn’t modify any of the dog class’s attributes - name or birthday. The
updateAttendance() method adds a day the Dog attended the pet sitting camp.
The attendance attribute is important to keep track of for billing Owners at the
end of the month.
Note: the underscore in _attendance denotes that the variable is protected, and
shouldn’t be modified directly. The updateAttendance() method is used to
change _attendance.
Closure Well done! You have just finished Lesson 3 of this module. Should there be
some parts of the lesson which you need clarification, feel free to ask your
teacher?
Module No. Module 1: Basic OOP Concepts
and Title
Lesson No. Lesson 4: UML notations
and Title
Learning Use different notations present in the Unified Modeling Language to represent
Outcomes different OOP concepts.
Time Frame 1 hour
Introduction This lesson will discuss what Unified Modelling Language (UML) is.
Problem:
Activity
In a library, a reader can borrow up to eight books. A particular book can be
borrowed by at most one reader.
1. With the problem above, try to develop a model that illustrates the
Analysis use of UML notations.
Abstraction What is UML?
Goals of UML
UML diagrams are made not only for developers but also for business users,
common people, and anybody interested in understanding the system. The
system can be a software or non-software system. Thus, it must be clear that
UML is not a development method; instead, it accompanies processes to make
it a successful system.
Object-Oriented Concepts
Objects are the real-world entities that exist around us, and the basic concepts
such as abstraction, encapsulation, inheritance, and polymorphism all can be
represented using UML.
UML is powerful enough to represent all the concepts that exist in object-
oriented analysis and design. UML diagrams are the representation of object-
oriented concepts only. Thus, before learning UML, it becomes important to
understand the OO concept in detail.
Things
Structural Things
Structural things define the static part of the model. They represent the physical
and conceptual elements. The following are brief descriptions of the structural
things.
Class
Attributes
Operations
Table 1.1 Sample Model of Class
Interface
Use Case – Use case represents a set of actions performed by a system for a
specific goal.
Use Case
Behavioral Things
State Machine – State machine is useful when the state of an object in its life
cycle is important. It defines the sequence of states an object goes through in
response to events. Events are external factors responsible for a state change.
State
Package
Annotational Things
Relationship
Dependency
UML diagrams are the ultimate output of the entire discussion. All the
elements, relationships are used to make a complete UML diagram, and the
diagram represents a system.
The visual effect of the UML diagram is the most important part of the entire
process. All the other elements are used to make it complete.
UML - Architecture
Different users use any real-world system. The users can be developers, testers,
business, people, analysts, and many more. Hence, before designing a system,
the architecture is made with different perspectives in mind. The most
important part is to visualize the system from the perspective of different
viewers. The better we understand, the better we can build the system.
The center is the Use Case view, which connects all these four. A Use Case
represents the functionality of the system. Hence, other perspectives relate to
the use case.
Structural Modeling
Structural modeling captures the static features of a system. They consist of the
following:
✔ Classes diagrams
✔ Objects diagrams
✔ Deployment diagrams
✔ Package diagrams
✔ Composite structure diagram
✔ Component diagram
The structural model represents the framework for the system, and this
framework is where all other components exist. Hence, the class diagram,
component diagram, and deployment diagrams are part of structural modeling.
They all represent the elements and the mechanism to assemble them.
The structural model never describes the dynamic behavior of the system. The
class diagram is the most widely used structural diagram.
Behavioral Modeling
Architectural Modeling
UML notations are the most important elements in modeling. Efficient and
appropriate use of notations is very important for making a complete and
meaningful model. The model is useless unless its purpose is depicted properly.
Structural Things
Graphical notations used in structural things are most widely used in
UML. These are considered as the nouns of UML models. Following is the list
of structural things.
✔ Classes
✔ Object
✔ Interface
✔ Collaboration
✔ Use case
✔ Active classes
✔ Components
✔ Nodes
Class Notation
The following figure represents the UML class. The diagram is divided into
four parts.
✔ The top section is used to name the class.
✔ The second one is used to show the attributes of the class.
✔ The third section is used to describe the operations performed by
the class.
✔ The fourth section is optional to show any additional
components.
Figure 1.15 Sample Class Diagram
Object Notation
The object is represented in the same way as the class. The only difference is
the name which is underlined, as shown in the following figure.
Interface Notation
Collaboration Notation
Collaboration is represented by a dotted eclipse, as shown in the
following figure. It has a name written inside the eclipse.
Actor Notation
An actor can be defined as an internal or external entity that interacts with the
system.
The initial state is defined to show the start of a process. This notation is used
in almost all diagrams.
The active class looks like a class with a solid border. Active class is generally
used to describe the concurrent behavior of a system.
Component Notation
Interaction Notation
Package Notation
Package notation is shown in the following figure and is used to wrap the
components of a system.
Node Notation
Relationships
Dependency Notation
Association Notation
Generalization Notation
For this activity, concentrate on the relationships between classes rather than
the details of their members. Explain and discuss your model with your teacher.
Well done! You have just finished Lesson 4 of this module. Should there be
some parts of the lesson which you need clarification, feel free to ask your
Closure
teacher?
Module No. Module 1: Basic OOP Concepts
and Title
Lesson No. Lesson 5: Creating class diagrams
and Title
Lesson 6: Representing inheritance, association, and composition
Time 2 hours
Frame
Introduction This lesson will discuss the importance of creating graphical models of classes
in OOP using class diagrams.
Consider the Student and Course Class relationships with the following
Activity constraints:
1. Each Course object maintains a list of the students on that course and
the lecturer who has been assigned to teach that course
2. The Course object has a behavior that allows the adding and removing
of students from the course, assigning a teacher, getting a list of the
currently assigned students, and the currently assigned teacher.
3. Teachers are modeled as Lecturer objects. As a lecturer may teach more
than one course, there is an association between Course and Lecturer.
The “taught by” relationship shows that a Course only has a single
teacher, but that a lecturer may teach several Courses.
4. Each Lecturer object also maintains a list of the Courses that it teaches.
5. There is a similar relationship between Course and Student. Zero or
more Students attend a course, and a Student may attend multiple
courses.
Class name
• write «interface» on top of interfaces' names
• use italics for an abstract class name
Attributes (optional)
• fields of the class
Operations / methods (optional)
• may omit trivial (get/set) methods
• but do not omit any methods from an interface!
• should not include inherited methods
(a) (b)
Figure 1.32 Sample class diagram for Rectangle and Student class.
Syntax:
visibility name(parameters): return_type
1. visibility
+ public
# protected
- private
~ package (default)
2. parameters listed as name: type
3. underline static methods
4. omit return_type on constructors and when return type is void
Comments
Generalization relationships
Association multiplicities
1. One-to-one
● Each car has exactly one engine.
● Each engine belongs to exactly one car.
2. One-to-many
● Each book has many pages.
● Each page belongs to exactly one book.
Figure 1.36 Sample class diagram for association relationship
Example 1:
Example 2:
Association Types
Inheritance
In the example above, Class A ‘inherits’ both the interface and implementation
of Class B.
Example: Inheritance
We can show classes to represent these on a UML class diagram. In doing so,
we can see some of the instance variables and methods these classes may have.
Book Class
Attributes ‘title’, ‘author,’ and ‘price’ are obvious. Attribute ‘copies’ signifies
how many books are currently in stock.
Magazine Class
orderQty is the number of copies received of each new issue, and currIssue is
the date/period of the current issue. When a newIssue is received, the old is
discarded, and orderQty copies are placed in stock. Therefore, recvNewIssue()
sets currIssue to date of the new issue and restores copies to orderQty.
adjustQty() modifies orderQty to alter how many copies of subsequent issues
will be stocked.
Problem:
Look at the Book and Magazine classes and identify the commonalities and
differences between the two classes.
Solution:
These classes have three instance variables in common: title, price, copies.
They also have in common, sellCopy().
We can separate these common members of the classes into a superclass called
Publication.
The differences will need to be specified as additional members for the subclass
Book and Magazine.
The inherited characteristics are not listed in the subclass. The arrow shows
they are acquired from the superclass.
Unidirectional association –
one class is aware of the
other and interacts with it.
Class Diagram Example 2: people
Each customer has a unique id and is linked to exactly one account. The
account owns a shopping cart and orders. The customer could register as a web
user to be able to buy items online. A customer is not required to be a web user
because purchases could also be made by phone or by ordering from catalogs.
The web user has a login name, which also serves as a unique id. Web users
could be in several states - new, active, temporary blocked, or banned, and
linked to a shopping cart. The shopping cart belongs to the account.
The account owns customer orders. The customer may have no orders.
Customer orders are sorted and unique. Each order could refer to several
payments, possibly none. Every payment has a unique id and is related to
exactly one account.
Each order has a current order status. Both order and the shopping cart have
line items linked to a specific product. Each line item is related to exactly one
product. A product could be associated with many line items or no item at all.
Well done! You have just finished Lesson 5 and 6 of this module. Should there
be some parts of the lesson which you need clarification, feel free to ask your
Closure
teacher?
Activity Work by pair to encourage peer to peer sharing of ideas and understanding
throughout the duration of the abovementioned lesson.
To better understand the topic, let us begin the lesson with giving examples of
real-world object. With your pair, utilize the table below. Fill the first column
with an object you can see inside the school campus. Second, write the
qualities of the object you have chosen. Third, specify your chosen object’s
behavior or the task it is able to perform.
2. 2. 2.
Analysis With the knowledge you now have of the basics of the Java programming
language, answer the following:
1. What is a class?
With OOP approach, it allows you to dvide complex problems into smaller sets
by creating objects.
2.1. CLASS
A class is a user defined blueprint or prototype from which objects are
created. It represents the set of properties or methods that are common to all
objects.
Syntax:
2.2. OBJECT
To better understand objects, software objects are conceptually similar to
real-world objects: they too consist of state and related behavior. An object
stores its state in fields/attributes (variables in some programming languages)
and exposes its behavior through methods (functions in some programming
languages). Objects in java is also known as instance of the class.
Figure 2.2.1
Creating an object from a class must specify the class name which is then
followed by the object’s identifier (variable) and the keyword “new”. The
sample below shows how to create or declare an object:
Syntax:
Figure 2.2.2
Java variables, in simplest term, are used to store data which java program
needs to perform its job. An instance variable is variable that needs to be
appended to the object reference with an intervening dot operator while
static variable is a variable that can be accessed at any point of the class
without the need to append it to the object reference.
Application Create a simple java program that declares an object whose name is “myself”.
The program should print at least 2 qualities of the object you have created.
The first quality should be stored in a static variable while the second should
be in an instance variable.
Sample output:
Beautiful
Smart
Closure If you have successfully created a java program that has carried out the
output specified, congratulations! Continue improving yourself and always
work with your peer to share and gain more ideas.
The topics discussed in this module will be useful in the upcoming lessons, so
make sure to revisit and remember this topic.
Introduction This lesson will help you better understand the implementation of attributes and
methods in a program. Now you will learn and enumerate the parts of the method
and their corresponding role upon the method’s execution; Trace the program flow
execution; Learn how to invoke methods with or without instance of a class and
parameters. Expect that at the end of the topic you will be identifying and debugging
semantic and syntax errors of a program that implements the syntaxes covered in this
lesson.
Activity Create a java program that contains the following:
1. an instance of a class.
2. a static variable.
3. a static method.
4. An instance variable
5. An instance method
Analysis Questions:
1. What is/are the difference/s between static methods and instance methods?
2. What is/are the difference/s between static variables and instance variables?
3. How does invoking/ calling process takes place for static variables and/ or
method?
Abstraction 3. ATTRIBUTES AND METHODS
Attributes and methods are among the two important class members that work with
the class’ object. Although an attribute is a vague term, let’s focus on attributes that
are instantiated inside the class that hold a value representing the object’s
characteristics or qualities. Remember that an object, as discussed in previous topic,
could be a real-world entity, thus, attributes may refer to the set of features that
describes it entity or the object. On the other hand, A method is a class member
which performs specified operations. In OOP, methods are procedures that defines
the behavior in which an object is able to perform.
3.1. ATTRIBUTES
Syntax:
As discussed in the previous lesson, there are two (2) types of variables – Static and
instance. Attributes and variables, though oftentimes used interchangeably, slightly
differs from each other. An attribute in object-oriented programming is a field that
defines the object in a class while a variable is a general term that holds values
including those that are not related to the object. Thus, both static and instance are
variables, however, in OOP languages, instance variables are attributes while static is
not. To make it more coherent, take the declaration of variables and attributes below.
The static keyword indicates that the variable can be accessed at any point of the
program without an object, provided however, that it meets the specifications of its
access modifier. On the other hand, attributes don’t have the “static” keyword upon
its declaration and can only be called by appending it to the object reference with an
intervening dot (.) operator.
Example (Attribute):
In the sample code, the variable color is attributed to our object (Bike), thus, object’s
Bike color now is “Blue” and will print an output “Blue”.
The picture above shows how to create a method with their parts being labelled.
These parts have their corresponding functions on or before the method’s execution.
4. Parameter list/s – also known as arguments which specify what type of data a
method can receive.
5. Method body – defines whole method itself. This is where the set of
operations and algorithms are located and are performed during its
execution.
Figure 3.3.0 is instance method which requires an instance of a class (object) for it to
be accessed while figure 3.3.1 is a static method, because of the static keyword,
which can be access at any point of the class without an instance (Object).
Example:
Figure 3.3.2. – Sample Code
The picture above shows the implementation of static and instance methods. Notice
how instance method is invoked in line 62 compared to static method in line 60.
Methods without a static keyword needs to be appended to the object reference with
an intervening dot operator (line 62) while static methods can be called without the
need to append the object reference (line 13).
Example:
Figure 3.3.3 below illustrates the execution flow after calling a method. Line 60 calls
the static method, performs its specified operation then goes back to the caller. Same
flow applies to the calling process of an instance method in line 62.
On the other hand, observe how “myPublicMethod()” method In the figure 3.3.3.
returns a value that correspond to its primitive return type in line 55. It returns a
value of 1 (line 56) since the data type specified in the return type is int which means
integer, thus, satisfying the first(1 st) condition. Meanwhile, the “myStaticMethod”
returns no value until it reaches the end of the method since it is a void type because
of the keyword “void”, thus, satisfying the second(2 nd) condition.
a. Number of parameter/s
3.5. CONSTRUCTORS
Methods and attributes as mentioned above are essential class members of the
object-oriented programming. A method is a class member which performs specified
operation that defines the behavior of an object. A constructor, is also a method that
performs specified operation; however, it can only be invoked when an object in a
class is created.
Example:
The picture above shows how the constructor “MyClass” is created and is used to
change the initial value of the attribute “color”. When an object is created, the
constructor is invoked changing the value of the attribute “color” from “none” to
“blue”.
Remember:
● Constructors’ name must match the class name and it cannot have any return
type.
● Java will create a default constructor if you do not create one, setting the
instantiated attributes into its primitive data type’s default value.
CONSTRUTOR PARAMETERS
Constructors can also take parameters. However, one should always remember that
the number of parameters including their data type in a constructor match the
number of parameters specified in the created instance of a class.
Notice that the object bike contains one String parameter whose value is “BMW”,
thus, the constructor “MyClass” should also have one String parameter as shown in
the above picture.
Another thing to remember is that the order of data type of parameters in the object
should also match the order of data type of parameters in the constructor.
Example:
The created object “bike” has two (2) parameters, “BMW’ and 8500, thus, the
constructor should also have the same order of parameters in terms of data type. As
shown in the above picture, constructor “MyClass” contains two parameters with
data type “string” and “int” which both conforms to the order of data type in the
object.
DESTRUCTORS
Destructor is a method called when the destruction of an object takes place. The
main goal of the destructor in general is to free up the allocated memory and also to
clean up resources like the closing of open files, closing of database connections,
closing network resources, etc. Although, there is no documented destructor in java
programming language unlike C++, java has garbage collector where developers can
free resources and save garbage collector’s work.
When java programs run on the Java Virtual Machine, objects are created on the
heap taking up space and allocation in the memory dedicated only for the program.
Eventually some of these programs are no longer needed, thus, we need destructors
to free up the heap or the allocated space intended for the java program.
JVM implements garbage collection however it please as long as it meets the JVM
specifications. The most common JVM used by far is Oracle which deploys multiple
garbage collection.
Application
Closure Thanks for helping Tom out! You really are great! Thanks for the help in saving the
world!
It’s urgent!
Please help Tom identify and change the error/s from the program below so that it will provide an
output “Congratulations! For debugging the program successfully” in just 30 mins so that he can save
the world!
Introductio This lesson will introduce the important feature of java programming that allows us to
n handle the runtime errors caused by exceptions. We will learn what is an exception,
types of it, exception classes and how to handle exceptions in java with examples.
Expect that at the end of this lesson you will create your own java program that will
implement the use of basic exception handling.
Activity Before we begin, open a PC or laptop and perform the following:
Analysis
Abstraction A. Running a Java program with semantic errors.
1. What happens to the flow of execution when you compile a java program with
semantic errors?
2. When you compile a java program with semantic errors, will the rest of the
code execute properly or will it get terminated in the block with error?
1. Upon running multiple applications in your computer system until one of them
no longer respond, are there any message the computer operating system has
prompted?
Application Create a java program that will implement the use of exception handling. You can
choose what exception to be handled as long the flow of execution will continue until it
reaches the end of the program. Remember to apply the basics of object-oriented
programming concepts.
Closure Congratulations for reaching the end of basic OOP concepts!
References:
REFERENCES:
1. Kendal, Simon (2009). Object-Oriented Programming using Java. Simon Kendal &
Ventus Publishing ApS
2. Poo, Danny. et.al. (2008). Object-Oriented Programming and Java. Second Edition.
Springer-Verlag London Limited.
3. What is Object-Oriented Programming? OOP Explained in Depth(2020). Retrieved from:
https://www.educative.io/blog/object-oriented-programming
4. Object-Oriented Programming Language (OOPL) (2020). Retrieved from:
https://www.techopedia.com/definition/8641/object-oriented-programming-language-
oop1
5. Fowler, Martin(2004).UML Distilled: A Brief Guide to the Standard Object Modeling
Language. Pearson Education, Inc.
6. Farrel, Joyce (2012). Java Programming
7. Geeksforgeeks.com (2018). “Errors V/s Exceptions in Java” retrieved from
https://www/google.coom/url?
sa=t&sources=web&rct=j&url=https://www.geeksforgeeks.org/errors-v-s-exceptions-in-
java/amp/&ved=2ahUKEwiw5uhJ2lvrAhXgw4sBHbFEBB4QFjAQegQIARAB&usg=A
OvVAW2QCyyUHL4XGlls0wpUGC8j&cf=1
MODULE SUMMARY
This module introduces the fundamental concepts, theories, and applications of object-oriented
approach in java programming language that will help participants better understand and apply the
difference between the traditional or procedural from object-oriented approach and encouraging
participants to implement important class members and program structure that demonstrate the
concepts of OOP. It will also include creating unified diagrams that represents entities and their
corresponding associations based from the setup of real-world scenario. In general, this module
presents the sequential method of understanding the real-world concepts and their application into
object-oriented programming concepts and structure.
At the end of every topics in this module, participants must undergo several activities to enable them to
utilize the general knowledge they have gained and to exercise their comprehension.
The following are the key important information that were focused in this module:
1. Object-oriented programming involves the creation of objects that model a business
problem you are trying to solve.
2. In creating an object-oriented program, you define the properties of a class of objects and
then create individual objects from this class.
3. Object-oriented principles involve abstraction, encapsulation, inheritance and
polymorphism.
4. The procedural approach to programming was the de facto approach in the early days of
programming. Here, code is modularized based on a system’s processes.
5. Object-oriented programming, on the other hand, models objects and their interactions in
the problem space and the production of a system based on these objects and their
interactions.
6. Object-oriented programming language (OOPL) is a high-level programming language
based on the object-oriented programming (OOP) model.
7. Classes are where the programmer creates a blueprint for the structure of methods and
attributes.
8. Objects are instances of classes created with specific data.
9. Attributes are the information that is stored.
10. Methods perform actions; methods might return information about an object, or update an
object’s data.
11. UML (Unified Modeling Language) is a standard language for specifying, visualizing,
constructing, and documenting the artifacts of software systems.
12. Class diagrams describe the system’s structure by showing the system’s classes, their
attributes, and the relationships among the classes.
MODULE ASSESSMENT
Choose only the letter of the correct answer.
1. A function which has the same name of the class which could be used for initialization of the uninitialized
instance variables.
a. Constructor c. Object
b. Method d. class
A
2. A word used to describe a block of code that will be executed whenever there is an object instantiation.
a. Method c. Object
b. Constructor d. Object Oriented Program
A
3. Java compiler distinguishes a constructor from a method using _____ and ______.
a. Datatype; access modifier c. Parameter; object
b. Identifier; return type d. Constructor name; parameter
A
4. This refers to the part of a method block which will set the visibility of the function or the method itself.
a. Static Keyword c. Access Modifier
b. Visibility Modifier d. Method Block
A
5. _________ is a Jargon used for function. They are bound to a class, define the behavior of a class and
performs specific task indicated by the user.
a. Algorithm c. Constructor
b. Method d. Object
C
6. A part of a method block which defines what the method actually does and how the variables are
manipulated.
a. Access Modifier c. Method Block
b. Return type d. Method’s task
A
7. Refers to the part of a method block which is used as an identifier.
a. Method Name c. Method Body
b. Access Modifier d. Return type
C
8. Which of the following best describes an instance variable?
a. These are variables that are declared outside any of methods, constructors, and or classes.
b. These are variables whose lifetime varies with the execution of a method or constructor block.
c. These are variables that may be static or non-static having its value initialized as default.
d. These are variables that are inside the class but outside any methods or constructors.
A
9. Which of the following best describes a local variable?
a. These are variables that are declared outside any of methods, constructors, and or classes.
b. These are variables whose lifetime varies with the execution of a method or constructor block.
c. These are variables that may be static or non-static having its value initialized as default.
d. These are variables that are inside the class but outside any methods or constructors.
B
10. Which of the following is true for a static variable?
a. Static variable is a variable that needs class instantiation to be used.
b. This is variable whose lifetime varies with method or constructor block execution.
c. Variables that can be accessed by any method or constructor.
d. These are variables that should be declared inside a method or constructor and should have
static keyword.
B.
1. Create an algorithm that will print any square value of an “int” input (specified by the user) using a static
void type of method whose access modifier is set to private.
2. Create a constructor, whose parameter is only one, that will automatically twice the value of the int
argument of a class instance.
3. Using the program structure you created in number 2, draw lines to illustrate the execution flow of
compiling a java program.