Disclaimer: This is an example of a student written essay.
Click here for sample essays written by our professional writers.

Any opinions, findings, conclusions or recommendations expressed in this material are those of the authors and do not necessarily reflect the views of UKEssays.com.

Abstraction Polymorphism Inheritance And Encapsulation Information Technology Essay

Paper Type: Free Essay Subject: Information Technology
Wordcount: 4422 words Published: 1st Jan 2015

Reference this

Abstraction refers to the feature in object oriented language to represent the essential features without showing the background details or the explanations. Classes use this concept to hide the details and are defined as a list of abstract attributes. In abstraction we can make the class abstract. An abstract class is one that cannot be instantiated but other functionalities are the same and the member fields, constructors and the methods are all accessed in the same way. The abstract cannot be instantiated so the class has to be subclassed to have much use out of it. A parent class contains the common functionality of a number of child classes but the parent class itself cannot use those functionality.

Get Help With Your Essay

If you need assistance with writing your essay, our professional essay writing service is here to help!

Essay Writing Service

Polymorphism – This concept in object oriented programming is defined as the ability of an object to take many forms. The common use of polymorphism occurs when a parent class reference is used to refer to a child class object. This concept is a result of the fact that the classes has their own name space. Within a class the names assigned will not conflict with the names which are outside the class. Method names are also protected. The name of a method in one class can’t conflict with method names in other classes; two very different classes could implement identically named methods.

When a request is sent to an object to do something the message tells the name of the method that the object has to perform. The methods are a part of an object interface. Different objects have different methods having the same name so the meaning has to be resolved correctly. The same message sent to two different objects could invoke two different methods. 

Advantage of using polymorphism is that it simplifies the programming interface. It permits conventions to be established that can be reused in class after class. Rather than using a new name each time a new function is added to the program, the same name can be used by either changing the number of arguments or the type of arguments. The interface can be signified as a set of abstract functionality which is different from the classes that is implementing them.


Assume that three subclasses (Cow, Dog and Snake) have been created based on the Animal abstract class, each having their own speak() method.

public class Animal


public static void main(String args[])

Cow aCow = new Cow(“Betty”);

Dog aDog = new Dog(“Ceaser”);

Snake aSnake = new Snake(“Adam”);

instance = newCow; instance.speak();

instance = newDog; instance.speak();

instance = newSnake; instance.speak();


Inheritance – Inheritance in objected oriented paradigm is the ability of a class to have access to the properties and methods of other classes while using its own properties and functionalities. One of the use of it can be an employee records system. In this a generic employee class can be created with states and some functions that are common to all of the employees. In addition to that more specific classes can be added for salaried and hourly employees. The generic class created is called the parent class and all the other classes are called the subclasses. Inheritance enhances the ability to use the code again and again thus making the design simpler and cleaner. Using inheritance the information is much more manageable and in a hierarchical order. The common keywords for the inheritance concept are extends and implements. These keywords decides whether one object IS-A type of another. These keywords can be used to make one object acquire the properties of another object.


public class Bicycle


public int cadence;

public int gear;

