Java Programming - Model Qus Paper - 2 by Silas
Java Programming - Model Qus Paper - 2 by Silas
2025 (Set 2)
1. What is JVM?
extends
4 bytes
start()
false
java.util
7. What does JDK stand for?
void
==
public
1. Encapsulation: Binding data and code together into a single unit known as a
class, restricting access using access modifiers.
2. Inheritance: Acquiring properties and behaviors from another class using
the "extends" keyword, promoting code reuse.
3. Polymorphism: Allowing the same method to have different
implementations (method overloading and overriding).
4. Abstraction: Hiding internal implementation and showing only the
functionality, implemented through abstract classes and interfaces.
5. Class and Object: Everything in Java is associated with classes and objects; a
class is a blueprint, and an object is an instance.
These features allow for modular, scalable, and maintainable code.
```java
import java.util.*; class PrimeCheck { public static void main(String[] args) {
Scanner sc = new Scanner(System.in); System.out.print("Enter a number: "); int
n = sc.nextInt(); boolean prime = true; for (int i = 2; i <= Math.sqrt(n); i++) { if (n
% i == 0) { prime = false; break; } } if (prime && n > 1) System.out.println(n + "
is a Prime Number"); else System.out.println(n + " is not a Prime Number"); } }
```
An applet goes through five states: 1. init(): Initializes the applet. 2. start():
Starts or resumes execution. 3. paint(): Draws the content. 4. stop(): Stops the
execution temporarily. 5. destroy(): Cleanup before unloading the applet.
Applets run in browsers using the JVM and do not have a main() method. Their
life cycle is controlled by the browser or applet viewer.
Java I/O uses streams to read and write data. There are two types:
Byte Streams: Handles binary data using InputStream and OutputStream
classes.
Character Streams: Handles character data using Reader and Writer classes.
File I/O uses classes like FileInputStream, FileOutputStream, FileReader, and
FileWriter.
Buffered streams like BufferedReader improve efficiency by reducing direct
disk I/O.
Download as PDF