oot4

17

Upload: shubham-kaushik

Post on 09-Mar-2016

216 views

Category:

Documents


3 download

DESCRIPTION

Exam zone Time 3 Hours Total Marks-100 a) Draw the class diagram of order management System. Ans: Que. 1 Attempt any two parts: (2*10=20 marks) c) Discuss the conceptual model of UML. Interface: Interface defines a set of operations which specify the responsibility of a class.

TRANSCRIPT

Page 1: oot4
Page 2: oot4

Exam zone

Page 3: oot4

Model Paper Of

Object Oriented Techniques (ECS-503)

Time 3 Hours Total Marks-100

Que. 1 Attempt any two parts: (2*10=20 marks)

a) Draw the class diagram of order management System.

Ans:

b) What is the Goal of modeling? What are the elements of OOPs? Discuss in brief.

Ans:

Goal: “Modeling is a way of thinking and reasoning about systems. The goal of modeling is to

come up with a representation that is easy to use in describing systems in a mathematically

consistent manner.”

Elements of OOPs:

1 Class: A class is a template for an object, a user-defined datatype that contains variables,

properties, and methods.

2 Instance : One can have an instance of a class; the instance is the actual object created at run-

time.

3 Method: Method is a set of procedural statements for achieving the desired result. It performs

different kinds of operations on different data types.

4 Message passing: The process by which an object sends data to another object or asks the other

object to invoke a method.

Page 4: oot4

5 Inheritance: Inheritance is a process in which a class inherits all the state and behavior of

another class. This type of relationship is called child-Parent or is-a relationship. "Subclasses"

are more specialized versions of a class, which inherit attributes and behaviors from their parent

classes, and can introduce their own.

6 Abstraction : Abstraction refers to the act of representing essential features without including

the background details or explanations. Classes use the concept of abstraction and are defined as

a list of abstract attributes.

7 Encapsulation : Encapsulation conceals the functional details of a class from objects that send

messages to it.

8 polymorphism: Polymorphism allows the programmer to treat derived class members just like

their parent class's members. More precisely, Polymorphism in object-oriented programming is

the ability of objects belonging to different data types to respond to calls of methods of the same

name, each one according to an appropriate type-specific behavior

9 Decoupling: Decoupling allows for the separation of object interactions from classes and

inheritance into distinct layers of abstraction. A common use of decoupling is to polymorphically

decouple the encapsulation.

c) Discuss the conceptual model of UML. Ans:

As UML describes the real time systems it is very important to make a conceptual model and

then proceed gradually. Conceptual model of UML can be mastered by learning the following

three major elements:

UML building blocks

Rules to connect the building blocks

Common mechanisms of UML

The building blocks of UML can be defined as:

Things

Relationships

Diagrams

(1) Things:

Things are the most important building blocks of UML. Things can be:

Structural

Behavioral

Grouping

Annotational

1. Structural things:

The Structural things define the static part of the model. They represent physical and

conceptual elements. Following are the brief descriptions of the structural things.

Class: Class represents set of objects having similar responsibilities.

Interface: Interface defines a set of operations which specify the responsibility of a class.

Page 5: oot4

Collaboration: Collaboration defines interaction between elements.

Use case: Use case represents a set of actions performed by a system for a specific goal.

Component: Component describes physical part of a system.

Node: A node can be defined as a physical element that exists at run time.

2. Behavioral things:

A behavioral thing consists of the dynamic parts of UML models. Following are the behavioral

things:

Interaction: Interaction is defined as a behavior that consists of a group of messages exchanged

among elements to accomplish a specific task.

State machine: State machine is useful when the state of an object in its life cycle is important.

It defines the sequence of states an object goes through in response to events. Events are external

factors responsible for state change.

3. Grouping things: Grouping things can be defined as a mechanism to group elements of

a UML model together. There is only one grouping thing available:

Package: Package is the only one grouping thing available for gathering structural and

behavioral things.

4. Annotational things:

Annotational things can be defined as a mechanism to capture remarks, descriptions, and

comments of UML model elements. Note is the only one Annotational thing available.

Note:A note is used to render comments, constraints etc of an UML element.

Page 6: oot4

(2) Relationship :

Relationship is another most important building block of UML. It shows how elements are

associated with each other and this association describes the functionality of an application.

There are four kinds of relationships available.

Dependency: Dependency is a relationship between two things in which change in one element

also affects the other one.

Association:Association is basically a set of links that connects elements of an UML model. It

also describes how many objects are taking part in that relationship.

Generalization:Generalization can be defined as a relationship which connects a specialized

element with a generalized element. It basically describes inheritance relationship in the world of

objects.

Realization:Realization can be defined as a relationship in which two elements are connected.

One element describes some responsibility which is not implemented and the other one

implements them. This relationship exists in case of interfaces.

(3) UML Diagrams:

UML diagrams are the ultimate output of the entire discussion. All the elements, relationships

are used to make a complete UML diagram and the diagram represents a system.

The visual effect of the UML diagram is the most important part of the entire process. All the

other elements are used to make it a complete one.

UML includes the following nine diagrams and the details are described in the following

chapters.

1. Class diagram

2. Object diagram

3. Use case diagram

4. Sequence diagram

5. Collaboration diagram

6. Activity diagram

7. Statechart diagram

8. Deployment diagram

9. Component diagram

Que. 2 Attempt any two parts: (2*10=20 marks)

Page 7: oot4

a) i) What is purpose of component diagram.

Ans:

Component diagram is a special kind of diagram in UML. The purpose is also different from all

other diagrams discussed so far. It does not describe the functionality of the system but it

describes the components used to make those functionalities.

So from that point component diagrams are used to visualize the physical components in a

system. These components are libraries, packages, files etc.

Component diagrams can also be described as a static implementation view of a system. Static

implementation represents the organization of the components at a particular moment.

A single component diagram cannot represent the entire system but a collection of diagrams are

used to represent the whole.

So the purpose of the component diagram can be summarized as:

Visualize the components of a system.

Construct executables by using forward and reverse engineering.

Describe the organization and relationships of the components.

ii) Write a note on Deployment diagram.

Ans:

Deployment diagram represents the deployment view of a system. It is related to the component

diagram. Because the components are deployed using the deployment diagrams. A deployment

diagram consists of nodes. Nodes are nothing but physical hardwares used to deploy the

application.

Deployment diagrams are useful for system engineers. An efficient deployment diagram is very

important because it controls the following parameters:

Performance

Scalability

Maintainability

Portability

So before drawing a deployment diagram the following artifacts should be identified:

Nodes

Relationships among nodes

The following deployment diagram is a sample to give an idea of the deployment view of order

management system. Here we have shown nodes as:

Monitor

Modem

Caching server

Server

The application is assumed to be a web based application which is deployed in a clustered

environment using server 1, server 2 and server 3. The user is connecting to the application using

internet. The control is flowing from the caching server to the clustered environment.

b) Draw the usecase diagram of Restaurant Management System.

Ans:

Page 8: oot4

c) Draw the sequence diagram of ‘edit item details' system use case.

Ans:

Que. 3 Attempt any four parts: (4*5=20 marks)

a) What are the advantages of Object Oriented Approach.

Ans:

Page 9: oot4

Reduced Maintenance: The primary goal of object-oriented development is the assurance that

the system will enjoy a longer life while having far smaller maintenance costs. Because most of

the processes within the system are encapsulated, the behaviors may be reused and incorporated

into new behaviors.

Real-World Modeling: Object-oriented system tend to model the real world in a more

complete fashion than do traditional methods. Objects are organized into classes of objects, and

objects are associated with behaviors. The model is based on objects, rather than on data and

processing.

Improved Reliability and Flexibility: Object-oriented system promise to be far more reliable

than traditional systems, primarily because new behaviors can be "built" from existing objects.

Because objects can be dynamically called and accessed, new objects may be created at any

time. The new objects may inherit data attributes from one, or many other objects. Behaviors

may be inherited from super-classes, and novel behaviors may be added without effecting

existing systems functions.

High Code Reusability: When a new object is created, it will automatically inherit the data

attributes and characteristics of the class from which it was spawned.

b) What is DFD? Draw the DFD for the Online Booking System.

Ans:

A data flow diagram (DFD) is a graphical representation of the "flow" of data through an

information system. DFDs can also be used for the visualization of data processing (structured

design). A DFD provides no information about the timing of processes, or about whether

processes will operate in sequence or in parallel.

DFD:

c) What are the principles of JSD(Jackson Structures Development)?

Ans:

Principles of operation and steps

Three basic principles of operation of JSD is that:

Development must start with describing and modelling the real world, rather than

specifying or structuring the function performed by the system. A system made using

JSD method performs the simulation of the real world before any direct attention is paid

to function or purpose of the system.

An adequate model of a time-ordered world must itself be time-ordered. Main aim is to

map progress in the real world on progress in the system that models it.

Online

Booking

System

USER

request

reference id ADMINISTRATOR

request

response

Page 10: oot4

The way of implementing the system is based on transformation of specification into

efficient set of processes. These processes should be designed in such a manner that it

would be possible to run them on available software and hardware.

When it was originally presented by Jackson in 1983, the method consisted of six steps.[1]

1. Entity/Action Step

2. Initial Model Step

3. Interactive Function Step

4. Information Function Step

5. System Timing Step

6. System Implementation Step

d) What are various steps involve in OMT?

Ans:

The Object Modeling Technique (OMT) software engineering methodology [#!omt!#] is

another well known example of a software engineering methodology. The OMT software

engineering methodology deals with object-oriented development in the analysis and design

phases.

The analysis phase starts with a problem statement which includes a list of goals and a definitive

enumeration of key concepts within a domain. This problem statement is then expanded into

three views, or models: an object model, a dynamic model, and a functional model. The object

model represents the artifacts of the system. The dynamic model represents the interaction

between these artifacts represented as events, states, and transitions. The functional model

represents the methods of the system from the perspective of data flow. The analysis phase

generates object-model diagrams, state diagrams, event-flow diagrams, and data-flow diagrams.

The analysis phase is now complete.

The system design phase follows the analysis phase. Here the overall architecture is established.

First the system is organized into subsystems which are then allocated to processes and tasks,

taking into account concurrency and collaboration. Then persistent data storage is established

along with a strategy to manage shared-global information. Next, boundary situations are

examined to help guide trade-off priorities.

The object design phase follows the system design phase. Here the implementation plan is

established. Object classes are established along with their algorithms with special attention to

the optimization of the path to persistent data. Issues of inheritance, associations, aggregation,

and default values are examined.

Implementation phase involes the implementation of the above design either using database or

by using Programming language.

e) How can a programmer manage inheritance by OO language?

Ans

Different kinds of objects often have a certain amount in common with each other. Mountain

bikes, road bikes, and tandem bikes, for example, all share the characteristics of bicycles (current

speed, current pedal cadence, current gear). Yet each also defines additional features that make

them different: tandem bicycles have two seats and two sets of handlebars; road bikes have drop

handlebars; some mountain bikes have an additional chain ring, giving them a lower gear ratio.

Page 11: oot4

Object-oriented programming allows classes to inherit commonly used state and behavior from

other classes. In this example, Bicycle now becomes the superclass of MountainBike,

RoadBike, and TandemBike. In the Java programming language, each class is allowed to have

one direct superclass, and each superclass has the potential for an unlimited number of

subclasses:

A hierarchy of bicycle classes.

The syntax for creating a subclass is simple. At the beginning of your class declaration, use the

extends keyword, followed by the name of the class to inherit from:

class MountainBike extends Bicycle {

// new fields and methods defining a mountain bike would go here

}

This gives MountainBike all the same fields and methods as Bicycle, yet allows its code to

focus exclusively on the features that make it unique. This makes code for your subclasses easy

to read. However, you must take care to properly document the state and behavior that each

superclass defines, since that code will not appear in the source file of each subclass.

f) What aspects of program should be documented?

Ans:

1. Basic usage is mostly covered in a man page.

2. More advanced usage can be achieved by listing ALL configuration options in the

documentation and giving examples on how to use them (take the very good Apache

documentation for example).

3. Source code, of course, because somebody may want to add features to the program.

4. Examples of usage to supply a working basic configuration file and document it heavily.

5. Installation of the program, because not all programs work with ./configure && make

&& make install.

6. User interface, especially if it is not a common point-and-click one.

Que 4. Attempt any two parts: (2*10=20 marks)

a) What is the difference between overloading and Overriding? Write code to support your

answer.

Page 12: oot4

Ans

Overloading

In Java it is possible to define two or more methods within the same class that share the

same name, as long as their parameter declarations are different. When this is the case,the

methods are said to be overloaded, and the process is referred to as method overloading.

Method overloading is one of the ways that Java implements polymorphism.

// OverLoad Demo class overload

{

void test(int a)

{

System.out.println(a*a);

}

void test(int a,double b)

{

System.out.println("overloadoutput"+(a+b)*2);

}

}

class overloaddemo

{

public static void main(String args[])

{

overload obj=new overload();

obj.test(2,3);

obj.test(4,5);

}

}

Overriding

when a method in a subclass has the same name and type signature as a method in its

superclass, then the method in the subclass is said to override the method in the superclass. When

an overridden method is called from within a subclass, it will always refer to the version of that

method defined by the subclass.

//Override Demo

class a

{

int i;int j;

void show()

{

System.out.println(i+j);

}

}

class b extends a

{

int k;

Page 13: oot4

void show()

{

System.out.println(i+j+k);

}

}

class override

{

public static void main(String ar[])

{

a superobj=new a();

b subobj=new b();

superobj.i=20;superobj.j=30;

subobj.i=1;subobj.j=2;subobj.k=3;

subobj.show();// op-6

}

}

b)Write short notes on the following:

(i) throw

The throw keyword denotes a statement that causes an exception to be initiated. It takes the

Exception object to be thrown as argument. The exception will be caught by an immediately

encompassing try-catch construction or propagated further up the calling hierarchy.

(ii) throws

The throws keyword is a modifier of a method that designates that exceptions may come

out of the mehtod, either by virtue of the method throwing the exception itself or because it fails

to catch such exceptions that a method it calls may throw.

(iii) finally

The finally block always executes when the try block exits. This ensures that the finally

block is executed even if an unexpected exception occurs. But finally is useful for more than

just exception handling — it allows the programmer to avoid having cleanup code accidentally

bypassed by a return, continue, or break. Putting cleanup code in a finally block is always a

good practice, even when no exceptions are anticipated.

c) Differentiate Following

i) Interface and Abstract class

Ans

Interface Abstract class

interface contains methods that must be

abstract

abstract class may contain concrete

methods.

interface contains variables that must be

static and final

abstract class may contain non-final and

final variables.

members in an interface are public by

default

abstract class may contain non-public

members.

interface is used to "implements" whereas abstract class is used to "extends".

Page 14: oot4

interface can be used to achieve multiple

inheritance

abstract class can be used as a single

inheritance.

interface can "extends" another interface abstract class can "extend" another class

and "implements" multiple interfaces.

interface is absolutely abstract abstract class can be invoked if a main()

exists.

interface is more flexible than abstract class

because one class can only "extends" one

super class, but "implements" multiple

interfaces.

(ii) Swing and AWT

Ans:

Several consequences result from this difference between AWT and Swing. AWT

is a thin layer of code on top of the OS, whereas Swing is much larger. Swing also has very

much richer functionality. Using AWT, you have to implement a lot of things yourself, while

Swing has them built in. For GUI-intensive work, AWT feels very primitive to work with

compared to Swing. Because Swing implements GUI functionality itself rather than relying on

the host OS, it can offer a richer environment on all platforms Java runs on. AWT is more

limited in supplying the same functionality on all platforms because not all platforms implement

the same-looking controls in the same ways. Swing components are called "lightweight"

because they do not require a native OS object to implement their functionality. JDialog and

JFrame are heavyweight, because they do have a peer. So components like JButton, JTextArea,

etc., are lightweight because they do not have an OS peer. A "peer" is a widget provided by the

operating system, such as a button object or an entry field object.

Que. 5 Attempt any two parts: (2*10=20 marks)

a) What is a Java Bean? Discuss the advantages of Java Bean.

Ans

Concept

JavaBeans™ is a portable, platform-independent component model written in the Java

programming language. The JavaBeans architecture was built through a collaborative industry

effort and enables developers to write reusable components in the Java programming language.

With the JavaBeans API you can create reuseable, platform-independent components. Using

JavaBeans-compliant application builder tools, you can combine these components into applets,

applications, or composite components.

JavaBean components are known as beans. Beans are dynamic in that they can be changed or

customized.

Advantages of Java Beans

A software component architecture provides standard mechanisms to deal with software building

blocks. The following list enumerates some of the specific benefits that Java technology provides

for a component developer:

A Bean obtains all the benefits of Java's "write-once, run-anywhere" paradigm.

Page 15: oot4

The properties, events, and methods of a Bean that are exposed to an application

builder tool can be controlled.

A Bean may be designed to operate correctly in different locales, which makes it useful

in global markets.

Auxiliary software can be provided to help a person configure a Bean. This software is

only needed when the design-time parameters for that component are being set. It does

not need to be included in the run-time environment.

The configuration settings of a Bean can be saved in persistent storage and restored

at a later time.

A Bean may register to receive events from other objects and can generate events that are

sent to other objects.

b) i). What is the servlet? What's the advantages using servlets than using CGI?

Ans

Servlets are modules that extend request/response-oriented servers, such as Java-enabled

web servers. For example, a servlet may be responsible for taking data in an HTML order-entry

form and applying the business logic used to update a company's order database. Servlets

provide a way to generate dynamic documents that is both easier to write and faster to run. It is

efficient, convenient, powerful, portable, secure and inexpensive. Servlets also address the

problem of doing server-side programming with platform-specific APIs: they are developed

with Java Servlet API, a standard Java extension.

ii) What is the difference between Difference between doGet() and doPost()?

Ans A doGet() method is limited with 2k of data to be sent, and doPost() method doesn't have this

limitation. A request string for doGet() looks like the following:

http://www.allapplabs.com/svt1?p1=v1&p2=v2&...&pN=vN doPost() method call doesn't need

a long text tail after a servlet name in a request. All parameters are stored in a request itself, not

in a request string, and it's impossible to guess the data transmitted to a servlet only looking at a

request string.

c) How you can use AWT controls? Write code for handling labels and CheckBox.

Ans

Controls are components that allow a user to interact with your application and the AWT

supports the following types of controls:

Labels,Push Buttons, Check Boxes, Choice Lists,Lists, Scrollbars, Text Components. These

controls are subclasses of Component.

// prg... to create three labels and add then on applet

import java.awt.*;

import java.applet.*;

//defineing applet tag

/*

Page 16: oot4

<applet code = LabelDemo width=500 height=400>

</applet>

*/

public class LabelDemo extends Applet

{

public void init() //"init()" method to initialize & add

{

Label l1 = new Label("1st label");

Label l2 = new Label("2nd label");

Label l3 = new Label("3rd label");

add(l1);

add(l2);

add(l3);

}

}

//CheckBoxDemo

import java.awt.event.*;

import java.awt.*;

import java.applet.*;

/* <applet code="checkboxdemo" height=300 width=400 > </applet>*/

public class checkboxdemo extends Applet implements ItemListener

{

Checkbox c1,c2,c3;CheckboxGroup cbg;String msg="";

public void init()

{

cbg= new CheckboxGroup();

c1=new Checkbox("mango",cbg,true);

add(c1);

c1.addItemListener(this);

c2=new Checkbox("apple",cbg,false);add(c2);c2.addItemListener(this);

c3=new Checkbox("orange",cbg,false);add(c3);c3.addItemListener(this);

}//init

public void itemStateChanged(ItemEvent e)

{

repaint();

}

public void paint (Graphics g)

{

Page 17: oot4

if ( cbg.getSelectedCheckbox()==c1)

{

msg="mango";

}

g.drawString(msg,6,150);

}

}//checkboxgroup