KEMBAR78
Java Test 3 July 2025 | PDF | Java (Programming Language) | Java Virtual Machine
0% found this document useful (0 votes)
39 views7 pages

Java Test 3 July 2025

The document consists of a series of multiple-choice questions covering various topics in Java, including its features, data types, operators, conditional statements, loops, input functions, arrays, and strings. Each section contains questions that test knowledge on specific Java concepts and syntax. The questions range from basic definitions to practical coding scenarios.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views7 pages

Java Test 3 July 2025

The document consists of a series of multiple-choice questions covering various topics in Java, including its features, data types, operators, conditional statements, loops, input functions, arrays, and strings. Each section contains questions that test knowledge on specific Java concepts and syntax. The questions range from basic definitions to practical coding scenarios.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 7

🔹 Java Introduction (Q1–Q6)

1. Which of the following is not a Java feature?


a) Object-oriented
b) Use of pointers
c) Portable
d) Platform Independent

2. Java was developed by:


a) Microsoft
b) Sun Microsystems
c) Oracle
d) IBM

3. What does JVM stand for?


a) Java Variable Machine
b) Java Virtual Method
c) Java Virtual Machine
d) Java Verified Machine

4. Which of the following is the correct file extension for a Java source file?
a) .js
b) .class
c) .java
d) .txt

5. Java programs are first compiled into:


a) Binary Code
b) Native Code
c) Bytecode
d) Assembly

6. Which keyword is used to define a class in Java?


a) function
b) def
c) class
d) define

---

🔹 Data Types (Q7–Q13)

7. What is the default value of a boolean variable in Java?


a) true
b) 1
c) 0
d) false

8. Which of the following is not a primitive data type in Java?


a) int
b) float
c) String
d) boolean

9. The size of int in Java is:


a) 4 bytes
b) 2 bytes
c) 8 bytes
d) 1 byte

10. Which data type is used to store a single character?


a) char
b) string
c) boolean
d) float

11. Which of these data types has the highest precision?


a) float
b) double
c) int
d) long

12. What is the range of values for the byte data type?
a) -128 to 127
b) 0 to 255
c) -255 to 255
d) -32,768 to 32,767

13. Which of the following is a correct declaration of a float variable?


a) float num = 5.4;
b) float num = 5.4f;
c) float num = "5.4";
d) float num = '5.4';

---

🔹 Operators (Q14–Q20)

14. Which operator is used to compare two values?


a) =
b) ==
c) !=
d) :=

15. Which operator is used for logical AND in Java?


a) &
b) &&
c) |
d) ||

16. What will 5 % 2 return?


a) 2
b) 2.5
c) 1
d) 0

17. Which of the following is a bitwise operator?


a) &&
b) ||
c) &
d) !=

18. What is the result of 10 + 20 + "Java"?


a) 30Java
b) Java30
c) 1020Java
d) Error

19. Which operator is used for incrementing a value by 1?


a) ++
b) +=
c) +
d) --

20. Which of the following is not an assignment operator in Java?


a) =
b) +=
c) ==
d) -=

---

🔹 Conditional Statements (Q21–Q26)

21. Which keyword is used for a simple decision-making structure?


a) if
b) for
c) while
d) switch

22. The else statement must be used with:


a) for
b) switch
c) if
d) case

23. What is the output of this code:

java
int a = 5;
if (a == 5)
System.out.println("Yes");
else
System.out.println("No");

a) Yes
b) No
c) Error
d) Nothing

24. Which of the following can replace multiple if-else blocks effectively?
a) loop
b) switch
c) method
d) class

25. In a switch statement, each case is followed by which keyword?


a) next
b) continue
c) break
d) return

26. Which of the following is invalid in a switch case?


a) int
b) char
c) String
d) float

---

🔹 Loops (Q27–Q34)

27. Which of the following is an entry-controlled loop?


a) do-while
b) while
c) switch
d) if

28. Which loop guarantees at least one execution?


a) for
b) while
c) do-while
d) if

29. How many times will this loop run?

java
for(int i=0; i<5; i++)
System.out.println(i);

a) 4
b) 5
c) 6
d) Infinite

30. Which keyword is used to exit a loop early?


a) stop
b) break
c) exit
d) return

31. Which keyword skips the current iteration?


a) break
b) continue
c) skip
d) pass

32. The while loop is best used when:


a) number of iterations is known
b) infinite loop is needed
c) condition is checked after execution
d) number of iterations is not known

33. Which loop is used for iterating arrays easily?


a) for
b) while
c) for-each
d) do-while

34. What is the output of:

java
int i = 1;
while(i <= 3) {
System.out.print(i + " ");
i++;
}

a) 1 2 3
b) 1 2
c) 0 1 2
d) Infinite

---

🔹 Input Function (Q35–Q38)

35. Which class is used for input in Java?


a) System.in
b) Input
c) Scanner
d) Console

36. To read a string input from the user using Scanner:


a) input.readString();
b) input.nextString();
c) input.getLine();
d) input.nextLine();

37. What is the package required to use Scanner?


a) java.lang
b) java.io
c) java.util
d) java.input

38. Which method is used to read an integer?


a) nextInt()
b) readInt()
c) parseInt()
d) getInt()

---

🔹 Arrays (Q39–Q44)

39. Arrays in Java are:


a) Dynamic
b) Fixed size
c) Heterogeneous
d) None of these

40. Which is the correct way to declare an array?


a) int arr\[] = new int\[5];
b) int arr = \[5];
c) array int arr = new array(5);
d) int arr(5);

41. What is the index of the first element in an array?


a) 1
b) 0
c) -1
d) Depends on array

42. How do you access the 3rd element in an array arr?


a) arr\[3]
b) arr(2)
c) arr\[2]
d) arr{3}

43. What is the output?

java
int[] arr = {10, 20, 30};
System.out.println(arr.length);

a) 2
b) 3
c) 1
d) Error

44. Which of the following is used to loop through an array?


a) for-each
b) switch
c) input
d) Scanner

---

🔹 Strings (Q45–Q50)

45. Strings in Java are:


a) Mutable
b) Immutable
c) Changeable
d) Primitive

46. What is the result of "Hello".length()?


a) 4
b) 5
c) 6
d) Error

47. How to compare two strings in Java?


a) ==
b) equals()
c) =
d) match()

48. What will be the output of:

java
String s = "Java";
System.out.println(s.charAt(1));

a) J
b) a
c) v
d) Error

49. Which method converts a string to uppercase?


a) toUpper()
b) upper()
c) toUpperCase()
d) changeUpper()

50. Which method is used to concatenate two strings?


a) append()
b) concat()
c) join()
d) add()

You might also like