Вы находитесь на странице: 1из 34

PROGRAMMING PARADIGMS

GLOBAL INSTITUTE OF ENGINEERING AND TECHNOLOGY


VELLORE 632 501
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
Third Year Computer Science and Engineering, 5th Semester
QUESTION BANK UNIVERSITY QUESTIONS
Subject Code & Name: CS2305 PROGRAMMING PARADIGMS
Prepared by: Mr.A.R.R Senthilkumar, AP/CSE
UNIT-I
PART A
1. Define constructor? (DEC 2012,CSE)
A constructor is a special method whose purpose is to construct and
initialize objects. Constructors always have the same name as the class

2.

3.
4.
5.

name.
List out the type of arrays.(DEC 2012,CSE)
Single dimension arrays
Multi dimensional arrays
How to create one dimensional array? (DEC 2012,IT)
TYPE ARRAYNAME[]= NEW TYPE[SIZE];
int ia[] = new int[100];
Mention some of the separators used in Java programming?(DEC 2012,IT)
COMMAS,Punctuations,Semicolon ,comments .
Define the term class. (May 2012 Two Mark IT)
A class is a blueprint or prototype from which objects are created. The
entire set of data and code of an object can be made of a user defined data
type with the help of a class. We can create any number of objects for the

same class.
6. What is finalizing method? (May 2012 Two Mark IT)
Finalizer methods are like the opposite of constructor methods; whereas a
constructor method is used to initialize an object, finalizer methods are
called just before the object is garbage collected and its memory reclaimed.
To create a finalizer method, include a method with the following signature
in your class definition:

Department of Compute Science and Engineering

Page 1

PROGRAMMING PARADIGMS
void finalize() { ... }
7. What do you mean by instance variables? (May 2012 Two Mark CSE)
Instance variables are used to define attributes or the state for a particular object.
This line of Java code declares a 32-bit integer variable named i: int i;
This line declares two 32-bit integer variables named i and j: int i , j;
This line declares i and j as above and initializes them: int i=3, j=4;

8. Mention the purpose of finalizes method. (May 2012 Two Mark CSE)
Finalizer methods are like the opposite of constructor methods; whereas a
constructor method is used to initialize an object, finalizer methods are
called just before the object is garbage collected and its memory reclaimed.
To create a finalizer method, include a method with the following signature
in your class definition:
void finalize() { ... }

9. What is the difference between static and non static variables?(DEC2010-IT)


Static Variables If you define a field as static, then there is only one such
field per class. In contrast, each object has its own copy of all instance
fields. For example, let's suppose we want to assign a unique identification
number to each employee. We add an instance field id and a static field
nextId to the Employee class:
class Employee {. . .
private int id;
private static int nextId = 1; }

10. What is the purpose of finalization? (DEC2010-IT)


The finalize method will be called before the garbage collector sweeps away the object. In
practice, do not rely on the finalize method for recycling any resources that are in short
supplyyou simply cannot know when this method will be called. If a resource needs to
be closed as soon as you have finished using it, you need to manage it manually. finalize()
does not trigger an object to be garbage-collected. Only removing all references to an
object will cause it to be marked for deleting, and even then, Java may or may not call the
finalize() method itselfregardless of whether or not youve already called it. Finalizer
methods are best used for optimizing the removal of an objectfor example, by removing
references to other objects, by cleaning up things that object may have touched, or for other
optional behaviors that may make it easier for that object to be removed.
Department of Compute Science and Engineering

Page 2

PROGRAMMING PARADIGMS
11. Define encapsulation.(DEC 2011) Encapsulation is the mechanism that binds together code
and the data it manipulates, and keeps both safe from outside interference and misuse.For
example, shifting gears does not turn on the headlights in car, because it encapsulates
the information about all process.
12. Define class.(DEC 2011)(CSE)
Class defines a new data type. Once defined, this new type can be used to create objects of
that type. Thus, a class is a template for an object, and an object is an instance of a class.A
class is a blueprint or prototype from which objects are created. The entire set of data and
code of an object can be made of a user defined data type with the help of a class. We can
create any number of objects for the same class.
13. List any four Java doc comments. (DEC 2011)(CSE)
Method comments
Field comments
General comments
Class comments
14. Define classes and object in Java.(DEC 2010)
Every class in Java extends Object class. The Object class defines the basic state and
behavior that all objects must have, such as the ability to compare with another object, to
convert to a string, to wait on a condition variable, to notify other objects that a condition
variable has changed, and to return the object's class.
15. How does one import a single package?(DEC 2010)
Java allows you to group classes in a collection called a package. A class can use all
classes from its own package and all public classes from other packages.
You can import a specific class or the whole package. You place import statements at the
top of your source files (but below any package statements). For example, you can import
all classes in the java.util package with the statement: import java.util.*;
16. Give the properties of abstract classes and methods and write a suitable example.(may
2011)
An abstract class is a type of class that is not allowed to be instantiated. The only reason
it exists is to be extended. Abstract classes contain methods and variables common to all
the subclasses, but the abstract class itself is of a type that will not be used directly.
abstract class A
{
Department of Compute Science and Engineering

Page 3

PROGRAMMING PARADIGMS
abstract void callme();// concrete methods are still allowed in abstract classes
void callmetoo() {
System.out.println("This is a concrete method.");
}
}
class B extends A
{
void callme() {
System.out.println("B's implementation of callme.");
}
}
class AbstractDemo
{
public static void main(String args[]) {
B b = new B();
b.callme();
b.callmetoo();
}
}
An abstract method is a method declaration that contains no functional code. The reason for
using an abstract method is to ensure that subclasses of this class will include an
implementation of this method. Any concrete class (that is, a class that is not abstract, and
therefore capable of being instantiated) must implement all abstract methods it has
inherited.
To declare an abstract method, use this general form:
abstract type name(parameter-list);
17. Why does java not support destructor and how does finalize method help in garbage
collection?(may 2011)
The most common activity in a destructor is reclaiming the memory set aside for objects.
Since Java does automatic garbage collection, manual memory reclamation is not needed,
and Java does not support destructors. Of course, some objects utilize a resource other than
memory, such as a file or a handle to another object that uses system resources. In this case,
it is important that the resource be reclaimed and recycled when it is no longer needed. You
can add a finalize method to any class. The finalize method will be called before the
garbage collector sweeps away the object.
PART B
1. Describe Concepts of Java in details ? . (May 2012 16 Mark IT)
Department of Compute Science and Engineering

Page 4

PROGRAMMING PARADIGMS
Review of OOPS
History of Java
Java Program Structure
Example Java
2. Explain Data types, Operators & Variable in Java ? . (May 2012 16 Mark IT)
Data types with Syntax & example
Operators types with Description
Arithmetic Operators
Relational and Conditional Operators
Shift and Logical Operators
Assignment Operators
Other Operators
Variable Syntax with examples
3. Define Java Class, Methods & Access Specifier . . (May 2012 16 Mark IT)
Class contents:
o Method Access Specifiers
o Methods Modifiers, Method return type, Method Parameters
o Methods Over Loading
Class Declaration
Declaring Member Variables
Access Specifier
Sample Program with Explanation
4. Explain Constructors? also use Final Method and give Example? . (May 2012 16 Mark IT)
Constructors type
Define Final Method
Coding that uses final method
5. Explain Array & String in detail? with example. (May 2012 16 Mark IT)
Array
o Declaration of Array
o Creation of Arrays
o Initialisation of Arrays
o Arrays Example
o Two Dimensional Arrays
o Demonstrate a two-dimensional array
o Variable Size Arrays
Department of Compute Science and Engineering

Page 5

PROGRAMMING PARADIGMS
String
o Introduction
o String Operations in Java:
o String Class:
o String operations and Arrays:
o String class Constructors:
o String class Example
6. Explain Package in with example? (DEC 12,CSE)(16Mark)
Declaring Package
Accessing other Package
Package Naming Conversion
Sample Package program with explanation

UNIT-II
PART A
1. What is the use of final keyword?(DEC 2012,CSE)
The keyword final has three uses.
Used to create the equivalent of a named constant.
Used to Prevent Overriding
Used to Prevent Inheritance
2. Define interface and write the syntax of the interface.(DEC 2012,CSE,IT)
An interface is a collection of method definitions (without implementations) and constant
values.
syntax of the interface
access interface name {
return-type method-name(parameter-list);
type final-varname = value;
}
3. What is meant by abstract base class?(DEC 2012,IT)
To declare a class abstract, you simply use the abstract keyword in front of the class
keyword at the beginning of the class declaration.
abstract class classname
{
public abstract type methodname();
// no implementation required
.. }
There can be no objects of an abstract class. That is, an abstract class cannot be directly
instantiated with the new operator. Such objects would be useless, because an abstract class
is not fully defined.Also, you cannot declare abstract constructors, or abstract static
Department of Compute Science and Engineering

Page 6

PROGRAMMING PARADIGMS
methods. Any subclass of an abstract class must either implement all of the abstract
methods in the superclass, or be itself declared abstract.
4. What is meant by reflection?(DEC 2012,IT)
Reflection is the ability of the software to analyze itself at runtime.
Reflection is provided by the java.lang.reflect package and elements in class.
This mechanism is helpful to tool builders, not application programmers.
The reflection mechanism is extremely used to
Analyze the capabilities of classes at run time
Inspect objects at run time
Implement generic array manipulation code
5. What is abstract class? (May 2012 Two Mark IT)
An abstract class is a type of class that is not allowed to be instantiated. The only reason
it exists is to be extended. Abstract classes contain methods and variables common to all
the subclasses, but the abstract class itself is of a type that will not be used directly. Even a
single abstract method requires that a class be marked abstract.
To declare a class abstract, you simply use the abstract keyword in front of the class
keyword at the beginning of the class declaration.
abstract class classname
{
public abstract type methodname();
// no implementation required
..
}
6. What is dynamic binding? (May 2012 Two Mark IT)
Selecting the appropriate method at runtime is called dynamic binding. Dynamic Binding
refers to the case where compiler is not able to resolve the call and the binding is done at
runtime only.
All the instance methods in Java follow dynamic binding.
Dynamic binding has a very important property:
It makes programs extensible without recompiling the existing code.
Suppose a new class is added, and there is the possibility that the variable refers to an
object of that class. The code contains the method invoking statement of that class need not
be recompiled. The method is called automatically if the object happens to refer to the
class.
7. What are the conditions to be satisfied while declaring abstract classes? (May 2012 Two
Mark CSE)
Abstract class is not allowed to be instantiated
Department of Compute Science and Engineering

Page 7

PROGRAMMING PARADIGMS
It should contain methods and variables common to all the subclasses
Abstract class itself is of a type that will not be used directly
Abstract class should starts with a keyword abstract.
8. Define inheritance. (May 2012 Two Mark CSE)
Inheritance is the process by which one object acquires the properties of another object.
This is important because it supports the concept of hierarchical classification.
For example The bird 'robin ' is a part of the class 'flying bird' which is again a part of the
class 'bird'. The concept of inheritance provides the idea of reusability.
9. What is an anonymous in inner class? (DEC2010-IT)
Anonymous inner classes have no name, and their type must be either a subclass of the
named type or an implementer of the named interface.
An anonymous inner class is always created as part of a statement, so the syntax will
end
the class definition with a curly brace, followed by a closing parenthesis to end the method
call, followed by a semicolon to end the statement: });
An anonymous inner class can extend one subclass, or implement one interface. It
cannot both extend a class and implement an interface, nor can it implement more than one
interface.
10. What is the use of reflection API? (DEC2010-IT)
Reflection is the ability of the software to analyze itself at runtime. Reflection
is provided by the java.lang.reflect package and elements in class. This mechanism is
helpful to tool builders, not application programmers. The reflection
mechanism is extremely used to

11. What is the purpose of final keyword? (DEC 2011)(IT)


The keyword final has three uses.
Used to create the equivalent of a named constant.
Used to Prevent Overriding
Used to Prevent Inheritance
12. What is polymorphism? (DEC 2011)(IT)
Polymorphism means the ability to take more than one form. Subclasses of a class can
define their own unique behaviors and yet share some of the same functionality of the
parent class.
13. State the difference between inner class and anonymous class. (DEC 2011)(IT)
Department of Compute Science and Engineering

Page 8

PROGRAMMING PARADIGMS
An inner class is a class that is defined inside another class.
Inner classes let you make one class a member of another class. Just as classes have
member variables and methods, a class can also have member classes.
Anonymous inner classes have no name, and their type must be either a subclass of the
named type or an implementer of the named interface.
An anonymous inner class is always created as part of a statement, so the syntax will
end
the class definition with a curly brace, followed by a closing parenthesis to end the
method call, followed by a semicolon to end the statement: });
An anonymous inner class can extend one subclass, or implement one interface. It
cannot both extend a class and implement an interface, nor can it implement more than one
interface.
14. What is interface and mention ITs uses. (DEC 2011)(IT)
An interface is a collection of method definitions (without implementations) and constant
values.
When you implement an interface method, method must be declared as public. (The
access level can be more accessible than that of the overridden method.)
Type signature of the implementing method must match exactly the type signature
specified in the interface definition. (The argument list and return type must exactly
match that of the overridden method.)
A class can implement one or more interfaces.
Partial Implementations: If a class includes an interface but does not fully implement the
methods defined by that interface, then that class must be declared as abstract.
15. What is interface? (DEC 2011)(CSE)
An interface is a collection of method definitions (without implementations) and constant
values.
Defining an Interface This is the general form of an interface:
An interface must be declared with the keyword interface.
access interface name { return-type method-name(parameter-list); type
final-varname = value; }

16. What is an anonymous in inner class? (DEC2010-IT)


Anonymous inner classes have no name, and their type must be either a subclass of the
named type or an implementer of the named interface.
An anonymous inner class is always created as part of a statement, so the syntax will
end
the class definition with a curly brace, followed by a closing parenthesis to end the
method call, followed by a semicolon to end the statement: });
An anonymous inner class can extend one subclass, or implement one interface. It
cannot both extend a class and implement an interface, nor can it implement more than one
Department of Compute Science and Engineering

Page 9

PROGRAMMING PARADIGMS
interface.
17. What is a cloneable interface and how many methods does it contain?
It is not having any method because it is a TAGGED or MARKER interface.
18. Define: Dynamic proxy.
A dynamic proxy is a class that implements a list of interfaces, which you specify at runtime
when you create the proxy. To create a proxy, use the static method java.lang.reflect.Proxy::
newProxyInstance(). This method takes three arguments:
The class loader to define the proxy class
An invocation handler to intercept and handle method calls
A list of interfaces that the proxy instance implements
19. Distinguish between static and dynamic binding.(2m-may 2011)
Static and dynamic binding in Java are two important concept which Java programmer
should be aware of. this is directly related to execution of code. If you have more than one
method of same name (method overriding) or two variable of same name in same class
hierarchy it gets tricky to find out which one is used during runtime as a result of there
reference in code "
PART B
1. Explain dynamic binding and final keyword with examples.(DEC 2012,CSE)(16Mark)
Definition
When compiler is not able to resolve the call/binding at compile time, such binding is
known as Dynamic or late Binding. Overriding is a perfect example of dynamic binding as
in overriding both parent and child classes have same method. Thus while calling the
overridden method, the compiler gets confused between parent and child class
method(since both the methods have same name).
Example
class A
{
public doIt( )
{
//this does something
}
}
class B extends A
{
public doIt( )
{
//this does something
}

Department of Compute Science and Engineering

Page 10

PROGRAMMING PARADIGMS
}
class C extends B
{
public doIt( )
{
//this does something
}
}
public static void main(String[] args) {
// this is a legal Java statement:
A x = new B( );
/*
What version of the doIt( ) method
will get executed by the statement below
- the one that belongs to class A, B, or C?
*/
x.doIt( );
}

Final in java is very important keyword and can be applied to class, method, and variables in Java.
In this java final tutorial we will see what is final keyword in Java, what does it mean by making
final variable, final method and final class in java and what are primary benefits of using final
keywords in Java and finally some examples of final in Java. Final is often used along with static
keyword in Java to make static final constant and you will see how final in Java can increase
performance of Java application.

class PersonalLoan{
public final String getName(){
return "personal loan";
}
}
class CheapPersonalLoan extends PersonalLoan{
@Override
public final String getName(){
return "cheap personal loan"; //compilation error: overridden method is
final
}
}

2. Write in detail about the following:


i).Abstract classes.( DEC 2012,CSE)(8Mark)

Department of Compute Science and Engineering

Page 11

PROGRAMMING PARADIGMS
An abstract class is a class that is declared abstractit may or may not include
abstract methods. Abstract classes cannot be instantiated, but they can be
subclassed.
An abstract method is a method that is declared without an implementation
(without braces, and followed by a semicolon), like this:
abstract void moveTo(double deltaX, double deltaY);
If a class includes abstract methods, then the class itself must be declared
abstract, as in:
public abstract class GraphicObject {
// declare fields
// declare nonabstract methods
abstract void draw();
}
When an abstract class is subclassed,

the subclass

usually provides

implementations for all of the abstract methods in its parent class. However, if
it does not, then the subclass must also be declared abstract.

ii).Interface.( DEC 2012,CSE)(8Mark)


An interface is a collection of abstract methods. A class implements an interface, thereby inheriting
the abstract methods of the interface.
An interface is not a class. Writing an interface is similar to writing a class, but they are two
different concepts. A class describes the attributes and behaviors of an object. An interface contains
behaviors that a class implements.
Unless the class that implements the interface is abstract, all the methods of the interface need to
be defined in the class.
An interface is similar to a class in the following ways:

An interface can contain any number of methods.


An interface is written in a file with a .java extension, with the name of the interface
matching the name of the file.

The bytecode of an interface appears in a .class file.

Interfaces appear in packages, and their corresponding bytecode file must be in a directory
structure that matches the package name.

However, an interface is different from a class in several ways, including:

You cannot instantiate an interface.

Department of Compute Science and Engineering

Page 12

PROGRAMMING PARADIGMS

An interface does not contain any constructors.

All of the methods in an interface are abstract.

An interface cannot contain instance fields. The only fields that can appear in an interface
must be declared both static and final.

An interface is not extended by a class; it is implemented by a class.

An interface can extend multiple interfaces.

3. Explain about inheritance in Java.(DEC 2012,IT)(16Mark)


Inheritance can be defined as the process where one object acquires the properties of
another. With the use of inheritance the information is made manageable in a hierarchical
order.
When we talk about inheritance, the most commonly used keyword would be extends and
implements. These words would determine whether one object IS-A type of another. By
using these keywords we can make one object acquire the properties of another object.
o Single
o Multi level
o Hierarchal inheritance
Examples
Explanations
4. Discuss the following: (May 2012 8+8 Mark IT)
i)
Inheritance
Definition
Example
Syntax
Explanation
ii)
Polymorphism
Definition
Syntax
Types of polymorphism
Explanation
5. Give an elaborate discussion on inheritance. (May 2012 16 Mark CSE)
Definition
Types of inheritance
Diagram
Department of Compute Science and Engineering

Page 13

PROGRAMMING PARADIGMS

Syntax
Example
Explanations

6. Differentiate method overloading and method overriding. Explain both with an example
program (May 2012 16 Mark CSE)
Method overloading
Definition
Syntax
Example program
Explanation
Method overriding
Definition
Syntax
Example program
Explanation
7. What is object cloning? Why it is needed? Explain how objects are cloned. (DEC2010IT)
The object cloning is a way to create exact copy of an object. For this purpose, clone()
method of Object class is used to clone an object.
The java.lang.Cloneable interface must be implemented by the class whose object clone
we want to create. If we don't implement Cloneable interface, clone() method generates
CloneNotSupportedException.
The clone() method is defined in the Object class. Syntax of the clone() method is
asfollows:
protected Object clone() throws CloneNotSupportedException
Example program
class Student implements Cloneable{
int rollno;
String name;
Student(int rollno,String name){
this.rollno=rollno;
this.name=name;
}
Department of Compute Science and Engineering

Page 14

PROGRAMMING PARADIGMS
public Object clone()throws CloneNotSupportedException{
return super.clone();
}
public static void main(String args[]){
try{
Student s1=new Student(101,"amit");
Student s2=(Student)s1.clone();
System.out.println(s1.rollno+" "+s1.name);
System.out.println(s2.rollno+" "+s2.name);
}catch(CloneNotSupportedException c){}
}
}
8. Give a brief overview on java packages. Write necessary code snippets. (DEC 2011)(IT)
Definition
Package syntax
Example program
Explanations
9. W
h
at
is

reflection? Explain. (DEC 2011)(IT)


Definition
Syntax
Example program
Explanations
10. Discuss in detail about inner class, with its usefulness. (DEC 2011)(CSE)
Inner classes are class within Class. Inner class instance has special relationship with
Outer class. This special relationship gives inner class access to member of outer class as if
they are the part of outer class.
Syntax for creating Inner Class

//outer class
Department of Compute Science and Engineering

Page 15

PROGRAMMING PARADIGMS
class OuterClass {
//inner class
class InnerClass {
}
}
Example program
Explanations
11. Explain the following with example (16m)
a) The clone able interface.
Need of Clonning
The Clone able interface
Overview
Alternatives
clone () and the Singleton pattern
clone () and class hierarchy
Clone () and final fields
References
UNIT-III
PART A
1. What is the relationship between the Canvas class and the Graphics class? (May 2012 Two
Mark CSE)
A Canvas object provides access to a Graphics object via its paint() method.
2. How would you create a button with rounded edges? .(DEC 2013,CSE)
Theres 2 ways. The first thing is to know that a JButtons edges are drawn by a
Border. so you can override the Buttons paintComponent(Graphics) method and draw a
circle or rounded rectangle (whatever), and turn off the border. Or you can create a custom
border that draws a circle or rounded rectangle around any component and set the buttons
border to it.
3. What is the difference between the Font and FontMetrics class? (May 2012 Two Mark

CSE)
The Font Class is used to render glyphs - the characters you see on the screen.
FontMetrics encapsulates information about a specific font on a specific Graphics object.
(width of the characters, ascent, descent)
Department of Compute Science and Engineering

Page 16

PROGRAMMING PARADIGMS
4. What is the difference between the paint() and repaint() methods? (May 2012 Two Mark

CSE)
The paint() method supports painting via a Graphics object. The repaint() method is used to
cause paint() to be invoked by the AWT painting thread.
5. Which containers use a border Layout as their default layout? .(DEC 2012,CSE)
The window, Frame and Dialog classes use a border layout as their default layout.
6. What is the difference between applications and applets? (May 2012 Two Mark CSE)
a)Application must be run on local machine whereas applet needs no explicit installation on
local machine.
b)Application must be run explicitly within a java-compatible virtual machine whereas
applet loads and runs itself automatically in a java-enabled browser.
c)Application starts execution with its main method whereas applet starts execution with its
init method.
d)Application can run with or without graphical user interface whereas applet must run within
a graphical user interface.
7. Difference between Swing and Awt? .(DEC 2012,CSE)
AWT are heavy-weight componenets. Swings are light-weight components. Hence swing works
faster than AWT.
8. What is a layout manager and what are different types of layout managers available in java
AWT? (May 2012 Two Mark CSE)
A layout manager is an object that is used to organize components in a container. The different
layouts are available are FlowLayout, BorderLayout, CardLayout, GridLayout and
GridBagLayout.
9. How are the elements of different layouts organized? (May 2012 Two Mark CSE)

Department of Compute Science and Engineering

Page 17

