0% found this document useful (0 votes)
16 views22 pages

OOPJ - Unit 6 7 8 9 Theory

The document covers key concepts in Object-Oriented Programming using Java, specifically focusing on Exception Handling, Multithreaded Programming, and IO Programming. It explains the use of keywords like final, finally, and finalize, as well as the differences between errors and exceptions, and provides examples of custom exception handling. Additionally, it discusses thread lifecycle, interprocess communication, and demonstrates file reading and writing operations.
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)
16 views22 pages

OOPJ - Unit 6 7 8 9 Theory

The document covers key concepts in Object-Oriented Programming using Java, specifically focusing on Exception Handling, Multithreaded Programming, and IO Programming. It explains the use of keywords like final, finally, and finalize, as well as the differences between errors and exceptions, and provides examples of custom exception handling. Additionally, it discusses thread lifecycle, interprocess communication, and demonstrates file reading and writing operations.
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/ 22

Sem-5 – OOPJ –Unit-6,7,8,9 Theory - 2016

L.J. Institute of Engineering & Technology


Object Oriented Programming using JAVA - 2150704

Unit-6 Exception Handling


1 Explain & illustrate by examples use of final, finally and method finalize.
The final keyword in java is used to restrict the user. The java final keyword can be used in many
context. Final can be:
final variable final method final class

If you make any variable as If you make any method as If you make any class as
final, you cannot change the final, you cannot override final, you cannot extend it.
value of final variable(It will it. -> Use to stop Inheritance.
be constant). -> Use To Stop Overriding
- > Use to stop value Example:
change Example: final class A
class A {
Example: { }
class A final void m1() class B extends A // Error
{ {} {
final int i =10; } }
void change() class B extends A
{ { //try to override it
i=15//Error void m1() // Error
} {}
}
}

2)finally : Exception handling keyword

finally block is a block that is used to execute important code such as closing connection, stream,
resources like port, files etc.

Java finally block is always executed whether exception is handled or not.

Java finally block follows try or catch block.

Syntax and Example:

public class TestFinallyBlock2{


public static void main(String args[]){
try{
int data=25/0;
System.out.println(data);
}
catch(ArithmeticException e){System.out.println(e);}
finally{System.out.println("finally block is always executed");}
System.out.println("rest of the code...");
}
}

Sem-5-OOPJ– Hemali Shah – LJIET Page 1


Sem-5 – OOPJ –Unit-6,7,8,9 Theory - 2016
3)finalize – It is method of Object class.
public void finalize(){} is a method which is work as a destructor in java. Before deleting object of class
finalize() method is called by java Garbage collector.
2 Enlist and explain the difference between error and exception. Explain Exception handling in
JAVA. Write an application that generates custom exception if any value from its command line
arguments is negative.
Errors Exceptions
Errors in java are of type java.lang.Error. Exceptions in java are of type java.lang.Exception.
Exceptions include both checked as well as
All errors in java are unchecked type.
unchecked type.
Checked exceptions are known to compiler where
Errors happen at run time. They will not be known
as unchecked exceptions are not known to compiler
to compiler.
because they occur at run time.
You can recover from exceptions by handling them
It is impossible to recover from errors.
through try-catch blocks.
Errors are mostly caused by the environment in Exceptions are mainly caused by the application
which application is running. itself.
Examples :
Examples : Checked Exceptions : SQLException, IOException
java.lang.StackOverflowError, Unchecked Exceptions :
java.lang.OutOfMemoryError ArrayIndexOutOfBoundsException,
ClassCastException, NullPointerException
Checked Exceptions Unchecked Exceptions
They are known at compile time. They are known at run time.
They are not checked at compile time. Because
They are checked at compile time.
they occur only at run time.
These are compile time exceptions. These are run time exceptions.
If these exceptions are not handled properly,
If these exceptions are not handled properly in they don’t give compile time error. But
the application, they give compile time error. application will be terminated prematurely at
run time.

All sub classes of java.lang.Exception Class All sub classes of RunTimeException and sub
except sub classes of RunTimeException are classes of java.lang.Error are unchecked
checked exceptions. exceptions.

