JAVA Unit 3
JAVA Unit 3
JAVA Unit 3
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
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.
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.
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
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)