PROGRAMMING PARADIGMS
FlowLayout: The elements of a Flow Layout are organized in a top to bottom, left to right fashion.
BorderLayout: The elements of a Border Layout are organized at the borders (North, South, East
and West) and the center of a container.
CardLayout: The elements of a CardLayout are stacked, on top of the other, like a deck of cards
GridLayout: The elements of a GridLayout are of equal size and are laid out using the square of a
grid.
GridBagLayout: The elements of a GridBagLayout are organized according to a grid. However,
the elements are of different size and may occupy more than one row or column of the grid. In
addition, the rows and columns may have different size. The default Layout Manager of Panel and
Panel sub classes is FlowLayout.
11) What is an event and what are the models available for event handling? .(DEC 2012,CSE)
An event is an event object that describes a state of change in a source. In other words,
event occurs when an action is generated, like pressing button, clicking mouse, selecting a list, etc.
There are two types of models for handling events and they are:
a) event-inheritance model and
b) event-delegation model
12) What is the difference between scrollbar and scrollpane? .(DEC 2013,CSE)
A Scrollbar is a Component, but not a Container whereas Scrollpane is a Conatiner and
handles its own events and perform its own scrolling.
13) Why wont the JVM terminate when I close all the application windows? .(DEC 2012,CSE)
The AWT event dispatcher thread is not a daemon thread. You must explicitly call
System.exit to terminate the JVM.
14) What is meant by controls and what are different types of controls in AWT?(DEC 2012,CSE)
Controls are components that allow a user to interact with your application and the AWT
supports the following types of controls: Labels, Push Buttons, Check Boxes, Choice Lists, Lists,
Scrollbars, and Text Components. These controls are subclasses of Component.
Department of Compute Science and Engineering

Page 18

PROGRAMMING PARADIGMS
15) What is the difference between a Choice and a List? .(DEC 2012,CSE)
A Choice is displayed in a compact form that requires you to pull it down to see the list of
available choices. Only one item may be selected from a Choice. A List may be displayed in such a
way that several List items are visible. A List supports the selection of one or more List items.

16) What is the purpose of the enableEvents() method? .(DEC 2012,CSE)


The enableEvents() method is used to enable an event for a particular object. Normally,an
event is enabled when a listener is added to an object for a particular event. The enableEvents()
method is used by objects that handle events by overriding their eventdispatch methods.
17) What is the difference between the File and RandomAccessFile classes? .(DEC 2012,CSE)
The File class encapsulates the files and directories of the local file system. The
RandomAccessFile class provides the methods needed to directly access data contained in any part
of a file.
18) What is the lifecycle of an applet? .(DEC 2012,CSE)
init() method - Can be called when an applet is first loaded start() method - Can be called
each time an applet is started. paint() method - Can be called when the applet is minimized or
maximized. stop() method - Can be used when the browser moves off the applets page. destroy()
method - Can be called when the browser is finished with the applet.
19) What is the difference between a MenuItem and a CheckboxMenuItem? .(DEC 2012,CSE)
The CheckboxMenuItem class extends the MenuItem class to support a menu item that
may be checked or unchecked.
20) What class is the top of the AWT event hierarchy? .(DEC 2012,CSE)
The java.awt.AWTEvent class is the highest-level class in the AWT event-class hierarchy.
Department of Compute Science and Engineering

Page 19

PROGRAMMING PARADIGMS
PART B
1. Explain Generic Programming in Detail?
Introduction

Simple Program

Hierarchy and classification

Motivation

Generic Methods with example

Generic Class with example

Wildcard

2. Expalin Generic Reflection in Detail?


o Generic Method Return Types
o Generic Method Parameter Types
o Generic Field Types
o Demonstrate a simple generic method

3. Explain Exception in Detail?


An exception is an event that occurs during the execution of a program that disrupts the
normal flow of instructions.The Catch or Specify Requirement
This section covers how to catch and handle exceptions. The discussion includes the
try, catch, and finally blocks, as well as chained exceptions and logging. How toThrow
Exceptions
This section covers the throw statement and the Throwable class and its subclasses.
Unchecked Exceptions The Controversy This section explains the correct and incorrect use of
the unchecked exceptions indicated by subclasses of RuntimeException.
Collections & Mappings
Utilities and Algorithms
Parameterized Types
Arrays to Lists
Concordance
Word
Checking
Exception Handling
Department of Compute Science and Engineering

Page 20

PROGRAMMING PARADIGMS

throws and throw


Effective Hierarchy

Advantages of Exceptions
The use of exceptions to manage errors has some advantages over traditional error management
techniques.
4. Give a example for StackTraceMethod? With explanation?
java.lang.Object java.lang.StackTraceElement
All Implemented Interfaces:
Serializable

5. Explain in detail about AWT event hierarchy? (DEC 2012,IT)(16Mark)


Source
Button

Event Class
ActionEvent

List, Choice,
Checkbox

ItemEvent

Keyboard

KeyEvent

Mouse

MouseEvent

MouseMotionListener

Class Methods
String
getActionComman
d( )
Object getItem( )
ItemSelectable
getItemSelectable(
)
char getKeyChar( )
int getKeyCode( )

Listener Interface
ActionListener

Interface Methods
actionPerformed(A
ctionEvent ae)

ItemListener

itemStateChanged(I
temEvent ie)

KeyListener

int getX( ) int


getY( )

MouseListener

keyPressed(KeyEv
ent ke)
keyReleased(KeyE
vent ke)
keyTyped(KeyEven
t ke)
mouseClicked(Mou
seEvent me)
mouseEntered(Mou
seEvent me)
mouseExited(Mous
eEvent me)
mousePressed(Mou
seEvent me)
mouseReleased(Mo
useEvent me)

mouseDragged(MouseEvent me)
mouseMoved(MouseEvent me)

6. Explain about applet lifecycle? How applets are prepared and executed.(DEC 2012,IT)
(16Mark)

init() method

Department of Compute Science and Engineering

Page 21

PROGRAMMING PARADIGMS

start() method
paint() method
stop() method
destroy() method
Example program
Explanation

7. Explain the various events handling in detail. (May 2012 16 Mark IT)
Events handling
Types of Event
Steps involved in event handling
Example program
Explanation
8. Explain any five swing component with an example program. (May 2012 16 Mark CSE)

Swing Components
javax.swing