Exception Handling: Exception = abnormal condition of program And Handling = Handle it.
- It is mechanism of java to handle abnormal condition of program.
- It is use to handle Run time exception.
- try, catch, finally, throw and throws are use to handle exception in java.

Example: to handle command line negative integer value.


class NegativeValueException extends Exception {
int value;
public NegativeValueException(int value) {
this.value = value;
}
public String toString() {
return "NegativeValueException{" + "value=" + value + "}is negative.";
Sem-5-OOPJ– Hemali Shah – LJIET Page 2
Sem-5 – OOPJ –Unit-6,7,8,9 Theory - 2016
}
}
public class CustomExceptionNegativeValueDemo {

public static void main(String[] args) {


try {
int a = Integer.parseInt(args[0]);
if (a < 0) {
NegativeValueException e = new NegativeValueException(a);
throw e;
}
System.out.println("You have entered positive value... :)" + a);
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("Command line Array Error " + e);

} catch (NumberFormatException e) {
System.out.println("Not a No Error: " + e);

} catch (NegativeValueException e) {
System.out.println("Value Error: " + e);

}
}
}

Output:
1)Run: java CustomExceptionNegativeValueDemo
Command line Array Error java.lang.ArrayIndexOutOfBoundsException: 0
2)Run: java CustomExceptionNegativeValueDemo -2
Value Error: NegativeValueException{value=-2}is negative.
3)Run: java CustomExceptionNegativeValueDemo a
Not No Error:java.lang.NumberFormatException: For input string: "a"
4) )Run: java CustomExceptionNegativeValueDemo 2
You have entered positive value... :) 2
3 Explain the following terms with respect to exception handling.
i) try ii) catch iii) finally iv) throw v)throws OR
Explain the importance of exception handling in java. Which key words are used to handle
exceptions? Write a program to explain the use of these keywords.

Exception Handling: Exception = abnormal condition of program And Handling = Handle it.
- It is mechanism of java to handle abnormal condition of program.
- It is use to handle Run time exception.
- try, catch, finally, throw and throws are use to handle exception in java

1)try block:

Java try block is used to enclose the code that might throw an exception.

It must be used within the method.

Java try block must be followed by either catch or finally block.

try{
//code that may throw exception

Sem-5-OOPJ– Hemali Shah – LJIET Page 3


Sem-5 – OOPJ –Unit-6,7,8,9 Theory - 2016
}catch(Exception_class_Name ref){}
OR
try{
//code that may throw exception
}finally{}

2)catch block:

Java catch block is used to handle the Exception. It must be used after the try block only.

You can use multiple catch block with a single try.

Example of try/catch

public class Testtrycatch2{


public static void main(String args[]){
try{
int data=50/0;
}catch(ArithmeticException e){System.out.println(e);}
System.out.println("rest of the code...");
}
}

3) finally block is a block that is used to execute important code such as closing connection, stream,
resources like port, files etc.

Java finally block is always executed whether exception is handled or not.

Java finally block follows try or catch block.

Syntax and Example:

public class TestFinallyBlock2{


public static void main(String args[]){
try{
int data=25/0;
System.out.println(data);
}
catch(ArithmeticException e){System.out.println(e);}
finally{System.out.println("finally block is always executed");}
System.out.println("rest of the code...");
}
}
4)throw keyword

The Java throw keyword is used to explicitly throw an exception.

We can throw either checked or uncheked exception in java by throw keyword. The throw keyword
is mainly used to throw custom exception. We will see custom exceptions later.

The syntax : throw exceptionObject

Sem-5-OOPJ– Hemali Shah – LJIET Page 4


Sem-5 – OOPJ –Unit-6,7,8,9 Theory - 2016
5)throws keyword

The Java throws keyword is used to declare an exception. It gives an information to the programmer
that there may occur an exception so it is better for the programmer to provide the exception handling
code so that normal flow can be maintained.

Exception Handling is mainly used to handle the checked exceptions. If there occurs any unchecked
exception such as NullPointerException, it is programmers fault that he is not performing check up
before the code being used.

Syntax :
return_type method_name() throws exception_class_name{
//method code
}

Note: You can write this program in any exception handling question
(Single program contain all 5 exception handling keywords)
Example:
public class EHDemo {
public static void main(String[] args) throws Exception {
try {
int a = -10;
if (a < 0) {
Exception e = new Exception (“a is negative”);
throw e;
}
System.out.println("You have entered positive value... :)" + a);
} catch (Exception e) {
System.out.println("Error " + e);

} finally{
System.out.println("I am finally – always run”);

}
}
}

Unit-7 Multithreaded Programming

1 Draw and explain life cycle of thread. Also list and explain various methods of thread class.
Multithreading: is a process of executing multiple threads simultaneously to get fast output and best CPU
utilization.

Sem-5-OOPJ– Hemali Shah – LJIET Page 5


Sem-5 – OOPJ –Unit-6,7,8,9 Theory - 2016

Thread states :

 1)New
The thread is in new state if you create an instance of Thread class but before the invocation of start()
method.
 2) Runnable
The thread is in runnable state after invocation of start() method, but the thread scheduler has not
selected it to be the running thread.

 3) Running
The thread is in running state if the thread scheduler has selected it.

 4) Non-Runnable (Blocked)
This is the state when the thread is still alive, but is currently not eligible to run.

 5) Terminated
A thread is in terminated or dead state when its run() method exits.

Thread class Methods:


public void run(): is used to perform action for a thread.
public void start(): starts the execution of the thread.JVM calls the run() method on the thread.
public void sleep(long miliseconds): Causes the currently executing thread to sleep (temporarily cease execution)
for the specified number of milliseconds.
public void join(): waits for a thread to die.
public void join(long miliseconds): waits for a thread to die for the specified miliseconds.
public int getPriority(): returns the priority of the thread.
public int setPriority(int priority): changes the priority of the thread.
public String getName(): returns the name of the thread.
public void setName(String name): changes the name of the thread.
public Thread currentThread(): returns the reference of currently executing thread.
public boolean isAlive(): tests if the thread is alive.
public void yield(): causes the currently executing thread object to temporarily pause and allow other threads to
execute.
public void suspend(): is used to suspend the thread(depricated).
public void resume(): is used to resume the suspended thread(depricated).
public void stop(): is used to stop the thread(depricated).
public void interrupt(): interrupts the thread.

Sem-5-OOPJ– Hemali Shah – LJIET Page 6


Sem-5 – OOPJ –Unit-6,7,8,9 Theory - 2016
public boolean isInterrupted(): tests if the thread has been interrupted.
public static boolean interrupted(): tests if the current thread has been interrupted.

2 Write an application that executes two threads. One thread displays "Good Morning" every 1000
milliseconds & another thread displays "Good Afternoon" every 3000 milliseconds. Create the
threads by implementing the Runnable interface. (OR Any Thread Program)

class MAThread implements Runnable {

Thread t;
String msg;
long st;
MAThread(String msg,long st) {
t = new Thread(this);
this.msg = msg;
this.st = st;
t.start();
}

public void run() {


for (int i = 0; i <= 20; i++) {
System.out.println(msg);
try {
Thread.sleep(st);
} catch (InterruptedException e) {
System.out.println("Error" + e);
}
}
}
}
public class HelloThreadDemo {

public static void main(String[] s) {


MAThread mt = new MAThread("Good Morning",1000);
MAThread at = new MAThread("Good Afternoon",1000);
try {
mt.t.join();
at.t.join();
} catch (InterruptedException ex) {
}
System.out.println("Good Bye Bye...");
}
}
Output:
Good Morning
Good Afternoon
Good Afternoon
Good Morning
Good Morning
Good Afternoon
Good Morning
Good Afternoon
Good Afternoon........

Sem-5-OOPJ– Hemali Shah – LJIET Page 7


Sem-5 – OOPJ –Unit-6,7,8,9 Theory - 2016
3 Explain interprocess communication mechanism (wait(), notify() and notifyall()) being used by
java to avoid polling .
Inter Process Communication:
wait, notify and notifyAll methods are used to communicate between threads in Java.

For example, if you have two threads running in your program e.g.Producer and Consumer then
producer thread can communicate to the consumer that it can start consuming now because there are
items to consume in the queue. Similarly, a consumer thread can tell the producer that it can also start
putting items now because there is some space in the queue, which is created as a result of consumption.
A thread can use wait() method to pause and do nothing depending upon some condition. For example,
in the producer-consumer problem, producer thread should wait if the queue is full and consumer thread
should wait if the queue is empty.

If some thread is waiting for some condition to become true, you can use notify and notifyAll
methods to inform them that condition is now changed and they can wake up.

wait( ) tells the calling thread to give up the monitor and go to sleep until some other
thread enters the same monitor and calls notify( ).
notify( ) wakes up the first thread that called wait( ) on the same object.
notifyAll( ) wakes up all the threads that called wait( ) on the same object. The
highest priority thread will run first

Unit-8 IO Programming

1 Write a program using to copy Content of one file File1.txt into another file File2.txt.
import java.io.*;
public class FileReadWriteDemo
{
public static void main(String[] a)
{
String fn="File1.txt";
String fun="File2.txt";
try
{
FileInputStream fin= new FileInputStream(fn);
FileOutputStream fo= new FileOutputStream(fun);
int d;
while((d=fin.read())!=-1)
{
fo.write(d);
}
fin.close();
fo.close();
}
catch(FileNotFoundException e)
{
System.out.println("File Not Found.");
i }
catch(IOException e)
{
System.out.println("IO error.");
}
Sem-5-OOPJ– Hemali Shah – LJIET Page 8
Sem-5 – OOPJ –Unit-6,7,8,9 Theory - 2016
}
}
2 Differentiate the followings:
Text I/O and Binary I/O.
Text I/O Binary I/O
It is also called Character I/O It is also called Byte I/O
Read and write process use char as a data unit Read and write process use byte as a data unit
It is conventional approach of I/O processing It is traditional approach of I/O processing
Have to convert byte to char to process with All internal devices and socket programming
devices(Console Input, Socket programing) work with binary I/O
Reader and Writer is a super class of Text I/O InputStream and OutputStream is super class of
Binary I/O
3 Write a program to count the total no. of chars, words, lines, alphabets, digits, white spaces in a
given file.
import java.io.*;

public class FileCounters {

public static void main(String[] args) {


try {
FileReader fr = new FileReader("File1.txt");
BufferedReader br = new BufferedReader(fr);
System.out.println("enter the String");
int wc = 0, lc = 0, ac = 0, dc = 0, cc = 0, sc = 0;
String s;
while ((s = br.readLine()) != null) {
lc++;
sc++;
int l = s.length();
wc = wc + s.split(" ").length;
for (int i = 0; i < l; i++) {
char ch = s.charAt(i);
if (Character.isLetter(ch)) {
++ac;
cc++;
} else if (Character.isDigit(ch)) {
++dc;
cc++;
} else if (Character.isWhitespace(ch)) {
sc++;
}
}
}
System.out.println("no of Lines=" + lc);
System.out.println("no of Words=" + wc);
System.out.println("no of Alphabets=" + ac);
System.out.println("no of Digit=" + dc);
System.out.println("no of Spaces=" + sc);
System.out.println("no of Charecte=" + cc);
} catch (Exception e) {
System.out.println("Error");
}
}

Sem-5-OOPJ– Hemali Shah – LJIET Page 9


Sem-5 – OOPJ –Unit-6,7,8,9 Theory - 2016
}
4 Write a program to replace all “word1” by “word2” from a file1, and output is written to file2 file
and display the no. of replacement.

import java.io.*;
class FileWordReplace {

public static void main(String[] args) throws IOException {


try {
FileReader fr = new FileReader("File1.txt");
BufferedReader br = new BufferedReader(fr);
String line = "", temp = "";
int x = 0, wordCount = 0;
while ((line = br.readLine()) != null) {
temp = temp + line;
}
String s[] = temp.split(" ");
for (int i = 0; i < s.length; i++) {
if (s[i].equalsIgnoreCase("word1")) {
wordCount++;
}
}
String newTemp = temp.replaceAll("word1", "word2");
FileWriter fout = new FileWriter("File2.txt");
fout.write(newTemp.toCharArray());
System.out.println("The Total Words replaces are:" + wordCount);
br.close();
fout.close();
} catch (FileNotFoundException e) {
System.out.println("The Error is:" + e);
}
}
}

