You are on page 1of 29

** Note: Students to be instructed to draw well labeled diagrams wherever necessary,

to support their answers (especially in level B and C questions)

Question Bank - Unit no.: 3


Program: BCA
Course Name: Fundamental of Computer and Elements of IT Course Code: 21BCA101
Academic year: 2022-23 Sem/Year: I/I
Level A. Easy Questions (2 marks each)
S. Questions CO*
No.
Q1 What is the purpose of 'Throw' and ' Throws' keywords. CO1
• throw is used to explicitly throw an exception in Java. It is followed by an instance of an exception
or a throwable. Example: throw new RuntimeException("This is an exception");
• throws is used in the method signature to declare that the method might throw certain types of
exceptions. It is used to indicate that the method does not handle the exceptions itself, and calling
methods should be aware of the possibility of exceptions. Example: void myMethod() throws
IOException { ... }

Q2 What is Synchronization? CO1,CO2

Synchronization in Java is the capability to control the access of multiple threads to shared resources. It
prevents multiple threads from accessing shared data simultaneously, which can lead to data inconsistency.
Q3 Explain the concept of Runnable Interface. CO1,CO2

The Runnable interface in Java is used for implementing multithreading. A class that implements Runnable
can be instantiated, passed as an argument to a Thread constructor, and then started. It provides a way to
run a code block in a separate thread.
Q4 How can you handle an Exception. CO1

Exceptions in Java can be handled using the try, catch, and finally blocks. The try block contains the code
that might throw an exception, and the catch block handles the exception. The finally block contains code
that is executed regardless of whether an exception occurs or not.
Q5 Elaborate the concept of Exception handling. CO1

Exception handling in Java allows developers to handle errors, such as runtime exceptions, gracefully. It
involves using try, catch, and finally blocks to control the flow of the program in the presence of
exceptions.
Q6 How can you catch multiple exceptions. CO1

Q7 How do we invoke constructor? CO1,CO2


Constructors are invoked automatically when an object is created using the new keyword. Example: MyClass
obj = new MyClass();
Q8 What is inter-thread communication? CO1
Inter-thread communication refers to communication between two or more threads in a multithreaded
environment. It is often achieved using methods like wait(), notify(), and notifyAll() to coordinate the
execution of threads.
Q9 Define throwable class in detail. CO1
Throwable is the superclass of all errors and exceptions in Java. It has two main subclasses: Error and
Exception. Errors are typically unrecoverable and indicate serious problems, while exceptions can be caught
and handled.
Q10 What do you mean by final variable and final method? CO1
A final variable is a variable that cannot be changed once it has been assigned a value. A final method is a
method that cannot be overridden by subclasses.
Q11 State the different access specifiers available in Java CO2
Java has four access specifiers: public, protected, default (package-private), and private. These specifiers
control the visibility of classes, methods, and variables.
Q12 Write a note on finalizer method. CO1,CO2
The finalizer method in Java is the finalize() method. It is called by the garbage collector before an object
is reclaimed by the memory management system. However, relying on the finalizer is discouraged, and it's
better to use other mechanisms for resource cleanup.
Q13 What are called members? CO1
Members in Java typically refer to fields (variables) and methods within a class.
Q14 Why it is considered as a good practice to define a constructor though compiler can CO1,CO2
automatically generate a constructor ?
Defining a constructor allows you to initialize object state and set up necessary resources when an object is
created. If you don't provide a constructor, the compiler generates a default constructor, which might not
suit your specific needs.
Q15 Write down the importance of destructor. CO2
Unlike some other programming languages, Java does not have explicit destructors. Instead, it relies on
garbage collection to automatically reclaim memory. This simplifies memory management and helps avoid
memory leaks. The absence of destructors in Java is considered an advantage in terms of simplicity and
robust memory management.
Q16 Mention the differences between constructor and destructor CO1,CO2
• Constructors:
• Purpose: Initializes the object's state and allocates resources.
• Called automatically when an object is created.
• Multiple constructors can exist with different parameter lists.
• No return type (not even void).
• Name is the same as the class name.
• Destructors:
• Purpose: Deallocates resources and performs cleanup tasks.
• Not present in Java; garbage collector handles memory
deallocation.
• Not explicitly called; automatically invoked by the system.
• Not defined in Java; the finalize() method is similar but is not a
true destructor.
• No concept of destructors in Java as in some other languages.

