[go: up one dir, main page]

0% found this document useful (0 votes)
2 views12 pages

java model paper 2 BCA

The document is a model paper on Object Oriented Programming (OOP) using Java, covering key concepts such as OOP definition, byte code, control structures, class syntax, and method overloading. It also discusses Java features, data types, I/O streams, applet life cycle, threading, JDK tools, type promotion, and the Collection Framework. Additionally, it explains JavaBeans conventions and provides examples for various topics.

Uploaded by

usharushar238
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)
2 views12 pages

java model paper 2 BCA

The document is a model paper on Object Oriented Programming (OOP) using Java, covering key concepts such as OOP definition, byte code, control structures, class syntax, and method overloading. It also discusses Java features, data types, I/O streams, applet life cycle, threading, JDK tools, type promotion, and the Collection Framework. Additionally, it explains JavaBeans conventions and provides examples for various topics.

Uploaded by

usharushar238
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/ 12

Oop’s using java

Model paper 2

2 marks

1. What is Object Oriented Programming?

Object Oriented Programming (OOP) is a way of writing programs using objects.

Objects have data (called fields) and actions (called methods). OOP helps make code
reusable and easier to manage.

2. What is Byte Code?

Byte code is the special code that Java programs are changed into after compilation.

It is not machine code but can run on any system using the Java Virtual Machine (JVM).

3. Mention the different types of control structures in Java.

The main control structures in Java are:

Decision-making: if, if-else, switch

Looping: for, while, do-while

Branching: break, continue, return

4. What is the general syntax for defining a class?

