Java Programming - Reappear Exam Answers (BCA202)
Section A: Very Short Answers (2 Marks each)
Q1. Java vs C++
- Java is platform-independent; C++ is platform-dependent.
- Java uses JVM; C++ compiles to machine code.
- Java doesn't support pointers explicitly; C++ does.
- Java supports garbage collection; C++ requires manual memory management.
Q2. Tokens in Java
- Smallest units: Keywords, Identifiers, Operators, Separators, Literals.
Q3. Type Casting
- Implicit: int a = 10; float b = a;
- Explicit: float a = 10.5f; int b = (int)a;
Q4. Recursion
- A method calling itself. Useful for factorial, Fibonacci, etc.
Q5. Method Overloading
class Overload {
void show(int a) { [Link]("Int: " + a); }
void show(String b) { [Link]("String: " + b); }
public static void main(String[] args) {
Overload obj = new Overload(); [Link](10); [Link]("Hello");
}
Q6. Wrapper Classes
- Convert primitives to objects. int -> Integer, etc.
Q7. Inheritance
- Single: One class inherits one. Multiple: One inherits multiple (via interfaces).
Q8. Interfaces
- Collection of abstract methods. Used for multiple inheritance.
Q9. Abstract Classes
- Have abstract methods. Can't be instantiated. Used as base class.
Q10. File Writing Program
import [Link];
import [Link];
public class WriteFile {
public static void main(String[] args) {
try {
FileWriter writer = new FileWriter("[Link]");
[Link]("Hello File!"); [Link]();
} catch(IOException e) { [Link](); }
}
Section B: Long Answer (10 Marks)
Q11. Java Evolution & Features
- 1991: Oak by James Gosling; 1995: Java
- Features: Platform-independent, OOP, Secure, Multithreaded, Robust
Q12. 2D Array & Procedural vs OOP
- Code for matrix multiplication provided.
- Procedural: Step-by-step (C), OOP: Objects, Encapsulation (Java)
Section C:
Q13. Interface Program
interface A { void show(); }
class B implements A {
public void show() { [Link]("Implemented show()"); }
public static void main(String[] args) { B obj = new B(); [Link](); }
Q14. Applet Life Cycle
- init(), start(), paint(), stop(), destroy()
Thread Synchronization
class Counter {
int count = 0;
synchronized void increment() { count++; }
Section D:
Q15. Inheritance & super
class Animal { void sound() { [Link]("Animal"); } }
class Dog extends Animal {
void sound() {
[Link](); [Link]("Dog barks");
Q16. Abstract Class & Final Keyword
abstract class Shape { abstract void draw(); }
class Circle extends Shape {
void draw() { [Link]("Drawing Circle"); }
Final:
final int x = 10; final class A {}; final void method() {}
Section E:
Q17. File I/O Program
import [Link].*;
public class CopyFile {
public static void main(String[] args) throws IOException {
FileInputStream in = new FileInputStream("[Link]");
FileOutputStream out = new FileOutputStream("[Link]");
int c; while((c = [Link]()) != -1) { [Link](c); }
[Link](); [Link]();
}
}
Q18. Thread Priority
class MyThread extends Thread {
public void run() { [Link]("Priority: " + [Link]()); }
public class PriorityDemo {
public static void main(String[] args) {
MyThread t1 = new MyThread(); MyThread t2 = new MyThread();
[Link](Thread.MIN_PRIORITY);
[Link](Thread.MAX_PRIORITY);
[Link](); [Link]();
Local vs Remote Applet
- Local: Runs from user system
- Remote: Loaded from web/internet
--- End of Answers ---