CS8392
CS8392
CS8392
UNIT I
PART A
1. Define classes in java
A class is a user defined blueprint or prototype from which objects are created. It represents
the set of properties or methods that are common to all objects of one type.
R.SARALA AP/IT
III SEM IT CS8392 OBJECT ORIENTED PROGRAMMING
The purpose of constructor is to initialize the object of a class while the purpose of a
method is to perform a task by executing java code. Constructors cannot be abstract, final, static
and synchronised while methods can be. Constructors do not have return types while methods do.
R.SARALA AP/IT
III SEM IT CS8392 OBJECT ORIENTED PROGRAMMING
14. Can an inner class declared inside of a method access local variables of this method
of this method?
These classes, however, can access the variables or parameters of the block that encloses it
only if they are declared as final or are effectively final. ... A local inner class defined inside a method body,
have access to it's parameters.
R.SARALA AP/IT
III SEM IT CS8392 OBJECT ORIENTED PROGRAMMING
A package as the name suggests is a pack(group) of classes, interfaces and other packages.
In java we use
packages to organize our classes and interfaces. We have two types of packages in Java: built-in
packages and the
packages we can create (also known as user defined package).
20.Define encapsulation
It is the process of binding of data and method together in a single entity called
class.
PART B
R.SARALA AP/IT
III SEM IT CS8392 OBJECT ORIENTED PROGRAMMING
ii. Demonstriate the static felds and methods used in java (6)
R.SARALA AP/IT
III SEM IT CS8392 OBJECT ORIENTED PROGRAMMING
UNIT II
PART A
Final keyword in java. ... First of all, final is a non-access modifier applicable only to a
variable, a method or a class. Following are different contexts where final is used. Final variables.
When a variable is declared with final keyword, its value can't be modified, essentially, a constant.
8. Describe wrapper classes? Why the wrapper classes are defined as final
Each of Java's eight primitive data types has a class dedicated to it. These are known as
wrapper classes because they "wrap" the primitive data type into an object of that class. The wrapper
classes are part of the java.lang package, which is imported by default into all Java programs
1. Use final.
2. Use private constructors.
3. Use a comment: // do not inherit.
4. Use a javadoc comment.
5. Make every method final, so people can't override them.
6. Use a runtime check in the class constructor: if (this. getClass() != MyClass. class) { throw new
RuntimeException("Subclasses not allowed"); }
R.SARALA AP/IT
III SEM IT CS8392 OBJECT ORIENTED PROGRAMMING
of the object. ... That's why the name shallow copy or shallow cloning in Java. If only primitive
type fields or Immutable objects are there then there is no difference between shallow and deep
copy in Java.
16. Create a java program to remove all white spaces from a string in java
a = a.replaceAll("\\s",""); In the context of a regex, \s will remove anything that
is a space character (including space, tab characters etc). You need to escape the
backslash in Java so the regex turns into \\s . Also, since Strings are immutable it is
important that you assign the return value of the regex to a .
17.Types of exception
Inheritance is the process by which objects of one class acquire the properties of
another class. It supports the concept of hierarchical classification. It provides the idea
R.SARALA AP/IT
III SEM IT CS8392 OBJECT ORIENTED PROGRAMMING
19. What is meant by visibility mode? Mention the visibility modes available.
Visibility mode specifies whether the features of the base class are privately
derived or publicly derived. There are three visibility modes. They are,
a. Private
b. Public
c. Protected
R.SARALA AP/IT
III SEM IT CS8392 OBJECT ORIENTED PROGRAMMING
PART B
R.SARALA AP/IT
III SEM IT CS8392 OBJECT ORIENTED
PROGRAMMING
UNIT III
PART A
1. What are the various traditional error handling methods?
The various traditional error handling methods are,
i. Returning error number.
ii. Global flag manipulation.
iii. Abnormal termination.
iii. catch for taking an action for specific exception.
R.SARALA AP/IT
III SEM IT CS8392 OBJECT ORIENTED PROGRAMMING
R.SARALA AP/IT
III SEM IT CS8392 OBJECT ORIENTED PROGRAMMING
Finally is usually used to close a code properly after its encountered an Exception or
Error. This means that no matter whether an exception/error comes or not, 1nce the try/try-
catch block ends, the finally block WILL be executed.
You can wrap an InputStream and turn it into a Reader by using the InputStreamReader class.
nputStreams are used to read bytes from a stream. So they are useful for binary data such as images, video
and serialized objects. Readers on the other hand are character streams so they are best used to read
character data.
18.Is it necessary that each try block must be followed by a catch block
It is not necessary that each try block must be followed by a catch block. Itshould be
followed by either a catch block or a finally block. And whatever exceptions are likely to be
thrown should be declared in the throws clause of the method.
R.SARALA AP/IT
III SEM IT CS8392 OBJECT ORIENTED PROGRAMMING
PART – B
1. Define exception. Why it is needed? Explain the different types of
exceptions and the exception hierarchy with appropriate examples
2. Explain briefly about user defined exceptions and the concept of
throwing and catching exception in java with examples
3. What are input and output streams? Explain them with illustrations
Describe the stack trace elements with an example
4. Summarize the concept of streams and stream classes and their
Classification
5. the most commonly used classes for handling i/o related
Exceptions
6. How exceptions are handled in Java? Explain the important methods
7. While reading a file how would you check whether you have reached
8. Explain how to handle arithmetic exception by giving a suitable
UNIT IV
PART A
1. Identify the different states in thread
A thread can be in any one of the following five states during its lifecycles:
R.SARALA AP/IT
III SEM IT CS8392 OBJECT ORIENTED PROGRAMMING
A thread, in the context of Java, is the path followed when executing a program.
AllJava programs have at least one thread, known as the main thread, which is created by
the Java Virtual Machine (JVM) at the program's start, when the main() method is invoked with the
main thread.
In a nutshell, generics enable types (classes and interfaces) to be parameters when defining
classes, interfaces and methods. Much like the more familiar formal parameters used in method
declarations, type parameters provide a way for you to re-use the same code with different inputs. The
difference is that the inputs to formal parameters are values, while the inputs to type parameters are
types.
notify() and notifyAll() methods with wait() method are used to for communication
between the threads. ... But when we use notifyAll() method then multiple threadsgot
the notification but execution of threads will be performed one by one because thread requires lock
and only one lock is available for one object.
6.Define generic in java
Generics are a facility of generic programming that were added to the Java programming
language in 2004 within version J2SE 5.0. They were designed to extend Java's type system to allow
“a type or method to operate on objects of various types while providing compile-time type safety”[1].
The aspect compile-time type safety was not fully achieved, since it was shown in 2016 that it is not
guaranteed in all cases.[2]
7.How to start a thread
The first way is to extend the Thread class, override the run() method with the code you want to
execute, then create a new object from your class and call start(). The second method is to pass an
implementation of the Runnable interface to the constructor of Thread, then call start().
R.SARALA AP/IT
III SEM IT CS8392 OBJECT ORIENTED PROGRAMMING
16. What if there is a break or return statement in try block followed by finally block?
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.
What are the different ways to handle exceptions? 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.
R.SARALA AP/IT
III SEM IT CS8392 OBJECT ORIENTED PROGRAMMING
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.
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.
PART B
R.SARALA AP/IT
III SEM IT CS8392 OBJECT ORIENTED PROGRAMMING
UNIT V
PART A
EVENT DRIVEN PROGRAMMING
1) What is source and listener?
source : A source is an object that generates an event. This occurs when the internal state of
that object changes in some way. listener : A listener is an object that is notified when an event
occurs.
It has two major requirements. First, it must have been registered with one or more
sources to receive notifications about specific types of events. Second, it must implement methods
to receive and process these notifications.
8) What is a layout manager and what are different types of layout managers available in java
AWT?
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
R.SARALA AP/IT
III SEM IT CS8392 OBJECT ORIENTED PROGRAMMING
GridBagLayout.
11) What is an event and what are the models available for event handling?
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
13) Why won͛t the JVM terminate when I close all the application windows?
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?
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.
R.SARALA AP/IT
III SEM IT CS8392 OBJECT ORIENTED PROGRAMMING
17) What is the difference between the File and RandomAccessFile classes?
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.
PART B
R.SARALA AP/IT
III SEM IT CS8392 OBJECT ORIENTED PROGRAMMING
R.SARALA AP/IT
III SEM IT CS8392 OBJECT ORIENTED PROGRAMMING
R.SARALA AP/IT
III SEM IT CS8392 OBJECT ORIENTED PROGRAMMING
R.SARALA AP/IT
III SEM IT CS8392 OBJECT ORIENTED PROGRAMMING
R.SARALA AP/IT