Java Question Paper - Detailed Solutions
Q.1 - All Questions are Compulsory
1. What is JVM?
The Java Virtual Machine (JVM) is an abstract machine that enables computers to run
Java programs. It converts Java bytecode into machine code specific to the
underlying hardware, making Java platform-independent. The JVM also handles
memory management and garbage collection.
2. Difference between Abstract and Concrete Class?
o Abstract Class: A class that cannot be instantiated. It may contain both
abstract (unimplemented) and concrete (implemented) methods. It serves as
a blueprint for subclasses.
o Concrete Class: A class that has a full implementation and can be instantiated
to create objects.
3. Difference between Overloading and Overriding?
o Method Overloading: Occurs within the same class. Methods have the same
name but different parameter lists (number, type, or both). It is an example of
compile-time (static) polymorphism.
o Method Overriding: Occurs in a subclass. A method in a subclass has the
same name and signature as a method in the superclass but provides a
different implementation. It is an example of runtime (dynamic)
polymorphism.
4. Four Byte Stream Classes?
o FileInputStream: Reads bytes from a file.
o FileOutputStream: Writes bytes to a file.
o ByteArrayInputStream: Reads bytes from an array.
o ByteArrayOutputStream: Writes bytes into an array.
5. Access Specifiers?
o Private: Accessible only within the same class.
o Public: Accessible from any other class.
o Protected: Accessible within the same package and by subclasses in other
packages.
o Default (Package-private): Accessible only within the same package.
6. Vector vs ArrayList?
o Vector: Synchronized, thread-safe but slower.
o ArrayList: Not synchronized, faster for single-threaded applications.
7. Polymorphism with Example?
Polymorphism allows the same method or object to perform differently based on
context. Example:
8. class Animal {
9. void makeSound() {
10. [Link]("Animal makes a sound");
11. }
12. }
13. class Dog extends Animal {
14. void makeSound() {
15. [Link]("Dog barks");
16. }
17. }
18. public class Main {
19. public static void main(String[] args) {
20. Animal myPet = new Dog();
21. [Link]();
22. }
23. }
24. Java Exceptions?
Java has two types of exceptions:
o Checked Exceptions (must be handled): IOException, SQLException
o Unchecked Exceptions (runtime errors): NullPointerException,
ArrayIndexOutOfBoundsException
25. Can a Class Extend an Interface?
No, a class must implement an interface using the implements keyword.
26. interface Vehicle {
27. void drive();
28. }
29. class Car implements Vehicle {
30. public void drive() {
31. [Link]("Driving a car");
32. }
33. }
34. Constructor?
A constructor is a special method that initializes an object.
class Car {
String brand;
Car(String brand) {
[Link] = brand;
11. Super Keyword?
Refers to the parent class and is used to access parent methods or constructors.
12. This Keyword?
Refers to the current instance of a class.
Q.2 - Attempt Any 3
1. C++ vs Java?
o C++: Supports multiple inheritance, uses pointers, manual memory
management.
o Java: Platform-independent, automatic garbage collection, no multiple
inheritance (interfaces used instead).
2. Java Features?
o Object-oriented
o Platform-independent
o Secure
o Multithreading support
3. Looping with Examples?
o For Loop:
4. for (int i = 0; i < 5; i++) {
5. [Link](i);
6. }
o While Loop:
7. int i = 0;
8. while (i < 5) {
9. [Link](i);
10. i++;
11. }
12. Method Overriding Example?
13. class Animal {
14. void makeSound() {
15. [Link]("Animal makes sound");
16. }
17. }
18. class Dog extends Animal {
19. void makeSound() {
20. [Link]("Dog barks");
21. }
22. }
23. Final vs Static?
o final: Prevents modification.
o static: Belongs to the class, not objects.
Q.3 - Attempt Any 3
1. String Methods?
o length(), equals(), charAt(), substring().
2. VectorList Class Example?
3. Vector<String> vector = new Vector<>();
4. [Link]("Apple");
5. Vector Methods?
o add(), remove(), size().
Q.4 - Attempt Any 3
1. Thread Priority?
2. Thread t1 = new Thread();
3. [Link](Thread.MAX_PRIORITY);
4. Exception Handling Example?
5. try {
6. int num = 5 / 0;
7. } catch (ArithmeticException e) {
8. [Link]("Cannot divide by zero");
9. }
10. Reader Class Example?
11. FileReader fr = new FileReader("[Link]");
Q.5 - Attempt Any 3
1. AWT Components?
o Button, Label, TextField, Frame, Panel.
2. Creating a Frame?
3. Frame f = new Frame("My Frame");
4. [Link](300, 300);
5. [Link](true);
6. Frame with Radio Buttons?
7. JRadioButton rb1 = new JRadioButton("Option 1");
This is the detailed version of the Java question paper. Let me know if you need further
modifications!