1. Who is known as the father of Java?
A) Dennis Ritchie
B) James Gosling
C) Bjarne Stroustrup
D) Guido van Rossum
2. Java was originally developed by which company?
A) IBM
B) Microsoft
C) Sun Microsystems
D) Apple
3. Which method acts as the entry point of a Java program?
A) start()
B) main()
C) run()
D) init()
4. What is the correct syntax of the main method in Java?
A) public void main(String args[])
B) static void main(String args)
C) public static void main(String[] args)
D) void static main()
5. What is the extension of a Java source file?
A) .class
B) .java
C) .javac
D) .exe
6. Which command is used to compile a Java program?
A) java filename
B) compile filename
C) javac filename
D) run filename
7. What does JVM stand for?
A) Java Variable Machine
B) Java Virtual Machine
C) Java Verified Method
D) Java Visual Machine
8. Which component is responsible for executing Java bytecode?
A) JDK
B) JRE
C) Compiler
D) JVM
9. Which statement is used to print output in Java?
A) print()
B) [Link]()
C) echo()
D) write()
10. Java is platform-independent because of:
A) JDK
B) Operating System
C) JVM
D) Compiler
import [Link];
public class BasicCalculator {
public static void main(String[] args) {
// Creating Scanner object for user input
Scanner input = new Scanner([Link]);
[Link]("--- Welcome to the Java Calculator ---");
// 1. Demonstration of Data Types (double for precision)
[Link]("Enter first number: ");
double num1 = [Link]();
[Link]("Enter second number: ");
double num2 = [Link]();
// 2. Using char data type for the operator
[Link]("Choose an operator (+, -, *, /): ");
char operator = [Link]().charAt(0);
double result = 0;
boolean validOperation = true;
// 3. Logic using Switch-Case
switch (operator) {
case '+':
result = num1 + num2;
break;
case '-':
result = num1 - num2;
break;
case '*':
result = num1 * num2;
break;
case '/':
// 4. Handling Division by Zero
if (num2 != 0) {
result = num1 / num2;
} else {
[Link]("Error: Division by zero is undefined.");
validOperation = false;
}
break;
default:
[Link]("Error: Invalid operator entered.");
validOperation = false;
}
// 5. Formatted Output
if (validOperation) {
[Link]("Calculation Result: %.2f %c %.2f = %.2f\n", num1,
operator, num2, result);
}
[Link]();
}
}