0% found this document useful (0 votes)
57 views149 pages

1 QB

Uploaded by

chinjuann03
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views149 pages

1 QB

Uploaded by

chinjuann03
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 149

Toc H Institute Of Science & Technology, Arakkunnam

Department of Computer Science & Engineering


CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

1. Why Do We Need Object‐Oriented Programming?


Object‐Oriented Programming was developed because limitations were discovered in earlier ap
proaches to programming.To appreciate what OOP does, we need to understand what these
limitations are and how they arose from traditional programming languages

Procedure‐Oriented Programming

C, Pascal, FORTRAN are example of procedural languages.Each statement in the language


tells the computer to do something: eg: get some input – add these numbers – divide by 6 -
display that output. A program in a procedural language is a list of instructions. Procedural
program is divided into functions .Each function has a clearly defined purpose and a
clearly defined interface to the other functions in the program.

Ms.Mithu Mary George ,CSE, TIST Page 1


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

In Multi‐function program important data items are placed as global so that they may be
accessed by all functions. Each function may have its own local data.

Procedure‐Oriented Programming Drawbacks

• Since every function has complete access to the global variables, a new
programmer can corrupt the data accidentally by creating function.
• We can access the data of one function from other since, there is no protection.
• In large program it is very difficult to identify what data is used by which function.
• Similarly, if new data is to be added, all the function needed to be modified to access
the data.
• Does not model real world problem very well.

Ms.Mithu Mary George ,CSE, TIST Page 2


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

Procedure‐Oriented Programming Characteristics

• Emphasis is on doing things (algorithms).


• Large programs are divided into smallerprograms known as functions.
• Most of the functions share global data.
• Data move openly around the system from function to function.
• Employs top‐down approach in program design.Top‐down process is breaking the
overall task into component parts until the lowest level of detail has been reached

2. Explain about Object‐Oriented Programming


Object‐Oriented Programming was introduced to overcome flaws in the procedural
approach to programming ; Such as lack of reusability & maintainability. The first object–
oriented language was Simula (Simulation of real systems) that was developed in 1960. The first
pure object-oriented programming language (OOPL) – Smalltalk. Some examples of object-
oriented programming languages are C++, Java, Smalltalk, Delphi, C#, Perl, Python, Ruby, and
PHP.
Fundamental idea behind object‐oriented languages is to combine into a single unit
both data and the functions that operate on that data.
Such a unit is called an object.In OOP,problem is divided into number of entities known as
objects;It builds data and functions around these objects.

Object ties the data more closely to the functions that operate on it, and protects it
from accidental modification from the outside functions. Data of an object can be accessed
only by the functions associated with that object.

Ms.Mithu Mary George ,CSE, TIST Page 3


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

Object‐Oriented Programming Characteristics

• Emphasis on data rather than procedure.


• Programs are divided into entities known as objects.
• Functions that operate on data of an object are tied together in data structures.
• Data is hidden and cannot be accessed by external functions.
• Objects communicate with each other through functions.
• New data and functions can be easily added whenever necessary.
• Follows bottom up approach in program design.It is the reverse top down approach
where lower level tasks are first carried out and are then integrated to provide the
solution of a single program.
• It promotes code reuse.

3.Explain the Key Differences Between OOP and POP.


• POP is a procedure oriented programming whereas, OOP is an object oriented
programming.
• The main focus of POP is on “how to get the task done” it follows the flow chart to get the
task done. OOP’s main focus is on data security as only the objects of a class are allowed to
access the attributes or function of a class.
• The functions are small units of the large programs that execute to get the main task done.
In OOP attributes and functions of the class are divided among the objects.
• In POP if some data is to be shared among all the functions in the program is declared
globally outside all functions. In OOP the data member of the class can be accessed through
the member functions of the class.
• In POP, there is no specific accessing mode to access attributes or functions in the program
whereas, in OOP there are three accessing modes “public”, “private”, “protected”, that are
used as an accessing share to access attributes or functions.
• POP does not support the concept of Overloading/polymorphism. OOP supp orts
Overloading/Polymorphism a which means using the same function name for performing
different functions. We can overload functions, constructor, and operators in OOP.
• There is no concept of inheritance in POP whereas, OOP supports inheritance which allows
using the attribute and functions of other class by inheriting it.

Ms.Mithu Mary George ,CSE, TIST Page 4


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

• POP is less secure as compared to OOP because in OOP the access specifier limits the access
to attributes or functions which increase the security.

4.Summarize about SOFTWARE ENGINEERING .

● SOFTWARE ENGINEERING
● Software engineering discusses systematic and cost-effective techniques for software
development. These techniques help develop software using an engineering approach.
● Software life cycle
● The life cycle of a software represents the series of identifiable stages through which it
evolves during its life time.
● A Software development life cycle (SDLC) model (also called software life cycle model
and software development process model ) describes the different activities that need to
be carried out for the software to evolve in its life cycle.

5. Explain classical waterfall model? .

● Classical waterfall model is intuitively the most obvious way to develop


software.
● It is simple but idealistic.

Ms.Mithu Mary George ,CSE, TIST Page 5


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

● In fact, it is hard to put this model into use in any non-trivial software development
project.
● All other life cycle models can be thought of as being extensions of the classical waterfall
model.
Phases of the classical waterfall model

Feasibility study
● The main focus of the feasibility study stage is to determine whether it
would be financially and technically feasible to develop the software.
Requirements analysis and specification
● The aim of the requirements analysis and specification phase is to understand the exact
requirements of the customer and to document them properly.
● This phase consists of two distinct activities, namely requirements gathering and analysis,
and requirements specification.
● Phases of the classical waterfall model

Ms.Mithu Mary George ,CSE, TIST Page 6


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

Design
● The goal of the design phase is to transform the requirements specified
in the SRS document into a structure that is suitable for implementation
in some programming language.
● In technical terms, during the design phase the software architecture is derived from the
SRS document.
● Two distinctly different design approaches
➢ Function-oriented design(Procedural design approach)
➢ Object-oriented design approach
● Phases of the classical waterfall model
Coding and unit testing
● The purpose of the coding and unit testing phase is to translate a
software design into source code and to ensure that individually each
function is working correctly.
● The coding phase is also sometimes called the implementation phase, since the design is
implemented into a workable solution in this phase.
● The end-product of this phase is a set of program modules that have been individually
unit tested.
● The main objective of unit testing is to determine the correct working of the individual
modules.
● Phases of the classical waterfall model
Integration and system testing
● During the integration and system testing phase, the different modules are integrated in a
planned manner.
● Integration of various modules are normally carried out incrementally over a number of
steps.

Ms.Mithu Mary George ,CSE, TIST Page 7


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

● Finally, after all the modules have been successfully integrated and tested, the full
working system is obtained.
● System testing is carried out on this fully working system
● Phases of the classical waterfall model
Maintenance
● Maintenance is carried out to correct errors that were not discovered during the product
development phase.
● Maintenance is carried out to improve the performance of the system, or to enhance the
functionalities of the system based on customer’s requests.

6. Explain software design approaches? .

APPROACHES TO SOFTWARE DESIGN

✓ Object-oriented Design
✓ Function-oriented Design
Salient features of the function-oriented design approach:
1. Top-down decomposition
● A system, to start with, is viewed as a black box that provides certain services (also
known as high-level functions) to the users of the system.
● In top-down decomposition, starting at a high-level view of the system, each high-level
function is successively refined into more detailed functions.
● Consider a function create-new-library member which essentially creates the record for a
new member, assigns a unique membership number to him, and prints a bill towards his
membership charge.

Ms.Mithu Mary George ,CSE, TIST Page 8


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

● This high-level function may be refined into the following subfunctions:


➢ assign-membership-number
➢ create-member-record
➢ print-bill
● Each of these subfunctions may be split into more detailed subfunctions and so on.


2.Centralised system state
● The system state can be defined as the values of certain data items that determine the
response of the system to a user
action or external event.
● For example, the set of books (i.e. whether borrowed by different users or available for
issue) determines the state of a library automation system.
● Such data in procedural programs usually have global scope and are shared by many
modules.
● For example, in the library management system, several functions such as the following
share data such as member-records for reference and updation:

Ms.Mithu Mary George ,CSE, TIST Page 9


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

✓ create-new-member
✓ delete-member
✓ update-member-record


Object-oriented Design
● In the object-oriented design (OOD) approach, a system is viewed as
being made up of a collection of objects (i.e. entities).
● Each object is associated with a set of functions that are called its methods.
● Each object contains its own data and is responsible for managing it.
● The data internal to an object cannot be accessed directly by other objects and only
through invocation of the methods of the object.
● The system state is decentralised since there is no globally shared data in the system and
data is stored in each object.

Ms.Mithu Mary George ,CSE, TIST Page 10


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

● For example, in a library automation software, each library member may be a separate
object with its own data and functions to operate on the stored data.
● The object-oriented design paradigm makes extensive use of the principles of abstraction
and decomposition as explained below.
● Objects decompose a system into functionally independent modules. Objects can also be
considered as instances of abstract data types (ADTs).
● Three important concepts associated with abstract data types (ADTs)
➢ Abstraction
➢ Data structure
➢ Data type

Data abstraction

Ms.Mithu Mary George ,CSE, TIST Page 11


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

● The principle of data abstraction implies that how data is exactly stored is abstracted
away.
● This means that any entity external to the object (that is, an instance of an ADT) would
have no knowledge about how data is exactly stored, organised, and manipulated inside
the object.
● The entities external to the object can access the data internal to an object only by calling
certain well-defined methods supported by the object.
Data structure:
● A data structure is constructed from a collection of primitive data items.
● Just as a civil engineer builds a large civil engineering structure using primitive building
materials such as bricks, iron rods, and cement;
● A programmer can construct a data structure as an organised collection of primitive
data items such as integer, floating point numbers, characters, etc.
Data type
● A type is a programming language terminology that refers to anything that can be
instantiated.
● For example, int, float, char etc., are the basic data types supported by C programming
language.
● Thus, we can say that ADTs are user defined data types.

7. Explain the differences between Object-oriented design and


Function oriented design
Object-oriented design VS Function oriented design

Ms.Mithu Mary George ,CSE, TIST Page 12


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

● Unlike function-oriented design methods in OOD, the basic abstraction is not the services
available to the users of the system such as issuebook ,display-book-details, find-issued-
books, etc., But real-world entities such as member, book, book-register, etc.
● For example in OOD, an employee pay-roll software is not developed by designing
functions such as update-employee-record, get-employee-address,etc., but by designing
objects such as employees, departments, etc.
● In OOD, state information exists in the f orm of data distributed among several objects
of the system.
● In contrast, in a procedural design, the state information is available in a centralised
shared data store.
● For example, while developing an employee pay-roll system, the employee data such as
the names of the employees, their code numbers, basic salaries, etc., are usually
implemented as global data in a traditional programming system; whereas in an object-
oriented design, these data are distributed among different employee objects of the
system.
● Objects communicate by message passing.
CASE STUDY Automated fire-alarm system
Customer requirements
● The owner of a large multi-storied building wants to have a computerised fire alarm
system designed, developed, and installed in his building.
● Smoke detectors and fire alarms would be placed in each room of the building.
● The fire alarm system would monitor the status of these smoke detectors.
● Whenever a fire condition is reported by any of the smoke detectors, the fire alarm
system should determine the location at which the fire has been sensed and then sound
the alarms only in the neighbouring locations
● The fire alarm system should also flash an alarm message on the computer console.

Ms.Mithu Mary George ,CSE, TIST Page 13


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

● Fire fighting personnel would man the console round the clock. After a fire condition has
been successfully handled, the fire alarm system should support resetting the alarms by
the fire fighting personnel.

Function-oriented approach:
● In this approach, the different high-level functions are first identified, and then the data
structures are designed
The functions which operate on the system state are:
➢ interrogate_detectors();
➢ get_detector_location();
➢ determine_neighbour_alarm();
➢ determine_neighbour_sprinkler();
➢ ring_alarm();
➢ activate_sprinkler();
➢ reset_alarm();
➢ reset_sprinkler();
➢ report_fire_location();
Object-oriented approach
● In the object-oriented approach, the different classes of objects are identified.
● Subsequently, the methods and data for each object are identified.
● Finally, an appropriate number of instances of each class is created.

Object-oriented approach
➢ class detector
attributes: status, location, neighbours
operations: create, sense-status, get-location,find-neighbours

Ms.Mithu Mary George ,CSE, TIST Page 14


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

➢ class alarm
attributes: location, status
operations: create, ring-alarm, get_location, resetalarm
➢ class sprinkler
attributes: location, status
operations: create, activate-sprinkler, get_location,reset- sprinkler

8. Summarize Basic Object Oriented concepts


▪ Object means a real-world entity such as a pen, chair, table, computer, watch, etc
▪ Object-Oriented Programming is a methodology or paradigm to design a program
using classes and objects
▪ The main aim of object-oriented programming is to implement real-world entities

Ms.Mithu Mary George ,CSE, TIST Page 15


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

Basic Object Oriented concepts


Object
✓ Any entity that has state and behavior is known as
an object.
✓ For example, a chair, pen, table, keyboard, bike, etc.
✓ It can be physical or logical.
✓ They are the combination of data & logic that represents some real world entity.
✓ Objects are the basic run‐time entities of an object oriented system.
✓ When a program is executed, the objects interact by sending messages to one another
✓ Each object contains data, and code to manipulate the data.
✓ A dog is an object because it has states like color, name, breed, etc. as well as behaviors
like wagging the tail, barking, eating, etc.
▪ The data of the object can only be accessed by the methods of the object.
▪ Consequently, the only access point to the data for the external Objects is through the
invocation of the methods of the object.
▪ No object can directly access the data of any other object.
▪ An object can access the private data of another object by invoking the methods
supported by that object.
▪ This mechanism of hiding data from other objects is popularly known as the principle of
data hiding o r data abstraction
▪ The data stored internally in an object are called its attributes, and the operations
supported by an object are called its methods.

Ms.Mithu Mary George ,CSE, TIST Page 16


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

CLASS
▪ Collection of objects is called class.
▪ CLASS are a blueprint or a set of instructions to build a specific type of object.
▪ An object is an instance of a class.
▪ Class in Java determines how an object will behave and what the object will contain.
▪ Let’s take Human Being as a class. My name is John, and I am an instance/object of
the class Human Being.
▪ Object has a physical existence while a class is just a logical definition.

Ms.Mithu Mary George ,CSE, TIST Page 17


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

▪ Car is the class and wheels, speed limits, mileage are their properties.
▪ A Class is a user defined data-type which has data members and member functions.
▪ Data members are the data variables and member functions are the functions used to
manipulate these variables and together these data members and member functions
defines the properties and behavior of the objects in a Class.
▪ In the above example of class Car, the data member will be speed limit, mileage etc and
member functions can be apply brakes, increase speed etc.

Attributes & methods in class


 Attributes represent the properties or state of an object
 Methods implement the behaviour of an object. Method is a function or procedure that
is defined for a class and can access the internal state of an object to perform some
operation.
Syntax for creating a class:
class <<classname>{
<<variable names>>
<<methods>>
}
Example
class Student{

Ms.Mithu Mary George ,CSE, TIST Page 18


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

String name;
int roll no,total_marks;
void total() {
System.out.println(“total mark:" +total_marks );
}
}

Syntax for creating object of a class:

<<class-name>><<object-name>>;
For example, if ”Student” is the class created by user
Student ram, shyam;
Here ram and shyam are name of objects for class Student.
Once a class has been defined we can create any number of objects for that class.we can
assign values to attributes during instantiation using this object .Methods defined can be
invoked with the objects. It can change the state of object attributes.

Understand the concept of Java Classes and Objects with an example.

Ms.Mithu Mary George ,CSE, TIST Page 19


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

Ms.Mithu Mary George ,CSE, TIST Page 20


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

Ms.Mithu Mary George ,CSE, TIST Page 21


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

Inheritance
▪ The capability of a class to derive properties and characteristic from another class is
called Inheritance.
▪ Sub Class : The class that inherits properties from another class is called Sub class
or Derived Class.
▪ Super Class : The class whose properties are inherited by sub class is called Base
Class or Super class.
▪ The subclass can add its own fields and methods in addition to the superclass fields and
methods.
▪ It supports the concept of hierarchical classification.

Ms.Mithu Mary George ,CSE, TIST Page 22


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

▪ Inheritance supports the concept of “reusability”,i.e. when we want to create a new


class and there is already a class that includes some of the code that we want, we can
derive our new class from the existing class. By doing this, we are reusing the fields and
methods of the existing class.
▪ Each derived class can be considered as a specialisation of its base class because it
modifies or extends the basic properties of the base class in certain ways.
▪ Therefore, the inheritance relationship can be viewed as a generalisation -specialisation
relationship.
▪ In addition to inheriting all the data and methods of the base class, a derived class usually
defines some new data and methods.
▪ A derived class may even redefine a method which already exists in the base class.

Advantages of inheritance
➢ Reusability: facility to use methods of base class with out rewriting the same.

Ms.Mithu Mary George ,CSE, TIST Page 23


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

➢ Data hiding: Using access specifiers, base class can decide to keep some data private so
that it cannot be altered by the derive class.
➢ Extensibility: extending the base class logic.
➢ Through effective use of inheritance, you can save lot of time in your programming and a
lso reduce errors, which in turn will increase the quality of work and productivity.
. The different types of Inheritance are:
1. Single Inheritance
2. Hierarchical Inheritance
3. Multiple Inheritance
4. Multi Level Inheritance
5.Hybrid Inheritance
• Single Inheritance − A subclass derives from a single super-class.
• Multiple Inheritance − A subclass derives from more than one super-classes.

o
• Multilevel Inheritance − A subclass derives from a super-class which in turn is derived
from another class and so on.
• Hybrid Inheritance − A combination of multiple and multilevel inheritance so as to form
a lattice structure.

Ms.Mithu Mary George ,CSE, TIST Page 24


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

o
• Hierarchical Inheritance − A class has a number of subclasses each of which may have
subsequent subclasses, continuing for a number of levels, so as to form a tree structure.

Encapsulation
▪ It is the process of binding both attributes and methods together in a single unit , as a
class.
▪ Through encapsulation, the internal details of a class can be hidden from outside.
▪ It permits the elements of the class to be accessed from outside only through the
interface provided by the class.

Ms.Mithu Mary George ,CSE, TIST Page 25


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

Binding (or wrapping) code and data together into a single unit are known as encapsulation.

For example: consider a Medical store. Lets say you have to buy
some medicines. You go to the medical store and ask the chemist for the medicines.
Only the chemist has access to the medicines in the store based on your prescription .Chemist
knows what medicines to give to you.
▪ In this example
▪ MEDICAL STORE: class
▪ MEDICINES: Member Variables.
▪ CHEMIST: Member Methods.
▪ You: External Application or piece of Code accessing members with method in class
▪ Through Encapsulation, Data is not accessible to the outside world, and only those
functions which are wrapped in the class can access it.
▪ In encapsulation, the variables of a class will be hidden from other classes and can be
accessed only through the methods of their current class. Therefore, it is also known
as data hiding.
To achieve encapsulation in Java −
▪ Declare the variables of a class as private for data hiding.
▪ Provide public setter and getter methods to modify and view the
variables values.

Ms.Mithu Mary George ,CSE, TIST Page 26


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

▪ Data Hiding: It is a way to achieve data hiding in Java because other class will not be
able to access the data through the private data members.

Ms.Mithu Mary George ,CSE, TIST Page 27


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

ADVANTAGES OF ENCAPSULATION
▪ Protection of data from accidental corruption,by means of access specifiers
(Private/Public),it provides security.
▪ Encapsulation protects an object from unwanted access by clients.
▪ Increased Flexibility: We can make the variables of the class as read-only or write-only
depending on our requirement.
▪ Reduction in complexity.

Abstraction
➢ Data Abstraction is the property by virtue of which only the essential details are
displayed to the user.
➢ Data Abstraction may also be defined as the process of identifying only the required
characteristics of an object ignoring the irrelevant details.

Ms.Mithu Mary George ,CSE, TIST Page 28


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

➢ In other words, the user will have the information on what the object d oes instead of how
it does it.
➢ The trivial or the non-essentials units are not displayed to the user. Ex: A car is viewed as
a car rather than its individual components.
● Basic Object Oriented concepts
Abstraction
➢ Consider a real-life example of a man driving a car.
➢ The man only knows that pressing the accelerators will increase the speed of car or
applying brakes will stop the car but he does not know about how on pressing the
accelerator the speed is actually increasing, he does not know about the inner me chanism
of the car or the implementation of accelerator, brakes etc in the car.
➢ In java, abstraction is achieved by interfaces and abstract classes.

POLYMORPHISM
➢ The word polymorphism means having many forms. Poly means many and morph
means form; which means objects can take many different forms .

Ms.Mithu Mary George ,CSE, TIST Page 29


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

➢ Suppose if you are in class room that time you behave like a student, when you are in
market at that time you behave like a customer, when you at your home at that time you
behave like a son or daughter, Here one person present in different-different behaviors.

➢ An operation may exhibit different behaviours in different instances. The behavior


depends upon the types of data used in the operation.

Ms.Mithu Mary George ,CSE, TIST Page 30


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

How to achieve Polymorphism in Java ?


➢ In java programming the Polymorphism principal is implemented with method overriding
concept of java.
➢ Polymorphism principal is divided into two sub principal they are:
✓ Static or Compile time polymorphism
✓ Dynamic or Runtime polymorphism
➢ Static polymorphism in Java is achieved by method overloading and Dynamic
polymorphism in Java is achieved by method overriding.

Ms.Mithu Mary George ,CSE, TIST Page 31


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

ADVANTAGES OF POLYMORPHISM
▪ Method overloading allows methods that perform similar or closely related
functions to be accessed through a common name. Method overloading allows you
to define three methods with the same name and different types of parameters to
handle the array of operations.
▪ Method overriding allows a sub class to use all the general definitions that a super
class provides and add specialized definitions through overridden methods.
▪ Method overriding works together with inheritance to enable code reuse of existing
classes without the need for re-compilation.
▪ It helps the programmer to reuse the codes.

Ms.Mithu Mary George ,CSE, TIST Page 32


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

9. List the advantages and disadvantages of object oriented design.


● Benefits of OOD
▪ User can create new user defined data type by making class.
▪ Data can be encapsulated from outside world .
▪ By using polymorphism, same functions or operators can be used for multitasking.
▪ Object oriented system can be easily upgrade from small system to large system.
▪ Software complexity can be easily managed.
▪ Maintenances cost is less.
▪ Code reuse by the use of predeveloped class libraries.
▪ Code reuse due to inheritance
▪ Simpler and more intuitive abstraction, i.e., better management of inherent problem and
code complexity
▪ Better problem decomposition.
● Disadvantages of OOD
▪ The principles of abstraction, data hiding, inheritance, etc. do incur run time overhead
due to the additional code that gets generated on account of these features. This causes an
project-oriented program to run a little slower than an equivalent procedural program.
▪ An important consequence of object-orientation is that the data that is centralised in a
procedural implementation, gets scattered across various objects in an object-oriented
implementation. Therefore, the spatial locality of data becomes weak and this leads to
higher cache miss ratios and consequently to larger memory access times. This finally
shows up as increased program run time.

Ms.Mithu Mary George ,CSE, TIST Page 33


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

10.Explain the software development process .

The essence of the software development process that consists of analysis, design,
implementation, testing, and refinement is to transform user’s needs into a software solution
that satisfies those needs. The software development process can be divided into smaller,
interacting sub processes. Generally software development can be seen as a series of
transformations, where the output of one transformation becomes the input of the
subsequent transformation.

● Transformation1(Analysis):Translates the user’s needs into system requirements and


responsibilities.
● Transformation 2 (design): formulate a detailed design that can be transformed into a
operational system. This includes the definition of how to build the software, its
development, and its testing.
● Transformation 3(Implementation): refines the detailed design into the system
deployment that will satisfy the user’s needs.It represents embedding the software
product within its operational environment.

11.Explain the Object oriented systems development life cycle .


• The major phases of software development using object–oriented methodology
◦ object-oriented analysis
◦ object-oriented design
◦ object-oriented implementation

Ms.Mithu Mary George ,CSE, TIST Page 34


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

Object–Oriented Analysis
• In this stage, the problem is formulated, user requirements are identified, and then a
model is built based upon real–world objects.
• The analysis produces models on how the desired system should function and how it
must be developed.
• The models do not include any implementation details so that it can be understood and
examined by any non–technical application expert.
Object–Oriented Design
This phase includes two stages: system design & object design.
System Design :
• In this stage, the complete architecture of the desired system is designed.
• The system is conceived as a set of interacting subsystems that in turn is composed of a
hierarchy of interacting objects, grouped into classes.
• System design is done according to system analysis model and proposed system
architecture.
• Emphasis is on the objects comprising the system rather than the processes in the
system.
Object Design
• a design model is developed based on both the models developed in the system analysis
phase and system design phase.
• All the classes required are identified.
• The designer decides whether :
◦ new classes are to be created from scratch,
◦ any existing classes can be used in their original form, or
◦ new classes should be inherited from the existing classes.

Ms.Mithu Mary George ,CSE, TIST Page 35


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

• The associations between the identified classes are established and the hierarchies of
classes are identified.
• Besides, the developer designs the internal details of the classes and their associations,
Object–Oriented Implementation and Testing
• In this stage, the design model developed in the object design is translated into code in
an appropriate programming language or software tool.
• The databases are created and the specific hardware requirements are ascertained.
• Once the code is ready, it is tested using specialized techniques to identify and remove
the errors in the code

Ms.Mithu Mary George ,CSE, TIST Page 36


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

11. Explain Unified Modeling Language (UML) .Summarize UML Diagrams.

UML is a language for specifying, constructing, visualizing and documenting the software
system and its components.UML is a graphical language with set of rules & semantics expressed
in English, in a form known as object constraint language (OCL) .

● UML is a language for documenting models.


● UML has its syntax (a set of basic symbols and sentence formation rules) and semantics
(meanings of basic symbols and sentences).
● It provides a set of basic graphical notations (e.g. rectangles, lines, ellipse s, etc.) that
can be combined in certain ways to document the design and analysis results.
● OBJECT MODELLING USING UML
➢ UML is a standard language for specifying, visualizing, constructing, and documenting
the artifacts of software systems.
➢ UML is powerful enough to represent all the concepts that exist in object-oriented
analysis and design.
➢ It can be used to model a variety of systems: software systems, business systems, or any
other system.
➢ A model is constructed by focusing only on a few aspects of the problem and ignoring
the rest.
➢ The model of a problem is called an analysis model.
➢ On the other hand, the model of the solution (code) is called the design model.
➢ The design model is usually obtained by carrying out iterative refinements to the
analysis model using a design methodology.
➢ UML is the most commonly and frequently used language for building software
system blueprints
➢ UML is not a programming language, it is rather a visual language.
What is a model?
● A model is an abstraction of a real problem (or situation), and is constructed by leaving
out unnecessary details.
Why construct a model?

Ms.Mithu Mary George ,CSE, TIST Page 37


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

● It helps to manage the complexity in a problem and facilitates arriving at good solutions
and at the same time helps to reduce the design costs.
● Analysis and Design models can be used for a variety of purposes during software
development:
● Analysis
● Specification
● Design
● Coding
● Visualisation and understanding of an implementation.
● Testing, etc.

Primary goals of design of UML


• Provides users a ready–to–use, expressive visual modeling language.
• Provide extensibility and specialization mechanisms to extend the core concepts
• Be independent of particular programming languages and development processes
• Provided a formal basis for understanding the modeling language
• Encourage the growth of Object Oriented tools .
UML Diagrams
Every complex system is best approached through small set of nearly independent views of
a model with number of diagrams at each development level. UML defines following graphical
diagrams:
1. Class diagram (static diagram)
2. Use–case diagram
3. Behavior diagram (dynamic diagram)
a. Interaction diagram
-Sequence diagram,
-Collaboration diagram
b. State chart diagram
c. Activity diagram
4. Implementation diagram
a.Component diagram
b.Deployment diagram

Ms.Mithu Mary George ,CSE, TIST Page 38


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

UML DIAGRAMS

11

UML diagrams can be divided into two categories. The first type representing structural
information. The second representing general types of behavior.

Structure diagrams are used in documenting the architecture of software systems and are
involved in the system being modeled.
Different structure diagrams are:
Class Diagram: represents system class, attributes and relationships among the classes.
Component Diagram: represents how components are split in a software system and
dependencies among the components.
Deployment Diagram: describes the hardware used in system implementations.
Object Diagram: represents a complete or partial view of the structure of a modeled system.

Ms.Mithu Mary George ,CSE, TIST Page 39


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

Behavior diagrams represent functionality of software system and emphasize on what must
happen in the system being modeled.
The different behavior diagrams are:
Activity Diagram: represents step by step workflow of business and operational components.
Use Case Diagram: describes functionality of a system in terms of actors, goals as use cases and
dependencies among the use cases.
UML State Machine Diagram: represents states and state transition.
Interaction Diagram: provides an overview and nodes representing communication diagrams.
Sequence Diagram: represents communication between objects in terms of a sequence of
messages.

12. Explain Use case diagrams ? or Summarize usecase modelling?


The diagram is used to model the system/subsystem of an application. It captures a
particular functionality of a system including internal and external influences. It consists of
actors, use cases and their relationships. Use cases are prepared and actors are identified when
a system is analyzed to gather its functionalities.
Purposes of use case diagrams :
• The use case model forms the core model to which all other models must conform.
• Usecase diagrams helps to identify the different types of users (actors).
• Used to gather the requirements of a system.
• Used to get an outside view of a system.
• Identify the external and internal factors influencing the system.
• Show the interaction among the requirements and actors.
• Specify the context of a system
• Validate a systems architecture
• Drive implementation and generate test casesShow the interaction among the
requirements are actors.
Use cases are nothing but the system functionalities written in an organized manner. Actors can
be defined as something that interacts with the system.Actors can be a human user,hardware,
some internal applications, or may be some external applications.
When we are planning to draw a use case diagram, we should have the following
items identified.

Ms.Mithu Mary George ,CSE, TIST Page 40


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

◦ Functionalities to be represented as use case


◦ Actors
◦ Relationships among the use cases and actors.
Use case diagram never describes how they are implemented. Use case diagram can be
imagined as a black box where only the input, output, and the function of the black box is
known.

USE CASE MODEL


● The users’ view captures the view of the system in terms of the functionalitie s offered
by the system to its users.
● The use case model for any system consists of a set of use cases.
● Intuitively, the use cases represent the different ways in which a system can be used
by the users.
● The use cases correspond to the high-level functional requirements.
● The use cases partition the system behaviour into transactions, such that each
transaction performs some useful action from the user’s point of view.
● A simple way to find all the use cases of a system is to ask the question
—“What all can the different categories of users do by using the system?”
● For the library information system (LIS), the use cases could be:
❖ issue-book
❖ query-book
❖ return-book
❖ create-member
❖ add-book, etc.

● A use case typically involves a sequence of interactions between the user and the
system.
● A use case consists of one main line sequence and several alternate sequences.
● The main line sequence represents the interactions between a user and the system
that normally take place.

Ms.Mithu Mary George ,CSE, TIST Page 41


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

● For example, in the mainline sequence of the withdraw cash use case supported by a
bank ATM would be—the user inserts the ATM card, enters password, selects the
amount withdraw option, enters the amount to be withdrawn, completes the
transaction, and collects the amount.
● Several variations to the main line sequence (called alternate sequences) may also exist.
● For the bank ATM example, consider the following variations or alternate sequences:
✓ Password is invalid.
✓ The amount to be withdrawn exceeds the account balance.

Guidelines to draw use case diagram


• The name of a use case should be chosen in such a way so that it can identify the
functionalities performed.
• Give a suitable name for actors.
• Show relationships and dependencies clearly in the diagram.
• Do not try to include all types of relationships, as the main purpose of the diagram is to
identify the requirements.
• Use notes whenever required to clarify some important points.

Actor Notations • the three representations of an actor are equivalent.

Example 1: Usecase diagram of a library system

Ms.Mithu Mary George ,CSE, TIST Page 42


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

In this Library system:Actors: Library user and Librarian


Usecases: register book loan, Register book return, Query book
availability, Add new book
Solid lines indicates the association of actors with usecases.

Use case diagram At a Glance

Ms.Mithu Mary George ,CSE, TIST Page 43


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

Use case diagram :Text description


● The text description should define the details of the interaction between the user and
the computer as well as other relevant aspects of the use case.
● The following are some of the information which may be included in a use case text
description in addition to the mainline sequence, and the alternate scenarios.
● Actors: some information about actors using a use case may be recorded
● Pre-condition: The preconditions would describe the state of the system
● before the use case execution starts.
● Post-condition: This captures the state of the system after the use case has
● successfully completed
● Exceptions, error situations

EXAMPLE Use case diagram :Text description


● U1: register-customer: Using this use case, the customer can register himself by
providing the necessary details.
Scenario 1: Mainline sequence
● 1. Customer: select register customer option
● 2 . System: display prompt to enter name, address, and telephone number.
● 3. Customer: enter the necessary values
● 4: System: display the generated id and the message that the customer has successfully
been registered.

Scenario 2: At step 4 of mainline sequence


4 : System: displays the message that the customer has already registered.
Scenario 3: At step 4 of mainline sequence
4 : System: displays message that some input information have not been entered. The
system displays a prompt to enter the missing values.

Ms.Mithu Mary George ,CSE, TIST Page 44


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

12.Explain Relationships in usecase diagram with examples?

1.ASSOCIATION BETWEEN ACTOR AND USECASE


● An actor must be associated with atleast one usecase.
● An actor can be associated with multiple usecases.
● Multiple actors can be associated with a single usecase.

2.GENERALIZATION OF USE CASE


● Use case generalisation can be used when you have one use case that is similar to
another, but does something slightly differently or something more.
● The child use case inherits the behaviour and meaning of the present use case.

Ms.Mithu Mary George ,CSE, TIST Page 45


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

3.INCLUDE BETWEEN TWO CASES


● The includes relationship implies one use case includes the behaviour of another use
case in its sequence.
● The includes relationship is appropriate when you have a chunk of behaviour that is
similar across a number of use cases.
● Thus, the includes relationship explores the issue of reuse by factoring out the
commonality across use cases.
● The includes relationship is represented using a predefined stereotype <<include>>.
● In the includes relationship, a base use case compulsorily and automatically includes the
behaviour of the common use case.

4.EXTEND BETWEEN TWO USE CASES


 The extend relationships show optional functionality or system behavior.
 An optional system behaviour is executed only if certain conditions hold, otherwise the
optional behaviour is not executed.
 Depict with a directed arrow having a dotted line. The tip of arrowhead points to the
base use case and the child use case is connected at the base of the arrow.

Ms.Mithu Mary George ,CSE, TIST Page 46


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

 The stereotype "<<extends>>" identifies as an extend relationship

Ms.Mithu Mary George ,CSE, TIST Page 47


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

5.GENERALIZATION OF AN ACTOR
✓ Generalization of an actor means an actor can inherit the role of the other actor.
✓ Descendent inherits all the usecases of the ancestor
✓ The descendent has one or more usecases that are specific to that role

13.Draw the usecase diagram for library management system with


include and extend relationship.

Ms.Mithu Mary George ,CSE, TIST Page 48


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

Ms.Mithu Mary George ,CSE, TIST Page 49


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

13.Draw the usecase diagram for ATM system with include and
extend relationship.

Ms.Mithu Mary George ,CSE, TIST Page 50


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

14.Draw the usecase diagram for order management system?

15.Explain Class diagram with notations?:


➢ A class diagram describes the static structure of a system.
● The static structure of a system comprises a number of class diagrams and their
dependencies.
● A class diagram in the Unified Modeling Language (UML) is a type of static structure
diagram that describes the structure of a system by showing the system's:
● classes,
● their attributes,
● operations (or methods),
● and the relationships among objects.

Ms.Mithu Mary George ,CSE, TIST Page 51


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

● The classes represent entities with common features, i.e., attributes and operations.
● Classes are represented as solid outline rectangles with compartments.
● Classes have a mandatory name compartment where the name is written centered in
boldface.
● The class name is usually written using mixed case convention and begins with an
uppercase (e.g. LibraryMember).
● Object names on the other hand, are written using a mixed case convention, but starts
with a small case letter (e.g., studentMember).
● Classes have optional attributes and operations compartments

Class notation
: Drawn as rectangle with three components – name, attributes, list of operations

● Class Name:
● The name of the class appears in the first partition.
● Class Attributes:
● Attributes are shown in the second partition.
● The attribute type is shown after the colon.
● Attributes map onto member variables (data members) in code
● Class Operations (Methods):
● Operations are shown in the third partition. They are services the class provides.
● The return type of a method is shown after the colon at the end of the method
signature.
● The return type of method parameters are shown after the colon following the
parameter name. Operations map onto class methods in code

Ms.Mithu Mary George ,CSE, TIST Page 52


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

Class Visibility

● The +, - and # symbols before an attribute and operation name in a class denote the
visibility of the attribute and operation.

● + denotes public attributes or operations

● - denotes private attributes or operations

● # denotes protected attributes or operations

Ms.Mithu Mary George ,CSE, TIST Page 53


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

16. Explain relationships in class diagrams?

Ms.Mithu Mary George ,CSE, TIST Page 54


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

1.Association
▪ Associations are relationships between classes in a UML Class Diagram. They are
represented by a solid line between classes.
▪ When two classes are associated, they can take each others help (i.e. invoke each others
methods) to serve user requests.
▪ If one class is associated with another bidirectionally, the object of one class to invoke
the methods of the corresponding object of the other class.
▪ A Student can register in one Elective subject. In this example, the class Student is
associated with the class ElectiveSubject.

Associations and Link


▪ An association describes a group of similar links.
▪ Alternatively, we can say that a link can be considered as an instance of an association
relation.
▪ "A person works for a company. Ram works for Infosys. Hari works for TCS.“
▪ In this example, an association relationship named works for exists between the classes
Person and Company.
▪ Ram works for Infosys, this implies that a link exists between the object Ram and the
object Infosys.
▪ Similarly, a works for link exists between the objects Hari and TCS.

2.Dependency
▪ A class is said to be dependent on another class, if any changes to the latter class
necessitates a change to be made to the dependent class..
▪ A dependency relation between two classes shows that any change made to the
independent class would require the corresponding change to be made to the dependent
class.

Ms.Mithu Mary George ,CSE, TIST Page 55


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

● Exists between two classes if changes to the definition of one may cause changes to the
other .
● Class1 depends on Class2

▪ The figure below shows another example of dependency. The Person class might ha ve a
hasRead method with a Book parameter that returns true if the person has read the book
(perhaps by checking some database).

3.Aggregation

● Aggregation represent part/whole relationships among objects.


● A special type of association.
● It represents a "part of" relationship.(Class2 is part of Class1)
● As an example, consider the following—A Book object can have upto ten Chapters.
● Aaggregation implicit a relationship where the child can exist independently of the
parent.

Ms.Mithu Mary George ,CSE, TIST Page 56


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

4.COMPOSITION
● Composition is a restricted form of Aggregation in which two entities are highly
dependent on each other.
● It represents part-of relationship.
● A special type of aggregation where parts are destroyed when the whole is destroyed.
● Objects of Class2 live and die with Class1.
● Class2 cannot stand by itself

5. INHERITANCE
● The inheritance relationship is represented by means of an empty arrow pointing from the
subclass to the superclass. The arrow may be directly drawn from the subclass to the
superclass.

Ms.Mithu Mary George ,CSE, TIST Page 57


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

Ms.Mithu Mary George ,CSE, TIST Page 58


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

17.Explain types of association?


Types of association
• Unary association: Associationbetween the same class .
Example :Person teaches Person,Person marries Person

• Binary association: Association between two classes; drawn as a solid path connecting two
classes.
Example : Person sits on a Chair

• Ternary association: Association among three classes.


• On the same line,n-ary association is an association among n classes
• Symbol is diamond with lines connecting to related classes.

 Associations may have an


◦ Association name
◦ optional black triangle ; point of triangle indicate the direction in
which to read the name

Ms.Mithu Mary George ,CSE, TIST Page 59


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

• Association navigation
• Arrow may be attached to the end of path to indicate that navigation is
supported in the direction of the class pointed to.

18.What is multiplicity in association relationship?


• Multiplicity: It specifies range of allowable associated classes; denoted by lower bound
……. Upper bound
Eg: 0....1
• * indicates unlimited upperbound
• Eg: 0....* means 0 to many

This means many employee works for 1 company

19.Compare Aggregation and composition .


Aggregation

Ms.Mithu Mary George ,CSE, TIST Page 60


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

◦ Means “a part of ”
◦ Form of association representing a structural relationship between a whole and its
parts.Aggregation implicit a relationship where the child can exist independently of
the parent.

Example

Composition
• Shows a relationship where the child cannot exist independent of the parent.

20 Represent the following entities using UML class diagram


i) Book ii) Vehicle iii)Employee

Ms.Mithu Mary George ,CSE, TIST Page 61


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

Ms.Mithu Mary George ,CSE, TIST Page 62


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

21. Draw the Class diagram of a Banking system.

In the above diagram, we can see the example for multiplicity and generalization
between multiple classes.

Ms.Mithu Mary George ,CSE, TIST Page 63


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

22. Draw the Class diagram of a Library management system

In the above diagram, we can see the example for generalization between multiple
classes.

Ms.Mithu Mary George ,CSE, TIST Page 64


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

23 Class diagram of a ATM system

24. Explain object diagram with example? OR Describe the


concept of modeling object structure?
● Object diagrams shows the snapshot of the objects in a system at a point in time.

● Since it shows instances of classes, rather than the classes themselves, it is often called
as an instance diagram.

● The objects are drawn using rounded rectangles.

Ms.Mithu Mary George ,CSE, TIST Page 65


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

● An Object Diagram can be referred to as a screenshot of the instances in a system and


the relationship that exists between them.

Object diagrams commonly contain · Objects and links

● Common Uses : To model object structures

You use object diagrams to model the static design view or static process view of a system just

as you do with class diagrams, but from the perspective of real or prototypical instances

● ·

25. List the purpose of class diagram?


● Purpose of Class diagrams
● The class diagram is the main building block of object-oriented modeling.

Ms.Mithu Mary George ,CSE, TIST Page 66


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

● It is used for general conceptual modeling of the structure of the application, and for
detailed modeling translating the models into programming code.

● Analysis and design of the static view of an application.

● Describe responsibilities of a system.

● Base for component and deployment diagrams.


● Forward engineering.

26. List the purpose of object diagram?

Purpose of Object diagrams


● Model the static design(similar to class diagrams ) or structure of a system.

● Helps us to understand the functionalities that the system should deliver to the users.

● Understand relationships between objects.

● Verify the class diagrams for completeness and accuracy by using Object Diagrams as
specific test cases.

28.Explain interaction diagrams in UML?


▪ Interaction diagrams, as their name itself implies, are models that describe how groups of
objects interact among themselves through message passing to realise some behaviour.

● Typically, each interaction diagram realises the behaviour of a single use case.

● For complex use cases, more than one interaction diagrams may be necessary to
capture the behaviour.

● An interaction diagram shows a number of example objects and the messages that are
passed between the objects within the use case.

Ms.Mithu Mary George ,CSE, TIST Page 67


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

● The interaction diagrams play a major role in any effective object oriented design
process

Different types of Interaction diagram

1. Sequence diagram

• Purpose - To visualize the sequence of a message flow in the system

• Shows the interaction between two lifelines

2. Collaboration diagram

• Also called as a communication diagram.

• Shows how various lifelines in the system connects.

3. Timing diagram

• Focus on the instance at which a message is sent from one object to another object.

1. Sequence diagram

● A sequence diagram shows interaction among objects as a two dimensional chart.

● The chart is read from top to bottom.

● The objects participating in the interaction are shown at the top of the chart as boxes
attached to a vertical dashed line.

● Inside the box the name of the object is written with a colon separating it from the
name of the class and both the name of the object and the class are underlined.

● The vertical dashed line is called the object’s lifeline.

● Any point on the lifeline implies that the object exists at that point. Absence of lifeline
after some point indicates that the object ceases to exist after that point in time,
particular point of time.

Ms.Mithu Mary George ,CSE, TIST Page 68


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

● A rectangle called the activation symbol is drawn on the lifeline of an object to indicate
the points of time at which the object is active.

● Thus an activation symbol indicates that an object is active as long as the symbol
(rectangle) exists on the lifeline.

● Each message is indicated as an arrow between the lifelines of two objects. The
messages are shown in chronological order from the top to the bottom.

Example of Sequence diagram

Collaboration diagram

● A collaboration diagram shows both structural and behavioural aspects

Ms.Mithu Mary George ,CSE, TIST Page 69


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

explicitly.

▪ This is unlike a sequence diagram which shows only the behavioural aspects.

● The structural aspect of a collaboration diagram consists of objects and links among
them indicating association.

● The behavioural aspect is described by the set of messages exchanged among the
different objects.

● A Collaboration is a collection of named objects and actors with links connecting them.
They collaborate in performing some task.

● The collaboration diagram is used to show the relationship between the objects in a
system.

● The sequence and the collaboration diagrams represent the same information but
differently.

● Instead of showing the flow of messages, it depicts the architecture of the object
residing in the system as it is based on object-oriented programming.

● The collaboration diagram, which is also known as a communication diagram, is used to


portray the object's architecture in the system.

Notations of a Collaboration Diagram

● Objects: The representation of an object is done by an object symbol with its name and
class underlined, separated by a colon.

● Actors: In the collaboration diagram, the actor plays the main role as it invokes the
interaction. Each actor has its respective role and name.

● Links: The link is an instance of association, which associates the objects and actors. It is
represented by a solid line.

Ms.Mithu Mary George ,CSE, TIST Page 70


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

● Messages: It is a communication between objects which carries information and


includes a sequence number, so that the activity may take place. It is represented by a
labeled arrow, which is placed near a link. The messages are sent from the sender to the
receiver and the receiver must understand the message.

Ms.Mithu Mary George ,CSE, TIST Page 71


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

29.How we can model a flow of control in behavioural modeling.


✓ You use interactions to model the dynamic aspect of collaborations, representing
societies of objects playing specific roles, all working together to carry out some
behavior that's bigger than the sum of the elements..
✓ You use interactions to model the flow of control within an operation, a class, a
component, a use case, or the system as a whole.
✓ Using interaction diagrams, you can reason about these flows in two ways. First,
you can focus on how messages are dispatched across time.

Ms.Mithu Mary George ,CSE, TIST Page 72


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

✓ Second, you can focus on the structural relationships among the objects in an
interaction and then consider how messages are passed within the context of
that structure.

Flow of Control by Time [sequence diagram]

Ms.Mithu Mary George ,CSE, TIST Page 73


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

Flow of Control by Organization [Collaboration diagram]

Figure is semantically equivalent to the previous one, but it is drawn as a collaboration


diagram, which emphasizes the structural organization of the objects. This figure shows the
same flow of control, but it also provides a visualization of the links among these objects.

31.List purpose of interaction diagram.


• To capture the dynamic behaviour of a system.
• To describe the message flow in the system.
• To describe the structural organization of the objects.
• To describe the interaction among objects.
• Interaction diagram visualizes the communication and sequence of message passing in the
system.
• Interaction diagram represents the ordered sequence of interactions within a system.
• Interaction diagrams can be used to explain the architecture of an object-oriented system.

Ms.Mithu Mary George ,CSE, TIST Page 74


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

32.List purpose of sequence diagram.


• Model high-level interaction between active objects in a system
• Model the interaction between object instances within a collaboration that realizes
a use case
• Model the interaction between objects within a collaboration that realizes an
operation

• Either model generic interactions (showing all possible paths through the
interaction) or specific instances of a interaction (showing just one path through the
interaction)

33.List purpose of collaboration diagram.


• Model collaborations between objects or roles that deliver the functionalities of use
cases and operations.

• Better suited for analysis activities.


• Support the identification of objects (hence classes) that participate in use cases.
• Model alternative scenarios within use cases.

34.Write short note on activity diagram?


Activity diagrams are one of the five diagrams in the UML for modeling the dynamic
aspects of systems. An activity diagram is essentially a flowchart, showing flow of control
from activity to activity.For the most part, this involves modeling the sequential (and
possibly concurrent) steps in a computational process.With an activity diagram, you can also
model the flow of an object as it moves from state to state at different points in the flow of

Ms.Mithu Mary George ,CSE, TIST Page 75


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

control. Activities ultimately result in some action, which is made up of executable atomic
computations that results in a change in state of the system or the return of a value.

Activity diagrams are not only important for modeling the dynamic aspects of a system,
but also for constructing executable systems through forward and reverse engineering.

● Activity diagram is another important behavioral diagram in UML diagram to describe


dynamic aspects of the system.

● Activity diagram is essentially an advanced version of flow chart that modelling the
flow from one activity to another activity.

● The activity can be described as an operation of the system.

● The activity diagram focuses on representing various activities. An activity is a state


with an internal action and one or more outgoing transitions which automatically
follow the termination of the internal activity.

● Activity diagrams support description of parallel activities.

● It is also called object-oriented flowchart.

● We can depict both sequential processing and concurrent processing of activities using
an activity diagram.

Activity Diagram Notations


Activity diagrams commonly contain · Activity states and action states,· Transitions,· Objects

Ms.Mithu Mary George ,CSE, TIST Page 76


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

Guards

In UML, guards are a statement written next to a decision diamond that must be true before moving
next to the next activity

Ms.Mithu Mary George ,CSE, TIST Page 77


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

Ms.Mithu Mary George ,CSE, TIST Page 78


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

35. What is meant by association? Explain various properties of association?

• An association is a structural relationship that specifies that objects of one thing


are connected to objects of another. Given an association connecting two classes,
you can navigate from an object of one class to an object of the othe r class, and
vice versa.
• An association that connects exactly two classes is called a binary association.
• Although it's not as common, you can have associations that connect more than two
classes; these are called n-ary associations.
• Graphically, an association is rendered as a solid line connecting the same or different
classes.
• Use associations when you want to show structural relationships.
• Associations are, by default, bidirectional
Name

An association can have a name, and you use that name to describe the nature of the
relationship

Role
When a class participates in an association, it has a specific role that it plays in that relationship;
a role is just the face the class at the near end of the association presents to the class at the
other end of the association

Multiplicity

Ms.Mithu Mary George ,CSE, TIST Page 79


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

An association represents a structural relationship among objects. In many modeling situations,it's


important for you to state how many objects may be connected across an instance of an association.
This "how many" is called the multiplicity of an association's role, and is written as an

expression that evaluates to a range of values or an explicit value as in Figure

36. Describe the terms events, state, state diagrams and


conditions in the context of dynamic modeling?
State
• A state is a condition during the life of an object during which it satisfies some
condition, performs some activity, or waits for some external event.

• A state corresponds to the interval between two events received by an object and
describes
the "value" of the object for that time period.

• A state is an abstraction of an object's attribute values and links, where sets of values
are grouped together into a state according to properties that affect the general
behavior of the object. For instance, stack is empty or stack is full are different states of
the object stack. As state corresponds to interval between two events received by an
object so it has duration.

Event

• An event is the specification of a significant occurrence. For a state machine, an event is


the occurrence of a stimulus that can trigger a state transition.
.

Ms.Mithu Mary George ,CSE, TIST Page 80


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

Conditions

 Condition is a Boolean function of object values.


 Eg temperature is below freezing
 Being in a state is a condition
 Conditions can be used as guards on transitions
 A guarded transition fires when its event occurs ,but only if the condition is true.
 Conditions can be used as guards on transitions “A guarded transition fires
when its events occur but only if the condition is true.

37. Illustrate state diagram/state chart of UML


• A state chart diagram is normally used to model how the state of an object changes in
its life time.State chart diagrams are good at describing how the behaviour of an object
changes across several use case executions.
• State chart diagrams show the different states of an entity.
• State machine diagrams can also show how an entity responds to various events by
changing from one state to another.
• State machine diagram is a UML diagram used to model the dynamic nature of a system
• It is also called a Statemachine or StateTransition diagram.

• An object goes through various states during itslifespan.The lifespan of an object


remains until the program is terminated.Each state represents some unique information
about the object.A state machine diagram describes all events (and states and
transitions for a single object)

Basic elements of a state chart


• State - A state is a constraint or a situation in the life cycle of an object .These are
represented by rectangles with rounded corners.

Ms.Mithu Mary George ,CSE, TIST Page 81


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

• Initial state: This represented as a filled circle.


• Final state: This is represented by a filled circle inside a larger circle.
• Events -An event is described as Event-name (comma-separated-parameter-list). Events
appear in the internal transition compartment of a state or on a transition between
states.
• Transition - Transition lines depict the movement from one state to another. Each
transition line is labeled with the event that causes the transition.

Events
• Represents incidents that cause objects to transition from one state to another..\
• Internal or External Events trigger some activity that changes the state of the system
and of some of its parts.
• An event signature is described as Event-name (comma-separated-parameter-list).
• Events appear in the internal transition compartment of a state or on a transition
between states.

Ms.Mithu Mary George ,CSE, TIST Page 82


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

The main purposes of using Statechart diagrams −

● To model the dynamic aspect of a system.

● To model the life time of a reactive system[a system that responds to external or
internal events.]

● To describe different states of an object during its life time.

● Define a state machine to model the states of an object.

38. Compare sequence diagram and collaboration diagram

Ms.Mithu Mary George ,CSE, TIST Page 83


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

39. Write short notes on JDK AND JRE.


▪ The Java Development Kit (JDK) is a software development environment which is used
to develop Java applications and applets.
▪ JDK – Java Development Kit (in short JDK) is Kit which provides the environment
to develop and execute(run) the Java program. JDK is a kit(or package) which includes
two things
➢ Development Tools(to provide an environment to develop your java programs)
➢ JRE (to execute your java program).

Ms.Mithu Mary George ,CSE, TIST Page 84


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

The Java Development Kit (JDK) is a software development environment used for developing
and executing Java applications and applets.

▪ It includes the Java Runtime Environment (JRE), an interpreter/loader (Java), a compiler


(javac), an archiver (jar), a documentation generator (Javadoc) and other tools needed
in Java development.
▪ JDK is only used by Java Developers.
Java Runtime Environment (JRE)

✓ JRE is also called as Java runtime, is a part of JDK.


✓ It pprovides minimum requirements for executing java application.
✓ It contains the class libraries, loader class, and JVM.
✓ If you want to run Java program you need JRE.
✓ All JDK versions comes bundled with Java Runtime Environment, so you do not need to
download and install the JRE separately in your PC.
✓ The runtime environment loads class files and ensures there is access to memory and
other system resources to run them.

Ms.Mithu Mary George ,CSE, TIST Page 85


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

✓ JRE is an installation package which provides environment to only run(not develop) the
java program(or application)onto your machine.

40.Summarize JVM
▪ JVM (Java Virtual Machine) is an abstract machine that enables your computer to run a
Java program.
▪ JVM is a program which provides the runtime environment to execute Java programs.
▪ JVM is a virtual machine that resides in the real machine (your computer) and the
machine language for JVM is byte code.
▪ Java compiler first compiles your Java code to bytecode.
▪ Then, the JVM translates bytecode into native machine code (set of instructions that a
computer's CPU executes directly).
▪ A virtual machine(VM) is a software implementation of an abstract computer.
▪ Java has a VM specification that formally describes what is required in a Java VM
implementation.
▪ Java Virtual Machine(JVM) is implemented as per Java VM specification to execute the
Java bytecode (ie, instruction set understandable to the VM).

Ms.Mithu Mary George ,CSE, TIST Page 86


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

▪ Most of the JVMs are implemented using C language, JVM developed for one platform
will not work on another. ie, JVM is platform dependent.
▪ It provides the runtime environment to execute Java programs (bytecode) on a
particular platform.
▪ Platform independency of Java is due to JVM.

Ms.Mithu Mary George ,CSE, TIST Page 87


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

41.Explain JVM Architecture.


The JVM is divided into three main subsystems:
▪ ClassLoader Subsystem
▪ Runtime Data Area
▪ Execution Engine

Ms.Mithu Mary George ,CSE, TIST Page 88


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

JVM - Runtime Data Area

Ms.Mithu Mary George ,CSE, TIST Page 89


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

JVM - Execution Engine

42.Explain Java Bytecode


▪ Java bytecode is the instruction set for the Java Virtual Machine.
▪ Bytecode is the compiled format for Java programs.

Ms.Mithu Mary George ,CSE, TIST Page 90


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

▪ When we write a program in Java, firstly, the compiler compiles that program and a
bytecode is generated for that piece of code.
▪ When a Java program is compiled, a Bytecode is generated for that program in the form
of a .class file.
▪ The bytecode generated after the compilation is run by the Java virtual machine.
▪ Resources required to run the bytecode are made available by theJava Virtual Machine,
which calls the processor to allocate the required resources.

▪ Java byte code is the instruction set for the Java Virtual Machine.
▪ It is the machine code in the form of a .class file.
▪ Byte code is a machine independent code.
▪ It is not completely a compiled code but it is an intermediate code somewhere in the
middle which is later interpreted and executed by JVM.
▪ Byte code is a machine code for JVM.
▪ Byte code implementation makes Java a platform- Independent language.

43.Explain the Advantages of Java Bytecode

Ms.Mithu Mary George ,CSE, TIST Page 91


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

▪ Platform independence is one of the soul reasons for which James Gosling started the
formation of java and it is this implementation of bytecode which helps us to achieve
this.
▪ When a program is written and compiled in JAVA a separate file is created for a
compiled program. This file (.class) is called bytecode in java.\
▪ Byte code generated in a particular platform can be executed in any other platform i.e.
the byte code generated in windows OS can also be executed in Unix OS.
▪ The one which makes this possible is the JVM (JAVA VIRTUAL MACHINE).
▪ When the program is written and compiled the compiler send the generated bytecodes
to the JVM in the machine and this JVM converts the byte codes into native code which
is readable by a particular machine. Thus the output is displayed.

Ms.Mithu Mary George ,CSE, TIST Page 92


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

44. Summarize Java Programming language platforms


▪ Allows applications written for that platform to run on any compatible system with all
the advantages of the Java.
▪ Major platforms are
▪ 1. Java Platform, Standard Edition (Java SE)
▪ 2. Java Platform, Enterprise Edition (Java EE)
▪ 3. Java Platform Micro Edition (Java ME)
Java Platform, Standard Edition (Java SE)
▪ Java SE's API provides the core functionality of the Java programming language.
▪ It defines everything from the basic types and objects of the Java programming
language to high-level classes that are used for networking, security, database access,
graphical user interface (GUI) development, and XML parsing.
▪ In addition to the core API, the Java SE platform consists of a virtual machine,
development tools, deployment technologies, and other class libraries and toolkits
commonly used in Java technology applications.
For the development of following applications, Java SE is used
● Standalone Applications for desktop computers.
● Web supportive applications (Applets) (It is outdated and nobody is using)
● Database interaction Application (JDBC)
● Integrated Application (XML)

Java EE [Java Enterprise Edition]


▪ The Java EE platform is built on top of the Java SE platform. The Java EE
platform provides an API and runtime environment for developing and
running large-scale applications..
▪ The Java EE provides a platform for developers with enterprise features
such as distributed computing and web services, Enterprise JavaBeans, Java
Server Pages, Servlets.
Ms.Mithu Mary George ,CSE, TIST Page 93
Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

▪ Java EE applications are usually run on reference run times such


as microservers or application servers.
Examples of some contexts where Java EE is used are e-commerce, accounting,
banking information systems.

For the development of following applications Java EE is used ● Web Application


(Servlets/JSPs/JSF)
● Enterprise Application (EJB)
● Interoperable Application (Web services)

Java ME [Java Micro Edition]


▪ The Java ME platform provides an API and a small-footprint virtual machine
for running Java programming language applications on small devices, like
mobile phones.
▪ The API is a subset of the Java SE API, along with special class libraries
useful for small device application development.
▪ Java ME applications are often clients of Java EE platform services.
▪ Java ME (Embedded) is designed for resource-constrained devices like
wireless modules for M2M, industrial control, smart-grid infrastructure,
environmental sensors and tracking, and more.
● The JME Embedded API is a subset of the Java SE API, along with special class
libraries useful for small device application development.
● Java Card technology provides a secure environment for applications that
run on smart cards and other devices with very limited memory and
processing.

Ms.Mithu Mary George ,CSE, TIST Page 94


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

JavaFX
▪ JavaFX is a software platform for creating and delivering desktop
applications, as well as rich Internet applications (RIAs) that can run across
a wide variety of devices.
▪ The applications built in JavaFX, can run on multiple platforms including
Web, Mobile and Desktops.
▪ JavaFX is intended to replace swing in Java applications as a GUI
framework.
▪ JavaFX is a set of graphics and media packages that enables developers to
design, create, test, debug, and deploy rich client applications that operate
consistently across diverse platforms.
▪ Java FX technology was a platform for creating rich internet applications
written in Java FX Script.
▪ Java FX Script is a statically typed declarative language that is compiled to
Java technology bytecode , which can then be run on a Java VM.
▪ Now it is merged with Java SE.

Ms.Mithu Mary George ,CSE, TIST Page 95


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

45. Explain applets in java.


▪ An applet is a Java program that can be embedded into a web page. It runs
inside the web browser and works at client side.
▪ An applet is a special kind of Java program that runs in a Java enabled
browser.
▪ This is the first Java program that can run over the network using the
browser.
▪ To create an applet, a class must class extends java.applet.Applet class.
▪ An Applet class does not have any main() method.
▪ It is viewed using JVM. The JVM can use either a plug-in of the Web
browser or a separate runtime environment to run an applet application.
▪ Note: Java Applet is deprecated since Java 9. It means Applet API is no
longer considered important.
Lifecycle of Java Applet
▪ Applet is initialized.
▪ Applet is started
▪ Applet is painted.
▪ Applet is stopped.
▪ Applet is destroyed.

45.Differentiate java applet and java application.

Ms.Mithu Mary George ,CSE, TIST Page 96


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

46.Summarize features of java [Java Buzzwords].


1.Simple

▪ Java was designed to be easy for the professional programmer to learn and
use effectively.
▪ If you already understand the basic concepts of object-oriented
programming, learning Java will be even easier.
▪ C++ programmer can move to JAVA with very little effort to learn.
▪ Java syntax is based on C++
▪ Java has removed many complicated and rarely-used features, for
example, explicit pointers, operator overloading, etc.
2. Object-Oriented
▪ Java strongly supports the concepts of Object-Oriented Programming .
▪ Java supports major Object-Oriented programming features like
Encapsulation, Abstraction, and Inheritance.

Ms.Mithu Mary George ,CSE, TIST Page 97


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

▪ Almost everything in Java is an object. All programs and data live within
objects and classes.
▪ ‘Objects’ model Java rather than the ‘processes’.
3.Secure

▪ When a Java Compatible Web browser is used, downloading can be done


safely without fear of viral infection or malicious intent.

▪ Java is a more secure language as compared to C/C++, as it does not allow


a programmer to explicitly create pointers.

▪ Programs run in a virtual machine sandbox – A separate environment that


allows users to execute their applications without affecting the underlying
system.

▪ It has a bytecode verifier that checks the code fragments for any illegal
code that violates the access right.

What makes java more secure than other languages?

➢ Doesn’t use pointers as other languages do

➢ Automated memory management

➢ The Java compiler check, detects and handles errors seamlessly.

➢ Java Sandbox

➢ Security API’s

➢ Exception Handling

➢ Foolproof data type checking

Ms.Mithu Mary George ,CSE, TIST Page 98


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

4.Robust

▪ Java is a strictly typed language, it checks your code at compile time.


However, it also checks your code at run time .

▪ Two of the main reasons for program failure: memory management


mistakes and mishandled exceptional conditions (that is,run-time errors).

▪ Java virtually eliminates these problems by managing memory allocation


and deallocation for you.

▪ Deallocation is completely automatic, because Java provides garbage


collection for unused objects.

▪ Java provides object-oriented exception handling. In a well-written Java


program, all run-time errors can—and should—be managed by your
program.

▪ Hence java is robust.

Ms.Mithu Mary George ,CSE, TIST Page 99


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

5.Multithreaded

▪ Multithreaded means handling multiple tasks simultaneously or executing


multiple portions (functions) of the same program in parallel.

▪ The code of java is divided into smaller parts and Java executes them in
a sequential and timely manner.

6.Architecture-Neutral

▪ This buzzword means that the program written on one platform or OS


is independent of other platforms or environments and can run on any
other Operating System without recompiling them. In other words, it is
based on the ‘Write-once-run-anywhere’ (WORA) or ‘Write-once-run-
everywhere’ (WORE) approach.

▪ Byte-code is not dependent on any machine architecture and Java Virtual


Machine (JVM) can easily translate bytecode into a machine-specific code.

7.Interpreted and Compiled

▪ The bytecode can either be interpreted or compiled to native code or


directly executed on the processor. But, if the bytecode is interpreted, it
directly affects the speed of the application.

▪ In order to speed up the performance, JIT compiler communicates with


JVM at the execution time in order to compile byte code sequences into
native machine code.

Ms.Mithu Mary George ,CSE, TIST Page 100


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

▪ Basically, when using JIT Compiler, the native code is easily executed by the
hardware when compared to JVM Interpreter. By doing so, there will be a
huge gain in execution speed.

8. Portable

▪ Java programs can execute in any environment (Linux,Window,Mac etc.)


for which there is a Java run-time system (JVM).

▪ That really means there is no implementation dependent features.


9. Platform Independent

▪ Being platform-independent means a program compiled on one machine


can be executed on any machine in the world without any change. Java
achieves platform independence by using the concept of the BYTE code.

▪ Java compiler converts the source code into an intermediate code called
the byte code and this byte code is further translated to machine-
dependent form by another layer of software called JVM (Java Virtual
Machine).

▪ Therefore, JVM can execute bytecode on any platform or OS .

▪ This is where the “Write Once, run anywhere” (WORA) slogan for Java
comes in, which means that we can develop applications on one
environment (OS) and run on any other environment without doing any
modification in the code.

Ms.Mithu Mary George ,CSE, TIST Page 101


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

10. Distributed

▪ Java is distributed because it encourages users to create distributed


applications.

▪ In Java, we can split a program into many parts and store these parts on
different computers. A Java programmer sitting on a machine can access
another program running on the other machine.

▪ Java helps us to achieve this by providing the concept of RMI (Remote


Method Invocation) and EJB (Enterprise JavaBeans).

▪ Java comes with an extensive library of classes for interacting, using TCP/IP
protocols such as HTTP and FTP, which makes creating network
connections much easier than in C/C++.

Ms.Mithu Mary George ,CSE, TIST Page 102


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

▪ It also enables multiple programmers at many locations to work together


on a single project.

47. Describe JAVA PROGRAM STRUCTURE

Documentation Section

▪ You can write a comment in this section. It helps to understand the code.
These are optional.
▪ It is used to improve the readability of the program.
▪ The compiler ignores these comments during the time of execution
▪ Types of comments that Java supports
Ms.Mithu Mary George ,CSE, TIST Page 103
Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

▪ Single line Comment


//This is single line comment
▪ Multi-line Comment
/* this is multiline comment.
and support multiple lines*/
Package Statement
▪ A package is a group of classes that are defined by a name.
▪ That is, if you want to declare many classes within one element, then you
can declare it within a package
Package is declared as: package package_name;
Eg: package mypackage;
Import Statement
▪ If you want to use a class of another package, then you can do this by
importing it directly into your program.
import java.util.Date; //imports the date class

Class Definition
▪ A Java program may contain several class definitions. Classes are the main
and essential elements of any Java program.
Main Method Class
▪ The main method is from where the execution actually starts .
▪ Every Java stand-alone program requires the main method as the starting
point of the program.
▪ This is an essential part of a Java program.
▪ There may be many classes in a Java program, and only one class defines
the main method
▪ Methods contain data type declaration and executable statements.

Ms.Mithu Mary George ,CSE, TIST Page 104


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

Basic structure of Java program


/*
This is a simple Java program.
Call this file "Example.java".
*/

class Example {
// Your program begins with a call to main().
public static void main(String args[]) {
System.out.println("This is a simple Java program.");
}
}

Analysing each line in the program


/*
This is a simple Java program.
Call this file "Example.java".
*/
They are the comment line; the code written inside the comment lines are ignored by the
compiler.There are thre ways of representing commentlines.

• 1st method :multiline comment (/*...*/)


Eg: /*
This is a simple Java program.
Call this file "Example.java".
*/
• 2nd method single line comment (//)
Eg: // Your program begins with a call to main().

• 3rd method documentation comment (/**…*/) .


This type of comment is used to produce an HTMLfile that documents your
program. The documentation comment begins with a /** and ends with a */.

class Example {
• This line uses the keyword class to declare that a new class is being defined.

Ms.Mithu Mary George ,CSE, TIST Page 105


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

• Example is an identifier that is the name of the class.


• The entire class definition, including all of its members, will be between the opening
curly brace ({) and the closing curly brace (}).

public static void main(String args[]) {


• All Java applications begin execution by calling main( ).
• The public keyword is an access specifier, which allows programmer to control the
visibility of class members.
• When a class member is preceded by public, then that member may be accessed by
code outside the class in which it is declared. In this case, main( ) must be declared as
public, since it must be called by code outside of its class when the program is started.
• The keyword static allows main( ) to be called without having to instantiate a particular
instance of the class.
• The keyword void simply tells the compiler that main( ) does not return a value.
• In main( ), there is only one parameter, String args[ ] .It declares a parameter named
args, which is an array of instances of the class String. In this case, args receives any
command-line arguments present when the program is executed.

System.out.println("This is a simple Java program.");

• This line outputs the string “This is a simple Java program.” followed by a new line on
the screen.
• Output is actually accomplished by the built-in println( ) method, defined in PrintStream
class.
• System is a final class in java.lang package .It provides standard input and output
functions.
• Out: is an object or variable of Output stream class in System class.

47. Summarize the steps in Implementing a Java program


Implementation of Java program involves three steps.
1) Coding the program: Program is edited in any text editor. We must save the
program in a file ensuring that filename contains the classname properly. This file is

Ms.Mithu Mary George ,CSE, TIST Page 106


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

called source file. If the program contains multiple class, the filename should be the
name of the class containing the main method.All source files have the extension “.java”.

2) Compiling the Program: To compile the program, execute the compiler, javac,
specifying the name of the source file on the command line, as shown here:
Eg: C:\>javac Example.java
Javac compiler creates a file called Example.class that contains bytecode
version of program.
3)Running the program: To actually run the program, you must use the Java application
launcher, called java.To do so, pass the class name as a command-line argument, as shown
here:
Eg: C:\>java Example
When the program is run, the output of the programis displayed on the output
console.

48. Draw the Use Case diagram of online railway ticket reservation
system .

Ms.Mithu Mary George ,CSE, TIST Page 107


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

49. Why are java programs said to be platform independent?

• Java compiler produces a unique type of code called bytecode unlike c compiler where
compiler produces only natively executable code for a particular machine.
• When the Java program runs in a particular machine it is sent to java compiler, which
converts this code into intermediate code called bytecode.

Ms.Mithu Mary George ,CSE, TIST Page 108


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

• This bytecode is sent to Java virtual machine (JVM) which resides in the RAM of any
operating system.
• JVM recognizes the platform it is on and converts the bytecodes into native machine
code. Hence java is called platform independent language.
• When a program is written and compiled in C/C++ language, the code is directly
converted into machine readable language .i.e. executable code.
• generated .exe file can run only on specific operating system. i.e. when the program is
compiled in windows OS .exe file can run only in windows OS and not on Unix OS.
• When the program written in java is compiled by the compiler the intermediate code
generated are called Byte codes. Like native codes Byte codes are not executable codes.
The virtual machine present in the machine executes these byte codes. These bytecodes
can be executed in any other platform irrespective of their generated platform.
• When a program is written and compiled in JAVA a separate file is created for a compiled
program. This file (.class) is called bytecode in java.
• The .class file created cannot be executed directly.
• Instead it will be converted into executable code by a virtual machine in the system. These
bytecodes generated by the compiled program are to achieve the purpose of platform
independency.
• Byte code generated in a particular platform can be executed in any other platform i.e. the
byte code generated in windows OS can also be executed in Unix OS. The one which
makes this possible is the JVM (JAVA VIRTUAL MACHINE).
• When the program is written and compiled the compiler send the generated bytecodes to
the JVM resent in the machine and this JVM converts the byte codes into native code
which is readable by a particular machine. Thus the output is displayed.

Ms.Mithu Mary George ,CSE, TIST Page 109


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

Irrespective of the platform the JVM belongs to, the generated bytecode can run on any JVM.
The outputs of the bytecode run on any JVM will be the same.

50.Why is the main method in java qualified as public, static, and


void?

Valid Signature of main method in Java

public static void main(String args[]) {}


• This is the line at which the program will start executing. All Java applications begin
execution main method in Java is public so that its visible to every other class, even
which are not part of its package. if its not public JVM classes might not able to access it.
• Making the main() method public makes it globally available. It is made public so that
JVM can invoke it from outside the class as it is not present in the current class.

• main method is static in Java, so that it can be called without creating any instance. While
JVM tries to execute Java program it doesn't know how to create instance of main class
as there is no standard constructor is defined for main class.

Ms.Mithu Mary George ,CSE, TIST Page 110


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

• The static main() method makes it very clear for the JVM to call it for launching the
Java Application
• main method is void in Java because it doesn't return any thing to caller which is JVM .

51. What are advantages of using UML?

A diagrammatic representation is for specifying the kind of Object Oriented Programming


design.
- It explains the concepts like business modeling, enterprise architecture and OOAD. To
understand the UML model, one need not know detailed technical knowledge.
- UML shows the future modeling where the entire applications are generated from high -level
UML models and highlights the best practices for adopting UML in an enterprise.

• A UML diagram is beneficial in that it is very readable. The diagram is meant to be


understood by any type of programmer and helps to explain relationships in a program in
a straightforward manner.

Ms.Mithu Mary George ,CSE, TIST Page 111


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

52. Illustrate the steps involved in Java compilation.


• In the Java programming language, all source code is first written in plain text
files and save with the .java extension. After compilation, .class files are generated
by javac compiler. A .class file does not contain code that is native to your processor; it
instead contains bytecodes (it is machine language of the Java Virtual Machine1
(JVM)).

Steps For compile Java Program

• First Save Java program with same as class name with .java extension.
Example: Sum.java
• Compile: javac Filename.java
Example, javac Sum.java
Note: Here javac is tools or application programs or exe files which is used for Compile the Java program.

Steps For Run Java Program

• For run java program use java tool.


• Run by: java Filename
Example: java sum
Note: Here java is tools or application programs or exe files which is used for run the Java program.

Ms.Mithu Mary George ,CSE, TIST Page 112


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

53. Differentiate between a class and an object.

Ms.Mithu Mary George ,CSE, TIST Page 113


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

54. Differentiate between links and associations?


A link is a physical or conceptual connection between object instances. In
OMT, link is represented by a line labeled with its name .

An association describes a group of links with common structure and common semantics
between two or more classes . Association is represented by a line labeled with the association
name in italics.

Ms.Mithu Mary George ,CSE, TIST Page 114


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

55. Consider a Banking System. Identify three entities in the system


which can be represented using classes and show the relationship
between them using UML class diagrams .

Ms.Mithu Mary George ,CSE, TIST Page 115


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

56 Draw Use case Diagram for online Pizza ordering system

57. Draw the Use case diagram of a movie reservation system

Ms.Mithu Mary George ,CSE, TIST Page 116


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

58. Is Java is Pure Object Oriented language?

There are seven qualities to be satisfied for a programming language to be pure Object
Oriented. They are:

1. Encapsulation/Data Hiding

2. Inheritance

Ms.Mithu Mary George ,CSE, TIST Page 117


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

3. Polymorphism

4. Abstraction

5. All predefined types are objects

6. All operations are performed by sending messages to objects

7. All user defined types are objects.

If you look at these seven qualities, Java does satisfy most of them. Java supports Encapsulation
at class and package level, It supports Abstraction, Inheritance and Polymorphism, and all user
defined types are also objects. What it doesn't support is #5, all predefined types are not
objects in Java, because you can define primitive types. This means it also violates #6. That's
why Java is not a pure object oriented language.

59. Summarize Garbage Collection in Java


➢ When JVM starts up, it creates a heap area which is known as runtime data area. This is
where all the objects (instances of class) are stored.
➢ Since this area is limited, it is required to manage this area efficiently by removing the
objects that are no longer in use.
➢ The process of removing unused objects from heap memory is known as Garbage
collection and this is a part of memory management in Java.
➢ Languages like C/C++ don’t support automatic garbage collection, however in java, the
garbage collection is automatic.
▪ In java, garbage means unreferenced objects.
▪ Garbage Collection is process of reclaiming the runtime unused memory automatically.
In other words, it is a way to destroy the unused objects.
▪ Main objective of Garbage Collector is to free heap memory by destroying unreachable
objects.

Ms.Mithu Mary George ,CSE, TIST Page 118


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

▪ Unreachable objects : An object is said to be unreachable iff it doesn’t contain any


reference to it.
▪ Eligibility for garbage collection : An object is said to be eligible for GC(garbage
collection) iff it is unreachable.
▪ finalize() method – This method is invoked each time before the object is garbage
collected and it perform cleanup processing.

Basic process.
▪ In the first step, unreferenced objects are identified and marked as ready for garbage
collection.
▪ In the second step, marked objects are deleted.
▪ Optionally, memory can be compacted after the garbage collector deletes objects, so
remaining objects are in a contiguous block at the start of the heap.
▪ The compaction process makes it easier to allocate memory to new objects sequentially
after the block of memory allocated to existing objects..

Ms.Mithu Mary George ,CSE, TIST Page 119


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

Request for Garbage Collection


▪ The garbage collection implementation lives in the JVM.
▪ We now know that the unreachable and unusable objects are available for garbage
collection but the garbage collection process doesn’t happen instantly.
▪ Which means once the objects are ready for garbage collection they must to have to wait
for JVM to run the memory clean-up program that performs garbage collection.
▪ We can request to JVM for garbage collection by calling System.gc() method.
Advantage of Garbage Collection
▪ It makes java memory efficient because garbage collector removes the unreferenced
objects from heap memory.
▪ It is automatically done by the garbage collector(a part of JVM) so we don't need to
make extra efforts.

60. Explain Lexical issues in Java (Java Tokens)


▪ Java Tokens are the smallest individual building block or smallest unit of a Java program.
▪ Java program is a collection of different types of tokens.

Ms.Mithu Mary George ,CSE, TIST Page 120


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

Whitespace
▪ Java is a free-form language. This means that you do not need to follow any special
indentation rules.
▪ There should be at least one whitespace character between each token that was not
already delineated by an operator or separator.
▪ In Java, whitespace is a space, tab, or newline.
▪ White space in Java is used to separate tokens in the source file. It is also used to improve
readability of the source code.
▪ Eg: int i = 0;
Identifiers
▪ Java Identifiers are the user-defined names of variables, methods,
classes, arrays, packages, and interfaces.
▪ An identifier may be any descriptive sequence of uppercase and lowercase letters,
numbers, or the underscore and dollar-sign characters.
▪ They must not begin with a number.
▪ Again, Java is case-sensitive, so VALUE is a different identifier than Value.
▪ Some examples of valid identifiers are

AvgTemp, count, a4..


Identifier must follow some rules.
➢ All identifiers must start with either a letter( a to z or A to Z ) or currency
character($) or an underscore.
➢ They must not begin with a digit.
➢ After the first character, an identifier can have any combination of characters.
➢ A Java keywords cannot be used as an identifier.
➢ Identifiers in Java are case sensitive, foo and Foo are two different

Ms.Mithu Mary George ,CSE, TIST Page 121


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

identifiers.
➢ They can be any length Eg: int a; char name;

Constants or Literals
➢ Literals or Constants are fixed values of a particular type of data, which cannot be
modified in a program.
➢ literals are constant variables with fixed values.
➢ For example, here are some literals:
➢ Eg int num = 100;

➢ float num = 88.9;


char example = ‘c’
String str = “hai”
boolean b = false;
Comments
▪ As mentioned, there are three types of comments defined by Java. You have already seen
two: single-line and multiline.
▪ The third type is called a documentation comment. This type of comment
is used to produce an HTML file that documents your program.
▪ The documentation comment begins with a /** and ends with a */.
Separators
▪ In Java, there are a few characters that are used as separators. The most commonly used

separator in Java is the semicolon .

Ms.Mithu Mary George ,CSE, TIST Page 122


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

The Java Keywords


• Keywords in Java are predefined or reserved words that have special meaning to the Java
compiler.
• Each keyword is assigned a special task or function and cannot be changed by the user
• These keywords, combined with the syntax of the operators and separators, form the
foundation of the Java language.
• These keywords cannot be used as names for a variable, class, or method.
• The keywords const and goto are reserved but not used.
• In addition to the keywords, Java reserves the following: true, false, and null. These are
values defined by Java.
• You may not use these words for the names of variables, classes, and so on.
• Eg:Boolean,int,byte,switch,if etc

Operators

Ms.Mithu Mary George ,CSE, TIST Page 123


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

An operator is a symbol that takes one or more arguments and operates on them to produce a
result.
• Unary Operator
• Arithmetic Operator
• shift Operator
• Relational Operator
• Bitwise Operator
• Logical Operator
• Ternary Operator
• Assignment Operator

61.Draw the object diagram of ATM?

Ms.Mithu Mary George ,CSE, TIST Page 124


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

62.Draw the class diagram of hospital management system?

63.Usecase diagram of airport check-in

Ms.Mithu Mary George ,CSE, TIST Page 125


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

63.Usecase diagram of online shopping

Ms.Mithu Mary George ,CSE, TIST Page 126


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

64.Usecase diagram of hospital management

65.Draw the various UML diagrams of library management system.

Ms.Mithu Mary George ,CSE, TIST Page 127


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

USECASE DIAGRAM OF LIBRARY MANAGEMENT

Ms.Mithu Mary George ,CSE, TIST Page 128


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

Sequence diagram for LIBRARAY MANGEMENT

Ms.Mithu Mary George ,CSE, TIST Page 129


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

Ms.Mithu Mary George ,CSE, TIST Page 130


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

COLLABORATION DIGRAM FOR LIBRARY MANGEMENT

Ms.Mithu Mary George ,CSE, TIST Page 131


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

Ms.Mithu Mary George ,CSE, TIST Page 132


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

ACTIVITY DIGRAM FOR LIBRARY MANAGEMENT

Ms.Mithu Mary George ,CSE, TIST Page 133


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

STATECHART DIAGRAM FOR LIBRARY MANGEMEN

66.Draw Sequence diagram and collaboration diagram of ATM

Ms.Mithu Mary George ,CSE, TIST Page 134


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

ATM COLLABORATION DIAGRAM

Ms.Mithu Mary George ,CSE, TIST Page 135


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

Ms.Mithu Mary George ,CSE, TIST Page 136


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

Ms.Mithu Mary George ,CSE, TIST Page 137


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

66.Draw State diagram of ATM?


State Diagram:- State transition diagrams provide a way to model the various states in which an

object can exist. While the class diagram show a static picture of the classes and their

relationships, state transition diagrams model the dynamic behavior of a systen in response to

extermal events (stimuli). State transition diagrams consist of the following:

1. States , which show the possible situations in which an object can find itself

2. Transitions , which show the different events which cause a change in the state of an object.

Here, is an example of the state diagram for the session of ATM.

Ms.Mithu Mary George ,CSE, TIST Page 138


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

67.Draw Activity diagram of ATM?


Activity Diagram:- Activity diagrams describe the activities of a class. They are similar to state
transition diagrams and use similar conventions, but activity diagrams describe the
behavior/states of a class in response to internal processing rather than external events. They
contain the following elements:

1. Swimlanes , which delegate specific actions to objects within an overall activity

Ms.Mithu Mary George ,CSE, TIST Page 139


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

2. Action States , which represent uninterruptible actions of entities, or steps in the execution
of an algorithm

3. Action Flows , which represent relationships between the different action states on an entity

4. Object Flows , which represent utilization of objects by action states, or influence of action
states on objects.

Following are the examples of Login, Withdraw Activity Diagrams

LOGIN ACTIVITY DIAGRAM

Ms.Mithu Mary George ,CSE, TIST Page 140


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

Ms.Mithu Mary George ,CSE, TIST Page 141


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

Withdraw Activity Diagrams

Ms.Mithu Mary George ,CSE, TIST Page 142


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

68.Differentiate abstraction and encapsulation?

Ms.Mithu Mary George ,CSE, TIST Page 143


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

69. Consider the process of ordering a pizza over the phone. Draw an activity diagram
representing each step of the process, from the moment you pick up the phone to the point
where you start eating the pizza. Do not represent any exceptions. Include activities that
others need to perform.

Ms.Mithu Mary George ,CSE, TIST Page 144


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

70. Draw the state diagram for a telephone line. At the start of a call, the telephone line is id le. Wh en
the phone is removed from the hook, it emits a dial tone and can accept the dialing of digits.Upon
entry of a valid number, the phone system tries to connect the call and route it to the proper
destination. The connection can fail if the number or trunk are busy. If the connection is successful the
called phone begins ringing. If the called party answers th e phone, a conversatio n can o ccur. Wh en
the called party hangs up the phone disconnects and rewards to idle when put on hook again.

Ms.Mithu Mary George ,CSE, TIST Page 145


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

71. A product vending machine accepts coins for a variety of products.


After the user has made a valid selection,. When the amount of money
deposited into the machine is equal to or greater than the price of any of
its available products the machine will dispense the product together
with the change . Draw the Activity Diagram, sequence diagram and
collaboration diagram for this vending machine.

ACTIVITY DIAGRAM OF VENDING MACHINE

Ms.Mithu Mary George ,CSE, TIST Page 146


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

SEQUENCE DIAGRAM OF VENDING MACHINE

Ms.Mithu Mary George ,CSE, TIST Page 147


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

COLLABORATION DIAGARM OF VENDING MACHINE

Ms.Mithu Mary George ,CSE, TIST Page 148


Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY

72. Draw a class diagram for order processing system.

Ms.Mithu Mary George ,CSE, TIST Page 149

You might also like