0% found this document useful (0 votes)
36 views

Java

This document provides an overview of algorithms and programming paradigms. It discusses algorithm definition, characteristics, types, and how to design an algorithm. It also covers the steps in program development including problem definition, design, coding, debugging, testing, and documentation. The document then discusses applications of algorithms and problem solving. It explains procedural programming, object-oriented programming, and event-driven programming paradigms. Finally, it demonstrates a books management system program and discusses debugging, coding standards, coding editors, and IDE usage.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views

Java

This document provides an overview of algorithms and programming paradigms. It discusses algorithm definition, characteristics, types, and how to design an algorithm. It also covers the steps in program development including problem definition, design, coding, debugging, testing, and documentation. The document then discusses applications of algorithms and problem solving. It explains procedural programming, object-oriented programming, and event-driven programming paradigms. Finally, it demonstrates a books management system program and discusses debugging, coding standards, coding editors, and IDE usage.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 77

PROGRAM TITLE: BTEC COMPUTING……………………………………………..

UNIT TITLE : PROGRAMMING………………………………………………………

ASSIGNMENT NUMBER: ASIGNMENT NUMBER 1……………………………….

ASSIGNMENT NAME: BOOKS MANGEMENT SYSTEM………………………….

SUBMISSION DATE: 09/24/2022………………………………………………………

DATE RECEIVED:09/14/2022 ………………………………………………………..

TUTORIAL LECTURER: MS.LUONG THAO HIEU…………………………………

WORD COUNT: 8139…………………………………………………………………..

STUDENTNAME: nguyen van thinh..

STUDENTID: BKC13107 ..................

MOBILENUMBER: 0325925546 .......


Summative Feedback:

Internal verification:
Table of Contents
I.INTRODUCTION ................................................................................................................. 4

II.ALGORITHM ...................................................................................................................... 5

Algorithm Defenition ........................................................................................................... 5

Characteristics of an algorithm ............................................................................................ 8

Properties of Algorithm: ...................................................................................................... 8

Types of Algorithms: ........................................................................................................... 9

Advantages of Algorithms: .................................................................................................. 9

Disadvantages of Algorithms: ............................................................................................. 9

How to Design an Algorithm? ....................................................................................... 10

III. STEPS IN PROGRAM DEVELOPMENT. .................................................................... 12

Problem Definition: ........................................................................................................... 12

Program Design: ................................................................................................................ 12

Coding: ........................................................................................................................... 12

Debugging: ..................................................................................................................... 13

Testing: .......................................................................................................................... 13

Documentation: .............................................................................................................. 13

Maintenance: .................................................................................................................. 13

IV. Applications of algorithms and problem solving ............................................................ 13

III. Programming paradigms ................................................................................................ 23

1 .Procedure Programming ................................................................................................ 23

A .METHODS: .............................................................................................................. 23

Syntax of a function ....................................................................................................... 24

Key Features of Procedural Programming..................................................................... 26

Advantages and Disadvantages of Procedural Programming ........................................ 26

2. Object Oriented Programming ....................................................................................... 32

Benefits of OOP ............................................................................................................. 33

Object ................................................................................................................................. 33

Class ................................................................................................................................... 33
OOPS concepts are as follows: .......................................................................................... 35

Benefits of OOP ............................................................................................................. 43

Disadvantages of OOP .................................................................................................. 44

3. event-drivent programming ........................................................................................... 45

4.the relationship between programming paradigms ......................................................... 46

II.DEMO ................................................................................................................................ 47

1.Content and requirements ............................................................................................... 49

2.Analysis problem ............................................................................................................ 49

3.Program solving .............................................................................................................. 51

3.1. classes used in this program : ................................................................................. 51

3.2 Coding và execute .................................................................................................... 52

4.DEBUGGING

III. Debug process .................................................................................................................. 62

IV. Coding standard ............................................................................................................... 64

Purpose of Having Coding Standards: ............................................................................... 64

Advantages of Coding Guidelines: .................................................................................... 67

V.Coding editer ...................................................................................................................... 67

VI.Using IDE ......................................................................................................................... 67

VII. REFERENCES

I.INTRODUCTION

java is a popular programming language, created in 1995.

It is owned by Oracle, and more than 3 billion devices run Java.

It is used for:

*Mobile applications (specially Android apps)

*Desktop applications

*Web applications

*Web servers and application servers

*Games
*Database connection

*And much, much more!

In addition

Java works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc.)

It is one of the most popular programming language in the world

It is easy to learn and simple to use

It is open-source and free

It is secure, fast and powerful

It has a huge community support (tens of millions of developers)

Java is an object oriented language which gives a clear structure to programs and allows code
to be reused, lowering development costs

As Java is close to C++ and C#, it makes it easy for programmers to switch to Java or vice
versa

II.ALGORITHM

Algorithm Defenition

The word Algorithm means ” A set of rules to be followed in calculations or other problem-
solving operations ” Or ” A procedure for solving a mathematical problem in a finite number
of steps that frequently involves recursive operations”.

Therefore Algorithm refers to a sequence of finite steps to solve a particular problem.


Algorithms can be simple and complex depending on what you want to achieve.
Algorithm

Set of rules to obtain


Input the expected output Output
from the given input

1.1 what’s algorithm