Unit-9 Collection Classes

1 What is collection in Java? Differentiate between Vector and ArrayList. Describe the Java
Collections Framework .
Collections in Java:
Collections in java is a framework that provides an architecture to store and manipulate the group
of objects.

All the operations that you perform on a data such as searching, sorting, insertion, manipulation,
deletion etc. can be performed by Java Collections.

Java Collection simply means a single unit of objects. Java Collection framework provides many
interfaces (Set, List, Queue, Deque etc.) and classes (ArrayList, Vector, LinkedList, PriorityQueue,
HashSet, LinkedHashSet, TreeSet, Properties etc).

The java.util package contains all the classes and interfaces for Collection framework.
Sem-5-OOPJ– Hemali Shah – LJIET Page 10
Sem-5 – OOPJ –Unit-6,7,8,9 Theory - 2016
Advantage Of Collection Framework:

 High-performance of framework. The implementations for the fundamental collections (dynamic


arrays, linked lists, trees, and hashtables) are highly efficient.
 The framework had to allow different types of collections to work in a similar manner and with
a high degree of interoperability.
 Extending and/or adapting a collection had to be easy.

List of Interfaces of java.util. – collection

Name If
Use
Interface
This enables you to work with groups of objects; it is at the top of the collections
Collection
hierarchy.
This extends Collection and an instance of List stores an ordered collection of
List
elements.
This extends Collection to handle sets, which must contain unique elements. Not
Set
allow duplicate elements
SortedSet The This extends Set to handle sorted sets

Sem-5-OOPJ– Hemali Shah – LJIET Page 11


Sem-5 – OOPJ –Unit-6,7,8,9 Theory - 2016
Map This maps unique keys to values.
Map.Entry This describes an element (a key/value pair) in a map. This is an inner class of Map.
SortedMap This extends Map so that the keys are maintained in ascending order.
The
This is legacy interface and defines the methods by which you can enumerate (obtain
Enumeration
one at a time) the elements in a collection of objects. This legacy interface has been
superceded by Iterator.

List Of Class and Use of Class:

AbstractCollection -Implements most of the Collection interface. Basic methods are implemented in
this abstract class.
AbstractList - Extends AbstractCollection and implements most of the List interface.
AbstractSequentialList - Extends AbstractList for use by a collection that uses sequential rather than
random access of its elements.
LinkedList -Implements a linked list by extending AbstractSequentialList.
ArrayList -Implements a dynamic array by extending AbstractList.
AbstractSet - Extends AbstractCollection and implements most of the Set interface.
HashSet - Extends AbstractSet for use with a hash table. Use hash function for storing and retrieving
data.
LinkedHashSet - Extends HashSet to allow insertion-order iterations.
TreeSet -Implements a set stored in a tree. Extends AbstractSet.
AbstractMap -Implements most of the Map interface.
HashMap -Extends AbstractMap to use a hash table.
TreeMap -Extends AbstractMap to use a tree. Store value based on key.
WeakHashMap -Extends AbstractMap to use a hash table with weak keys.
LinkedHashMap -Extends HashMap to allow insertion-order iterations.

No. ArrayList Vector

1) ArrayList is not synchronized. Vector is synchronized.

2) ArrayList is not a legacy class. Vector is a legacy class.

ArrayList increases its size by Vector increases its size by


3)
50% of the array size. doubling the array size.

Unit-10 Networking with java.net

1 Write a note on Network programming in Java.

Java Networking: java.net.* package is use for the java network programing.
network programming refers to writing programs that execute across multiple devices (computers), in

Sem-5-OOPJ– Hemali Shah – LJIET Page 12


Sem-5 – OOPJ –Unit-6,7,8,9 Theory - 2016
which the devices are all connected to each other using a network.

