Module 1
Module 1
Analysis
1. Describe the current state and list two or three things you can do
with that object.
______________________________________________________
______________________________________________________
______________________________________________________
______________________________________________________
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
Closure some parts of the lesson you need clarification, feel free to ask your teacher?
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
Closure some parts of the lesson which you need clarification, feel free to ask your
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:
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 diagram below represents how to design an OOP: grouping the related data
and behaviors to form a simple template. In this case, the Dog class is a
simplified representation of everything we want to store in the software about
dogs. The Dog class is a generic template - containing only the structure about
information and behaviors common to all dogs. To create an individual dog, the
programmer instantiates an instance of the Dog Class and passes in information
from the individual 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;
}
getAge() {
//Getter
return this.calcAge();
}
calcAge() {
//calculate age using today's date and birthday
return Date.now() - this.birthday;
}
bark() {
return console.log("Woof!");
}
updateAttendance() {
//add a day to the dog's attendance days at the petsitters
this._attendance++;
}
}
Remember, the class is a template for modeling a dog, and an object is
instantiated from the class representing a single real-world thing - Rufus, the
dog.
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;
}
getAge() {
//Getter
return this.calcAge();
}
calcAge() {
//calculate age using today's date and birthday
return Date.now() - this.birthday;
}
bark() {
return console.log("Woof!");
}
updateAttendance() {
//add a day to the dog's attendance days at the petsitters
this._attendance++;
}
}
//instantiate a new object of the Dog class, and individual dog named Rufus
const rufus = new Dog("Rufus", "2/1/2017");
Attributes
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 {
//Declare protected (private) fields
_attendance = 0;
constructor(name, birthday) {
this.namee = name;
this.birthday = birthday;
}
getAge() {
//Getter
return this.calcAge();
}
calcAge() {
//calculate age using today's date and birthday
return this.calcAge();
}
bark() {
return console.log("Woof!");
}
updateAttendance() {
//add a day to the dog's attendance days at the petsitters
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.
Activity Problem:
Analysis 1. With the problem above, try to develop a model that illustrates the
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.
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
Node - A node can be defined as a physical element that exists at run time.
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
Grouping Things
Package
Annotational Things
Relationship
Dependency
UML Diagrams
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.
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
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.
Figure 1.21 Sample initial state notation
The final state is used to show the end 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
Node Notation
Interaction Notation
State machine describes the different states of a component in its life cycle. It is
used to describe different states of a system component. The state can be active,
idle, or any other depending upon the situation.
Figure 1.26 Sample state machine notation
Package Notation
Package notation is shown in the following figure and is used to wrap the
components of a system.
Node Notation
Relationships
Association Notation
Generalization Notation
Application From your experience, try to develop a model that illustrates the use of the
following UML notation elements:
● Dependency
● Association
● Generalization
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
Closure 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 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.
Activity Consider the Student and Course Class relationships with the following
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
Example:
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 hollow-centered arrow denotes inheritance.
The inherited characteristics are not listed in the subclass. The arrow shows
they are acquired from the superclass.
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
Closure be some parts of the lesson which you need clarification, feel free to ask your
teacher?
Analysis With the knowledge you now have of the basics of the Java programming
language, answer the following:
1. What is a class?
2. What is the difference between procedural and object-oriented
programming?
3. What do you think is the role played by objects in a class?
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:
To create a class in java, one must simply
declare a class name followed by an open and
close bracket as seen in the picture.
The name of the class is “MyClass”.
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
“Bike” is now an object/instance of the class “MyClass” created inside the
class “MyClass” in line number 6.
To use the attribute “bikeName”, append the attribute’s name/variable to the
object reference with an intervening dot operator(.) as shown in line number
8.
2.3. INSTANCE AND STATIC VARIABLES
We are done with creating an instance of a class (object) in a class, and we
need variables as storage of information that will define our object.
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.
It should apply the concepts of static and instance variables as discussed
above.
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.
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?
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.
DECLARING ATTRIBUTES VS DECLARING VARIABLE
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”.
3.2 CREATING METHODS
Figure 3.2.0
– Parts of a Method
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.
1. Access modifier – determines the method’s accessibility to other members of
the class and/or other inherited class.
2. Return type – Should be explicitly specified when declaring a method since
this will determine what data type to be return. A return type could be
primitive type or void type (returns nothing).
3. Method name/Identifier –can be used when the method needs to be invoked
at any point in program by calling method name.
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. – Instance method Figure 3.3.1. – Static method
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.
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.
● Constructors are always called whenever an object is created.
● 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.
● How important is destructor?
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.
● What is a garbage collector?
Closure Thanks for helping Tom out! You really are great! Thanks for the help in saving the
world!
Figure 6.2 – Java Error classes Figure 6.3 –Java Exception classes
We will narrow down our lesson and focus on the exception class hierarchy (figure
6.3).
To prevent a program execution to stop in a certain line, one must anticipate and
consider handling abnormal conditions. These conditions are being represented by
standard exception classes. Consider the example code below.
The sample program above contains a semantic error that will cause the termination of
the execution flow of the program. Length of a String primitive data type cannot be
counted if it contains null value (this occurs when users try to input nothing in a field).
Without exception handling, it will provide the sample code will terminate the flow of
execution.
How to handle exception?
Basically, we wouldn’t want our code to abnormally terminate because of any reasons.
Java has essential customized keywords upon handling exceptions – try, catch, throw,
and finally. These keywords have their own blocks and role in handling exceptions. Try
block is where program statements are being contained. If by any chance exception
occurs within the try block, your code can throw the exception into the catch block and
handle it in some rational manner without the JVM terminating the execution of the
program. These exception is thrown outside the try block and could also be prompted
as such to users to identify the line/s with exception. Finally block must be executed
after try block is completed.
Consider this example:
The program contains semantic error trying to access the index 4. Knowing that
indexes of array starts at 0, the above example array is already defined with a length of
4. In this case, it will throw and exception and will terminate the flow of execution in
the line “int I = arr[4];”. To fix it, we need to catch the exception and throw it so that
the “Hi, I want to execute” will be executed.
Points to remember:
1. In a method, statements should be put in its own try block and provide
exception handlers since there can be many statements that might throw
exception.
2. One can specify the exception handler in the catch block provided however,
that the exception specified is associated with the exception of the program
statement within the try block. There can be more than one catch block to
catch possible exceptions indicated by its argument and must be the name of
the class that inherits from the throwable class.
3. There can only be one finally block. Try blocks can have zero or more catch
blocks.
4. Finally block will always be executed whether or not the try block contains
exceptions. If by any chance try block contains exceptions, finally block will be
executed after the catch block. Finally block is used commonly in cleaning up
codes.
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=AOvVAW2
QCyyUHL4XGlls0wpUGC8j&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
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
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
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
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
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
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
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.
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.
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.