0% found this document useful (0 votes)
31 views2 pages

BCA Java OOP Exam Questions 2024

The document outlines the BCA Semester Exam for Object Oriented Programming Using Java, covering short and medium answer questions. Key topics include Java API, differences between String and StringBuffer, abstract classes, Java features, constructors, method overloading vs overriding, applet life cycle, thread creation, and user-defined exceptions. Each section provides essential definitions and rules related to Java programming concepts.

Uploaded by

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

BCA Java OOP Exam Questions 2024

The document outlines the BCA Semester Exam for Object Oriented Programming Using Java, covering short and medium answer questions. Key topics include Java API, differences between String and StringBuffer, abstract classes, Java features, constructors, method overloading vs overriding, applet life cycle, thread creation, and user-defined exceptions. Each section provides essential definitions and rules related to Java programming concepts.

Uploaded by

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

BCA Semester Exam - Object Oriented Programming Using Java (July/August 2024)

PART - A (Short Answer Questions)

PART - A (2 Marks Each)

1) What is Java API?


Java API is a set of classes and interfaces provided by Java to help developers perform common tasks like file I/O,
networking, data structures, and GUI. It acts as a library to simplify programming.

2) Differences between String and StringBuffer:


- String is immutable; StringBuffer is mutable.
- StringBuffer is thread-safe; String is not.
- String creates a new object on modification; StringBuffer modifies the same object.

3) Differences between this and super keywords:


- this refers to the current class object; super refers to the superclass object.
- this() calls a constructor of the same class; super() calls the superclass constructor.
- this is used for member disambiguation; super accesses overridden members.

4) Define abstract class:


An abstract class in Java is declared with the abstract keyword. It can have both abstract methods (without body) and
concrete methods. It cannot be instantiated directly.

5) Four methods of InputStream and OutputStream:


- read()
- read(byte[] b)
- write(int b)
- write(byte[] b, int off, int len)

6) Typecasting in Java:
Typecasting is converting one data type into another.
- Widening: Implicit (e.g., int to double)
- Narrowing: Explicit using casting (e.g., double to int -> int a = (int) 4.5;)

PART - B (Medium Answer Questions)

PART - B (5 Marks Each)

7) Features of Java:
- Simple: Easy syntax, no pointers.
- Object-Oriented: Based on classes and objects.
BCA Semester Exam - Object Oriented Programming Using Java (July/August 2024)

- Platform Independent: Write once, run anywhere via JVM.


- Secure: Runtime checks and no explicit memory access.
- Multithreaded and Robust: Handles errors and concurrent execution.

8) What is constructor? Rules:


- Name must match class.
- No return type.
- Can be overloaded.
- Can use this() or super() to chain constructors.

9) Method Overloading vs Overriding:


Overloading: Same class, different parameters.
Overriding: Subclass, same method signature.

10) Applet Life Cycle:


- init(): Initializes applet
- start(): Called after init or resume
- paint(Graphics g): For GUI drawing
- stop(): Called when applet is inactive
- destroy(): Cleanup resources

11) Creating thread using Thread class:


1. Extend Thread
2. Override run()
3. Create object
4. Call start()

12) User-defined Exception:


class MyException extends Exception {
MyException(String msg) {
super(msg);
}
}
throw new MyException("error");

Common questions

Powered by AI

User-defined exceptions in Java allow developers to create custom exception classes by extending the Exception class, enabling precise control over error handling . For example, class MyException extends Exception { MyException(String msg) { super(msg); } } allows for tailored error messages and handling unique to developer needs. The main advantage over standard exceptions is the ability to encapsulate application-specific errors, offering better clarity and specificity in error reporting and debugging processes. This customization enhances code robustness and maintainability by addressing specific application logic requirements .

Widening conversions in Java occur implicitly, where a smaller data type is converted to a larger one, such as converting an int to a double, without explicit casting needed . For example, int a = 10; double b = a; is a widening conversion. Narrowing conversions require explicit casting, as they involve converting a larger data type to a smaller one, such as converting a double to an int, which can cause data loss. This requires explicit syntax, like int c = (int) 4.5; . Widening is safe and automatic, whereas narrowing requires careful handling to avoid precision loss.

Utilizing read(byte[] b) and write(byte[] b, int off, int len) methods in Java's InputStream and OutputStream classes allows for batch processing of data, which is more efficient than processing data byte by byte . These methods enable buffer-level operations that minimize the number of I/O operations, reducing overhead and enhancing throughput. Correct use, such as choosing appropriate buffer sizes and offsets, can further optimize performance, particularly in high-load scenarios or when handling large data streams, helping to avoid common pitfalls like buffer overflows and excessive memory use.

Java's platform independence, achieved through the Java Virtual Machine (JVM), ensures that financial applications can run on any operating system without modification, reducing development and deployment costs . Its robust security features, such as runtime checks and lack of explicit memory access, prevent unauthorized access to sensitive financial data and minimize vulnerabilities, which are crucial for maintaining trust and compliance in the finance industry . These features collectively enhance reliability and security critical to financial software applications.

The 'this' keyword is used to refer to the current object within an instance method or constructor. It is useful in situations where parameter names are similar to instance variable names, as it helps clarify which variable is being referenced . In contrast, 'super' is used to refer to the superclass' methods or constructors, often employed when calling a superclass's version of an overridden method or when needing to explicitly call the superclass constructor . Thus, 'this' is essential for clarity within the current class context, whereas 'super' is critical when relationships or dependencies with superclass elements need to be addressed.

String in Java is immutable, meaning any change to a String creates a new object, whereas StringBuffer is mutable, allowing internal changes to the same object . StringBuffer is thread-safe due to synchronized methods, making it slower but safer for multithreading. In contrast, String being immutable is inherently thread-safe but can lead to performance overhead due to constant creation of new objects during modifications .

Java integrates object-oriented principles such as encapsulation, inheritance, and polymorphism to streamline software development . Encapsulation allows for data hiding, providing interfaces via methods while safeguarding internal states. Inheritance enables class hierarchies, promoting code reuse and logical organization through superclass-subclass relationships. Polymorphism allows objects to be treated as instances of their parent class, facilitating method overriding for dynamic behavior. These principles collectively lead to more manageable and scalable codebases, fostering quicker development cycles and higher-quality software outcomes .

InputStream and OutputStream in Java provide a set of methods such as read(), write(int b), and write(byte[] b, int off, int len) that facilitate reading and writing bytes to and from files, forming the backbone of Java's I/O system . These streams allow for efficient byte-level operations but can be prone to errors such as file not found exceptions, improper stream closure leading to resource leaks, and synchronous I/O blocking operations which might not be suitable for high-performance applications. Proper exception handling and resource management are crucial to mitigate these issues.

Method overloading involves having multiple methods in the same class with the same name but different parameters, enabling compile-time polymorphism where method calls are resolved at compile time . In contrast, method overriding occurs when a subclass has a method with the same signature as a method in its superclass, providing runtime polymorphism where the appropriate method is determined during execution . Overloading enhances code readability by providing different ways to invoke a method, while overriding allows specific implementations in derived classes, crucial for dynamic method dispatch and runtime behavior flexibility.

The applet life cycle in Java, consisting of init(), start(), paint(Graphics g), stop(), and destroy(), dictates the stages of an applet's execution . Each method corresponds to critical phases: init() for initialization, start() and stop() for transitioning between active and idle states, paint() for rendering, and destroy() for cleanup. The life cycle enables controlled resource management and user interactivity. Variations in browser implementations can affect performance, such as how state transitions are handled or graphics are rendered, leading developers to ensure compatibility and proper handling across different environments .

You might also like