it can be understood by taking the example of cooking a new recipe. To cook a new
recipe, one reads the instructions and steps and executes them one by one, in the given
sequence. The result thus obtained is the new dish cooked perfectly. Every time you use
your phone, computer, laptop, or calculator you are using Algorithms. Similarly,
algorithms help to do a task in programming to get the expected output.
The Algorithm designed are language-independent, i.e. they are just plain instructions that
can be implemented in any language, and yet the output will be the same, as expected.

Example 1: Traffic Lights


Here’s an algorithm we frequently experience; the next time you're in your car stuck at a red
light, consider the algorithm the traffic light is executing.
1.2 the flowchart illustration.
Characteristics of an algorithm
WHAT’RE THE CHARACTERISTICS OF AN ALGORITHM ?

Well-definited
Well-definited
inputs
output

Characteristics
Clear and
of an algorithm Finite-ness
unambiguous

Language
feasible
independent

2.1 . illustration of characteristics

As one would not follow any written instructions to cook the recipe, but only the standard
one. Similarly, not all written instructions for programming is an algorithms. In order for
some instructions to be an algorithm, it must have the following characteristics:
• Clear and Unambiguous: The algorithm should be clear and unambiguous. Each of
its steps should be clear in all aspects and must lead to only one meaning.
• Well-Defined Inputs: If an algorithm says to take inputs, it should be well-defined
inputs.
• Well-Defined Outputs: The algorithm must clearly define what output will be yielded
and it should be well-defined as well.
• Finite-ness: The algorithm must be finite, i.e. it should terminate after a finite time.
• Feasible: The algorithm must be simple, generic, and practical, such that it can be
executed with the available resources. It must not contain some future technology or
anything.
• Language Independent: The Algorithm designed must be language-independent, i.e.
it must be just plain instructions that can be implemented in any language, and yet the
output will be the same, as expected.
Properties of Algorithm:
• It should terminate after a finite time.
• It should produce at least one output.
• It should take zero or more input.
• It should be deterministic means giving the same output for the same input case.
• Every step in the algorithm must be effective i.e. every step should do some work.
Types of Algorithms:
There are several types of algorithms available. Some important algorithms are:
1. Brute Force Algorithm: It is the simplest approach for a problem. A brute force
algorithm is the first approach that comes to finding when we see a problem.
2. Recursive Algorithm: A recursive algorithm is based on recursion. In this case, a
problem is broken into several sub-parts and called the same function again and again.
3. Backtracking Algorithm: The backtracking algorithm basically builds the solution by
searching among all possible solutions. Using this algorithm, we keep on building the
solution following criteria. Whenever a solution fails we trace back to the failure point and
build on the next solution and continue this process till we find the solution or all possible
solutions are looked after.
4. Searching Algorithm: Searching algorithms are the ones that are used for searching
elements or groups of elements from a particular data structure. They can be of different
types based on their approach or the data structure in which the element should be found.
5. Sorting Algorithm: Sorting is arranging a group of data in a particular manner
according to the requirement. The algorithms which help in performing this function are
called sorting algorithms. Generally sorting algorithms are used to sort groups of data in
an increasing or decreasing manner.
6. Hashing Algorithm: Hashing algorithms work similarly to the searching algorithm.
But they contain an index with a key ID. In hashing, a key is assigned to specific data.
7. Divide and Conquer Algorithm: This algorithm breaks a problem into sub-problems,
solves a single sub-problem and merges the solutions together to get the final solution. It
consists of the following three steps:
• Divide
• Solve
• Combine
8. Greedy Algorithm: In this type of algorithm the solution is built part by part. The
solution of the next part is built based on the immediate benefit of the next part. The one
solution giving the most benefit will be chosen as the solution for the next part.
9. Dynamic Programming Algorithm: This algorithm uses the concept of using the
already found solution to avoid repetitive calculation of the same part of the problem. It
divides the problem into smaller overlapping subproblems and solves them.
10. Randomized Algorithm: In the randomized algorithm we use a random number so it
gives immediate benefit. The random number helps in deciding the expected outcome.

Disadvantages of Algorithms:
Advantages of Algorithms:

• It is easy to understand. • Writing an algorithm takes a long time


• An algorithm is a step-wise so it is time-consuming.
representation of a solution to a given • Understanding complex logic through
problem. algorithms can be very difficult.
• In Algorithm the problem is broken • Branching and Looping statements are
down into smaller pieces or steps difficult to show in Algorithms(imp)
hence, it is easier for the programmer
to convert it into an actual program.
How to Design an Algorithm?

In order to write an algorithm, the following things are needed as a pre-requisite:

1. The problem that is to be solved by this algorithm i.e. clear problem definition.
2. The constraints of the problem must be considered while solving the problem.
3. The input to be taken to solve the problem.
4. The output to be expected when the problem is solved.
5. The solution to this problem, is within the given constraints.
Then the algorithm is written with the help of the above parameters such that it solves the
problem.
Example: Consider the example to add three numbers and print the sum.

• Step 1: Fulfilling the pre-requisites


