You are on page 1of 9

See discussions, stats, and author profiles for this publication at: https://www.researchgate.

net/publication/276203962

A Mathematical Modeling of Object Oriented Programming Language : a case


study on Java programming language

Article · April 2014

CITATIONS READS

3 1,126

2 authors:

Manoj Kumar Srivastav Asoke Nath


CHAMPADANI ADARSH SHARMIK VIDYAMANDIR St. Xavier's College, Kolkata
35 PUBLICATIONS   84 CITATIONS    278 PUBLICATIONS   2,058 CITATIONS   

SEE PROFILE SEE PROFILE

Some of the authors of this publication are also working on these related projects:

Building a Movie Recommendation System using SVD algorithm View project

Hash and Salt based Steganographic Approach with Modified LSB Encoding View project

All content following this page was uploaded by Asoke Nath on 12 May 2015.

The user has requested enhancement of the downloaded file.


Current Trends in Technology and Science
ISSN: 2279-0535. Volume: 3, Issue: 3

A Mathematical Modeling of Object Oriented Programming


Language : a case study on Java programming language
Manoj Kumar Srivastav*, Dr.Asoke Nath
Designation : Student * ,Organization : Indira Gandhi National Open University*,
Email ID* : mksrivastav2011@rediffmail.com,
Designation : Associate Professor, Organization : Department of Computer Science, St. Xavier‟s College
(Autonomous), Kolkata, India Email ID : asokejoy1@gmail.com

Abstract - Srivastav et al already developed method to The basic objective of any computer program is to get
describe procedural language using mathematical optimal solution of the given problem. The same problem
model. As a case study the authors taken C-language can be solved in different ways even though the output
as the procedural language. Using simple concept the of the program may exactly be the same. The same
authors tried to develop some unified mathematical problem can be solved using different languages also. So
model to explain procedural language. In the present therefore, the main point to be noted here is to get the
work the authors made an attempt to describe Object solution of a problem in minimum time and to solve
Oriented language using simple mathematical model. many problems in some stipulated time to make the
The class, object defined using simple concept of solution optimal.
optimality test of decision function. The inheritance 1.1 Introduction to Procedural language:
also describe in terms of set concept. In procedural language a program comprises of several
instructions. A program creates a set of instructions and
Keywords - [class, object, mathematical modeling, the computer carries them out. So, a procedural language
object oriented language, Procedural language]. is divided into functions and each function has clearly
defined interface to other function in the program. The
1. INTRODUCTION idea of breaking a program into functions can be further
Any mathematical problem depends on the process of its extended by grouping a number of functions together into
computation. It is mainly depends on the number of steps a larger entity called a module which is a group of
taken to solve a problem and the time required to solve a components. Dividing a program into functions and
problem. A mathematical problem can be solved using modules is termed as structured programming. If the size
various methods/algorithms but we want to find a best of the program grows even larger and more complex then
possible solution out of all those solutions. One can claim procedural language may produce of the following type
that a problem can have an optimal solution if it is of problems.
giving an optimal value. The optimal solution may be (a) Reuse of same code is restricted.
obtained if the number of steps to solve a problem is (b) Unrelated functions and data provide a poor model
optimal and the time taken to solve a problem will be of programming.
minimum. Now optimal solution and feasible solution
can be defined in the context of any Object oriented 2. RELATION AMONG TIME, COST AND
programming language as follows: AREA OF A RELATED PROBLEM
(i) Optimal solution: values of the decision variable Relation between time, cost and coverage of a related
which satisfied the condition in lowest effort/cost. problem in programming language:
(ii) Feasible solution: all possible solutions that include Let T =total time for computation of a problem
exception handling such as divide by zero, A=total coverage area of the related problem
exceeding array Index upper bound ,format error , Ce =total expenditure cost to prepare a problem
data type error etc. These type of exceptional Cv = total valuation cost a problem after preparing it.
handling generally not possible in procedural 2.1Expenditure cost on solving a problem in a
language such as in C-language. programming language follows the following rule:
All the programming language follows the time and 2.1.1Note: The relationship between Procedural
space complexity of a program. The following cases can language and Object Oriented language can be further
occur during the running of a program: explored as follows:

Table-1: Space and time requirement Procedural Object –Oriented Remarks


Maximum space Maximum time Language Language
Minimum space Minimum time (i)when the total
Minimum space Maximum time Ce T1 Ce T2 coverage area of a
Maximum space Minimum time with respect to problem is constant.
procedural (ii) T1>=T2 where
Optimal space Optimal time
language
Copyright © 2014 CTTS.IN, All right reserved
134
Current Trends in Technology and Science
ISSN: 2279-0535. Volume: 3, Issue: 3

T1, T2 corresponds (ii) A1,A2


to computation time corresponds to total
taken in Procedural coverage area of
and Object oriented procedural
programming language and object
language oriented language
respectively. respectively.
(i)when the total Cv 1/(T1*A1) Cv (i)When both time
Ce A1 Ce A2 computation time of Hence, (T2*A2) and area vary.
With respect to a problem is Cv =p/(T1*A1) Hence (ii)Here, p and r are
constant Cv=r*(T2* variation constant.
(ii) A1 >=A2 where A2)
A1,A2 corresponds 2.3.Comparision of valuation cost in the programming
to coverage area language with the symbol stated above:
taken in Procedural
Let T1=T2=T, A1=A2=A
and Object oriented
programming
language Procedural Language Object Oriented
respectively. Programming
Ce Ce (T2* A2) (i) When both time Cv=p/(T*A) Cv=r*(T*A)
T1*A1 Hence and area vary.
Hence, Ce=k*(T2*A2) (ii) Here, m and k Conclusion: From the above table it is clear that
Ce are variation valuation cost in procedural language is less than equal to
=m*T1*A1 constant. valuation cost in object Oriented Language.
Optimality Test: Let Ce1 represents Expenditure cost in
Conculsion: Expenditure cost in the procedural language
Procedural Language and Ce2 represents Expenditure cost
is >= Object oriented programming language.
in Object Oriented Language.
2.2Valuation cost of solved problem follows the Let Cv1 rep represents valuation cost in Procedural
following rule Language and Cv2 represents valuation cost in Object
Oriented Language.
Procedural Object – Remarks Since, Ce1>=Ce2 which implies that -Ce1<=-Ce2
Language Oriented And Cv1<=Cv2
Language Therefore ( Cv1-Ce1 )<= (Cv2-Ce2 )
(i)when the total Hence, we can conclude thatObject Oriented
Cv 1/T1 Cv T2 coverage area Programming is giving more profit than procedural
A1,A2 of a
language.
procedural
language and object
oriented language 2.4 Conculsion: We may conclude that we can get an
respectively. optimal cost from object Oriented programming if the
(ii) T1,T2 problem becomes larger and better cost in procedural
corresponds to language if the problem is smaller with small time of
valuation time of
computation.
program developed
using procedural
language and object 3. MATHEMATICAL DESCRIPTION OF OBJECT
oriented language ORIENTED PROGRAMMING LANGUAGE
respectively. Object-Oriented programming language is based on the
(i)when the total following properties:
Cv 1/A1 Cv A2 valuation time T1, (i) Class and Object
T2 remains (ii)Data Abstraction and Encapsulation
constant in (iii)Inheritance
procedural (iv)Polymorphism
language and object Class is a collection of objects of similar type.
oriented language
respectively.
Copyright © 2014 CTTS.IN, All right reserved
135
Current Trends in Technology and Science
ISSN: 2279-0535. Volume: 3, Issue: 3

3.1 Class concept in Java Programming Explain with Gender :Male


