7/31/2019 OOPS Finale Assignment 1 Pre http://slidepdf.com/reader/full/oops-finale-assignment-1-pre 1/35 GUJARAT TECHNOLOGICAL UNIVERSITY AHMEDABAD & C-DAC, PUNE M.E in IT Systems and Network Security Semester-I, Year 2012-14 Module Name Pre Assignment of OOPS Date : 06 Aug 2012 Dipak Zala (ITSNS) 1 | Page
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
A compiled language is written and then run through a compiler which checks its syntax and
compresses it into a binary executable. Since an interpreted language is not compiled, it must be checked
for errors at run-time, which makes it quite a bit slower than a compiled language (like C or Java).
There also exist hybrid languages, such as Java and Python, which have qualities of both compiledand interpreted languages. Java, for example, can be compiled into byte code which must then itself be run
by an interpreter referred to as a virtual machine. Since Java source code itself does not have an
interpreter, it's reasonable to consider Java to be a compiled language.
• Pros:
• No problem with cycles.
• Memory writes have no cost.
• Only touches live data.
• No fragmentation; automatically compacts
• Cons:
• Fragmentation
• Cost proportional to heap size
• Sweep phase needs to traverse whole heap
• Will probably increase locality
• Requires twice the memory space
• Like mark and sweep, need to stop the world
2. Study of object - oriented features and support from known languages (C++,
Java etc)
Ans.
Features of OOP
OOP stands for Object Oriented Programming and the language that support this Object Oriented
programming features is called Object oriented Programming Language. An example of a language thatsupport this Object oriented features are C++ and JAVA.
The Objects Oriented programming language supports all the features of normal programming
languages. In addition it supports some important concepts and terminology which has made it popular
among programming methodology.
The important features of Object Oriented programming are:
Methods - We know that a class can define both attributes and behaviors. Again attributes are defined by
variables and behaviors are represented by methods. In other words, methods define the abilities of an
object.
3. What are the challenges in memory management - How garbage collection
features of java overcome these.
Ans.
In Object Oriented Programming, Objects typically reside on the Heap. In languages like C# and
Java you cannot create objects that reside on stack, so in these languages all objects reside on the heap
resulting in a distinction between Value and Reference Types. Languages like C++, Objective C, and Object
Pascal all provide a means of allocating objects either on the stack or on the heap. When your objects are
allocated on the heap you need a means of freeing the memory allocated to them when they are no longer
needed. There are a number of different approaches that object oriented programming languages take to
this problem.
Memory management is a simple concept, but is complicated by the interconnected nature of
object oriented programs. It may be difficult to determine when an object is safe to delete.
Freeing and Allocating Memory Manually
Languages like C++ and Object Pascal require that you manage memory yourself. These languages two
functions for memory management. One to allocate space on the heap, and another to free the space used.
Advantages: You are in complete control in this environment, and can provide fine control over when
objects are created and freed. This level of control is particularly helpful when working with devices that
have relatively small amount of RAM available for applications (for instance, a mobile phone or an
embedded engine controller within a car)
Disadvantages: Freeing objects adds complexity that programmers have to carefully manage. Failing to
free an object will result in a memory leak, while prematurely freeing an object has the potential to cause
significant runtime problems that may be hard to debug. When working in teams these problems become
even more of an issue as the memory management of your objects needs to be clearly understood by alldevelopers working on the program. The composite aggregation relationship in a UML class diagram can
be used to indicate that when thewhole is freed it frees its parts.
C++ uses obj = new class_name(params) to create an object, and delete obj to free the space
allocated to these objects. new (C++) on wikipedia
Object Pascal uses obj := class_name.Create(params) to create an object, and obj.Free() to free
Reference counting is one approach to overcoming the issues of manual memory management. With
reference counting each object maintains a count of the number of references that refer to it. When new
things refer to the object its reference count is increased, when a reference is removed the count isreduced. The object is then responsible for releasing itself when its reference count reaches 0.
Advantages: Objects are freed when their reference count reaches 0, meaning they are freed as soon as
they are no longer needed.
Disadvantages: Circular references mean that objects are never released. For example if A -> B -> C -> A
then the reference count of each is 1, and yet no other objects have references to any in this loop. This
issue can be avoided through specific loop detection code or by appropriate diligence from developers.
Garbage Collection
The latest evolution of memory management looks to address the issues of circular reference counts by
delegating memory management to the program runtime. With this kind of memory management there is
a Garbage Collector that is responsible for freeing objects when they are no longer accessed. This is done
by identifying those objects that cannot be reached from root links such as stack and global variables. Once
these objects are identified the garbage collector frees the memory they are using. This typically involves
calling a destructor or finaliser method to indicate that the object is about to be freed [3].
Advantages: The developers are released from having to deal with memory issues. This significantly
simplifies the process of developing software, regardless of the number of developers working in the team.
Disadvantages: Requires overhead in the runtime to check object links and objects are not freed until the
garbage collector runs, resulting in a larger memory footprint than is actually required.
Java, C#, and Visual Basic use garbage collectors.
Version 2 of Objective C has the option to use a garbage collector.
4. What is inheritance, different types of inheritance, support from known
languages (C++, Java etc)
Ans.
In object-oriented programming (OOP), inheritance is a way to reuse code of existing objects, or to
establish a subtype from an existing object, or both, depending upon programming language support.
In classical inheritance where objects are defined by classes, classes can inherit attributes and behavior
from pre-existing classes called base classes, superclasses, parent classes or ancestor classes. The
resulting classes are known as derived classes, subclasses or child classes. The relationships of classes
through inheritance gives rise to a hierarchy. In prototype-based programming, objects can be defined
directly from other objects without the need to define any classes, in which case this feature is
Single inheritance enables a derived class to inherit properties and behavior from a single parent class. Itallows a derived class to inherit the properties and behavior of a base class, thus enabling code reusabilityas well as adding new features to the existing code. This makes the code much more elegant and less
repetitive. Inheritance is one of the key features of object-oriented programming (OOP).
2) Multi Level Inheritance
It is the enhancement of the concept of inheritance. When a subclass is derived from a derived class thenthis mechanism is known as the multilevel inheritance. The derived class is called the subclass or childclass for it's parent class and this parent class works as the child class for it's just above ( parent ) class.Multilevel inheritance can go up to any number of level.
3) Multiple Inheritance
Multiple inheritance is a feature of some object-oriented computer programming languages in whicha class can inherit behaviors and features from more than one super class. You can derive a class from anynumber of base classes. Deriving a class from more than one direct base class is called multipleinheritance.
It is the process of deriving two or more classes from single base class. And in turn each of the derived
classes can further be inherited in the same way. Thus it forms hierarchy of classes or a tree of classeswhich is rooted at single class.
5) Hybrid Inheritance
In this type of inheritance, we can have combination of number of inheritances but this can produce an error of using same name function from no of classes, which will bother the compiler to how to use the functions.Therefore, it will generate errors in the program. This has known as ambiguity or duplicity.
Sequence diagrams describe interactions among classes in terms of an exchange of messagesover time. Sequence diagrams show a detailed flow for a specific use case or even just part of a specific
use case. They are almost self explanatory; they show the calls between the different objects in their
sequence and can show, at a detailed level, different calls to different objects.
A sequence diagram has two dimensions: The vertical dimension shows the sequence of
messages/calls in the time order that they occur; the horizontal dimension shows the object instances to
In UML, an activity diagram is used to display the sequence of activities. Activity diagrams show theworkflow from a start point to the finish point detailing the many decision paths that exist in the progression
of events contained in the activity. They may be used to detail situations where parallel processing may
occur in the execution of some activities. Activity diagrams are useful for business modeling where they are
used for detailing the processes involved in business activities.
An activity is the specification of a parameterized sequence of behavior. An activity is shown as a
round-cornered rectangle enclosing all the actions, control flows and other elements that make up the
activity. An activity diagram illustrates the dynamic nature of a system by modeling the flow of control from
activity to activity. An activity represents an operation on some class in the system that results in a change
Returns a new string that is a substring of this string.
39 char[] toCharArray()
Converts this string to a new character array.
40 String toLowerCase()
Converts all of the characters in this String to lower case using the rules of the default locale.
41 String toLowerCase(Locale locale)
Converts all of the characters in this String to lower case using the rules of the given Locale.
42 String toString()
This object (which is already a string!) is itself returned.
43 String toUpperCase()
Converts all of the characters in this String to upper case using the rules of the default locale.
44 String toUpperCase(Locale locale)
Converts all of the characters in this String to upper case using the rules of the given Locale.
45 String trim()
Returns a copy of the string, with leading and trailing whitespace omitted.
46 static String valueOf(primitive data type x)
Returns the string representation of the passed
Math Class:
Some basic math functions can be found in the Math class. The Math class is a wrapper
class for a set of useful mathematical functions and constants. All of the methods and fields
are static, and there is no public constructor.
Math ConstantsTwo common constants are defined in the Math class.doubleMath.E() : Value of e, 2.71828, base of the natural logarithms.doubleMath.PI() : Value of pi, 3.14159265
Math Methods
Trigonometric Methods All trigonometric method parameters are measured in radians, the normal mathematical system of angles,
and not in degrees, the normal human angular measurement system. Use the toRadians or toDegrees
methods to convert between these systems, or use the fact that there are 2*PI radians in 360 degrees. In
addition to the methods below, the arc methods are also available.
double Math.sin(ar) Returns the sine of ar.double Math.cos(ar) Returns the cosine of ar.
double Math.tan(ar) Returns the tangent of ar.double Math.toRadians(d) Returns d (angle in degrees) converted to radians.double Math.toDegrees(ar) Returns ar (angle in radians) converted to degrees.
Exponential MethodsThe two basic functions for logarithms and power are available. These both use the base e (Math.E) as is
the usual case in mathematics.
double Math.exp(d) Returns e (2.71...) to the power d.double Math.pow(d1, d2) Returns d1d2.double Math.log(d) Returns the logarithm of d to base e.double Math.log10(d) Returns the logarithm of d to base 10.
Misc Methods
double Math.sqrt(d) Returns the square root of d.Math.abs(x) Returns absolute value of x with same type as the parameter: int,
long, float, or double.Math.max(x, y) Returns maximum of x and y with same type as the parameter: int,
long, float, or double.Math.min(x, y) Returns minimum of x and y with same type as the parameter: int,
long, float, or double.
Integer Related MethodsThe following methods translate floating point values to integer values, altho these values may still be stored
in a double.double Math.floor (d) Returns the closest integer-valued double which is equal to or less
than d.double Math.ceil(d) Returns the closest integer-valued double which is equal to or
greater than d.double Math.rint(d) Returns the closest integer-valued double to d.long Math.round(d) Returns the long which is closest in value to the double d.int Math.round(f) Returns the int which is closest in value to the float f.
Random Numbersdouble Math.random() Returns a number x in the range, 0.0 <= x < 1.0.
10. Create some web pages using simple HTML by incorporating following
features
General Tags,Formatting ,Hyperlinking & Image handling, Tables, Forms.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML><HEAD><TITLE>Google</TITLE><META http-equiv=content-type content="text/html; charset=UTF-8"><STYLE>BODY {