Programming
Programming
…Programming……………
SUBMISSION DATE:
1
Summative Feedback:
Internal verification:
2
TABLE OF CONTENTS
I. Overview.........................................................................................................................................4
II. Procedural programming.............................................................................................................4
1. Definition........................................................................................................................................
2. Some principles of procedural programming.................................................................................
3. Pros and Cons of Procedural Programming....................................................................................
III. Object-orientated programming..................................................................................................5
1. Definition........................................................................................................................................
2. Structure of object-oriented programming.....................................................................................
3. Four basics of OOP.........................................................................................................................
4. Pros and Cons of OOP..................................................................................................................
IV. Event-driven programming........................................................................................................14
1. Definition......................................................................................................................................
2. Some principles of event-driven programming............................................................................
3. Pros and Cons...............................................................................................................................
V. The different of the procedural, object-orientated, and event-driven paradigms......................15
1. The procedural, object-orientated, and event-driven paradigms..................................................
2. Procedural Programming and Object-Oriented Programming.....................................................
VI. An analysis of suitable IDEs.....................................................................................................16
1. IDE................................................................................................................................................
2. Some suitable IDEs.......................................................................................................................
VII. Compare the procedural, object-orientated, and event-driven paradigms used in given source
code of an application..........................................................................................................................18
1. Examples.......................................................................................................................................
2. Evaluate the source code of an application which implements the procedural, object-
orientated. 20
VIII. References..............................................................................................................................20
3
I. Overview.
It is quite important to secure and run the software effectively in projects. The investigation
programming paradigms are necessary for the job. The term programming paradigm refers to a style
of programming. In another way, programming paradigms are a way to classify programming
languages based on their features. It does not refer to a specific language, but rather it refers to the
way you program. This report includes research about procedural, object-orientated, and event-
driven programming.
A procedure can store local data that is not accessible from outside the procedure’s scope and can
also access and modify global data variables.
Procedural Programming.
4
point has its data and logic. In a program system, variables have certainly visible scopes. In a program,
functions work independently of each other. Data is converted back and forth through function call
parameters. Dividing a program into functions allows multiple people to participate in the program’s
construction. Each person constructs one or more functions independently of the other. This approach
leads to a new concept – abstraction. Abstraction can be thought of as the ability to observe a thing
without considering its internal details.
In a procedural program, we just need to know what a particular function can do. It doesn’t matter
how it does the job, as long as the function is reliable, you can use it without knowing how it does its
job. This is called functional abstraction (also known as specialization) and is the foundation of
procedural programming.
OOP focuses on the objects that developers want to manipulate rather than the logic required to
manipulate them. This approach to programming is well-suited for programs that are large, complex,
5
and actively updated or maintained. This includes programs for manufacturing and design, as well as
mobile applications; for example, OOP can be used for manufacturing system simulation software.
Classes: are user-defined data types that act as the blueprint for individual objects, attributes, and
methods.
Objects: are instances of a class created with specifically defined data. Objects can correspond to
real-world objects or an abstract entity. When class is defined initially, the description is the only
object that is defined.
Methods: are functions that are defined inside a class that describe the behaviors of an object. Each
method contained in class definitions starts with a reference to an instance object. Additionally, the
subroutines contained in an object are called instance methods. Programmers use methods for
reusability or keeping functionality encapsulated inside one object at a time.
Attributes: are defined in the class template and represent the state of an object. Objects will have
data stored in the attributes field. Class attributes belong to the class itself.
6
3. Four basics of OOP.
a. Encapsulation.
Encapsulation is defined as the wrapping up of data under a single unit. It is the mechanism that
binds together code and the data it manipulates. Another way to think about encapsulation is, it is a
protective shield that prevents the data from being accessed by the code outside this shield.
The variables or data of a class is hidden from any other class and can be accessed only
through any member function of its own class in which it is declared.
Encapsulation can be achieved by declaring all the variables in the class as private and
writing public methods in the class to set and get the values of variables.
Some advantages of encapsulation: data hiding, increased flexibility, reusability, and
testing code is easy.
Encapsulation in Java.
Example:
public class Student {
private String name;
private int khoa;
public Student() {
}
7
public class TestStudent {
Result:
Ten: Pham Ha Ngan
Khoa: 12
b. Abstraction.
Abstraction is the property by virtue of which only the essential details are displayed to the user.
The trivial or the non-essentials units are not displayed to the user.
Data abstraction may also be defined as the process of identifying only the required
characteristics of an object ignoring the irrelevant details. The properties and behaviours of an object
differentiate it from other objects of similar type and also help in classifying or grouping the objects.
Abstract classes and Abstract methods:
- An abstract class is declared with an abstract keyword while an abstract method
is declared without implementation.
- An abstract class may or may not have all abstract methods. Some of them can
be concrete methods.
- There can be no object of an abstract class. That is, an abstract class cannot be
directly instantiated with the new operator.
Some advantages of Abstraction:
- It reduces the complexity of viewing the things.
- Avoids code duplication and increases reusability.
- Helps to increase the security of an application of program as only important
details are provided to the user.
Example:
package Abstraction;
8
return color;
}
}
double length;
double width;
@Override
double area() {
return length * width;
}
@Override
public String toString() {
return "Rectangle color is " + super.getColor() + " and area is : " + area();
}
}
System.out.println(s2.toString());
}
}
Result:
Shape constructor called
Rectangle constructor called
Rectangle color is Yellow and area is : 20.0
c. Inheritance.
Inheritance is a mechanism in which one object acquires all the properties and behaviours of a
parent object. It is an important part of OOP.
The idea behind inheritance is that you can create new classes that are built upon existing
classes. The inherited class can reuse methods and fields of the parent class.
9
Reusability: is a mechanism which facilitates you to reuse the fields and methods of an
existing class when creating a new class.
To reduce the complexity and simplify the language, multiple inheritance is not supported in
Java.
Example:
public class Father {
private String name;
private int age;
public Father() {
super();
}
10
System.out.println(getName() + " " + moTa);
}
}
}
}
Result:
Thich choi bong ro
Son choi rat hay
Thich choi da bong
d. Polymorphism.
Polymorphism is the ability of an object to take many forms. To simply put, polymorphism in
Java allows performing the same action in many different ways.
Polymorphism in Java can be performed by two different methods:
- Method Overloading: a process that can create multiple methods of the same name
in the same class, and all the methods work in different ways. Method overloading
occurs when there is more than one method of the same name in the class.
- Method Overriding: a process when the subclass has the same method as declared
in the parent class.
Some advantages of Polymorphism:
- It provides reusability to the code.
- A single variable can be used to store multiple data values.
- With lesser lines of code, it becomes easier for the programmer to debug code.
Example:
public class DaGiac {
private int soCanh;
private double kichThuoc[];
11
}
}
this.kichThuoc = kichThuoc;
this.soCanh = kichThuoc.length;
}
import java.util.Scanner;
12
public static void main(String[] args) {
double kt[] = { 3.0, 4.0, 6.0 };
try {
TamGiac t = new TamGiac(kt);
System.out.println("Chu vi: " + t.chuVi() + ", Dien tich: " +
t.dienTich());
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("Nhap so canh: ");
Scanner in = new Scanner(System.in);
int n = in.nextInt();
double kt2[] = new double[n];
for (int i = 0; i < n; i++) {
System.out.printf("Canh[%d]= ", i);
kt2[i] = in.nextDouble();
}
in.close();
try {
DaGiac daGiac = new DaGiac(kt2);
System.out.println(daGiac.chuVi());
} catch (Exception e) {
e.printStackTrace();
}
}
}
Result:
13
Object-Oriented programs tend to be slower and use up a high amount of memory.
Over-generalization.
Programs built using this paradigm may take longer to be created.
A set of functions that handle events. Depending on the implementation these can be
blocking or non-blocking.
A mechanism for binding the registered functions to events.
The main loop constantly polls for new events and calls the matching event handler when a
registered event is received.
14
Suitability for Graphical Interfaces.
Simplicity of programming.
It is one good way to model systems that need to be both asynchronous and reactive.
It can be implemented using hardware interrupts, which will reduce the power used
by the computer.
It allows sensors and other hardware to easily interact with software.
Cons:
Difficult to find the error.
Programs with complex Graphical User Interface (GUI) may be slower to load and
run than simpler programs particularly if RAM is insufficient.
Provides character user interface Provides command writing in Provides graphical user interface
to write the commands. modules. to create the programs.
Commands are written in linear Objects and functions are Actions are defined on events.
fashion and executed also in prepared for interaction to These events could be occurred
linear fashion. perform specific tasks. by mouse clicking and moving
or keyboard strokes.
Focuses on sequential execution Focuses on objects or data and Focuses on selecting user
of steps. facilitate to secure it from interface.
unauthorized access.
Most common languages which Most common languages which Most common languages which
follow this paradigm are Basic, follow this paradigm are follow this paradigm are Visual
Fortran and COBOL. Smalltalk, C++, and JAVA. Basic and C#.
15
Procedural Programming Object-Oriented Programming
Program is divided into small parts called Program is divided into small parts called
functions. objects.
Function is more important than data. Data is more important than function.
16
2. Some suitable IDEs.
These are some IDEs suitable for different paradigms, devices, and programming languages:
Eclipse: It functions by having a base workspace and an extensible plugin environment where
we can download and customize the workspace available. It supports debugging and profiling.
It has a drag and drop functionality and allows us to analyze the code using static analysis. If
you are comfortable in eclipse IDE, you can code in any famous language like Python, Java, and
C++. The OS supports for this IDE are Windows, Linux, and macOS.
Screenshot of Eclipse.
Visual Studio: It has a wide functioning which allows it to develop almost anything. It also
supports IntelliSense coding for C++. It can be used in both Windows and MAC and allows us
to create applications for any platform. It enables us to test apps and correct errors on the go.
17
Eclipse and Visual Studio Code are primarily classified as "Integrated Development
Environment" and "Text Editor" tools respectively.
"Does it all", "Integrates with most of tools" and "Easy to use" are the key factors why
developers consider Eclipse; whereas "Powerful Multilanguage IDE", "Fast" and "Front-end
develop out of the box" are the primary reasons why Visual Studio Code is favored.
Visual Studio Code is an open source tool with 78.4K GitHub stars and 10.9K GitHub forks.
In my opinion, I prefer to use Eclipse for Java programming. The Eclipse IDE is a well-known
open-source framework that was originally released in late 2001 and has been long favored for
Java code development. Although initially tailored to Java, the IDE is highly extensible and has
support for many languages including C, C++, C#, Java, and several others. Its fan
base numbers in the millions and its users are pleased with the code highlighting and refactoring
options, version control system integration, and advanced debugging features. Eclipse is being
continuously developed and updated, with releases currently on a 13-week cycle. With the
concept of open-source at the very heart, it has an exceptionally active community and
worldwide contributors to the project.
a. Procedural paradigm.
Code:
public class HCN {
float chieuDai;
float chieuRong;
public HCN() {
18
}
Result:
Chu vi h1: 18.00, dien tich 20.00
b. Object-orientated paradigm.
Code:
import java.util.Scanner;
Result:
19
Nhap do dai 2 canh a, b:
4
5
Chu vi: 18.00, dien tich: 20.00
A significant difference lies in the usage of access specifiers in object-oriented programs. Access
specifiers protect data from unauthorized access and are implementations of the data encapsulation
principle mentioned above. Due to the data encapsulation and abstraction principles, programs designed
in object-oriented programming are much more secure and based on the real world.
VIII. References.
Procedural Programming, Wikipedia, https://en.wikipedia.org/wiki/Procedural_programming
Procedural Programming, deepsource, https://deepsource.io/glossary/procedural-programming/
Sagar B. , 2021, Procedural Programming, hackr.io, https://hackr.io/blog/procedural-
programming
Object-Oriented Programming, Wikipedia, https://en.wikipedia.org/wiki/Object-
oriented_programming
Alexander S. Gillis, Object-Oriented Programming (OOP), TechTarget,
https://searchapparchitecture.techtarget.com/definition/object-oriented-programming-OOP
Event-Driven Programming, Wikipedia, https://en.wikipedia.org/wiki/Event-
driven_programming
What is An Integrated Development Environment (IDE), Veracode,
https://www.veracode.com/security/integrated-development-environment
20