Class ClassName {

// fields

// methods

A class starts with the keyword class, followed by the class name and body.

5. What is the difference between String and StringBuffer?

String is immutable (cannot be changed after creation).

StringBuffer is mutable (can be changed).

StringBuffer is better for many string changes.

6. What is method overloading?

Method overloading means having more than one method with the same name but with
different parameters.

It helps perform different tasks with the same method name.


7. What is an Interface in Java?

An interface is like a blueprint.

It contains method names but no body.

Classes use interfaces to show they can perform certain actions.

8. What is the difference between Character and Byte Streams?

Character Streams work with text (characters).

Byte Streams work with binary data (like images or files).

Use Character Stream for reading/writing text. Use Byte Stream for other files.

9. What is a Panel and Frame in AWT?

Panel is a container used to group components.

Frame is a window with a title bar and close button.

Frame is the main window; Panel is used inside Frame.

10. What is Multithreading?

Multithreading means running multiple tasks at the same time in a program.

Each task is called a thread. It helps programs run faster and smoother.

6 marks

11. Explain the Features of Java.

Java is a powerful programming language. Some important features are:

1. Simple

Java is easy to learn if you know basic programming. It removes complex things like
pointers.

2. Object-Oriented

Everything in Java is based on objects and classes. This helps organize code better.

3. Platform Independent

Java programs run on any system with a JVM (Java Virtual Machine). You can write once
and run anywhere.

4. Secure

Java provides security with features like bytecode verification and no direct memory
access.
5. Robust

Java checks errors at compile and run time. It has strong memory management.

6. Multithreaded

Java can do many tasks at the same time using threads. This helps in creating fast and
efficient programs.

7. Portable

Java code can run on any device or system. It is not system-dependent.

8. High Performance

Java is faster than other interpreted languages because of Just-In-Time (JIT) compiler.

12. Explain the Basic Data Types used in Java.

Java has 8 basic data types, divided into 4 groups:

1. Integer Types

Byte: 1 byte, -128 to 127

Short: 2 bytes, -32,768 to 32,767

Int: 4 bytes, used for whole numbers

Long: 8 bytes, used for large numbers

2. Floating-Point Types

Float: 4 bytes, for decimal numbers (less precision)

Double: 8 bytes, for decimal numbers (more precision)

3. Character Type

Char: 2 bytes, used to store single characters like ‘A’, ‘1’

4. Boolean Type

Boolean: true or false, used in conditions

Example:

Int age = 20;

Float price = 99.99f;

Char grade = ‘A’;

Boolean passed = true;


13. How to declare, initialize and access single dimensional arrays? Explain with an
example.

An array is used to store many values of the same type.

1. Declaration:

Int[] numbers;

2. Initialization:

Numbers = new int[5]; // creates an array with 5 elements

3. Assign values:

Numbers[0] = 10;

Numbers[1] = 20;

Numbers[2] = 30;

Numbers[3] = 40;

Numbers[4] = 50;

4. Access elements:

System.out.println(numbers[2]); // prints 30

Full Example:

Public class ArrayExample {

Public static void main(String[] args) {

Int[] marks = {85, 90, 78, 88, 95};

For (int i = 0; i < marks.length; i++) { System.out.println(“Mark “ + i + “: “ +


marks[i]);

14. Explain the classification of I/O Streams in Java.

In Java, I/O (Input/Output) is used to read or write data.

Java has 2 types of streams:

1. Byte Streams

Used to read/write binary data.


Classes: FileInputStream, FileOutputStream

2. Character Streams

Used to read/write text data.

Classes: FileReader, FileWriter

Byte Stream Example:

FileInputStream fin = new FileInputStream(“file.txt”);

Int i = fin.read();

System.out.print((char)i);

Character Stream Example:

FileReader fr = new FileReader(“file.txt”);

Int i = fr.read();

System.out.print((char)i);

15. Explain the life cycle of an Applet.

An applet is a small Java program that runs in a web browser.

Life Cycle Methods:

1. init() – Called once to initialize the applet.

2. start() – Called when applet starts or resumes.

3. paint() – Called to draw on the screen.

4. stop() – Called when applet is stopped.

5. destroy() – Called to remove the applet from memory.

Example:

Public class MyApplet extends Applet {

Public void init() {

System.out.println(“Applet initialized”);

Public void start() { System.out.println(“Applet started”);

Public void paint(Graphics g) {


g.drawString(“Welcome to Applet”, 20, 20);

Public void stop() { System.out.println(“Applet stopped”);

Public void destroy() { System.out.println(“Applet destroyed”);

16. What is the difference between extending Thread and implementing Runnable
interface? Write a program to create multiple threads and explain.

Difference:

Extending Thread | Implementing Runnable

Inherits Thread class -Implements Runnable interface

Can’t extend other classes-Can extend other classes

Uses start() directly-Pass object to Thread class and then call start()

Example using Runnable:

Class MyTask implements Runnable {

Public void run() { System.out.println(“Thread running: “ +


Thread.currentThread().getName());

Public class TestThread {

Public static void main(String[] args) {

MyTask task1 = new MyTask();

MyTask task2 = new MyTask();

Thread t1 = new Thread(task1);

Thread t2 = new Thread(task2);

T1.start();

T2.start();

}
}

This will create and run two threads at the same time.

8 marks

17. (a) What is JDK? List the Important Tools of JDK.

JDK stands for Java Development Kit. It is a software development kit used to develop
Java applications. It includes everything needed to write, compile, and run Java
programs.

Important tools in JDK:

1. javac – Java compiler, converts .java to .class files.

2. java – Used to run Java programs

3. javadoc – Generates documentation from comments in code.

4. jdb – Java debugger.

5. jar – Creates and manages JAR (Java Archive) files.

6. javap – Disassembles class files.

7. javah – Generates header files (used with native methods).

8. jconsole – Monitors Java performance.

17. (b) Describe the concept of type promotion in Java. Explain how Java handles mixed
data types in expressions with examples.

Type promotion in Java means converting smaller data types into bigger ones
automatically during calculations.

Example:

Int a = 10;

Float b = 5.5f;

Float result = a + b; // int is promoted to float

In mixed data type expressions:

Byte → short → int → long → float → double Java converts all data types to the largest type
in the expression.

18. Explain the different loop statements in Java with examples.

Java has 3 main loops:


1. For loop

For (int i = 0; i < 5; i++) {

System.out.println(i);

2. While loop

Int i = 0;

While (i < 5) {

System.out.println(i);

I++;

3. Do-while loop

Int i = 0;

Do {

System.out.println(i);

I++;

} while (i < 5)

Each loop helps repeat block of code multiple times.

19. (a) Explain the usage of static keyword in Java with examples.

The static keyword is used to create variables or methods that belong to the class, not
the object.

Example:

Class MyClass {

Static int count = 0;

Static void showCount() {

System.out.println(count);

Usage:
Static variable: Shared among all objects.

Static method: Called without creating an object.

Static block: Used for static initialization.

19.(b) What is Character class? Explain any five methods of Character Class.

The Character class wraps a char value and provides utility methods for char
operations.

5 methods:

1. isLetter(‘a’) → true

2. isDigit(‘5’) → true

3. toUpperCase(‘a’) → ‘A’

4. toLowerCase(‘B’) → ‘b’

5. isWhitespace(‘ ‘) → true

It helps work with characters more easily.

20. (a) Explain instanceof operator with an example.

The instanceof operator checks if an object is an instance of a particular class.

Example:

String s = “Hello”;

System.out.println(s instanceof String); // true

It is used for safe type checking before casting objects.

20. (b) How can a class implement multiple interfaces? Explain with an example.

A class can implement more than one interface using commas.

Example:

Interface A {

Void methodA();

Interface B {

Void methodB();

}
Class MyClass implements A, B {

Public void methodA() { System.out.println(“A”); }

Public void methodB() { System.out.println(“B”); }

This is Java’s way of achieving multiple inheritance.

21. Explain Reader and Writer Classes.

Reader and Writer are abstract classes in Java used for character input and output.

Common Reader classes:

FileReader: Reads characters from files.

BufferedReader: Reads text efficiently.

Common Writer classes:

FileWriter: Writes characters to files.

BufferedWriter: Writes text efficiently.

Example:

FileWriter fw = new FileWriter(“file.txt”);

Fw.write(“Hello”);

Fw.close();

They are used to handle text data.

21. (b)What are Key Events? Explain KeyListener Interface and KeyEvent Class Methods.

Key events occur when a user types on the keyboard.

KeyListener is an interface used to handle key events.

Methods:

1. keyPressed(KeyEvent e)

2. keyReleased(KeyEvent e)

3. keyTyped(KeyEvent e)

KeyEvent class provides info about the key like:

getKeyChar()

getKeyCode()
22. (b) What is the difference between throw and throws statement in Java? Explain with
an example.

Throw is used to throw an exception manually.

Throws is used to declare that a method might throw an exception.

Example:

Void checkAge(int age) throws Exception {

If (age < 18) {

Throw new Exception(“Not allowed”);

22. (c) Write the steps involved in creating a thread by extending Thread class.

Steps:

1. Create a class and extend Thread.

2. Override the run() method.

3. Create an object of the class.

4. Call start() method.

Example:

Class MyThread extends Thread {

Public void run() {

System.out.println(“Thread is running”);

MyThread t = new MyThread();

t.start();

23. (a) Write the benefits of Collection Framework.

Benefits:

1. Easy to use data structures (List, Set, Map).

2. Reduces programming effort.


3. Increases performance.

4. Provides algorithms (sorting, searching).

5. Improves code reusability and maintenance.

6. Supports generics.

7. Allows dynamic data storage.

8. Interoperability between different types of collections.

23. (b) Explain the JavaBeans Conventions. Write a Simple Program to Illustrate a
JavaBean.

JavaBeans are reusable software components.

Conventions:

1. Class must be public.

2. Should have a public no-arg constructor.

3. Use private fields.

4. Use public getters/setters.

Example:

Public class Student {

Private String name;

Public Student() {}

Public void setName(String n) {

Name = n;

Public String getName() {

Return name;

You might also like