Constructor

Methods

JLabel() JLabel(String text)


JLabel(String text, int
horizontalAlignment)
JButton( ) JButton(String str)

void setText(String str) String


getText( )

Component
JLabel
JButton
JList
JRadioButton

JComboBox
JCheckbox

JTextField
JTextArea

void setLabel(String str) String


getLabel( )
JList() JList(String[] )
Object getSelectedValue( ) int
getSelectedIndex( ) String[]
getSelectedItems( )
JRadioButton() JRadioButton(String text)
JRadioButton(String text, boolean selected)
JRadioButton(String text, Icon icon, boolean
selected)
JComboBox()
void add(String name) String
JComboBox(Object items[])
getSelectedItem( ) int
getSelectedIndex( )
JCheckbox( )
boolean getState( ) void
JCheckbox(String str)
setState(boolean on) String
JCheckbox(String str, boolean
getLabel( ) void setLabel(String
on) JCheckBox(String text,
str)
Icon icon)
JTextField(int numChars)
String getText( ) void
JTextField(String str, int
setText(String str) void
numChars)
setEditable(boolean canEdit)
JTextArea(int numLines, int
void append(String str) void
numChars) JTextArea(String
insert(String str, int index)
str, int numLines, int
numChars)

Department of Compute Science and Engineering

Page 22

PROGRAMMING PARADIGMS
JPasswordField

JPasswordField(String text, int


columns)

void setEchoChar(char echo)

9. Discuss mouse listener and mouse motion listener. Give an example program. (May 2012
16 Mark CSE)
Definition
Diagram
Syntax
Program
Explanation
10. How is a frame created? Write a java program that creates a product enquiry form using
frames. (DEC2010-IT)
Definiton
Frame syntax
Example program
Explanation
UNIT-IV
PART A
1. What is an exception? .(DEC 2011-2m)

An exception is an event, which occurs during the execution of a


program, that disrupts the normal flow of the program's instructions.
2. What is error? .(DEC 2011-2m)
An Error indicates that a non-recoverable condition has occurred that should not be
caught. Error, a subclass of Throwable, is intended for drastic problems, such as
OutOfMemoryError, which would be reported by the JVM itself.
3. Which is superclass of Exception? .(DEC 2011-2m)

"Throwable", the parent class of all exception related classes.


4. What are the advantages of using exception handling? .(DEC 2012-2m)

Exception handling provides the following advantages over "traditional" error management
techniques: Separating Error Handling Code from "Regular" Code.
Propagating Errors Up the Call Stack. Grouping Error Types and Error Differentiation.
5. What are the types of Exceptions in Java .(DEC 2012-2m)

There are two types of exceptions in Java, unchecked exceptions and checked exceptions.
Department of Compute Science and Engineering

Page 23

PROGRAMMING PARADIGMS
Checked exceptions: A checked exception is some subclass of Exception (or Exception
itself), excluding class RuntimeException and its subclasses. Each method must either
handle all checked exceptions by supplying a catch clause or list each unhandled checked
exception as a thrown exception.
Unchecked exceptions: All Exceptions that extend the RuntimeException class are
unchecked exceptions. Class Error and its subclasses also are unchecked.
6. Why Errors are Not Checked? .(DEC 2010-2m)

A unchecked exception classes which are the error classes (Error and its subclasses) are
exempted from compile-time checking because they can occur at many points in the
program and recovery from them is difficult or impossible. A program declaring such
exceptions would be pointlessly.
7. How does a try statement determine which catch clause should be used to handle an

exception? .(DEC 2010-2m)


When an exception is thrown within the body of a try statement, the catch clauses of the try
statement are examined in the order in which they appear. The first catch clause that is
capable of handling the exception is executed. The remaining catch clauses are ignored.
8. What is the purpose of the finally clause of a try-catch-finally statement? .(DEC 2010-2m)

The finally clause is used to provide the capability to execute code no matter whether or
not an exception is thrown or caught.
9. What is the difference between checked and Unchecked Exceptions in Java? .(DEC 2010-

2m)
All predefined exceptions in Java are either a checked exception or an
unchecked exception. Checked exceptions must be caught using try.. catch () block or we
should throw the exception using throws clause. If you dont, compilation of program will
fail.
10. What is the difference between exception and error? .(DEC 2010-2m)

The exception class defines mild error conditions that your program
encounters. Exceptions can occur when trying to open the file, which does not exist, the
network connection is disrupted, operands being manipulated are out of prescribed ranges,
the class file you are interested in loading is missing. The error class defines serious error
Department of Compute Science and Engineering

Page 24

PROGRAMMING PARADIGMS
conditions that you should not attempt to recover from. In most cases it is advisable to let
the program terminate when such an error is encountered.
11. What is the catch or declare rule for method declarations? (May 2012 Two Mark IT CSE)
If a checked exception may be thrown within the body of a method, the method must either
catch the exception or declare it in its throws clause.
12. When is the finally clause of a try-catch-finally statement executed? .(DEC 2010-2m)
The finally clause of the try-catch-finally statement is always executed unless the thread of
execution terminates or an exception occurs within the execution of the finally clause.
13. What if there is a break or return statement in try block followed by finally block? .(DEC
2010-2m)
If there is a return statement in the try block, the finally block executes right after the return
statement encountered, and before the return executes.
14. What are the different ways to handle exceptions? .(DEC 2010-2m)

There are two ways to handle exceptions:


Wrapping the desired code in a try block followed by a catch block to catch the exceptions.
List the desired exceptions in the throws clause of the method and let the caller of the
method handle those exceptions.
15. How to create custom exceptions? (May 2012 Two Mark IT CSE)
By extending the Exception class or one of its subclasses.
Example:
classMyExceptionextendsException{
publicMyException()
{
super();
publicMyException(Strings)
{
super(s);
}

16. Can we have the try block without catch block? .(DEC 2010-2m)

Yes, we can have the try block without catch block, but finally block should follow the try
block.
Note: It is not valid to use a try clause without either a catch clause or a finally clause.
17. What is the difference between swing and applet?
Swing is a light weight component whereas Applet is a heavy weight Component. Applet
does not require main method, instead it needs init method.

Department of Compute Science and Engineering

Page 25

PROGRAMMING PARADIGMS
18. What is the use of assert keyword? (May 2012 Two Mark IT CSE)

Assert keyword validates certain expressions. It replaces the if block effectively and
throws an AssertionError on failure. The assert keyword should be used only for critical
arguments (means without that the method does nothing).
19. How does finally block differ from finalize() method? .(DEC 2010-2m)

Finally block will be executed whether or not an exception is thrown. So it is used to free
resoources. finalize() is a protected method in the Object class which is called by the JVM
just before an object is garbage collected.
20. What is the difference between throw and throws clause? (May 2012 Two Mark IT CSE)

throw is used to throw an exception manually, where as throws is used in the case of
checked exceptions, to tell the compiler that we haven't handled the exception, so that the
exception will be handled by the calling function.
21. What are the different ways to generate and Exception? .(DEC 2010-2m)

There are two different ways to generate an Exception. Exceptions can be generated by the
Java run-time system. Exceptions thrown by Java relate to fundamental errors that violate the
rules of the Java language or the constraints of the Java execution environment. Exceptions can be
manually generated by your code. Manually generated exceptions are typically used to report some
error condition to the caller of a method.
22. Where does Exception stand in the Java tree hierarchy? .(DEC 2010-2m)

java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.Error
23. What is StackOverflowError?

(May 2012 Two Mark IT CSE)


The StackOverFlowError is an Error Object thorwn by the Runtime System when it

Encounters that your application/code has ran out of the memory. It may occur in case of
recursive methods or a large amount of data is fetched from the server and stored in some
object. This error is generated by JVM.
e.g. void swap(){
swap();
}
24. Explain the exception hierarchy in java. .(DEC 2010-2m)

Department of Compute Science and Engineering

Page 26

PROGRAMMING PARADIGMS
The hierarchy is as follows: Throwable is a parent class off all Exception
classes. They are two types of Exceptions: Checked exceptions and UncheckedExceptions.
Both type of exceptions extends Exception class
25. How do you get the descriptive information about the Exception occurred during the

program execution? (May 2012 Two Mark IT CSE)


All the exceptions inherit a method printStackTrace() from the Throwable class.
This method prints the stack trace from where the exception occurred. It prints the most
recently entered method first and continues down, printing the name of each method as it
works its way down the call stack from the top.
PART B
1.
2.
3.
4.
5.

Explain generic classes and their methods).(DEC 2012,CSE)(16Mark)


Explain the throwing and catching exception. (DEC 2012,IT,CSE)(16Mark)
Explain in detail about inheritance, generics and reflection.(DEC 2012,IT)(16Mark)
Explain exception handling feature of Java in detail. (May 2012 16 Mark IT)
Explain the following (May 2012 16 Mark CSE)
i) Generic classes
ii) Generic methods
6. Discuss on exception handling in detail. (May 2012 16 Mark CSE)
7. What is an exception? Explain how to throw, catch and handle exceptions. (DEC2010-IT)
8. What is generic programming and why is it needed? List the limitations and restrictions of
generic programming. (DEC2010-IT)
9. Where can we write generic? Explain with a simple example. (DEC 2011)(IT)
10. Discuss about translating generic expression and calling legacy code. (DEC 2011)(CSE)
11. Explain the concept of generic type information in virtual machine. (DEC 2011)(CSE)
12. Define exception and explain its different types. With appropriate examples using java.
(DEC 2011)(CSE)
13. What are stack trace elements? Explain. (DEC 2011)(CSE)
14. i)Explain the generic classes and generic methods with example.(8m)
ii) Explain the exception hierarchy.(8m)(DEC 2010)
15. i)Explain the concept of throwing and catching exception in java.98m)
ii) State the situations where assertion are not used.(4m)(DEC 2010)
iii) Give an overview of logging.(4m)
16. Draw the exception hierarchy in java and explain with examples throwing and catching
exceptions and the common exceptions.(16m-may 2011)
17. With suitable example consider the number of restrictions to consider when working with
java generics. (16m-may 2011).
Department of Compute Science and Engineering

Page 27

PROGRAMMING PARADIGMS
UNIT-V
PART A
1) Explain different way of using thread? .(2m-may 2013)

The thread could be implemented by using runnable interface or by inheriting from the
Thread class. The former is more advantageous, 'cause when you are going for multiple
inheritance..the only interface can help.
2) What are the different states of a thread? (2m-may 2011)
The different thread states are

ready,

running,

waiting

dead.

3) Why are there separate wait and sleep methods? .(2m-may 2011)
The static Thread.sleep(long) method maintains control of thread execution but
delays the next action until the sleep time expires. The wait method gives up control over thread
execution indefinitely so that other threads can run.
4) What is multithreading and what are the methods for inter-thread communication and what is
the class in which these methods are defined? .(2m-may 2011)
Multithreading is the mechanism in which more than one thread run independent of each other
within the process. wait (), notify () and notifyAll() methods can be used for inter-thread
communication and these methods are in Object class. wait() : When a thread executes a call to
wait() method, it surrenders the object lock and enters into a waiting state. notify() or notifyAll() :
To remove a thread from the waiting state, some other thread must make a call to notify() or
notifyAll() method on the same object.

Department of Compute Science and Engineering

Page 28

PROGRAMMING PARADIGMS
5) What is synchronization and why is it important? .(2m-may 2011)
With respect to multithreading, synchronization is the capability to control the access of
multiple threads to shared resources. Without synchronization, it is possible for one thread to
modify a shared object while another thread is in the process of using or updating that object's
value. This often leads to significant errors.
6) How does multithreading take place on a computer with a single CPU? .(2m-may 2011)
The operating system's task scheduler allocates execution time to multiple tasks. By
quickly switching between executing tasks, it creates the impression that tasks execute
sequentially.
7) What is the difference between process and thread? .(2m-may 2011)
Process is a program in execution whereas thread is a separate path of execution in a
program.
8) What happens when you invoke a thread's interrupt method while it is sleeping or waiting?(2mmay 2011)
When a task's interrupt() method is executed, the task enters the ready state. The next time
the task enters the running state, an InterruptedException is thrown.
9) How can we create a thread? .(2m-may 2011)
A thread can be created by extending Thread class or by implementing Runnable
interface. Then we need to override the method public void run().
10) What are three ways in which a thread can enter the waiting state? .(2m-may 2011)
A thread can enter the waiting state by invoking its sleep() method, by blocking on I/O, by
unsuccessfully attempting to acquire an object's lock, or by invoking an object's wait() method. It
can also enter the waiting state by invoking its (deprecated) suspend() method.

