Unit 1 - Practice Quiz

CSE310

1 Who is known as the primary inventor of the Java programming language?

A. Dennis Ritchie
B. James Gosling
C. Bjarne Stroustrup
D. Guido van Rossum

2 Which of the following serves as the entry point for a standalone Java application?

A. public void main(String args[])
B. public static void main(String args[])
C. private static void main(String[] args)
D. static void main(String args)

3 What was the original name of the Java programming language?

A. Oak
B. Pine
C. C++--
D. JScript

4 Which component is responsible for converting bytecode into machine-specific code?

A. JDK
B. JVM
C. JRE
D. JIT

5 What constitutes the 'Platform Independence' feature of Java?

A. The source code is compiled into an executable file (.exe)
B. The source code is interpreted directly
C. The source code is compiled into intermediate Bytecode
D. The code runs only on Linux

6 Which of the following statements accurately describes the relationship between JDK, JRE, and JVM?

A.
B.
C.
D.

7 What is the size of the int data type in Java?

A. 16 bits
B. 32 bits
C. 64 bits
D. Depends on the operating system

8 Which of the following is NOT a valid Java identifier?

A. _myVariable
B. $value
C. 1stVariable
D. variable1

9 What is the default value of a local variable defined inside a method?

A. null
B.
C. false
D. No default value (Must be initialized)

10 Which keyword is used to declare a constant variable in Java?

A. const
B. final
C. static
D. immutable

11 In the statement byte b = (byte) 130;, what is the result of the narrowing conversion?

A. 130
B. -126
C. 127
D. Compilation Error

12 What is the output of the bitwise operation ?

A. 1
B. 3
C. 5
D. 7

13 Which wrapper class corresponds to the char primitive type?

A. Char
B. Character
C. String
D. Text

14 What does the static keyword imply when applied to a variable inside a class?

A. The variable is local to the method
B. The variable cannot be changed
C. The variable belongs to the class, not instances
D. The variable is accessible only within the package

15 Evaluate the following expression assuming standard precedence:

A. 90
B. 70
C. 60
D. 30

16 Which command is used to compile a Java source file?

A. java
B. javac
C. javadoc
D. jar

17 What is the output of the following ternary operator usage? int x = (5 > 10) ? 10 : 20;

A. 5
B. 10
C. 20
D. true

18 Which access modifier makes a member accessible only within the same class?

A. public
B. protected
C. default
D. private

19 What is the result of 10 % 3?

A. 3.33
B. 3
C. 1
D.

20 If a Java file is named Test.java, which of the following classes MUST be defined inside it?

A. class Test
B. public class Test
C. private class Test
D. static class Test

21 Which data type would be best suited to store a flag that is either true or false?

A. int
B. short
C. boolean
D. byte

22 What happens if you provide fewer command-line arguments than the program expects/accesses?

A. Compilation Error
B. ArrayIndexOutOfBoundsException
C. NullPointerException
D. The variables get default values

23 What is the result of the left shift operator: ?

A. 2
B. 4
C. 16
D. 32

24 Which of the following is a 'short-circuit' logical operator?

A. &
B. |
C. &&
D. !

25 Which concept allows a primitive int to be assigned directly to an Integer object?

A. Type Casting
B. Autoboxing
C. Unboxing
D. Polymorphism

26 What is the correct syntax for a switch statement?

A. switch(x) { case 1: ... }
B. switch(x) { when 1: ... }
C. select(x) { case 1: ... }
D. case(x) { switch 1: ... }

27 Which of these is NOT a Java keyword?

A. transient
B. volatile
C. sizeof
D. synchronized

28 What is the decimal value of the octal literal 010?

A. 10
B. 8
C. 2
D. 16

29 What is the return type of the assignment operator (e.g., a = 5) in Java?

A. void
B. boolean
C. The value assigned
D. null

30 Which of the following types is allowed in a switch case expression in Java 7 and later?

A. long
B. double
C. float
D. String

31 What is the value of x after: int x = 5; int y = x++;?

A. 5
B. 6
C. 4
D. Runtime Error

32 Which statement is true regarding the break statement in a switch block?

A. It is mandatory for every case.
B. It stops the execution of the switch block.
C. It restarts the switch block.
D. It is used to check the next case.

33 Java uses Unicode to represent characters. How many bits does a Java char occupy?

A. 8 bits
B. 16 bits
C. 32 bits
D. 7 bits

34 What is the output of System.out.println(10 + 20 + "Java");?

A. 1020Java
B. 30Java
C. Java1020
D. Error

35 Which operator is used to perform a bitwise Exclusive OR (XOR)?

A. |
B. &
C. ^
D. !

36 What is the default value of an instance variable of type Object?

A.
B. undefined
C. null
D. Object()

37 Which method is used to convert a String like "123" into an integer primitive?

A. Integer.toString()
B. Integer.parseInt()
C. (int)"123"
D. Integer.valueOf()

38 Identify the bitwise operator that preserves the sign bit during a right shift.

A. >>
B. >>>
C. <<
D. <<<

39 If int a = 10;, what is the value of ~a (bitwise complement)?

A. -10
B. -11
C. 9
D. 5

40 Which syntax is correct to define a single-line comment in Java?

A. # Comment
B. / Comment /
C. // Comment
D. <!-- Comment -->

41 What is the purpose of the args array in the main method?

A. To store the return value
B. To store command-line arguments
C. To store local variables
D. To import packages

42 Which of these assignments causes a compilation error?

A. double d = 100;
B. float f = 10.5;
C. int i = 'A';
D. long l = 100;

43 What is the associativity of the assignment operator =?

A. Left to Right
B. Right to Left
C. Random
D. Center out

44 Can the main method be overloaded in Java?

A. Yes
B. No
C. Only in abstract classes
D. Only in interfaces

45 Which control flow statement is best used when there are many specific distinct values to check against a single variable?

A. if-else
B. for loop
C. while loop
D. switch-case

46 Which data type has the widest range?

A. int
B. long
C. float
D. double

47 What happens if a static method calls a non-static method directly without an instance?

A. It works fine
B. Runtime Exception
C. Compile-time Error
D. Warning

48 What is the correct way to declare a float variable?

A. float f = 3.14;
B. float f = 3.14f;
C. float f = (float) 3.14d;
D. Both B and C

49 The J in J2SE stands for?

A. JavaScript
B. Junit
C. Java
D. JSharp

50 Which statement about the default case in a switch block is true?

A. It must be the last case.
B. It executes only if no other case matches.
C. It is mandatory.
D. It requires a break statement.