java model paper 2 BCA
java model paper 2 BCA
Model paper 2
2 marks
Objects have data (called fields) and actions (called methods). OOP helps make code
reusable and easier to manage.
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).
Class ClassName {
// fields
// methods
A class starts with the keyword class, followed by the class name and body.
Method overloading means having more than one method with the same name but with
different parameters.
Use Character Stream for reading/writing text. Use Byte Stream for other files.
Each task is called a thread. It helps programs run faster and smoother.
6 marks
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
8. High Performance
Java is faster than other interpreted languages because of Just-In-Time (JIT) compiler.
1. Integer Types
2. Floating-Point Types
3. Character Type
4. Boolean Type
Example:
1. Declaration:
Int[] numbers;
2. Initialization:
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:
1. Byte Streams
2. Character Streams
Int i = fin.read();
System.out.print((char)i);
Int i = fr.read();
System.out.print((char)i);
Example:
System.out.println(“Applet initialized”);
16. What is the difference between extending Thread and implementing Runnable
interface? Write a program to create multiple threads and explain.
Difference:
Uses start() directly-Pass object to Thread class and then call start()
T1.start();
T2.start();
}
}
This will create and run two threads at the same time.
8 marks
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.
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;
Byte → short → int → long → float → double Java converts all data types to the largest type
in the expression.
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)
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 {
System.out.println(count);
Usage:
Static variable: Shared among all objects.
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
Example:
String s = “Hello”;
20. (b) How can a class implement multiple interfaces? Explain with an example.
Example:
Interface A {
Void methodA();
Interface B {
Void methodB();
}
Class MyClass implements A, B {
Reader and Writer are abstract classes in Java used for character input and output.
Example:
Fw.write(“Hello”);
Fw.close();
21. (b)What are Key Events? Explain KeyListener Interface and KeyEvent Class Methods.
Methods:
1. keyPressed(KeyEvent e)
2. keyReleased(KeyEvent e)
3. keyTyped(KeyEvent e)
getKeyChar()
getKeyCode()
22. (b) What is the difference between throw and throws statement in Java? Explain with
an example.
Example:
22. (c) Write the steps involved in creating a thread by extending Thread class.
Steps:
Example:
System.out.println(“Thread is running”);
t.start();
Benefits:
6. Supports generics.
23. (b) Explain the JavaBeans Conventions. Write a Simple Program to Illustrate a
JavaBean.
Conventions:
Example:
Public Student() {}
Name = n;
Return name;