Docsity

Java Programming: Comprehensive Q&A on OOP Concepts, Summaries of Java Programming

Toggle sidebar
bg1
AKTU Java Long Answer Questions with Answers
1. Explain Object Oriented Programming (OOP) concepts in Java with examples.
Answer: OOP concepts: Encapsulation, Inheritance, Polymorphism, Abstraction. Example: Animal class with
Dog subclass.
2. What is inheritance in Java? Explain its types with a suitable program.
Answer: Inheritance lets a class acquire properties of another. Types: Single, Multilevel, Hierarchical.
Example: class A, class B extends A.
3. Differentiate between an abstract class and interface with examples.
Answer: Abstract class can have concrete methods, interface can't (before Java 8). A class can implement
multiple interfaces.
4. Explain exception handling in Java with a program.
Answer: Use try-catch-finally. Example: try { int a=1/0; } catch(Exception e) { }
5. Write short notes on JVM, JDK, and JRE.
Answer: JVM runs bytecode, JDK is dev kit, JRE is JVM + libraries.
6. Explain multithreading with an example.
Answer: Threads run concurrently. Example: extend Thread or implement Runnable.
7. Explain the lifecycle of an applet.
Answer: Methods: init(), start(), stop(), destroy(), paint().
8. Explain packages. How to create and use them with example.
Answer: Use 'package' keyword. Example: package mypack; import mypack.*;
9. Explain constructor overloading with an example.
Answer: Multiple constructors with different parameters. Example: Student(), Student(int id).
10. What is garbage collection? Explain finalize() method.
Answer: GC removes unused objects. finalize() runs before GC.
11. Explain difference between method overloading and overriding.
Answer: Overloading: same name, diff params. Overriding: same method in child class.
12. Explain final keyword.
Answer: final var = constant; final method = no override; final class = no inheritance.
13. Explain synchronization in multithreading.
Answer: Controls access to shared resources. Use synchronized keyword.
pf3

Partial preview of the text

Download Java Programming: Comprehensive Q&A on OOP Concepts and more Summaries Java Programming in PDF only on Docsity!

AKTU Java Long Answer Questions with Answers

1. Explain Object Oriented Programming (OOP) concepts in Java with examples. Answer: OOP concepts: Encapsulation, Inheritance, Polymorphism, Abstraction. Example: Animal class with Dog subclass. 2. What is inheritance in Java? Explain its types with a suitable program. Answer: Inheritance lets a class acquire properties of another. Types: Single, Multilevel, Hierarchical. Example: class A, class B extends A. 3. Differentiate between an abstract class and interface with examples. Answer: Abstract class can have concrete methods, interface can't (before Java 8). A class can implement multiple interfaces. 4. Explain exception handling in Java with a program. Answer: Use try-catch-finally. Example: try { int a=1/0; } catch(Exception e) { } 5. Write short notes on JVM, JDK, and JRE. Answer: JVM runs bytecode, JDK is dev kit, JRE is JVM + libraries. 6. Explain multithreading with an example. Answer: Threads run concurrently. Example: extend Thread or implement Runnable. 7. Explain the lifecycle of an applet. Answer: Methods: init(), start(), stop(), destroy(), paint(). 8. Explain packages. How to create and use them with example. Answer: Use 'package' keyword. Example: package mypack; import mypack.*; 9. Explain constructor overloading with an example. Answer: Multiple constructors with different parameters. Example: Student(), Student(int id). 10. What is garbage collection? Explain finalize() method. Answer: GC removes unused objects. finalize() runs before GC. 11. Explain difference between method overloading and overriding. Answer: Overloading: same name, diff params. Overriding: same method in child class. 12. Explain final keyword. Answer: final var = constant; final method = no override; final class = no inheritance. 13. Explain synchronization in multithreading. Answer: Controls access to shared resources. Use synchronized keyword.

14. Explain input and output streams in Java. Answer: InputStream reads data, OutputStream writes data. Example: FileInputStream. 15. What is String class? How is it different from StringBuffer? Answer: String is immutable, StringBuffer is mutable. 16. What is wrapper class? Explain with example. Answer: Wraps primitives as objects. int -> Integer. 17. Explain event handling in Java AWT. Answer: Uses listener interfaces. Example: ActionListener for button. 18. Explain polymorphism with real-life example. Answer: Compile-time: overloading; Runtime: overriding. Example: Animal sound(). 19. Explain command line arguments in Java. Answer: args[] in main. Example: java MyClass arg1 arg2. 20. Explain super keyword with example. Answer: Access parent members. Example: super.method(). 21. Explain the difference between checked and unchecked exceptions with examples. Answer: Checked: IOException, must handle. Unchecked: ArithmeticException. 22. What is the purpose of the static keyword in Java? Explain with example. Answer: Static members shared by all objects. Example: static int count. 23. Explain JDBC and its architecture. Answer: Java Database Connectivity: API for DB access. Layers: Driver, Connection, Statement. 24. Write a program to demonstrate use of this keyword. Answer: this.var resolves ambiguity. Example: this.x = x. 25. Explain the concept of method overriding and dynamic method dispatch. Answer: Overriding: same method in child class. Dynamic dispatch: runtime decision. 26. What is an abstract method? Give an example. Answer: Method without body. Example: abstract void draw(). 27. Explain inner classes and their types with example. Answer: Member, static, local, anonymous. Example: class Outer { class Inner {} }. 28. Describe the steps to create a Java swing application. Answer: Import javax.swing, create JFrame, add components, setVisible(true).