11) How can i tell what state a thread is in ? .(2m-may 2011)


Department of Compute Science and Engineering

Page 29

PROGRAMMING PARADIGMS
Prior to Java 5, isAlive() was commonly used to test a threads state. If Alive()
returned false the thread was either new or terminated but there was simply no way to differentiate
between the two.
12) What is synchronized keyword? In what situations you will Use it? .(2m-may 2011)
Synchronization is the act of serializing access to critical sections of code. We will use this
keyword when we expect multiple threads to access/modify the same data. To understand
synchronization we need to look into thread execution manner.
13) What is serialization? (Dec2010-IT)
Serialization is the process of writing complete state of java object into output stream, that stream
can be file or byte array or stream associated with TCP/IP socket.
14) What does the Serializable interface do? (Dec2010-IT)
Serializable is a tagging interface; it prescribes no methods. It serves to
assign the Serializable data type to the tagged class and to identify the class as one which the
developer has designed for persistence. ObjectOutputStream serializes only those objects which
implement this interface.
15) When you will synchronize a piece of your code? (Dec2010-IT)
When you expect your code will be accessed by different threads and these
threads may change a particular data causing data corruption.
16) What is daemon thread and which method is used to create the daemon thread?
(Dec2010-IT)

Daemon thread is a low priority thread which runs intermittently in

the back ground doing the garbage collection operation for the java runtime system. setDaemon
method is used to create a daemon thread.
17) What is the difference between yielding and sleeping? (Dec2010-IT)
When a task invokes its yield() method, it returns to the ready state. When a task
invokes its sleep() method, it returns to the waiting state.
Department of Compute Science and Engineering

Page 30

PROGRAMMING PARADIGMS
18) What is casting? (Dec2010-IT)
There are two types of casting, casting between primitive numeric types and casting between
object references. Casting between numeric types is used to convert larger values, such as double
values, to smaller values, such as byte values. Casting between object references is used to refer to
an object by a compatible class, interface, or array type reference.
19) What classes of exceptions may be thrown by a throw statement? (Dec2010-IT)
A throw statement may throw any expression that may be assigned to the
Throwable type.
20) A Thread is runnable, how does that work? (Dec2010-IT)
The Thread class' run method normally invokes the run method of the
Runnable type it is passed in its constructor. However, it is possible to override the thread's run
method with your own.
21) Can I implement my own start() method? (Dec2010-IT)
The Thread start() method is not marked final, but should not be overridden.
This method contains the code that creates a new executable thread and is very specialised. Your
threaded application should either pass a Runnable type to a new Thread, or extend Thread and
override the run() method.
22) Do I need to use synchronized on setValue(int)? .(DEC 2012,IT)
It depends whether the method affects method local
variables, class static or instance variables. If only method local variables are changed, the value is
said to be confined by the method and is not prone to threading issues.
23) What is thread priority? .(DEC 2012,IT)
Thread Priority is an integer value that identifies the relative
order in which it should be executed with respect to others. The thread priority values ranging from
Department of Compute Science and Engineering

Page 31

PROGRAMMING PARADIGMS
1- 10 and the default value is 5. But if a thread have higher priority doesn't means that it will
execute first. The thread scheduling depends on the OS.
24) What are the different ways in which a thread can enter into waiting state? .(DEC 2012,IT)
There are three ways for a thread to enter into waiting state. By invoking its sleep()
method, by blocking on I/O, by unsuccessfully attempting to acquire an object's lock, or by
invoking an object's wait() method.
25) How would you implement a thread pool? .(DEC 2012,IT)
The ThreadPool class is a generic implementation of a thread
pool, which takes the following input Size of the pool to be constructed and name of the class
which implements Runnable (which has a visible default constructor) and constructs a thread pool
with active threads that are waiting for activation. once the threads have finished processing they
come back and wait once again in the pool.
26) What is a thread group? .(DEC 2012,IT)
A thread group is a data structure that controls the
state of collection of thread as a whole managed by the particular runtime environment.
PART B
1. Write in detail about multi thread programming with example.(DEC 2012,CSE)(16Mark)

Thread
Multi Thread
Use of Thread
How to create thread
Thread properties
Thread State

2. Describe Executors? In detail.


Executor Interfaces define the three executor object types.
ExecutorInterface
ExecutorServiceInterface
Department of Compute Science and Engineering

Page 32

PROGRAMMING PARADIGMS

ScheduledExecutorServiceInterface
Thread Pools are the most common kind

of executor implementation

3. Explain in detail about thread safe collections.(DEC 2012,CSE)(16Mark)


Definition
Syntax
Program
Explanations
4. What are interrupting threads? Explain thread states and synchronization.(DEC 2012,IT)
(16Mark)
Thread definitions
Thread states
Synchronization
Example program
Explanations
5. Write the life cycle of a thread. Give an example of a Java program to explain the use of
thread priorities. (May 2012 16 Mark IT)
New
Runnable
Waiting
Timed waiting
Terminated

Department of Compute Science and Engineering

Page 33

PROGRAMMING PARADIGMS

6. Write notes on multi-threaded programming. (May 2012 16 Mark IT)


Thread definitions
Multi threading
Syntax
Programs
Explanations
7. Explain how to create threads. Write a java program that prints numbers from 1 to 10 line
after every 5 seconds(DEC2010-IT)
Thread creation
Thread definitions
Programs
Explanations

Department of Compute Science and Engineering

Page 34

Вам также может понравиться