public Bicycle(int startCadence, int startGear) {

gear = startGear;

cadence = startCadence;


public void setCadence(int newValue) {

cadence = newValue;


public void setGear(int newValue) {

gear = newValue;



A class declaration for a MountainBike class that is a subclass of Bicycle might look like this:

public class MountainBike extends Bicycle {

public int seatHeight;

public MountainBike(int startHeight, int startCadence, int startGear) {

super(startCadence, startGear);

seatHeight = startHeight;


public void setHeight(int newValue) {

seatHeight = newValue;



MountainBike inherits all the fields and methods of Bicycle and adds the field seatHeight and a method to set it. Except for the constructor, it is as if you had written a new MountainBike class entirely from scratch, with four fields

Encapsulation – Encapsulation is a method to bind or wrap the data and the codes that operates on the data into a single entity. This helps to keep the data secure, outside the interface and away from misuse. Encapsulation can be thought as a protective covering that prevents the code and the data from being accessed by other code outside the wrapper. For example the Dog class has a bark() method variable, data. The functionality of the bark() method is provided which describes the way the dog barks (eg inhale(), pitch, volume etc). The user does not need to know how the dog is barking. Thus encapsulation is achieved by describing which classes can use the member of an object. Thus the object is exposed to any class a certain interface- those members accessible to the class. The idea behind encapsulation is to avoid the users of an interface from depending on the parts of the implementation that may change in future and thus allowing the changes to be made more easily and without making changes to the user. For example and interface can be made to check that puppies can only be added to an object to the dog class. The members are defined as public, private or protected. This defines whether they are available to the sub-classes or all the classes or the defining class only.

Final – Final keyword can be used in classes, methods and fields. The final keyword is used in places where the user does not want variables, methods or a class to be modified.

Final Methods – By using this keyword the methods of a class can be made final. It signifies that no changes to the method can be done. The method cannot be overridden by the subclasses. The methods can be made final where the implementation should not be changed and is critical to a state of an object. For example, you might want to make the getFirstPlayer method in this ChessAlgorithm class final:

class ChessAlgorithm {

enum ChessPlayer { WHITE, BLACK }

final ChessPlayer getFirstPlayer() {

return ChessPlayer.WHITE;



Final Classes:- In java the class organization is like this

class A{}

class B extends A{}

which results in a superclass A and a subclass B. But this type of organization can be modified by declaring the class to be final as final class A{} and thus the class A cannot be extended or subclassed. The benefit of using this feature is that there is a control over the class and it provides more security to the class as it cannot be extended. For example, java.lang.String is a final class. This means that the String class cannot be extended and the length() method cannot be overridden which might implement something different from returning the string length.

Final Fields:-  Final keyword can be used to define the fields to be final. This is different than declaring the methods or the class to be final. The fields once declared final cannot be changed or modified. The field which is set to be final can be set once for instance when the object is created. If any changes is tried to be made on the fields the compiler will generate the compile time errors and raise exceptions. Constants can be defines by using the final keyword, static and public. For example in a math program pi can be defined as:-

public class MathProgram {

public static final double pi = 3.14;


Static and Dynamic Polymorphism – Polymorphism can be broadly divided into two parts static and dynamic polymorphism. Static polymorphism is exhibited by overloaded functions and dynamic polymorphism is exhibited by using late binding.

Static Polymorphism – Static polymorphism can be described to an entity which exists in different forms at the same time. It involves the binding of functions on the sequence of arguments or the number of arguments. The parameters of the function are specified in the function declaration and thus the function are bound to calls at the compile time. This is called early binding because when the program is executed the calls are bound to the specified functions. The calls can be based on the sequence of arguments or the type of arguments or the number of arguments declared for each function. For example:

void add(int , int);

void add(float, float);

When the add() function is called the parameters provided will decide which function has to be executed. This resolution to decide which function has to be called is done at the compile time. Function overloading is an example of static polymorphism.

Dynamic Polymorphism – Dynamic polymorphism is defined as an entity which changes its form depending on the conditions. A function is said to show this feature when it exists in more than one form and calls to its different forms take place dynamically at the run time when the program is executed. This can be referred to as late binding. This makes the program more flexible allowing the different methods to be called depending on the condition. Method overriding is dynamic polymorphism.

Overloading – Polymorphism concept can be described by using overloading feature of the object oriented programming. The methods can have the same name but with different implementation. By overloading we can perform different functionalities depending on the number of parameters or the type of parameters. At run time the compiler resolves the actual methods. To create overloaded functions the method names have to be same with different number of arguments or types of arguments. Thus the following is an example of an overloaded markanswer method

void markanswer(String answer){ }

void markanswer(int answer){ }

Overriding – Overriding a method is defined as that the complete functionality of the method has been replaced. Overriding is done in the subclass or the child class where the method has different functionality than the parent class. To override the method a new method with the same name is created as the one defined in the parent class with the same signature. This will block the method defined in the parent and the functionality will not be accessed directly. By overriding we can define some behavior which can be specific to the child class. The child class can define the method of parent class with different requirements. For example

class Animal{

public void move(){

System.out.println(“Animals can move”);



class Dog extends Animal{

public void move(){

System.out.println(“Dogs can walk and run”);



Upcasting and downcasting – Complex programs can be easily build using the simple syntax and structure by using the upcasting or downcasting feature of object oriented programming which provides advantages like polymorphism or grouping of objects. In java the object of a subclass can be treated as an object of a superclass type. This feature is called upcasting which is done automatically. Downcasting is a feature in which the object of a superclass has to be downcasted to the object of subclass type. But this has to be done manually by the programmer. These are not like casting primitives from one to other. Taking the example of animal hierarchy.

Find Out How UKEssays.com Can Help You!

Our academic experts are ready and waiting to assist with any writing project you may have. From simple essay plans, through to full dissertations, you can guarantee we have a service perfectly matched to your needs.

View our services

Using the casting feature we are only changing the label of the object not the object as a whole. For example, if you create a Cat and upcast it to Animal, then the object doesn’t stop from being a Cat. It’s still a Cat, but it’s just treated as any other Animal and it’s Cat properties are hidden until it’s downcasted to a Cat again.


Cat c = new Cat();


Mammal m = c; //Upcasting

But downcasting must always be done manually.

Cat c1 = new Cat();

Animal a = c1; //Automatic upcasting to animal

Cat c2 = (Cat) a; //Manual downcasting back to a Cat

Object Oriented Programming and Procedural Programming Language

Procedural programming languages involves creating a step by step procedure that is used to build applications using a number of instructions. All the instructions are executed in some order defined by the language. The procedural programming evolves around the idea that the algorithms are implemented by using methods and the data which is accessible and changeable. Object oriented programming is more closer the way the real world works. Programs in object oriented is created by using many entities called as objects. These objects are the building blocks of an application and have some behavior and specific purpose involved. In this objects cannot access other objects data but instead can send a message to carry out some function or to request data.

Benefits of Object-Oriented programming include: 

Ability to simulate real-world event much more effectively.

Code is reusable thus less code may have to be written.

Data becomes active.

Better able to create GUI applications.

Programmers are able to reach their goals faster.

Programmers are able to produce faster, more accurate and better-written applications.

OOP has the advantage of inheritance, abstraction and polymorphism to provide data security and reusability.

Essay 2

An I/O stream defines an input source or an output destination. A stream can represent different types of sources and destinations, for example devices, disk files and memory arrays. Streams support different types of data for example bytes or characters and objects. Some streams transforms the data and others simply transfer the data. A stream is nothing but a sequence of dara.

A program uses the input stream to read data from the source. Detailed diagram is shown below:-

Reading information into a program.

Reading data into a program

A program uses output stream to to write data into destination. A detailed diagram is shown below:-

Writing information from a program.

Writing data from a program

There are two types of streams in Java :-

Byte Stream (read/write binary data)

Character Stream (read/write character data)

Byte Stream – Program uses byte stream to perform input and output of 8 bit bytes. All the byte stream classes come from InputStream and OutputStream. There are many byte stream classes. When the data is written to a binary stream the data is written to a stream which is a series of bytes which is the same as in the memory. The data is not changed. The binary data are written in a series of bytes.

Character Stream – Input and output implemented with byte streams translates to and from character set. The character stream classes comes from reader and writer. With the byte streams there are character stream classes that specialize in file I/O ie filereader and filewriter.

Character streams are often wrappers for the byte streams. The character stream utilizes the byte stream to perform the physical I/O, whereas the character stream manages the translation between characters and bytes. With character streams, your program reads and writes Unicode characters, but the stream will contain characters in the equivalent character encoding used by the local computer.

Data input stream and data output stream supports for creating data streams for the primitive data types. Serialization/deserialization is a process by which objects are stored and retrieved in an external file. Serialization is a process in which the object is written to a file and deserialization is a process in which the objects are retrieved from a file. In serialization the static members of a class are not written to a file. An array is also a type of an object and can be serialized and also of primitive type like int or double. Serialization is a method for writing a graph of objects into a stream of data. This stream of data can then be programmatically modified and the reverse process can be implemented that is called deserialization. The three main use of serialization are:-

As a persistence mechanism – If the stream being used is FileOutputStream, in that cane the data will be written to a file.

As a copy mechanism – If the stream being used is ByteArrayOutputStream, in that case the data will be written to a byte array in memory which can be used to create a copy of the original objects.

As a communication mechanism – If the stream being used comes from a socket, in that case the data is sent over to the receiving socket.

Serialization is implemented by using a pair of streams. There are four steps to make a class serializable. The steps are as follows :-

Implement the serializable interface.

Ensure that the instance level, defined state is serialized properly.

Ensure that the superclass is serialized properly.

Override the equals() and hascode() if required.

Persistence is one of the main feature in application development. Almost all the applications these days require persistent data and thus it is important for the application or the system to preserve the data entered by the application users. In java it is storing data in a relational database using SQL. Relational technique provides a method to share data between different application or between technologies that are part of some applications. Hibernate enables the programmer to provide database and even handles a state of persistent objects. Transient is meant that to create in the state by means of new. This kind of object is not connected with session of hibernate. It is normal object and can be changed into state. Transient is a keyword in java which shows It marks a member variable not to be serialized when it is persisted to streams of bytes. When an object is transferred through the network., the object has to be serialized. Serialization converts the object state to serial bytes. Member variables marked with the keywords transient keyword are not transferred, they are lost. Syntax :-

Private transient

Or Transient private

Persistence is something in which objects are connected with both data in a database and a given object of session class. Hibernate detects changes in them and put them to a database at the end of a session. Java persistence could be defined as storing anything to any persistence store in java programming language. There are many methods to persist data in java like jdbc, serialization, object database. Many of the data in general is persisted in databases specially relational databases. Many of the applications or web site that involves storing data, involving accessing relational database. Relational databases are standard persistence store for most corporations. Many java applications use java objects to model their application data because java is an object oriented language, storing java objects is a natural and common approach to persisting data from java. Many ways to access relational database from java. Jpa is many of the different specifications but seems to be the direction that java persistence is heading.

Essay 3

A collection represents a group of objects which is called as elements. Some collections are ordered and some are unordered. Some of them allow duplicate elements and some do not. Direct implementation of the interfaces are not allowed but it in turn provides implementation of subinterfaces like Set and List. These interfaces are typically used to pass collections around and modify where more generality is required. All general purpose collection implementation classes provides no argument constructors and standard constructors which creates an empty collection and a constructor with a single argument to type Collection, which creates a new collection with same elements as its argument. The latter constructor allows the user to make duplicate of any collections thus producing an equivalent collection of the desired implementation type.

The destructive methods which contains in the interface that is the methods that modify the collection on which they work are specified to throw unsupported operation exception if the collection won’t support the operation, if the calling would have no effect on the collection. For example sort(Collection) method on unchangeable collection, but it is not necessary to invoke the exception if the collection to be added is empty. Some collection implementation have restrictions on the elements that it contains. In fact some implementations avoid the null elements and have some restrictions on the types of their elements. When a try is made to query the presence of an wrong element may invoke an exception or it returns false, some implementations will show the former behavior and some will show the latter. In general when trying an operation on any ineligible element whose completion will not result in the insertion of an ineligible element into the collection may throw an exception otherwise it might not be complete. By the implementation unexpected results may result from the invocation of any function on a collection that might be started by another thread, but this involves direct invocations, passing the collection to a function that performs invocations and examining the collections. There are many methods in Collections framework interfaces are defined in terms of the equals method. When the implementations of different frameworks interfaces take the use of the some specified behavior of the object methods when the object implementing is correct.

Java.util contains all the collections framework, collection classes, event model, date and other utility classes. The collection API interface provides structures and the related operations on the interface. For example isEmpty, size, contains, remove, toArray. Some of the sample collections are ArrayList, Array, LinkedList, Stack, Hashtable. API is like the directory of Java language and has as index or collections of all the packages, classes and interfaces with all of their functions, variables and constructors. The collections and arrays which are the part of the collections framework and it helps for various algorithms with collection classes. There are various operations with sorting and searching. Sorting arrays – The treeset and treemap classes provides the sorting of sets and maps. Before the framework there was not built in help for the sorting arrays. All the sorting methods the items are comparable to one another and if they are not a class cast exception will be thrown. If the element type implements comparable then sort can be used or we have to implement comparator and use sort method. There are various different methods to implement the sorting of the arrays and two methods to sorting the primitive types of elements and four are for the sorting of the object arrays. For sorting arrays just calling the method arrays.sort() with the arrays as argument. Searching – Apart from the sorting the collections and arrays classes provides ways to search a list or array as well as find minimum and maximum values within a collection. Searching is much faster of the list or array is sorted like the binary search method. Example

public static int binarySearch(List list, Object key)

Array searching works like after using one of the sort method, then searching the element which is required. If the object in the collection doesn’t implement comparable then the comparator have to be implemented.

Equality – The classes also provides the equal method to compare two byte arrays. With array classes equality of any array of primitive or object type can be implemented. Two arrays are equal if the elements are in the same order. Checking equality with arrays of objects depends on the equals method of each object for checking equality.

Manipulation – The collections and arrays classes offer various ways of modifying the elements within a list or array. With a list the collection class allows you to manipulate the other interfaces Set and Map. The collection allows to replace all each element or copy the list or reverse the list or shuffle the list. Example

void fill(List list, Object element)

void copy(List source, List destination)

void reverse(List list)

The difference between the collection classes and the new implementations within the collection framework is that the new classes are not thread safe. If synchronization is not wanted then it is not used and things works faster but if collections is used in a multi-threaded environment where threads can modify the collection simultaneously, just the modifications needs to be synchronized. Vector and arrayList are similar to each other. ArrayList and vector both represents a growable array where the elements are accesses by an index. ArrayList is a part of the collection framework. The main difference between the ArrayList and Vector is that they are not synchronized objects and ArrayList are not. One object reference can be type cast into another object reference. The cast can be its own class type or to one of its subclass or superclass types or interface. The casting of object reference depends on the relation in the same hierarchy. When the cast is along the class hierarchy towards the root it is called upcasting. All of these entities are serializable.


Cite This Work

To export a reference to this article please select a referencing stye below:

Reference Copied to Clipboard.
Reference Copied to Clipboard.
Reference Copied to Clipboard.
Reference Copied to Clipboard.
Reference Copied to Clipboard.
Reference Copied to Clipboard.
Reference Copied to Clipboard.

Related Services

View all

DMCA / Removal Request

If you are the original writer of this essay and no longer wish to have your work published on UKEssays.com then please: