Java Question Paper-2
Java Question Paper-2
1 Marks Question
The javac command is used in Java to compile Java source code files (files
with a .java extension) into bytecode files (files with a .class extension)
that can be executed by the Java Virtual Machine (JVM).
An array in Java is used to store multiple values of the same data type under
a single variable name. It provides a convenient way to work with collections
of data elements.
g) What is an exception?
Answer:
javaCopy code
boolean endsWith(String suffix)
i) What is a package?
Answer:
2 Marks Question
Storage in a Program:
Command line arguments are stored in the args parameter of the main
The command line arguments can be accessed within the program using
the args array.
Frame in Java:
Method Overloading:
Method Overriding:
4 Marks Question
// Constructor
Triangle(double base, double height) {
this.base = base;
this.height = height;
}
b) Write a Java Program to copy the contents from one file into
another file. While copying, change the case of all the alphabets
& replace all the digits by '*'.
Answer:
4 Marks Question
Swing:
Swing components are lightweight and are not dependent on the native
platform's resources.
// Java program
public class NumberProgram {
// Static method to calculate the sum of the first and
static int sumOfDigits(int num) {
int lastDigit = num % 10;
int firstDigit = 0;
while (num != 0) {
firstDigit = num % 10;
num /= 10;
}
import java.util.Scanner;
scanner.close();
}
}
3 Marks Question
When applied to a class, it indicates that the class cannot be inherited (i.e., it
is a final class).
Example:
class Example {
final int constantValue = 10;
import java.util.Scanner;
// Parameterized constructor
public Emp(int eid) {
Eid = eid;
}
// Display method
void display() {
System.out.println("Employee ID: " + Eid);
// Parameterized constructor
public EmpName(int eid, String ename) {
// Call the constructor of the base class using su
super(eid);
Ename = ename;
}
scanner.close();
}
}