As discussed above, in order to write an algorithm, its pre-requisites must be fulfilled.
1. The problem that is to be solved by this algorithm: Add 3 numbers and print
their sum.
2. The constraints of the problem that must be considered while solving the
problem: The numbers must contain only digits and no other characters.
3. The input to be taken to solve the problem: The three numbers to be added.
4. The output to be expected when the problem is solved: The sum of the three
numbers taken as the input i.e. a single integer value.
5. The solution to this problem, in the given constraints: The solution consists of
adding the 3 numbers. It can be done with the help of ‘+’ operator, or bit-wise, or
any other method.
• Step 2: Designing the algorithm
Now let’s design the algorithm with the help of the above pre-requisites:
Algorithm to add 3 numbers and print their sum:
1. START
2. Declare 3 integer variables num1, num2 and num3.
3. Take the three numbers, to be added, as inputs in variables num1, num2, and num3
respectively.
4. Declare an integer variable sum to store the resultant sum of the 3 numbers.
5. Add the 3 numbers and store the result in the variable sum.
6. Print the value of the variable sum
7. END
• Step 3: Testing the algorithm by implementing it.
In order to test the algorithm, let’s implement it in java language.
PROGRAM:

OUTPUT:
One problem, many solutions: The solution to an algorithm can be or cannot be more
than one. It means that while implementing the algorithm, there can be more than one
method to implement it. For example, in the above problem to add 3 numbers, the sum can
be calculated in many ways like:
• + operator
• Bit-wi9se operators
• . . etc

III. STEPS IN PROGRAM DEVELOPMENT.

Problem Definition:

• The first step in the process of program development is the thorough understanding
and identification of the problem for which is the program or software is to be
developed.
• In this step the problem has to be defined formally.
• All the factors like Input/output, processing requirement, memory requirements, error
handling, interfacing with other programs have to be taken into consideration in this
stage.

Program Design:

• The next stage is the program design. The software developer makes use of tools like
algorithms and flowcharts to develop the design of the program.
o Algorithm
o Flowchart

Coding:

• Once the design process is complete, the actual computer program is written, i.e. the
instructions are written in a computer language.
• Coding is generally a very small part of the entire program development process and
also a less time consuming activity in reality.
• In this process all the syntax errors i.e. errors related to spelling, missing commas,
undefined labels etc. are eliminated.
• For effective coding some of the guide lines which are applied are :
o Use of meaningful names and labels of variables,
o Simple and clear expressions,
o Modularity with emphasis on making modules generalized,
o Making use of comments and indenting the code properly,
o Avoiding jumps in the program to transfer control.

Bổ sung hình vẽ code python, C#....

Debugging:

• At this stage the errors in the programs are detected and corrected.
• This stage of program development is an important process. Debugging is also
known as program validation.
• Some common errors which might occur in the programs include:
o Un initialization of variables.
o Reversing of order of operands.
o Confusion of numbers and characters.
o Inverting of conditions eg jumping on zero instead of on not zero.

Testing:

• The program is tested on a number of suitable test cases.


• A test plan of the program has to be done at the stage of the program design itself.
• This ensures a thorough understanding of the specifications.
• The most trivial and the most special cases should be identified and tested.
• It is always useful to include the maximum and minimum values of all variables as
test data.

Documentation:

• Documentation is a very essential step in the program development.


• Documentation help the users and the people who maintain the software.
• This ensures that future modification if required can be done easily. Also it is
required during redesigning and maintenance.

Maintenance:

• Updating and correction of the program for changed conditions and field experience
is accounted for in maintenance.
• Maintenance becomes essential in following situations:
o Change in specification,
o Change in equipment,
o Errors which are found during the actual execution of the program.

IV. Applications of algorithms and problem solving

1.Here, I will give an example of basic operations on a one-dimensional array


Using some algorithm to interact with elements .
Such as :input , export , looking for , eliminate , arrangerment,..
Below coding illustrate the algorithms by JAVA language throught netbean
1. Algorithms addition : input the value of element in array
Data representation : Program including :
Int [] a
Int n : the number of elements wanting to add on array.
DIAGRAM:

PROGRAM :
OUTPUT :

2. Algorithm output : export the all the value of element in array


After entering all the data for the array, I will create an algorithm that outputs all the data of
the element in the array (here is an array a with n characters)
Data representation : Program including :
Int [] a
Int n : the number of elements wanting to add on array
DIAGRAM :

PROGRAM :
OUTPUT:

3 . Algorithm find : Looking for that whether the value “x” is in the array “a”
or not . if it’s true , program will print out the position of value “x”.
Data representation : Program including :
Int [] a
Int n : the number of elements wanting to add on array

PROGRAM :
OUTPUT:

4.ALGORITHM ELEMINATE : Get rid of value at any position in the array


Data representation : Program including :
Int [] a
Int n : the number of elements wanting to add on array
PROGRAM :

OUTPUT:
5 . ALGORITHM ARRANGERMENT: sorting the value of elements from smallest to
bigest .
Data representation : Program including :
Int [] a
Int n : the number of elements wanting to add on array
PROGRAM :

OUTPUT:

6.ALGORITHM INSERT : add any value of elenment in array


Data representation : Program including :
Int [] a
Int n : the number of elements wanting to add on array
PROGRAM:

OUTPUT:
III. Programming paradigms

1 .Procedure Programming

Procedure Programming (PP): is a traditional programming technique in which a program


is divided into functions (subroutines).

Each program can also be divided into many other subroutines to simplify their work.

