java model paper 3
java model paper 3
Model paper 3
2 marks
Java is called platform independent because Java code runs on any operating system
using the Java Virtual Machine (JVM). You write code once and run it anywhere.
Encapsulation: Wrapping data and methods together in a class. It hides internal details.
Inheritance: One class can use the properties and methods of another class.
A constructor is a special method used to create and initialize objects in Java. It has the
same name as the class.
8. What are Layout Managers? What is the use of Layout Managers in Java?
Layout Managers arrange GUI components in a window. They help control how buttons,
labels, etc., are placed.
An exception is an error that happens while a program is running. Java uses try-catch to
handle it.
6 marks
11. Explain the four core concepts of Object-Oriented Programming (OOP) with
examples.
1. Encapsulation:
Example: A class has private variables and public methods to access them.
Class Person {
2. Inheritance:
It means one class can use the properties and methods of another class.
Example:
Class Animal {
3. Polymorphism:
Class Animal {
4. Abstraction:
Java Tokens are the smallest parts of a Java program that the compiler can understand.
There are 5 main types:
Example:
Int a = 5 + 10;
Constructor Overloading means having more than one constructor in a class with
different arguments.
Example:
Class Student {
Int id;
String name;
// Constructor 1
Student() {
Id = 0;
Name = “Unknown”;
// Constructor 2
Student(int i, String n) {
Id = i;
Name = n;
Void display() {
System.out.println(id + “ “ + name);
How it works:
Java chooses the constructor based on the number and type of arguments.
Import java.util.Scanner;
System.out.println(“Hello “ + name);
Uses System.out
System.out.println(“Welcome”);
Uses System.err
System.err.println(“Error occurred”);
Applet Example:
Import java.applet.Applet;
Import java.awt.Graphics;
1. Sleep():
2. Join():
3. isAlive():
If(t1.isAlive()) { ... }
Example:
System.out.println(i);
T1.start();
8 marks
Type Promotion means converting smaller data types into larger ones automatically
during operations.
Example:
Byte a = 10;
Byte b = 20;
System.out.println(c);
Syntax:
// use var
Example:
For(int n : nums) {
System.out.println(n);
}
18 (a). Explain else-if ladder with an example.
Example:
System.out.println(“Grade A”);
System.out.println(“Grade B”);
System.out.println(“Grade C”);
} else {
System.out.println(“Fail”);
Example:
System.out.println(i);
// Output: 1 2 4 5
System.out.println(i);
// Output: 1 2
19 (a). What is Math class? Mention important mathematical functions.
Important Methods:
Example:
System.out.println(Math.sqrt(16)); // 4.0
Method Overloading: Same method name, different parameters in the same class.
Class Example {
Class Animal {
Runtime Polymorphism means deciding which method to run during execution time.
Class Animal {
Class Main {
Features:
Lightweight components
Example:
Import javax.swing.*;
f.add(b);
f.setSize(300, 300);
f.setLayout(null);
f.setVisible(true);
Java uses DataInputStream and DataOutputStream to handle primitive data types like
int, char, double.
Example:
Dos.writeInt(10);
Dos.writeDouble(12.5);
To Read:
Int i = dis.readInt();
Double d = dis.readDouble();
21 (b). Program to read and write character data using FileReader and FileWriter.
Program:
Import java.io.*;
Fw.write(“Hello File”);
Fw.close();
Int ch;
Fr.close();
}
c.add(“Java”);
c.add(“Python”);
Example: Missing ;
Java Security Manager controls what a Java program can and cannot do.
Example Rules:
How it works: It checks permissions during runtime and blocks unsafe actions.
System.setSecurityManager(new SecurityManager());
Class Box<T> {
T value;
Class Test {
System.out.println(data);