The java.net package of the J2SE APIs contains a collection of classes and interfaces that provide the
low-level communication details, allowing you to write programs that focus on solving the problem at
hand.
Java socket programming provides facility to share data between different computing devices.

Advantage of Java Networking:


sharing resources
centralize software management

Use And Methods of classes of .net Package


InetAddress Class Methods : This class represents an Internet Protocol (IP) address.
Example: Example:To disply ip Address of Hosted machine / Local Machine:
File: DisplayIPOfServerDemo.java
import java.net.*;

class DisplayIPOfServerDemo
{
public static void main(String args[]) {
try {
InetAddress local = InetAddress.getLocalHost();
System.out.println("Local IP : " + local);

} catch (Exception ex) {


System.out.println("Error : " + ex.getMessage());
}
}
}

Output:
Local IP : Laptop/192.168.109.20

TCP Programming Classes:

Socket and ServerSocket


Sockets provide the communication mechanism between two computers using TCP. A client program
creates a socket on its end of the communication and attempts to connect that socket to a server.
When the connection is made, the server creates a socket object on its end of the communication. The
client and server can now communicate by writing to and reading from the socket.

The java.net.Socket class represents a socket, and the java.net.ServerSocket class provides a mechanism
for the server program to listen for clients and establish connections with them.

The java.net.Socket class represents the socket that both the client and server use to communicate with
each other. The client obtains a Socket object by instantiating one, whereas the server obtains a Socket
object from the return value of the accept() method.

UDP – Connectionless Programming:

Sem-5-OOPJ– Hemali Shah – LJIET Page 13


Sem-5 – OOPJ –Unit-6,7,8,9 Theory - 2016

DatagramSocket and DatagramPacket

Java DatagramSocket and DatagramPacket classes are used for connection-less socket programming.

Java DatagramSocket class


Java DatagramSocket class represents a connection-less socket for sending and receiving datagram
packets.

A datagram is basically an information but there is no guarantee of its content, arrival or arrival time.

Java DatagramPacket class


Java DatagramPacket is a message that can be sent or received. If you send multiple packet, it may
arrive in any order. Additionally, packet delivery is not guaranteed.

Unit-11 Introduction to Objects

1 What do you mean by object-orientation? Briefly discuss the characteristics of OO approach. ‘


What do you mean by object-orientation? (Refer Q-3 of Unit-1)
Objects Identity
Classification
Inheritance
Polymorphism

characteristics of OO approach:
Objects – The instances of a class which are used in real functionality – its variables and operations

Abstraction – Specifying what to do but not how to do ; a flexible feature for having a overall view of an
object’s functionality.

Encapsulation – Binding data and operations of data together in a single unit – A class adhere this feature

Inheritance and class hierarchy – Reusability and extension of existing classes

Polymorphism – Multiple definitions for a single name - functions with same name with different
functionality; saves time in investing many function names Operator and Function overloading

Unit-12&13 Class Modelling and Advanced Class Modelling

1 Draw class diagram for online restaurant system.(RMS – restaurant management system)

Sem-5-OOPJ– Hemali Shah – LJIET Page 14


Sem-5 – OOPJ –Unit-6,7,8,9 Theory - 2016

2 Draw class diagram for ATM.

Sem-5-OOPJ– Hemali Shah – LJIET Page 15


Sem-5 – OOPJ –Unit-6,7,8,9 Theory - 2016

5 Explain „ordered‟, „bags‟, „sequences‟ in class diagram with suitable examples.

Sets, Ordered Sets, Bags, and Sequences