Q17 Draw the inheritance hierarchy for the frame and component classes in AWT and Swing. CO1,CO2

Q18 What are the advantages of using swing over awt? CO1
• Swing provides a rich set of lightweight components compared to AWT's heavyweight components.
• Swing components have a consistent look and feel across different platforms.
• Swing supports more advanced and flexible GUI features, such as pluggable look-and-feel,
customizable components, and enhanced layout managers.
• Swing supports double buffering, which can enhance the performance of graphical components.
Q19 How do achieve special fonts for your text? Give example. CO1

Q20 Enlist atleast 4 differences between constructors and java method. CO2
1. Name and Return Type:
• Constructor name is the same as the class name, and it has no return type (not even void).
• Method name can be any valid identifier, and it has a return type (including void).
2. Invocation:
• Constructors are automatically invoked when an object is created using the new keyword.
• Methods are invoked explicitly by calling them using an object or class reference.
3. Multiple Constructors:
• A class can have multiple constructors with different parameter lists (overloading).
• Methods can also be overloaded, but each method must have a unique signature,
considering the method name and parameter types.
4. Purpose:
• Constructors are used to initialize the object's state and allocate resources during object
creation.
• Methods are used to define behavior and perform actions when called.

Level B. Intermediate Questions (5 marks each)

Q21 Explain Types of error and exception classes. CO1


Q22 What is difference between packages and interfaces explain with example? CO1,CO2
Table 02 [optional]
Q23 Explain Life cycle of thread and thread priority? CO1,CO2

Q24 What are the types of exceptions in Java API? Explain each in detail. CO1,CO2
Q25 Explain the use of try, catch, finally, throw and throws with example? CO1
Q26 What is multiple inheritance and how to perform it in Java? CO3,CO4
done
Q27 Explain the fundamentals of Exception Handling and the exception types. CO2,
CO3
Q28 Give a detailed sketch of the differences between Single, Multilevel &Hierarchical CO2
Inheritance?
1. Single Inheritance:

• Definition:
• Single Inheritance involves a child class inheriting from only one
parent class.
• Each class can have at most one direct superclass.

2. Hierarchical Inheritance:

• Definition:
• Hierarchical Inheritance involves multiple classes inheriting from a
single superclass.
• It forms a tree-like structure with a common base class and multiple
derived classes.

3. Multilevel Inheritance:

• Definition:
• Multilevel Inheritance involves a chain of inheritance, where a class
serves as a superclass for another class, and that subclass becomes
the superclass for another class, forming a chain.

Q29 Define two ways to create Threads. CO2,


done CO3
Q30 Describe how to set the priority to threads? What are the different ranges. CO2
Level C. Difficult Questions (10 marks each)

Q31 What is Multithreading? Illustrate the ways to create multiple threads in java. CO2,
CO3
Q32 Elaborate the concept of Threads. Explain thread life cycle in detail. CO2,
CO3
Threads are the smallest units of execution within a process. They enable concurrent execution of
tasks, allowing different parts of a program to run in parallel. Each thread has its own program
counter, register set, and stack but shares the same memory space with other threads in the same
process. Threads are widely used in modern programming to improve the performance and
responsiveness of applications.
Q33 Write a java program to create two threads and execute simultaneously. CO2,
CO3
Q34 Write a Java program that creates three threads. First thread displays ― Good Morning ǁ CO3,CO4
every one second, the second thread displays Hello ǁ every two seconds.
Q35 What is multithreaded programming? How we create thread and explain its life cycle? CO3,CO4

Multithreaded programming is a programming paradigm where a process is divided into two or


more threads, and each thread can execute independently, concurrently, and asynchronously. A
thread is the smallest unit of execution within a process, and a process can have multiple threads
running concurrently.

In a multithreaded program, each thread represents an independent flow of execution. These


threads share the same resources, such as memory space and file descriptors, but they have their
own program counter, register set, and stack space. The concurrent execution of threads allows
for better utilization of the available resources and can lead to improved performance,
responsiveness, and efficiency in certain types of applications.

Q36 Describe interfaces & how to implement them with a Java CO4,CO5
** Note: Students to be instructed to draw well labeled diagrams wherever necessary,
to support their answers (especially in level B and C questions)

You might also like