0% found this document useful (0 votes)
11 views3 pages

Java Questions

The document outlines various topics related to Java programming, categorized into understanding, application, and analysis levels. It includes explanations and descriptions of concepts such as method overloading, method overriding, abstract classes, exception handling, and multithreading, along with practical programming tasks. Additionally, it emphasizes critical thinking by analyzing synchronization, deadlock, and the differences between byte and character streams.

Uploaded by

Kani
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views3 pages

Java Questions

The document outlines various topics related to Java programming, categorized into understanding, application, and analysis levels. It includes explanations and descriptions of concepts such as method overloading, method overriding, abstract classes, exception handling, and multithreading, along with practical programming tasks. Additionally, it emphasizes critical thinking by analyzing synchronization, deadlock, and the differences between byte and character streams.

Uploaded by

Kani
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

7 Marks – K2 (Understand)

1. K2 – Explain
Explain method overloading and method overriding with suitable examples.
2. K2 – Describe
Describe the concept of abstract classes and explain their significance in Java.
3. K2 – Explain
Explain dynamic method dispatch with the help of a simple class hierarchy.
4. K2 – Describe
Describe the usage of the final keyword with respect to variables, methods, and
classes.
5. K2 – Explain
Explain Java packages and their role in access protection.
6. K2 – Describe
Describe the life cycle of a thread in Java.
7. K2 – Explain
Explain the concept of byte streams and character streams in Java.

10 Marks – K2 (Understand)

1. K2 – Differentiate
Differentiate between method overloading and method overriding with suitable
code snippets.
2. K2 – Explain
Explain interfaces in Java, including definition, implementation, and extending
interfaces.
3. K2 – Describe
Describe exception handling in Java and explain try, catch, finally, throw, and
throws.
4. K2 – Explain
Explain multithreading in Java using Thread class and Runnable interface.
5. K2 – Describe
Describe the Java I/O stream hierarchy and explain different stream classes.

🟢 K3 – APPLY (Implement / Demonstrate / Write)


(Practical usage – program-based questions)

7 Marks – K3 (Apply)

1. K3 – Implement
Write a Java program to demonstrate method overriding.
2. K3 – Demonstrate
Write a Java program using an abstract class and implement its methods.
3. K3 – Apply
Write a Java program to demonstrate custom exception handling.
4. K3 – Implement
Write a Java program to create a thread using the Runnable interface.
5. K3 – Demonstrate
Write a Java program to read input from the console and display output.

10 Marks – K3 (Apply)

1. K3 – Implement
Write a Java program to demonstrate dynamic method dispatch using base and
derived classes.
2. K3 – Apply
Write a Java program to demonstrate synchronization using synchronized methods.
3. K3 – Implement
Write a Java program to create, throw, and handle a user-defined exception.
4. K3 – Demonstrate
Write a Java program to perform file handling operations (read and write to a file).
5. K3 – Apply
Write a Java program to demonstrate inter-thread communication using wait() and
notify().

🔵 K4 – ANALYZE (Analyze / Compare / Examine /


Identify Issues)
(Critical thinking & problem-solving)

7 Marks – K4 (Analyze)

1. K4 – Analyze
Analyze the impact of method overriding on runtime polymorphism.
2. K4 – Compare
Compare abstract classes and interfaces with suitable use cases.
3. K4 – Analyze
Analyze the need for synchronization in multithreaded programs.
4. K4 – Examine
Examine the causes of deadlock in Java programs.
5. K4 – Analyze
Analyze the difference between byte streams and character streams based on
application scenarios.

10 Marks – K4 (Analyze)
1. K4 – Analyze
Analyze how dynamic method dispatch helps in achieving runtime polymorphism
with an example.
2. K4 – Examine
Examine the problems that arise due to lack of synchronization in multithreaded
environments.
3. K4 – Analyze
Analyze the exception propagation mechanism in Java using throw and throws.
4. K4 – Compare
Compare synchronized methods and synchronized blocks and analyze their
performance implications.
5. K4 – Examine
Examine how deadlock occurs in Java and analyze possible prevention techniques.

Common questions

Powered by AI

Dynamic method dispatch is a mechanism in Java by which a call to an overridden method is resolved at runtime rather than compile-time. This is achieved through virtual method tables that manage method calls. For a base class reference pointing to a subclass object, the override in the subclass is invoked, not the base class version, demonstrating runtime polymorphism. It allows Java programs to call methods on references of superclass types and select which method's body to execute dynamically, enhancing flexibility and decoupling method definitions from their implementations .

