CS3391 Object Oriented Programming
CS3391 Object Oriented Programming
CS3391 Object Oriented Programming
CS3391
OBJECT ORIENTED PROGRAMMING
Question Bank
Vision of Institution
To build Jeppiaar Engineering College as an Institution of Academic Excellence in Technical
education and Management education and to become a World Class University.
Mission of Institution
To equip students with values, ethics and life skills needed to enrich their lives and
M3
enable them to meaningfully contribute to the progress of society
M4 To prepare students for higher studies and lifelong learning, enrich them with the
practical and entrepreneurial skills necessary to excel as future professionals and
contribute to Nation’s economy
M3 To produce engineers with good professional skills, ethical values and life skills for the
betterment of the society.
PEO3 Apply ethical knowledge for professional excellence and leadership for the
betterment of the society.
PEO4 Develop life-long learning skills needed for better employment and
entrepreneurship
To interpret real-time problems with analytical skills and to arrive at cost effective and
PSO2 optimal solution using advanced tools and techniques.
1. To understand Object Oriented Programming concepts and basics of Java programming language
2. To know the principles of packages, inheritance and interfaces
3. To develop a java application with threads and generics classes
4. To define exceptions and use I/O streams
5. To design and build Graphical User Interface Application using JAVAFX
Overview of OOP – Object oriented programming paradigms – Features of Object Oriented Programming
– Java Buzzwords – Overview of Java – Data Types, Variables and Arrays – Operators – Control
Statements – Programming Structures in Java – Defining classes in Java – Constructors-Methods -Access
specifiers - Static members- Java Doc comments
Overloading Methods – Objects as Parameters – Returning Objects –Static, Nested and Inner Classes.
Inheritance: Basics– Types of Inheritance -Super keyword -Method Overriding – Dynamic Method
Dispatch –Abstract Classes – final with Inheritance. Packages and Interfaces: Packages – Packages and
Member Access –Importing Packages – Interfaces.
Exception Handling basics – Multiple catch Clauses – Nested try Statements – Java’s Built-in Exceptions
– User defined Exception. Multithreaded Programming: Java Thread Model–Creating a Thread and
Multiple Threads – Priorities – Synchronization – Inter Thread Communication- Suspending –Resuming,
and Stopping Threads –Multithreading. Wrappers – Auto boxing.
I/O Basics – Reading and Writing Console I/O – Reading and Writing Files. Generics: Generic
Programming – Generic classes – Generic Methods – Bounded Types – Restrictions and Limitations.
Strings: Basic String class, methods and String Buffer Class.
JAVAFX Events and Controls: Event Basics – Handling Key and Mouse Events. Controls: Checkbox,
ToggleButton – RadioButtons – ListView – ComboBox – ChoiceBox – Text Controls – ScrollPane.
Layouts – FlowPane – HBox and VBox – BorderPane – StackPane – GridPane. Menus – Basics – Menu –
Menu bars – MenuItem.
COURSE OUTCOMES:
CO1: Apply the concepts of classes and objects to solve simple problems
CO3: Make use of exception handling mechanisms and multithreaded model to solve real world problems
CO4: Build Java applications with I/O packages, string classes, Collections and generics concepts
CO5: Integrate the concepts of event handling and JavaFX components and controls for developing GUI
based applications
TOTAL: 45 PERIODS
TEXT BOOKS:
1. Herbert Schildt, “Java: The Complete Reference”, 11 th Edition, McGraw Hill Education, New
Delhi, 2019
REFERENCE:
1. Cay S. Horstmann, “Core Java Fundamentals”, Volume 1, 11 th Edition, Prentice Hall, 2018.
C205.1 Apply the concepts of classes and objects to solve simple problems.
C205.3 Make use of exception handling mechanisms and multithreaded model to solve real world
problems
C205.4 Build Java applications with I/O packages, string classes, Collections and generics concepts
Integrate the concepts of event handling and JavaFX components and controls for developing
C205.5
GUI based applications
INDEX
Class is a template for a set of objects that share a common structure and a C205.1 BTL 1
common behaviour. A class is a blueprint, or prototype, that defines the variables
1 and the methods common to all objects of a certain kind.
import java.util.Vector;
class Test {
Vector vector;
Test() {
vector = new Vector();
}
}
What is the default access to a member in a class? MAY/JUNE – 2011
Default is no access specifier. For classes, and interface declarations, the
default is package private. This falls between protected and private, allowing C205.1 BTL 1
only classes in the same package access. (protected is like this, but also allowing
3 access to subclasses outside of the package.
For interface members (fields and methods), the default access is public.
But note that the interface declaration itself defaults to package private.
{ /**
Javadoc utility enables you to keep the code and the documentation in
sync easily. The javadoc utility lets you put your comments right next to your
code, inside your ".java" source files.
All you need to do after completing your code is to run the Javadoc utility to
create your HTML documentation automatically.
Java offers four access specifiers, listed below in decreasing accessibility: C205.1 BTL 1
public
protected
private
Private
Private methods and fields can only be accessed within the same class to
which the methods and fields belong. private methods and fields are not visible
7 within subclasses and are not inherited by subclasses. So, theprivate access specifier
is opposite to the public access specifier. It is mostly used for encapsulation: data are
hidden within the class and accessor methods are provided. An example, in which
the position of the upper-left corner of a square can be set or obtained by accessor
methods, but individual coordinates are not accessible to the user.
C205.1 BTL 1
14
An object has behavior (it can do things and can have things done to it).
What gives java it’s “write once and run anywhere” nature?
27 All Java programs are compiled into class files that contain bytecodes. These byte
codes can be run in any platform and hence java is said to be platform independent. C205.1 BTL 1
What is static variable and static method?
Static variable is a class variable which value remains constant for the entire class.
28
Static method is the one which can be called with the class itself and can hold only C205.1 BTL 1
the static variables.
PART B
1 (i) What is a constructor? What is the use of new method? (4) NOV/DEC
2010
Refer page no: 144 C205.1 BTL 1
(ii) Give the syntax for static method and its initialization. (4) NOV/DEC
2010
Refer page no: 132
(iii) Explain arrays in java. (8)
NOV/DEC 2010
Refer page no:90
4 (ii) Define package. Explain the types of package with its importance. (8)
NOV/DEC 2011,
C205.1 BTL 1
What is package? How to add a class into a package? Give example. (8)
MAY/JUNE 2013
6 Write a java program for push and pop operations in stack using arrays in
classes and object. (16)
NOV/DEC 2011 C205.1 BTL 1
Refer page no:90
Write a java program to sort ten names in descending order. (16)
7 MAY/JUNE 2012
Refer notes
Refer notes
9
What is meant by package? How it is created and implemented in JAVA. (8)
NOV/DEC 2013 C205.1 BTL 1
(ii) Write a JAVA program to find the smallest number in the given list. (8)
iv) Explain the term static fields and methods and explain its types with
examples (8) APR/ MAY 2015
12 Define array. What is array sorting and explain with an example? APR/
MAY 2015
C205.1 BTL 1
C205.1 BTL 1
UNIT – 2
Inheritance – Super classes- sub classes –Protected members – constructors in sub classes- the Object
class – abstract classes and methods- final methods and classes – Interfaces – defining an interface,
implementing interface, differences between classes and interfaces and extending interfaces - Object
cloning -inner classes, Array Lists – Strings
test(no,name,t1,t2,t3) // parametized
constructor
st.no = no;
st.name = name;
m1 = t1;
m2 = t2;
m3 = t3;
};
8 What is Interface?
NOV/DEC 2011
An interface is basically a kind of class. Like classes, C205.2 BTL 1
interfaces contain methods and variables but but with
a major difference.The difference is that interfaces define
only abstract methods and final fields. This means that
interfaces do not specify any code to implement these
methods and data fields contain only constants
9 What is object cloning? NOV/DEC 2011 , How to
object clone? MAY/JUNE 2013, What is meant by
object cloning? NOV/DEC 2013, MAY/JUNE 2014 C205.2 BTL 1
It is the process of duplicating an object so that two
identical objects will exist in the memory at the same
time.
12
}
}
UNIT – 3
Exceptions - exception hierarchy - throwing and catching exceptions – built-in exceptions, creating own
exceptions, Stack Trace Elements. Input / Output Basics – Streams – Byte streams and Character streams
– Reading and Writing Console – Reading and Writing Files
The exceptions which occur at run time are called as C205.3 BTL 1
run time exceptions. These exceptions are unknown to
compiler. All sub classes of
java.lang.RunTimeException and java.lang.Error are
run time exceptions. These exceptions are unchecked
type of exceptions. For example,
NumberFormatException, NullPointerException,
ClassCastException,
ArrayIndexOutOfBoundException,
StackOverflowError etc.
9 There are three statements in a try block – statement1,
statement2 and statement3. After that there is a catch
block to catch the exceptions occurred in the try block. C205.3 BTL 1
Assume that exception has occurred in statement2.
Does statement3 get executed or not?
19 What is stream?
A stream is a sequential and contiguous one-way flow
of data.Java does not differentiate between the various C205.3 BTL 1
types of data sources or sinks (e.g., file or network) in
stream I/O.
20 Mention the different ways to generate an
Exception?
There are two different ways to generate an C205.3 BTL 1
Exception.
1. 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.
2. Exceptions can be manually generated by the code.
Manually generated exceptions are typically used to
report some error condition to
the caller of a method.
21 What is OutOfMemoryError in java?
OutOfMemoryError is the sub class of C205.3 BTL 1
java.lang.Error which occurs when JVM runs out of
memory.
22 Give some examples to checked exceptions?
ClassNotFoundException, SQLException, C205.3 BTL 1
IOException
23 Give some examples to unchecked exceptions?
extends Object
implements Serializable
PART B
1 (ii) Explain the exception hierarchy.
(8) NOV/DEC 2010
C205.3 BTL 1
Refer page no:553
UNIT – 4
Differences between multi-threading and multitasking, thread life cycle, creating threads, synchronizing
threads, Inter-thread communication, daemon threads, thread groups. Generic programming – Generic
classes – generic methods – Bounded Types – Restrictions and Limitations.
Timed waiting: A runnable thread can enter the timed waiting state
for a specified interval of time. A thread in this state transitions back
to the runnable state when that time interval expires or when the
event it is waiting for occurs.
Every Java object with a critical section of code gets a lock associated
with the object. To
synchronized(object) {
// statements to be synchronized
3 Mention the two mechanisms for protecting a code block from concurrent
access. MAY/JUNE 2011
Java 5 introduces general purpose synchronizer classes, including C205.4 BTL 1
semaphores, mutexes, barriers, latches, and exchangers, which facilitate
coordination between threads. These classes are a apart of the
java.util.concurrent package
A thread is a program's path of execution. Most programs written today run as a C205.4 BTL 1
single thread, causing problems when multiple events or actions need to occur
at the same time. Let's say, for example, a program is not capable of drawing
pictures while reading keystrokes. The program must give its full attention to
the keyboard input lacking the ability to handle more than one event at a time.
The ideal solution to this problem is the seamless execution of two or more
sections of a program at the same time.
5 What is multithreading. NOV/DEC 2011 , MAY/JUNE – 2012,
MAY/JUNE 2013, NOV/DEC 2014
Multithreading enables us to write very efficient programs that make C205.4 BTL 1
maximum use of the CPU, because idle time can be kept to a minimum.
wait( ): This method 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( ): This method wakes up the first thread that called wait( )
on the same object.
notifyAll( ): This method wakes up all the threads that called wait(
) on the same object.c The highest priority thread will run first.
id: the thread's id (a unique, positive long generated by the system when the
thread was created)
daemon: the thread's daemon status. A daemon thread is one that performs
services for other threads, or periodically runs some task, and is not expected to
run to completion.
wait() sleep()
wait() method releases the lock sleep() method doesn't release the lock.
The isInterrupted() method returns the interrupted flag either true or C205.4 BTL 1
false. The static interrupted() method returns the interrupted flag
afterthat it sets the flag to false if it is true.
27
What if we call run() method
C205.4 BTL 1
directly instead start() method?
Each thread starts in a separate call stack.
Invoking the run() method from main thread, the run() method
goes onto the current call stack rather than at the beginning of a
new call stack.
28 Define daemon thread?
A daemon thread is a thread that does not prevent the JVM from exiting
when the program finishes but the thread is still running. An example for a C205.4 BTL 1
daemon thread is the garbage collection. You can use the
setDaemon(boolean) method to change the Thread daemon properties before
the thread starts.
29
List out the different Methods for Java Daemon thread by
C205.4 BTL 1
Thread class
30
C205.4
How to perform single task by BTL 1
multiple threads?
If you have to perform single task by many threads, have only one run() method.
For example:
3. System.out.println("task one");
4. }
9.
10. t1.start();
11. t2.start();
12. t3.start();
13. }
14. }
PART B
1 (i) What is a thread? Explain its states and methods. (8) NOV/DEC 2010 C205.4 BTL 1
Refer page no:716
(ii) Explain thread properties. (8) NOV/DEC 2010
Refer page no:733
2 (i) Explain the methods of interrupting threads in java. (8) C205.4 BTL 1
NOV/DEC 2010
(ii) What is Event-driven programming? Explain. (8)
NOV/DEC 2010, MAY/JUNE 2014
Refer page no:728
3 Explain the procedure for running a task in a separate thread and running C205.4 BTL 1
multiple threads. (16) MAY/JUNE 2011
Refer page no:731
4 Explain the states of threads and how the thread is interrupted? C205.4 BTL 1
MAY/JUNE 201, MAY/JUNE 2014, NOV/DEC 2014
5 (i) Explain how threads are created in Java. (8) NOV/DEC 2011 C205.4 BTL 1
(ii) Write about various threads states in Java. (8) NOV/DEC 2011
7 Explain the following (i) States of a thread with a neat diagram. [10] C205.4
MAY/JUNE 2012
(ii) Thread priorities. (6) MAY/JUNE 2012
8 i) How to implement runnable interface for creating and starting threads? C205.4
(8) MAY/JUNE 2013
ii) Define threads. Describe in detail about thread life cycle. (8)
UNIT – 5
Graphics programming - Frame – Components - working with 2D shapes - Using color, fonts, and mages
- Basics of event handling - event handlers - adapter classes - actions - mouse events - AWT event
hierarchy - Introduction to Swing – layout management - Swing Components – Text Fields , Text Areas –
Buttons- Check Boxes – Radio Buttons – Lists- choices- Scrollbars – Windows –Menus – Dialog Boxes.
C205.5 BTL 1
• the JVM has no instantiations of generic types
• a generic type definition is compiled once only, and
a corresponding raw type is produced
– the name of the raw type is the same name but type
variables removed
getUIClassID()
Returns a string that specifies the name of the L&F class that
renders this component.
isDefaultButton()
isDefaultCapable()
paramString()
Returns a string representation of this JButton.
extends Object
implements WindowListener
BorderLayout( )
BorderLayout(int horz, int vert)
The Font Class is used to render ‘glyphs’ - the characters you see C205.5 BTL 1
on the screen. FontMetrics encapsulates information about a
specific font on a specific Graphics object. (width of the characters,
ascent, descent)
There’s 2 ways. The first thing is to know that a JButton’s edges C205.5 BTL 1
are drawn by a Border. so you can override the Button’s
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 button’s border to it.
29 What is an event and what are the models available for event
handling?
C205.5 BTL 1
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
PART B
1 Explain about the concepts of creating and positioning of frame (8)
APR/MAY 2015
C205.5 BTL 1
2 Define Event handling write a program to handle a button event(8)
APR/MAY 2015 C205.5
BTL 1
3 Explain the classes under 2D shapes. Working with 2D Shapes
C205.5 BTL 1
4 Explain event handling with examples. EVENT HANDLING
C205.5
BTL 1
5 Explain action event with an example. Actions
C205.5 BTL 1
6 What are the swing components? Explain. Swing Component
C205.5 BTL 1
7 Describe the AWT event hierarchy. The AWT Event Hierarchy
C205.5 BTL 1
8 Give the methods available in graphics for COLOR and FONTS
Color and fonts Using Color
C205.5 BTL 1