real life Example: Object-P1
Consider Person as a class .Now we can have some Name Of Person : Aditya
properties associated with this class Person such as Skin color : White
1.Attributes of Person: Gender : Male
(i) Name of Person
(ii) Gender Object-P2
(iii)Skin color Set: A set is well- defined collection of distinct objects of
(iv) Hair color etc. our perception or our thought ,to be conceived as a
Now these are general properties which form the whole.
template of the class Person,and above properties are Set of sets: we have defined a set as a collection of its
called as attributes of the class. elements. If the elements be set themselves, then we have
Now Person class may have some functionality such as a family of sets, or set of sets. For example ,the collection
1.Talking of all subsets of a non-empty set S is a set of sets. This
2.Walking set is said to be the power set of S and is denoted by
3.Eating P(S).
Thus in short class have Class may be defined as follows:
1.Class Name In set theory and its application throughout
2.Properties or Attributes mathematics, a class is collection of sets where each
3.Common function set has some common property. The members of a
Now we are going to create object of the class.i.e., actual class is countable.
instance of the class. Let us say that we have created So therefore, class={ sets : where all members have
object such as “Aayush ”,” Aditay”. Both will have the some common property}
same attributes and functionality but have different The basic form of a class in object –oriented
attribute value: programming is
class classname
Name Of Person :----------------------------------- {
Skin color : ---------------------------------- parameter declaration;
Gender :---------------------------------- Method declaration;

Now this is just a template, called as „class‟ and object as


Object: The members of a class is called an object. Since
instance of the class. the members of a class is a set .Therefore it should
possesses some property. Objects are real world entity
Name of Person : Aayush such as pen, chair,
Color : white tables,etc.
Similar comparision between set theory and object oriented language :

Object-Oriented Programming is a methodology or Thus class is a set of object and object is a set having
paradigm to design a program using classes and some common feature. We can write the class by the
objects. Any entity that has state and behavior is symbol , , ……etc and object by X,Y, Z…….
known as an object. For example: chair, pen, table, etc.
etc. It can be physical and logical. 3.2 MEMORY SPACE :An object is in Java is
Collection of objects is called class. It is a logical essentially a block of memory that contains space to store
entity. all instance variables. i.e each object of a class contain an
Any programming problem is analyzed in terms of address in memory space.
objects and the nature of communication between Memory space for an object={address of the instance
them. An object takes up space in the memory and variables: variables are members of class}
has an associated address like structure in C. Creating an object is also referred to as instantiating an
object. Objects in Java are created using the new
Copyright © 2014 CTTS.IN, All right reserved
136
Current Trends in Technology and Science
ISSN: 2279-0535. Volume: 3, Issue: 3

operator.The new operator creates an object of the Domain Range


specified class and returns a reference to that object Class Object Class
object.Therefore the address of the new object is An object is a HCF The name of Q1
changed. software object is H.
bundle that The following
encapsulates steps are
Initial object has New object have variables and taken in the
an address new address methods range set:- (i)
operating on Declaring an
Therefore we define a mapping f:(X, ) (Y, ) such that those object
variables. (ii)instantiatin
f(address of object)=address of new object[ Here X and Y So in domain g an
are object set and are set of sets with respect to object X part here object/initializ
hcf(int a,int b) ing an object.
and are set of sets with respect to object Y.Actually is taken as So, there is
represents classes for domain and represents method new address
function and a, for the new
class for range in the above function and f represents b ,r are object.
main function. variables.Ther
fore there is
some address
Progam1 : Input two numbers a, b. Calculate and print for the object
H.C.F of two numbers. variable.
import java.io.*;
Class HCF Program2 :-Write a program to input an integer and
{ display whether it is even or odd.
int hcf(int a, int b) import java.io.*;
{ Class q2
int r; {
while((r=a%b)!=0) public static void main(string args[]) throws IO
{ Exception
a=b; {
b=r; int n;
} BufferedReader br=new BufferedReader (new
return b; InputStreamReader(System.in));
} System.out.print(“\n Enter any integer=”);
} n=Integer.parseInt(br.readLine());
class q1 if((n%2)==0)
{ System.Out.println(n+”is even”);
public static void main(String args[])throws IO else
Exception System.Out.println(n+”is odd”);
{ }
int a, b,h; }
{ Explaination :-The mapping defined in the above
Buffered Reader br= new Buffered Reader(new Input
program is in the following way: f :(X, ) (X, )
Stream
Reader(System.in));
System.out.print(“Enter ist number=”); i.e we are taking f as an identity mapping.
a=Integer.parseInt(br.readLine());
System.out.print(“Enter 2nd number=”); Program 3: Write a program by creating constructor
b=Integer.parseInt(br.readLine()); to show that each object has its own copy of the
HCF H=new HCF(); instance variables of its class.
h=H.hcf(a,b); class Student
System.out.println(“\na=”+a+b”=”+b+” HCF=”+h); {
} int roll_numb;
} int age;
Let explain the above program:- void display()
{
System.out.print(roll_numb);
System.out.println(age);
}
Student(int Rn, int ag)
{
Copyright © 2014 CTTS.IN, All right reserved
137
Current Trends in Technology and Science
ISSN: 2279-0535. Volume: 3, Issue: 3

roll_numb=Rn; Now Class ={collection of object which share some


age =ag; common feature}
} Let =class={set of objects sharing some common
public static void main(String arg[]) property say p1}
{ ={object :each object has common property
Student shivam=new Student(1100,4); say p1}
Student subham=new Student(1105,2); Let =class={set of objects sharing some common
shivam.display(); property say p2}
subham.display(); ={object :each object has common
} property say p2 which includes property p1 also}
} i.e = {some extra property than the member of
Output }
1100 4 i.e.child class/subclass=parent class/superclass +some
1105 2 extra property
Explaination : Therefore, We can say that class is inheritance of class
Domain Range .
Object Class Object Class
If we think the above thing in the sense of memory view
An object is a Student Shivam Student
software bundle for the class we have
that encapsulates = S={address of object : object is a member of a class}
Shubham
variables and ={a1,a2,a3,……………an: ai R,set of real
methods operating numbers}
on those variables. .Each object has
its own copy of Since, = {some extra property than the member of
the instance }
So in domain part variables of its
here void display()
and student (int
class. = {a1,a2,a3,……………an: ai R,set of real numbers}
Rn, int ag) are {b1,b2,b3,………,bn for extra member of object
taken as method Therefore there :bi R, set of real number}
function and is new address ={a1,a2,a3,………an,b1,b2,b3………..bn}
roll_numb, for the objects
This property follows by the class is known as
age,Rn,ag as Shivam,Shubham
inheritance property.
variables.Therefore
Single level inheritance:
there is some
address for the = {some extra property than the member of }
variables of the Multilevel inheritance:
given class/object.. = {some extra property than the member of } .
Note:It is important to understand that each object has its Hierarchical inheritance:
own copy of the instance variables of its class.This = {some extra propertyp1 than the member of }
means that any changes to the variables of one object = {some extra propertyp2 than the member of }
have no effect on the variables of another. It is also
= {some extra property pn than the member of
possible to create two or more references to the same
}
object.
Multiple inheritance:
3.3 INHERITANCE: When one object acquires all the
properties and behaviors of parent object, i.e. known as = 1 {some extra property than the member of 1 }
inheritance. It provide code reusability. It is used to
= 2 {some extra property than the member of 2 }
achieve runtime polymorphism. Inheritance aids in the
reuse of code.A class can inherit the features of another But this type of case will not follow directly because
class and add its modification. The parent class is known logically here left hand side is same .So the right hand
as the super class and the newly created child class is side should be identical
known as the subclass.A subclass inherits all the Note :Java does not support multiple inheritance amongst
properties and methods of the super class, and can have classes. It can still be achieved with the help of interface..
additional attributes and methods. . Program: //Write a program to show inheritance in a
Collection of a class is an object. All the object of a class class
import java.io.*;
have unique address and its value is a real number. Since
the number of object in a class is finite. Therefore we can interface Sum
prepared a set S having the collection of finite number of {
address . static final int x=100;
Hence S={address of object : object is a member of a int sum(int n);
class} void display(int s);
}
Copyright © 2014 CTTS.IN, All right reserved
138
Current Trends in Technology and Science
ISSN: 2279-0535. Volume: 3, Issue: 3

sodd=SP.sum_odd(n);
interface Product System.out.print("\nSum=");
{ SP.display(s);
final static float pi=3.1415926F; System.out.print("\nProduct=");
int product(int n); SP.display(p);
} System.out.print("\nSum od odd numbers=");
SP.display(sodd);
class SUMPRODUCT implements Sum,Product
{ }
int i; }
public int sum(int n)
{
int s;
s=0; class SUMPRODUCT Mutiple inheritance
for(i=1;i<=n;i++) implements Sum,Product
s+=i;
return s; class SUM1 extends Single level inheritance
} SUMPRODUCT
public int product(int n)
{
int p; Method Overriding: {f: function f override from the
p=1; superclass to subclass with same name and type
for(i=1;i<=n;i++) signature}
p*=i; Example:
return p; class A
} {
public void display(int s) int i=0;
{ void dooverride(int k)
System.out.print(s); {
} i=k;
} }
} //subclass definition starts here
class SUM1 extends SUMPRODUCT class B extends A
{ { //Method Overriding
int sum_odd(int n) void doOverride(int k)
{ {
int s,i; i=2*k;
int x=999; System.out.println(“The value of i is :”+i);
float pi=1.234F; }
s=0; public static void main(String args[])
for(i=1;i<=n;i=i+2) {
s+=i; B b=new B(); //Create an instance of classB
System.out.print("x="+x); b.dooverride(12); //class B dooverride() will be called
System.out.print("\nValue of Pi="+pi); }
return s; }
} Hence we can get optimal solution of a problem by
} taking optimal time by making an inheritance on a class.
class interface1 3.4 ENCAPSULATION
{ Definition: the ability of an object to hide its data and
public static void main(String args[])throws methods from the rest of the world - one of the
IOException fundamental principles of OOP. Because objects
{ encapsulate data and implementation, the user of an
BufferedReader br=new BufferedReader(new object can view the object as a black box that provides
InputStreamReader(System.in)); services. Instance variables and methods can be added,
int n,s,p,sodd; deleted, or changed, but as long as the services provided
System.out.print("\nEnter n:"); by the object remain the same, code that uses the object
n=Integer.parseInt(br.readLine()); can continue to use it without being rewritten.
SUM1 SP=new SUM1(); 3.5 ABSTRACTION Abstraction refers to the act of
s=SP.sum(n); representing essential features without including the
p=SP.product(n); background details or explanations .
Copyright © 2014 CTTS.IN, All right reserved
139
Current Trends in Technology and Science
ISSN: 2279-0535. Volume: 3, Issue: 3

Classes use the concept of abstraction and are defined as else


a list of abstract attributes. System.out.println(b+”is greater”);
}
Hence we can get the optimal solution of a problem from
public static void main(String args[])
a without source knowledge of an object.
{
Over loadDemo O= new Over loadDemo();
3.6 POLYMORPHISM: When one task is performed by
O.max(23L,12L);
different ways i.e.known as polymorphism.
O.max(2,3);
Polymorphism is the ability of an object to take on many
O.max(54.0,35f);
forms. In programming languages polymorphism is the
O.max(43f,35f);
capability of an action or method to do different things
}
based on the object that it is acting upon. This is the third
}
basic principle of object oriented programming. The
Output:
three types of polymorphism are: ad-hoc (overloading
max method with long argument invoked
and overriding), parametric (generics) and dynamic
23 is greater
method binding.
max method with long argument invoked
3 is greater
3.6.1 Method Overloading: Method Overloading is one
max method with double argument invoked
way of achieving polymorphism in Java. Each method in
54.0 is greater
a class is uniquely identified by its name and parameter
max method with float argument invoked
list. What it means is that we can have two or more
43.0 is greater
methods with the same name, but each with different
ThusOverloaded methods are methods with the same
parameter list. This is a powerful feature of the language
name signature but either a different number of
called method overloading. Overloading allows us to
parameters or different types in the parameter list.
perform the same action on different types of inputs. In
In mathematical way overloading can be defined in the
Java whenever a method is being called, first the name of
following way :-
the method is matched and then , the number and types of
S={collection of function:function have either a different
arguments passed to the method are matched. In
number of parameters or different types in the parameter
method overloading, two methods can have the same
list}.
name but different signature, i.e. different numbers or
type of parameters. ={f R: f have either a different number of parameters
Advantages: The overloading concept is advantageous or different types in the parameter list}
where similar activities are to be performed but with ={f R : same function f can be defined on any
different input parameters dimension in the Eucliedian space}
Program: R is set of real number.
class overloadDemo Overridden methods are methods that are redefined
{ within an inherited or subclass. They have the same
void max(float a,float b) signature and the subclass definition is used.
{ Parametrics are generic typing procedures.
System.out.println(“max method with float argument Dynamic (or late) method binding is the ability of a
invoked”); program to resolve references to subclass methods at
If(a>b) runtime. For example assume that three subclasses
System.out.println(a+”is greater”); (Cow, Dog and Snake) have been created based on the
else Animal abstract class, each having their own speak()
System.out.println(b+”is greater”); method. Although each method reference is to an Animal
} (but no animal objects exist), the program is will resolve
void max(double a,double b) the correct method reference at runtime.
{ public class AnimalReference
System.out.println(“max method with doublet argument {
invoked”); public static void main(String args[])
If(a>b) Animal ref // set up var for an Animal
System.out.println(a+”is greater”);
else Cow aCow = new Cow("Bossy"); // makes specific
System.out.println(b+”is greater”); objects
} Dog aDog = new Dog("Rover");
void max(long a,long b) Snake aSnake = new Snake("Ernie");
{ // now reference each as an Animal
System.out.println(“max method with long argument ref = aCow; ref.speak();
invoked”); ref = aDog; ref.speak();
If(a>b) ref = aSnake; ref.speak();
System.out.println(a+”is greater”); }
Copyright © 2014 CTTS.IN, All right reserved
140
Current Trends in Technology and Science
ISSN: 2279-0535. Volume: 3, Issue: 3

4. SUMMARY OF OBJECT-ORIENTED AUTHOR’S PROFILE


CONCEPTS Dr. Asoke Nath is an Associate
I. Everything is an object. Professor in the Department
II. Computation is performed by objects Department of Computer Science.
communicating with each other, requesting that Presently he is busy with
other objects perform actions. Objects communicate Cryptography and Network
by sending and receiving messages. A message is a Security Steganography, Green
request for action, bundled with whatever arguments Computing, e-learning,
may be necessary to complete the tasks. Mathematical Formulation of
III. Each object has its own memory, which consists of computer Language.
other objects.
IV. Every object is an instance of a class. A class Mr. Manoj Kumar Srivastav
simply represents a grouping of similar objects, such has been Post graduate in Pure
as Integers or lists. Mathematics from University of
V. The class is the repository for behaviour associated Calcutta in year 2004 with
with an object. That is, that all objects that are Special paper in Advanced
instances of the same class can perform the same functional analysis and category
actions. theory, universal algebra and
VI. Classes are organized into a singly rooted tree lattice theory. At present he is
structure, called the inheritance hierarchy. Memory doing MCA from IGNOU and
and behaviour associated with instances of a class he is working as a postgraduate
are automatically available to any class associated teacher in Mathematics in an
with a descendant in this tree structure esteemed institution.
VII. We can get optimal solution for same type related
problem

REFERENCES
[1] Mathematical modeling of various statements of
C-type Language, Manoj Kumar Srivastav , Asoke
Nath, International Journal of Advanced
Computer
[2] Research(IJACR), Vol-3,Number-1, Issue-13,
Page:79-87 Dec(2013).
[2]Mathematical Description of variables,
pointers, structures, Unions used in C-type
language, Manoj Kumar Srivastava, Asoke Nath,
Joiurnal of Global Research Computer Science,
Vol-5, No-2, Page:24-29, Feb(2014)
[3] E Balaguruswamy- Programming with Java-
TataMcGrawHill EductionP rivate Limited.,2011
[4] Sachin Malhotra, Sourabh Choudhary-
Programming in Java- OXFORD University
Press,2012
[5] Herbert Schildt, Java TM 2: The Complete
Reference, TataMcGraw-Hill Publishing
Company Limited,2001
[6] Satish Jain,Vineeta Pillai,Kratika, Introduction to
Object Oriented Programming through Java,BPB
Publications,2011
[7] S.K.Mapa, Real Analysis , Asoke Prakasan 1998
[8] S.K.Mapa Higher Algebra, -Sarat Book
Distribution,2000
Website reference:
[9] www.c4learn.com
[10] www.ctp.bilkent.edu.tr

Copyright © 2014 CTTS.IN, All right reserved


141

View publication stats

You might also like