Abstract classes and interfaces both provide a way to achieve abstraction but serve different purposes and have different capabilities. Abstract classes can have instance variables, constructors, and can provide some implemented methods, allowing for shared code among subclasses. Interfaces, however, are fully abstract and cannot hold state or provide constructors but allow implementing classes to simulate multiple inheritance by implementing multiple interfaces. Abstract classes are suitable when there is a need to define default behavior and state. Interfaces are preferred when only a contract, that different classes can adhere to independently, is needed .

Byte streams in Java, using InputStream and OutputStream classes, are intended for raw binary data transfer, suitable for images, audio files, and other non-text data. Character streams, based on Reader and Writer classes, are designed for character data, thus beneficial when dealing with text files where encoding is crucial. Byte streams process data one byte at a time, whereas character streams process data two bytes at a time in Unicode, providing a level of abstraction appropriate for character encoding and operations involving character manipulation .

Method overriding is a key component in achieving runtime polymorphism because it allows a subclass to provide a specific implementation of a method that is already defined in its superclass. When a method of an overridden superclass is called on a subclass object, the Java Virtual Machine decides at runtime which method implementation to execute, depending on the object type. This enables dynamic method dispatch, which is the essence of runtime polymorphism in Java. It provides the flexibility to invoke methods on objects without knowing their exact class, allowing for implementations to be swapped seamlessly .

Deadlock in Java typically occurs when two or more threads are blocked forever, each waiting on the other to release resources. This situation arises usually because each thread holds a lock that the other needs. Prevention techniques include avoiding nested locks, using a timeout for lock attempts, breaking circular wait conditions by imposing an ordering on resource acquisition, and utilizing sophisticated constructs like `Lock` and `ReentrantLock` from the `java.util.concurrent` package, which provide more flexible lock management .

Synchronization in multithreaded Java programs ensures that concurrent threads do not exhibit unpredictable behavior due to inconsistent view of shared resources. Without synchronization, critical section problems can arise, where multiple threads modify shared data concurrently, leading to race conditions and data corruption. By using synchronization constructs like `synchronized` methods or blocks, Java ensures mutual exclusion and memory consistency, preventing threads from interfering with each other while offering a reliable view of shared resources .

The key components of Java's exception handling mechanism include `try`, `catch`, `finally`, `throw`, and `throws`. A `try` block is used to wrap code that might throw an exception. The `catch` block follows the `try` block to handle specific exceptions. `Finally` is an optional block that executes after `try` and `catch`, regardless of whether an exception was thrown, to perform cleanup. The `throw` statement is used to explicitly throw an exception, while `throws` is a keyword used in method signatures to indicate that a method can throw exceptions. Together, these components allow developers to detect, handle, and propagate exceptions in a controlled, systematic way .

Method overloading occurs when multiple methods have the same name but differ in parameters (type, number, or both) within the same class. For example, a class might have `void display(int x)` and `void display(String y)`. Method overriding, on the other hand, happens when a subclass provides a specific implementation for a method declared in its superclass, like `class Subclass extends Superclass { @Override void display() { // implementation } }`. In overloading, method calls are resolved at compile time, while in overriding, the method call is resolved at runtime, providing polymorphic behavior .

Java's thread lifecycle involves several states: New, Runnable, Blocked, Waiting, Timed Waiting, and Terminated. A thread begins in the New state after creation. It moves to Runnable when the `start()` method is called. While a Runnable thread is eligible to run, but not necessarily running, it may change to Blocked if it attempts to acquire a lock busy with another thread. Waiting occurs when a thread waits indefinitely for another thread's actions, while Timed Waiting is for a specified waiting time. Finally, the thread enters Terminated once run completes or exits abruptly .

Java packages serve as a namespace mechanism to organize classes and interfaces and also provide access protection by controlling access levels. A package in Java, defined with the `package` keyword, groups related classes and interfaces. Visibility modifiers like `public`, `protected`, and package-private control accessibility: `public` elements are accessible from any package; `protected` elements within the same package or subclasses; and package-private elements only within the same package. This encapsulation restricts unauthorized access and helps maintain encapsulation .

You might also like