To make it easy to understand, in structured programming, the program will be divided into
many subfunctions and called in the main function. Some structure-oriented languages like
C, Pascal...

Example :

A .METHODS:

In this tutorial, we will spare some time and discuss functions. In java, a method is the same
as a function. All the functions must be defined within a class. By that, we can summarize by
defining a Java method as a function belonging to a class. A function is a named unit of code
that can be invoked anywhere in the class.
Syntax of a function

▪ Access specifier – this shows the scope of availability of a fuction. ‘Public’ means that
the function can be called from aywhere in the program. We have other access
specifiers such as private and protected.Protected, the method can only be called within
the class and its subslcasses. Private can oly be called inside the class

▪ Modifier – ‘static’ is optional in a fuction defination. In this case static means the
function is a not an object of the main class but a method that belongs to the main class.

▪ Retur type – We have functions that return a value and functions that do not return
anything. Void, means that the function does not have a return value. If the fuction was
to return a value, replace void with the data type of the returned value.

▪ Function name – This the name of the function

▪ Parameter list – it informs the compiler about the data type it will receive and the
value to be returned.

FOR EXAMPLE :
public static void Export(int[] a , int n){}:

Export: name of function.

Int[] a , int n : parameter .

EXAMPLE 2:

I have created an one dimensional array named A , n is the number of elements of the array .
Immediately after entering all the data for the elements then I called the “export” function to
output all the data entered to the screen.

CONCLUSION:
Key Features of Procedural Programming

The key features of procedural programming are given below:

• Predefined functions: A predefined function is typically an instruction identified by


a name. Usually, the predefined functions are built into higher-level programming
languages, but they are derived from the library or the registry, rather than the
program. One example of a pre-defined function is ‘charAt()’, which searches for a
character position in a string.

• Local Variable: A local variable is a variable that is declared in the main structure of
a method and is limited to the local scope it is given. The local variable can only be
used in the method it is defined in, and if it were to be used outside the defined
method, the code will cease to work.

• Global Variable: A global variable is a variable which is declared outside every


other function defined in the code. Due to this, global variables can be used in all
functions, unlike a local variable.

• Modularity: Modularity is when two dissimilar systems have two different tasks at
hand but are grouped together to conclude a larger task first. Every group of systems
then would have its own tasks finished one after the other until all tasks are complete.

• Parameter Passing: Parameter Passing is a mechanism used to pass parameters to


functions, subroutines or procedures. Parameter Passing can be done through ‘pass
by value’, ‘pass by reference’, ‘pass by result’, ‘pass by value-result’ and ‘pass by the
name’.

Advantages and Disadvantages of Procedural Programming

Procedural Programming comes with its own set of pros and cons, some of which are
mentioned below.
Advantages

• Procedural Programming is excellent for general-purpose programming


• The coded simplicity along with ease of implementation of compilers and interpreters
• A large variety of books and online course material available on tested algorithms,
making it easier to learn along the way
• The source code is portable, therefore, it can be used to target a different CPU as well
• The code can be reused in different parts of the program, without the need to copy it
• Through Procedural Programming technique, the memory requirement also slashes
• The program flow can be tracked easily

Disadvantages

• The program code is harder to write when Procedural Programming is employed


• The Procedural code is often not reusable, which may pose the need to recreate the
code if is needed to use in another application
• Difficult to relate with real-world objects
• The importance is given to the operation rather than the data, which might pose
issues in some data-sensitive cases
• The data is exposed to the whole program, making it not so much security friendly

FOR EXAMPLE :

The following program will denote the nature and functionality of procedural
programming

Data representation : Program including :


Double [] a .
Int n : the number of elements wanting to add on array.
Int chon : the option that ilustrate the function selected in menu() function.

PROGRAM :

OUTPUT:
Then , I initialize the do-while loop to print out the menu and input the variable “chon”.

System will re-print out the menu and record the value of varibale “chon” after executed
the function before.
Next using Switch-case statement to drive system to function which illustrated by the
variable “chon”.

Finally , 5 options are 5 algorithm represented in section”Algorithm” belove.

1. Input the value of elements in array.


2.Deleting value of any element

3.print out the value of elements

4.Findding an element whether in array or not .


5.arrange the value from smallest to biggest

6. Adding one element in array


2. Object Oriented Programming

Object Oriented programming (OOP) is a programming paradigm that relies on the


concept of classes and objects. It is used to structure a software program into simple, reusable
pieces of code blueprints (usually called classes), which are used to create individual instances
of objects. There are many object-oriented programming languages including
JavaScript,c++,java, and python

A class is an abstract blueprint used to create more specific, concrete objects. Classes often
represent broad categories, like Car or Dog that share attributes. These classes define what
attributes an instance of this type will have, like color, but not the value of those attributes for
a specific object.

Classes can also contain functions, called methods available only to objects of that type.
These functions are defined within the class and perform some action helpful to that specific
type of object.

For example, our Car class may have a method repaint that changes the color attribute of our
car. This function is only helpful to objects of type Car, so we declare it within the Car class
thus making it a method.

Class templates are used as a blueprint to create individual objects. These represent specific
examples of the abstract class, like myCar or goldenRetriever. Each object can have unique
values to the properties defined in the class.

For example, say we created a class, Car, to contain all the properties a car must
have, color, brand, and model. We then create an instance of a Car type object, myCar to
represent my specific car.

