Java Programming Lab (IT-306) - Important Questions
-
Unit 214 Marks High Priority
Write a Java program to demonstrate constructor overloading in a class Person with fields name and age. Provide at least three overloaded constructors: a default constructor, a parameterized constructor, and a constructor that invokes another constructor using this(...). Instantiate objects using each constructor and print their state to show which constructor was invoked.
Core programmatic concept in Unit 2: constructor overloading and use of this() to delegate between constructors; frequently asked as a programming problem.
-
Unit 27 Marks High Priority
Explain constructor chaining in Java. Provide a concise example involving a superclass and a subclass where the subclass constructor calls the superclass constructor using super(...). Describe the order in which constructors execute during object creation.
Core conceptual topic: constructor chaining within an inheritance hierarchy; common short-theory plus example question.
-
Unit 210 Marks High Priority
Write a Java program to implement a copy constructor for a class Complex with fields real and imaginary. Create objects using the copy constructor and by simple assignment. Demonstrate and explain the difference between deep copy and shallow copy in this context.
Standard programming exercise testing constructors and copying semantics; often used to test object cloning concepts along with constructors.
-
Unit 214 Marks High Priority
Write a Java program to demonstrate single inheritance, multilevel inheritance, and hierarchical inheritance. Use appropriate classes and methods, and include examples of method overriding. Show the output for each inheritance type and explain how inheritance relationships are formed.
Comprehensive inheritance programming problem covering forms of inheritance and overriding; frequent in lab exams as multi-part coding task.
-
Unit 27 Marks High Priority
Explain method overriding and runtime polymorphism (dynamic method dispatch) in Java. Provide a short code example demonstrating how a superclass reference can refer to a subclass object and invoke the overridden method at runtime.
Theoretical-practical question on polymorphism and overriding; common short-answer question in Unit 2.
-
Unit 210 Marks High Priority
Write a Java program that uses an abstract class and an interface together. Create an abstract class with at least one concrete and one abstract method, an interface with at least one method, and a concrete class that extends the abstract class and implements the interface. Demonstrate polymorphic behavior through references of the abstract class and the interface.
Design-level question combining abstract classes and interfaces to test understanding of inheritance and multiple-type subtyping in Java.
-
Unit 214 Marks High Priority
Write a Java program to create threads by extending the Thread class and by implementing the Runnable interface. For both approaches, override the run() method, create and start multiple threads, and demonstrate use of getName() and setName() to show thread identity. Explain differences between the two approaches.
Core multithreading programming task covering both approaches to thread creation; standard lab assignment.
-
Unit 210 Marks High Priority
Explain synchronization in Java. Write a Java program that demonstrates a race condition when multiple threads update a shared counter. Then modify the program to fix the race condition using synchronized methods or synchronized blocks and show the corrected output.
Synchronization and race condition are high-value learning outcomes; typical ask is to demonstrate a problem then fix it with synchronized constructs.
-
Unit 214 Marks High Priority
Describe inter-thread communication using wait(), notify(), and notifyAll() in Java. Write a producer-consumer Java program that uses a shared buffer and coordinates producer and consumer threads using wait() and notify()/notifyAll(). Explain how thread coordination is achieved.
Classic producer-consumer inter-thread communication question; frequent practical examination topic.
-
Unit 27 Marks High Priority
Explain try-catch-finally behavior in Java with examples. Specifically, show what happens when an exception is thrown in a try block and there is a return statement in the finally block. Describe the order of execution and the value returned, if any.
Fundamental exception-handling behavior question; tests conceptual understanding of try-catch-finally semantics.
-
Unit 210 Marks High Priority
Write a Java program that defines and uses a user-defined checked exception and a user-defined unchecked exception. Demonstrate how to declare, throw, and catch each type of custom exception, and explain when you would choose checked versus unchecked exceptions.
Practical exercise on creating and using custom exceptions; tests declaration, throwing, and catching of both checked and unchecked user-defined exceptions.
-
Unit 27 Marks High Priority
Explain the difference between throw and throws in Java with examples. Also describe checked versus unchecked exceptions and explain how exception propagation works across the call stack with a brief code illustration.
Theory question covering two commonly confused constructs and exception propagation; standard short-answer topic in Unit 2.
Quick Add to Notes
Save questions, your own notes and screenshots into notes filed by unit. It takes a free account.
Create free accountHave an account? Log in
Notes Panel