The UML offers a choice in the type of collection used for an association end with a multiplicity
greater than one.
You may choose one of the following four types:
Set: Every element may be present in the collection only once. This is the default collection type for
association ends with a multiplicity larger than one.
Ordered Set: A set in which the elements are ordered. There is an index number for each element.
Note that the elements are not sorted, that is, an element with a lower index number is not in any way
larger or smaller than one with a higher index. An association end with this type is indicated in the
diagram by adding the marking <ordered>.
Bag: An element may be in the collection more than once. In the marriage example this means that, for
instance, Mary may be married to John twice. Note that if one end of an association has this type, than
Sem-5-OOPJ– Hemali Shah – LJIET Page 16
Sem-5 – OOPJ –Unit-6,7,8,9 Theory - 2016
the other end must be either a bag or a sequence. The type is indicated in the diagram by <bag>.
Sequence: A bag in which the elements are ordered. It is indicated in the diagram by <sequence> or
<seq>. If one end of an association has this type, than the other end must be either a bag or a sequence.
Ex: Person has multiple address and require sequence of address priority wise. No duplication allow to
store address then – we have to use {sequence}
1 {sequence}
Person Address
*
6 Define the following terms:
Aggregation, Abstract Class, Generalization, Reification, Constraints, Package,
Metadata.
1) Aggregation (aka shared aggregation) is shown as binary association decorated with a hollow diamond as a
terminal adornment at the aggregate end of the association line.

2 ) Abstract class was defined as class that can't be directly instantiated. No object may be a direct
instance of an abstract class.

abstract class but provides no definition. We may assume that abstract class does not have complete
declaration and "typically" can not be instantiated.

The name of an abstract class is shown in italics.

Class SearchRequest is abstract class.


3) Generalization is shown as a line with a hollow triangle as an arrowhead between the symbols representing the
involved classifiers. The arrowhead points to the symbol representing the general classifier. This notation is
referred to as the "separate target style."

3) Constraint: could have an optional name, though usually it is anonymous. A constraint is shown as a
text string in curly braces according to the syntax:

constraint ::= '{' [ name ':' ] boolean-expression '}'

For an element whose notation is a text string (such as a class attribute, etc.), the constraint string may
follow the element text string in curly braces.

Sem-5-OOPJ– Hemali Shah – LJIET Page 17


Sem-5 – OOPJ –Unit-6,7,8,9 Theory - 2016
Example:

Bank account attribute constraints - non empty owner and positive balance.

5) Package:

Package is the only one grouping thing available for gathering structural and behavioral things.

6) Reification: It is promotion of something that is not an object into and object and can be use for meta
application.

* 1...*
Substance SabstanceName

Unit-14 State Modelling


1 What do you mean by an event in state diagram? Discuss various types of events.
State represents a discrete, continuous segment of time wherein the object’s behaviour will be stable
The object will stay in a state until it is stimulated to change by an event
Event : An event is an instant in time that may be significant to the behaviour of the objects in a class
Events tend to represent
1. Commands or requests from other objects
2. Circumstances or happenings in other objects
Events are written simply as text strings Open
Deposit(Amount)
Withdraw(Amount)
Close
Types of Event:
In UML, there are four types of events:
1Change events occur when a condition becomes true denoted by the keyword ‘when’
e.g. when[balance < 0]
2. Call events occur when an object receives a call for one of its operations to be perfomed
3. Signal events occur when an object receives an explicit (real-time) signal
4. Time events mark the passage of a designated period of time
e.g. after[10 seconds]

2 Explain Nested States. Draw the Nested states diagram for the phone line.
Nested State: Nest states to show their commonality & share behavior. Refines values & link that object
can have.
In phoneline diagram,all state except idle are nested state as active.

Sem-5-OOPJ– Hemali Shah – LJIET Page 18


Sem-5 – OOPJ –Unit-6,7,8,9 Theory - 2016

Unit-15 Interaction Modelling

1 Draw activity diagram for book issue process of library.

Sem-5-OOPJ– Hemali Shah – LJIET Page 19


Sem-5 – OOPJ –Unit-6,7,8,9 Theory - 2016

2 Prepare a sequence diagram for issuing book in the library management system.

Sem-5-OOPJ– Hemali Shah – LJIET Page 20


Sem-5 – OOPJ –Unit-6,7,8,9 Theory - 2016

3 Draw use case diagram for Library Management System.

Sem-5-OOPJ– Hemali Shah – LJIET Page 21


Sem-5 – OOPJ –Unit-6,7,8,9 Theory - 2016

Sem-5-OOPJ– Hemali Shah – LJIET Page 22

You might also like