We could then set the value of the properties defined in the class to describe my car, without
affecting other objects or the class template.

We can then reuse this class to represent any number of cars.


Benefits of OOP

• OOP models complex things as reproducible, simple structures


• Reusable, OOP objects can be used across programs
• Allows for class-specific behavior through polymorphism
• Easier to debug, classes often contain all applicable information to them
• Secure, protects information through encapsulation

a/
Object
This is the basic unit of object-oriented programming. That is both data and function that
operate on data are bundled as a unit called an object.
Class
When you define a class, you define a blueprint for an object. This doesn't actually define
any data, but it does define what the class name means, that is, what an object of the class
will consist of and what operations can be performed on such an object.
OOP has four basic concepts on which it is totally based. Let's have a look at them
individually −
Books : class name .
Id , name , author , language , …. are properties
Private , public , protected are access modifiers
private - Only the current class will have access to the field or method.

protected - Only the current class and subclasses (and sometimes also same-package
classes) of this class will have access to the field or method.

public - Any class can refer to the field or call the method.

Public Books(){} : constructor is a block of codes similar to the method. It is called when an
instance of the class is created. At the time of calling constructor, memory for the object is
allocated in the memory.

Access Modifier: Defines the access type of the method i.e. from where it can be accessed in
your application. In Java, there are 4 types of access specifiers:

public: Accessible in all classes in your application.

protected: Accessible within the package in which it is defined and in its subclass(es)
(including subclasses declared outside the package).

private: Accessible only within the class in which it is defined.

default (declared/defined without using any modifier): Accessible within the same class
and package within which its class is defined.

The return type: The data type of the value returned by the method or void if it does not
return a value.

Method Name: The rules for field names apply to method names as well, but the convention
is a little different.

Parameter list: Comma-separated list of the input parameters that are defined, preceded by
their data type, within the enclosed parentheses. If there are no parameters, you must use
empty parentheses ().
Exception list: The exceptions you expect the method to throw. You can specify these
exception(s).

Method body: It is the block of code, enclosed between braces, that you need to execute to
perform your intended operations.

Message Passing: Objects communicate with one another by sending and receiving
information to each other. A message for an object is a request for execution of a procedure
and therefore will invoke a function in the receiving object that generates the desired results.
Message passing involves specifying the name of the object, the name of the function and the
information to be sent.

Now that we have covered the basic prerequisites, we will move on to the 4 pillars of OOPs
which are as follows. But, let us start by learning about the different characteristics of an
Object-Oriented Programming Language.

OOPS concepts are as follows:

Let us now discuss the 4 pillars of OOPs:

a)Encapsulation

Encapsulation is achieved when the object of the class maintains the private state. Other
objects are not allowed to access these objects; despite that, the other objects can only access
or invoke the list of public functions.
In simple words, encapsulation means wrapping the data, methods into the class, i.e., into a
single unit. Encapsulation automatically accepts the data hiding by making variables private
and access them with the help of methods that are public. Access modifiers are used to
accomplished data hiding.

EXAMPLE:

PROGRAM

OUTPUT:

b)Abtraction:

Abstraction in OOP is used to collect more detail and show the only appropriate amount of
the object’s attributes. The primary purpose of Abstraction in OOP is to hide unnecessary
information from the outside world. That helps in reducing the effort and complexity in
programming. Fetching, removing, and selecting the user information is known as
Abstraction. Programmers can use the same data and information for other instances and
programs with a few changes or no modifications.

EXAMPLE:
c): Encapsulation

It is defined as the wrapping up of data under a single unit. It is the mechanism that binds
together the code and the data it manipulates. Another way to think about encapsulation is
that it is a protective shield that prevents the data from being accessed by the code outside
this shield.

Technically, in encapsulation, the variables or the data in a class is hidden from any other
class and can be accessed only through any member function of the class in which they are
declared.

In encapsulation, the data in a class is hidden from other classes, which is similar to what data-
hiding does. So, the terms “encapsulation” and “data-hiding” are used interchangeably.

Encapsulation can be achieved by declaring all the variables in a class as private and writing
public methods in the class to set and get the values of the variables.

EXAMPLE :

d): Inheritance

Inheritance is an important pillar of OOP (Object Oriented Programming). It is the mechanism


in Java by which one class is allowed to inherit the features (fields and methods) of another
class.

Let us discuss some frequently used important terminologies:


Superclass: The class whose features are inherited is known as superclass (also known as base
or parent class).

Subclass: The class that inherits the other class is known as subclass (also known as derived
or extended or child class). The subclass can add its own fields and methods in addition to the
superclass fields and methods.

Reusability: Inheritance supports the concept of “reusability”, i.e. when we want to create a
new class and there is already a class that includes some of the code that we want, we can
derive our new class from the existing class. By doing this, we are reusing the fields and
methods of the existing class.

EXAMPLE:

PROGRAM:

People{} is super class


Class student{} is subclass extends from class People {} , this class has addition property is
mark.
Class Lecture{} is also subclass extends from class People{} , this class has addition property
is salary .

Pillar 4: Polymorphism

It refers to the ability of object-oriented programming languages to differentiate between


entities with the same name efficiently. This is done by Java with the help of the signature
and declaration of these entities.

Polymorphism in Java is mainly of 2 types:

1.Overloading

2. Overriding

Example 1:

Overloading:

Method Overloading allows different methods to have the same name, but different signatures
where the signature can differ by the number of input parameters or type of input parameters,
or a mixture of both.
Method overloading is also known as Compile-time Polymorphism, Static Polymorphism,
or Early binding in Java. In Method overloading compared to parent argument, child
argument will get the highest priority.
Overriding :

In any object-oriented programming language, Overriding is a feature that allows a


subclass or child class to provide a specific implementation of a method that is already
provided by one of its super-classes or parent classes. When a method in a subclass has the
same name, same parameters or signature, and same return type(or sub-type) as a method
in its super-class, then the method in the subclass is said to override the method in the
super-class.

Method overriding is one of the way by which java achieve Run Time Polymorphism.The
version of a method that is executed will be determined by the object that is used to invoke it.
If an object of a parent class is used to invoke the method, then the version in the parent class
will be executed, but if an object of the subclass is used to invoke the method, then the version
in the child class will be executed. In other words, it is the type of the object being referred
to (not the type of the reference variable) that determines which version of an overridden
method will be executed.

EXAMPLE:
OUTPUT :

c/

Benefits of OOP

• We can build the programs from standard working modules that communicate with one
another, rather than having to start writing the code from scratch which leads to saving
of development time and higher productivity,
• OOP language allows to break the program into the bit-sized problems that can be
solved easily (one object at a time).
• The new technology promises greater programmer productivity, better quality of
software and lesser maintenance cost.
• OOP systems can be easily upgraded from small to large systems.
• It is possible that multiple instances of objects co-exist without any interference,
• It is very easy to partition the work in a project based on objects.
• It is possible to map the objects in problem domain to those in the program.
• The principle of data hiding helps the programmer to build secure programs which
cannot be invaded by the code in other parts of the program.
• By using inheritance, we can eliminate redundant code and extend the use of existing
classes.
• Message passing techniques is used for communication between objects which makes
the interface descriptions with external systems much simpler.
• The data-centered design approach enables us to capture more details of model in an
implementable form.
While it is possible to incorporate all these features in an OOP, their importance depends
upon the type of project and preference of the programmer. These technology is still
developing and current products may be superseded quickly.
Developing a software is easy to use makes it hard to build.

Disadvantages of OOP

• The length of the programmes developed using OOP language is much larger than the
procedural approach. Since the programme becomes larger in size, it requires more
time to be executed that leads to slower execution of the programme.
• We can not apply OOP everywhere as it is not a universal language. It is applied only
when it is required. It is not suitable for all types of problems.
• Programmers need to have brilliant designing skill and programming skill along with
proper planning because using OOP is little bit tricky.
• OOPs take time to get used to it. The thought process involved in object-oriented
programming may not be natural for some people.
• Everything is treated as object in OOP so before applying it we need to have excellent
thinking in terms of objects.
EXAMPLE :
import java.io.*;

class OOPS {
public static void main(String[] args)
{
System.out.println("GfG!");

Dog dog = new Dog();


dog.name = "Bull dog";
dog.color = "Brown";
dog.bark();
dog.run();

Cat cat = new Cat();


cat.name = "Rag doll";
cat.pattern = "White and slight brownish";
cat.meow();
cat.run();

Animal animal = new Animal();

animal.name = "My favourite pets";


animal.run();
}
}

class Animal {
String name;
public void run()
{

System.out.println("Animal is running!");
}
}

class Dog extends Animal {

/// the class dog is the child and animal is the parent

String color;
public void bark()
{
System.out.println(name + " Wooh ! Wooh !"
+ "I am of colour " + color);
}
}

class Cat extends Animal {

String pattern;

public void meow()


{
System.out.println(name + " Meow ! Meow !"
+ "I am of colour " + pattern);
}
}

3. Event-driven programming

Event-driven programming is a programming paradigm in which the flow of program


execution is determined by events - for example a user action such as a mouse click, key press,
or a message from the operating system or another program. An event-driven application is
designed to detect events as they occur, and then deal with them using an appropriate event-
handling procedure. The idea is an extension of interrupt-driven programming of the kind
found in early command-line environments such as DOS, and in embedded systems (where
the application is implemented as firmware).

EXAMPLE:
4.the relationship between programming paradigms
In structured programming, the problem is taken, and analyzed from top to bottom, when
you find a logical situation too complex, you try to divide it into parts (like pizza slices).
The idea is to divide the logical complexity into functions or procedures that are easy to
understand and solve. The classic, divide and win.

If properly worked, functions or procedures will appear that are reused in different parts of
the code.

With OOP, on the other hand, the approach is to discover the elements involved in the
problem (people, documents, products, etc.) by analyzing the data (properties) that each one
manages, together with the methods (which are nothing other than functions or methods).
Then, you create derived classes (sub-classes) of the main classes (for example of people:
employees, suppliers, customers, etc.) that reuse the methods and properties of the main
class (inherit) and add the specific ones.

In event-oriented programming, procedures, objects, methods etc. They "fire" when an


"event" occurs (mouse click, keyboard click, window activation, etc.) and is common when
you have to program a GUI. Generally, the code is distributed in a structured way in the
application (modules, libraries) where classes and subclasses are defined. If the application
has to work with events, in some part of the code the events will be associated with the
procedures, functions or methods that manage them.

