0% found this document useful (0 votes)
3 views

BCA202 Java Reappear Answers

The document contains answers to a Java programming reappear exam, covering topics such as the differences between Java and C++, type casting, recursion, method overloading, and file I/O. It also discusses Java's evolution, features, inheritance, interfaces, abstract classes, and thread synchronization. Additionally, it includes code examples demonstrating various concepts and distinctions between local and remote applets.

Uploaded by

indersharma148
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)
3 views

BCA202 Java Reappear Answers

The document contains answers to a Java programming reappear exam, covering topics such as the differences between Java and C++, type casting, recursion, method overloading, and file I/O. It also discusses Java's evolution, features, inheritance, interfaces, abstract classes, and thread synchronization. Additionally, it includes code examples demonstrating various concepts and distinctions between local and remote applets.

Uploaded by

indersharma148
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
You are on page 1/ 5

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) { System.out.println("Int: " + a); }

void show(String b) { System.out.println("String: " + b); }

public static void main(String[] args) {

Overload obj = new Overload(); obj.show(10); obj.show("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 java.io.FileWriter;

import java.io.IOException;

public class WriteFile {

public static void main(String[] args) {

try {

FileWriter writer = new FileWriter("output.txt");

writer.write("Hello File!"); writer.close();

} catch(IOException e) { e.printStackTrace(); }

}
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() { System.out.println("Implemented show()"); }

public static void main(String[] args) { B obj = new B(); obj.show(); }

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() { System.out.println("Animal"); } }

class Dog extends Animal {

void sound() {

super.sound(); System.out.println("Dog barks");

Q16. Abstract Class & Final Keyword

abstract class Shape { abstract void draw(); }

class Circle extends Shape {

void draw() { System.out.println("Drawing Circle"); }

Final:

final int x = 10; final class A {}; final void method() {}

Section E:

Q17. File I/O Program

import java.io.*;

public class CopyFile {

public static void main(String[] args) throws IOException {

FileInputStream in = new FileInputStream("input.txt");

FileOutputStream out = new FileOutputStream("output.txt");

int c; while((c = in.read()) != -1) { out.write(c); }

in.close(); out.close();

}
}

Q18. Thread Priority

class MyThread extends Thread {

public void run() { System.out.println("Priority: " + this.getPriority()); }

public class PriorityDemo {

public static void main(String[] args) {

MyThread t1 = new MyThread(); MyThread t2 = new MyThread();

t1.setPriority(Thread.MIN_PRIORITY);

t2.setPriority(Thread.MAX_PRIORITY);

t1.start(); t2.start();

Local vs Remote Applet

- Local: Runs from user system

- Remote: Loaded from web/internet

--- End of Answers ---

You might also like