Personally, I use a combination of these three paradigms. But in any case, it depends on
what type of program is being solved.
Object oriented:

1. Main focus is on 'data security'. Hence, only objects are permitted to access the
entities of a class.
2. Entire program is divided into objects.
3. Access specifier are "public", "private", "protected".
4. Inheritance achieved in three modes public private and protected.
Procedural oriented:

1. Main focus is on "how to get the task done" i.e. on the procedure or structure of a
program
2. Large program is divided into units called functions.
3. No access specifier observed.
4. Their is no provision of inheritance.

II.DEMO

In this demo, continuing from problem analysis in as1, I apply the knowledge of basic
programming combined with object-oriented programming to design a Book
management software for the company.

public class Books {

private int id;


private String name;
private String author;
private String language;
private double price;
private String publishdate;
private String ISBN;
private long number;
}
1.Content and requirements

I will write a program to manage the students in my class. The program includes the following
main functions:

-import: With this function, users can add Book input from the keyboard.

-export : with this function , users can see the information about books

-delete : user can eliminate 1 book in class

-look for : find out 1 book in class through ID.

-sort : arrange the books’s spive from smallest to biggest

-edit: This function is used to update book information

- find by author : users can find 1 book by author

-find by name : users can find 1 book by name

- find by spices : users can find 1 book by spice

-find by languages : users can find 1 book by languages

- exit : this function , system will exit and return to menu

2.Analysis problem

When running program , system will print out “ how many elements do you want”
And you have to input all the information about object .

Here is main menu of program and you have 2 option . 1 is Books managerment , 2 . tools
managerment

3 . exit

When choosing 1 , system will execute menuBooks() and print out the below menu :

When choosing 2 , system will execute menuTools() and print out the below menu:
3.Program solving

3.1. classes used in this program :

This section , I will develop my program . My program include 3 class

1. Books{}:

Class Books has 8 properties and 2 methods (input() and output()).

2. Testbooks{}

Class Testbooks has 2 properties are n ( type : integer ) and list(type : Bools[])
And 7 methods in menu book.
3. Tools{}

Class Tools has 2 properties are n ( type : integer ) and list(type : Bools[])
And 6 methods in menu Tools.
3.2 Coding và execute

a) Books manegement

1.input()

PROGRAM:

OUTPUT:

1. Inport Books();

PROGRAM
OUTPUT:

2.export{}
OUTPUT:

3.delete{}

OUTPUT:

4.look for{}

OUTPUT:
5.edit{}

PROGRAM:

OUTPUT:

6.exit{}
OUTPUT:

b)Tools manegements:

1. Find by author{}

OUTPUT:

2.find by name{}
OUTPUT:

3 . find by spices{}

OUTPUT:

4.findBylanguage{}
OUTPUT:

5.sortbycost{}

OUTPUT:
4.DEBUGGING

4.1 open class Mainmenu{}

4.2 Set a breakpoint


4.3

Start the local debugger by either using the keyboard shortcuts of Ctrl + F5 or Ctrl + Shift +
F5 or using the Debug menu or selecting ‘Debug‘ on right clicking the project in the Projects
window

4.4

Press F8 to let the control flow normally, F7 to go into a method, Ctrl + F7 to come out of a
block, F5 to let the control flow till next breakpoint, F4 to run to cursor and Shift + F5 to end
the show.
III. Debug process

how to debug a java program.

For example, I write a program in Netbean as follows:


In order to debug, we have to let the program run in line with each command to check. But to
do so, we must mark the breakpoint to start compiling line by line.

With netbean, you put the mouse pointer on the command line to set as a breakpoint and click
to form a pink line like the image above.

Then go to menu Debug > Debug Project. Debug interface appears as follows:
IV. Coding standard

Different modules specified in the design document are coded in the Coding phase according
to the module specification. The main goal of the coding phase is to code from the design
document prepared after the design phase through a high-level language and then to unit test
this code.

Good software development organizations want their programmers to maintain to some well-
defined and standard style of coding called coding standards. They usually make their own
coding standards and guidelines depending on what suits their organization best and based on
the types of software they develop. It is very important for the programmers to maintain the
coding standards otherwise the code will be rejected during code review.

Purpose of Having Coding Standards:

A coding standard gives a uniform appearance to the codes written by different engineers.

It improves readability, and maintainability of the code and it reduces complexity also.

It helps in code reuse and helps to detect error easily.

It promotes sound programming practices and increases efficiency of the programmers.


Some of the coding standards are given below:

Limited use of globals:

These rules tell about which types of data that can be declared global and the data that can’t
be.

Standard headers for different modules:

For better understanding and maintenance of the code, the header of different modules should
follow some standard format and information. The header format must contain below things
that is being used in various companies:

Name of the module

Date of module creation

Author of the module

Modification history

Synopsis of the module about what the module does

Different functions supported in the module along with their input output parameters

Global variables accessed or modified by the module

Naming conventions for local variables, global variables, constants and functions:

Some of the naming conventions are given below:

Meaningful and understandable variables name helps anyone to understand the reason of
using it.

Local variables should be named using camel case lettering starting with small letter (e.g.
localData) whereas Global variables names should start with a capital letter (e.g. GlobalData).
Constant names should be formed using capital letters only (e.g. CONSDATA).

It is better to avoid the use of digits in variable names.

The names of the function should be written in camel case starting with small letters.

The name of the function must describe the reason of using the function clearly and briefly.

Indentation:
Proper indentation is very important to increase the readability of the code. For making the
code readable, programmers should use White spaces properly. Some of the spacing
conventions are given below:

There must be a space after giving a comma between two function arguments.

Each nested block should be properly indented and spaced.

Proper Indentation should be there at the beginning and at the end of each block in the
program.

All braces should start from a new line and the code following the end of braces also start
from a new line.

Error return values and exception handling conventions:

All functions that encountering an error condition should either return a 0 or 1 for simplifying
the debugging.

On the other hand, Coding guidelines give some general suggestions regarding the coding
style that to be followed for the betterment of understandability and readability of the code.
Some of the coding guidelines are given below :

Avoid using a coding style that is too difficult to understand:

Code should be easily understandable. The complex code makes maintenance and debugging
difficult and expensive.

Avoid using an identifier for multiple purposes:

Each variable should be given a descriptive and meaningful name indicating the reason behind
using it. This is not possible if an identifier is used for multiple purposes and thus it can lead
to confusion to the reader. Moreover, it leads to more difficulty during future enhancements.

Code should be well documented:

The code should be properly commented for understanding easily. Comments regarding the
statements increase the understandability of the code.

Length of functions should not be very large:

Lengthy functions are very difficult to understand. That’s why functions should be small
enough to carry out small work and lengthy functions should be broken into small ones for
completing small tasks.

Try not to use GOTO statement:

GOTO statement makes the program unstructured, thus it reduces the understandability of the
program and also debugging becomes difficult.
Advantages of Coding Guidelines:

Coding guidelines increase the efficiency of the software and reduces the development time.

Coding guidelines help in detecting errors in the early phases, so it helps to reduce the extra
cost incurred by the software project.

If coding guidelines are maintained properly, then the software code increases readability and
understandability thus it reduces the complexity of the code.

It reduces the hidden cost for developing the software.

V.Coding editer

1.Definition

Text Editor does not have a built-in compiler or interpreter inside it, which means that to run
the application, you must use an external compiler separately. These Text Editors are often
used for web application development, such as Sublime text, Atom, Bracket, Notepad++,
Vscode, …

VI.Using IDE

An IDE, or Integrated Development Environment is a software suite that consolidates basic


tools required to write and test software.

Developers use numerous tools throughout software code creation, building and testing.

The IDE has a built-in compiler or interpreter inside it that helps you execute code directly
while programming applications, such as Visual Studio, Esclipe, Xcode, Android studio, …

Throughout the process of writing, creating, and testing software, developers employ a variety
of tools. Text editors, code libraries, bug tracking software, compilers, and test platforms are
among the most common development tools. A developer who does not use an IDE has to
choose, deploy, integrate, and monitor these tools individually.

IDEs increase programmer productivity by combining common activities of writing software


into a single application: editing source code, building executables, and debugging.

Most IDE capabilities, such as intelligent code completion and automatic code creation, are
designed to save time by eliminating writing out complete character sequences. The integrated
toolset aims to make software development easier while also detecting and reducing code
errors and typos.
Other popular IDE features assist developers in streamlining their workflow and problem-
solving. IDEs parse code as it is written, identifying problems caused in real time. Most IDEs
also include syntax highlighting, which employs visual clues to discern grammar in the text
editor.

❖ Advantages and disadvantages of IDE


• Advantages
o Less time and effort
o Project management
o Enforce project or company standards
• Disadvantages
o Learning curve
o A sophisticated IDE may not be a good tool for beginning programmers
o Will not fix bad code, practices, or design
Netbeans

1.Download

Visit the site https://netbeans.apache.org/download/index.html and choose Download the


most recent version.

In the Installers section, choose to download according to your platform, here I use Windows
so I will choose the platform as Windows
Select the link after the line We suggest the following mirror site for your download

Choose where to save the file and select Save.

Right-click the NetBeans IDE icon after the download has finished and choose Run as
administrator.
The settings interface pops up showing the supported programming languages. You can go to
Customize to choose more or less languages. Select Next to continue the installation process.

Check the box I accept the terms in the license agreement and select Next.
The installer will automatically find where to install the NetBeans IDE and locate the newly
installed JDK. If you want to change the installation drive, you can change it back by selecting
Browse and choosing where you want to install. Then select Next to continue the installation
process.

Check the Check for Update check box to check if NetBeans has an updated version
immediately. Select Install to proceed with the installation.
Select Finish to finish the installation of NetBeans IDE.

2.Create new project

Launch the NetBeans IDE.

In the NetBeans IDE, choose File | New Project....


In the New Project wizard, expand the Java category and select Java Application as shown
in the following figure:
In the Name and Location page of the wizard, do the following (as shown in the figure below):

Click Finish.
3.create a new class

Create a new Java Application(as part 2)

Right-click on the Source Packages folder and select New -> Java Package. Enter your
webmail user name for the name of the project

Right-click the user name package and select New -> Java Package...
Name your class Menu. Choose Finish.

Conclution

VII. REFERENCES

1.Tutorials List - Javatpoint

2. GeeksforGeeks | A computer science portal for geeks

You might also like