1Who is known as the primary inventor of the Java programming language?
A.Dennis Ritchie
B.James Gosling
C.Bjarne Stroustrup
D.Guido van Rossum
Correct Answer: James Gosling
Explanation:James Gosling initiated the Java language project in June 1991 for use in one of his many set-top box projects.
Incorrect! Try again.
2Which 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)
Correct Answer: public static void main(String args[])
Explanation:The main method must be public (accessible by JVM), static (called without object), void (returns nothing), and take a String array as arguments.
Incorrect! Try again.
3What was the original name of the Java programming language?
A.Oak
B.Pine
C.C++--
D.JScript
Correct Answer: Oak
Explanation:Java was originally called Oak after an oak tree that stood outside James Gosling's office. It was later renamed Java.
Incorrect! Try again.
4Which component is responsible for converting bytecode into machine-specific code?
A.JDK
B.JVM
C.JRE
D.JIT
Correct Answer: JVM
Explanation:The JVM (Java Virtual Machine) interprets the bytecode and translates it into machine code for the specific platform it is running on.
Incorrect! Try again.
5What 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
Correct Answer: The source code is compiled into intermediate Bytecode
Explanation:Java compilers generate Bytecode (.class files), which is platform-agnostic. Any machine with a JVM can execute this bytecode, adhering to 'Write Once, Run Anywhere'.
Incorrect! Try again.
6Which of the following statements accurately describes the relationship between JDK, JRE, and JVM?
A.
B.
C.
D.
Correct Answer:
Explanation:The JVM is the core execution engine. The JRE contains the JVM plus libraries. The JDK contains the JRE plus development tools (compilers, debuggers). Therefore, JVM is inside JRE, which is inside JDK.
Incorrect! Try again.
7What 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
Correct Answer: 32 bits
Explanation:In Java, the size of primitive data types is fixed to ensure portability. An int is always 32 bits (4 bytes).
Incorrect! Try again.
8Which of the following is NOT a valid Java identifier?
A._myVariable
B.$value
C.1stVariable
D.variable1
Correct Answer: 1stVariable
Explanation:Identifiers in Java cannot start with a digit. They can start with a letter, an underscore _, or a currency character like $.
Incorrect! Try again.
9What is the default value of a local variable defined inside a method?
A.null
B.
C.false
D.No default value (Must be initialized)
Correct Answer: No default value (Must be initialized)
Explanation:Local variables (stack variables) do not get default values in Java. They must be explicitly initialized before use, otherwise a compile-time error occurs.
Incorrect! Try again.
10Which keyword is used to declare a constant variable in Java?
A.const
B.final
C.static
D.immutable
Correct Answer: final
Explanation:The final keyword is used to apply restrictions on class, method, and variable. For a variable, final means its value cannot be changed once initialized.
Incorrect! Try again.
11In the statement byte b = (byte) 130;, what is the result of the narrowing conversion?
A.130
B.-126
C.127
D.Compilation Error
Correct Answer: -126
Explanation:A byte ranges from -128 to 127. When 130 (binary 0000...10000010) is cast to byte (8 bits), the leading bits are truncated, leaving 10000010. In 2's complement, this represents .
Incorrect! Try again.
12What is the output of the bitwise operation ?
A.1
B.3
C.5
D.7
Correct Answer: 1
Explanation:5 in binary is 101. 3 in binary is 011. Performing bitwise AND (&): 101 & 011 = 001, which is decimal 1.
Incorrect! Try again.
13Which wrapper class corresponds to the char primitive type?
A.Char
B.Character
C.String
D.Text
Correct Answer: Character
Explanation:The wrapper class for the primitive type char is java.lang.Character.
Incorrect! Try again.
14What 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
Correct Answer: The variable belongs to the class, not instances
Explanation:A static variable is a class-level variable. A single copy is shared among all instances of that class.
Incorrect! Try again.
15Evaluate the following expression assuming standard precedence:
A.90
B.70
C.60
D.30
Correct Answer: 70
Explanation:Multiplication (*) has higher precedence than addition (+). So, , then .
Incorrect! Try again.
16Which command is used to compile a Java source file?
A.java
B.javac
C.javadoc
D.jar
Correct Answer: javac
Explanation:javac (Java Compiler) is the command-line utility included in the JDK to compile .java files into .class files.
Incorrect! Try again.
17What is the output of the following ternary operator usage? int x = (5 > 10) ? 10 : 20;
A.5
B.10
C.20
D.true
Correct Answer: 20
Explanation:The condition 5 > 10 is false. Therefore, the ternary operator returns the second value (after the colon), which is 20.
Incorrect! Try again.
18Which access modifier makes a member accessible only within the same class?
A.public
B.protected
C.default
D.private
Correct Answer: private
Explanation:private is the most restrictive access modifier. Members marked private are only accessible within the class they are declared in.
Incorrect! Try again.
19What is the result of 10 % 3?
A.3.33
B.3
C.1
D.
Correct Answer: 1
Explanation:The modulus operator % returns the remainder of the division. is 3 with a remainder of 1.
Incorrect! Try again.
20If 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
Correct Answer: public class Test
Explanation:If a class is declared public, the filename must match the class name. Therefore, Test.java must contain public class Test.
Incorrect! Try again.
21Which data type would be best suited to store a flag that is either true or false?
A.int
B.short
C.boolean
D.byte
Correct Answer: boolean
Explanation:The boolean data type is designed specifically to store two possible values: true and false.
Incorrect! Try again.
22What 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
Correct Answer: ArrayIndexOutOfBoundsException
Explanation:If code attempts to access args[i] where i is greater than or equal to the length of the array provided at runtime, an ArrayIndexOutOfBoundsException is thrown.
Incorrect! Try again.
23What is the result of the left shift operator: ?
A.2
B.4
C.16
D.32
Correct Answer: 32
Explanation:Left shifting by bits is equivalent to multiplying by . .
Incorrect! Try again.
24Which of the following is a 'short-circuit' logical operator?
A.&
B.|
C.&&
D.!
Correct Answer: &&
Explanation:The && (logical AND) operator is short-circuiting. If the left operand is false, the right operand is not evaluated because the result is already known to be false.
Incorrect! Try again.
25Which concept allows a primitive int to be assigned directly to an Integer object?
A.Type Casting
B.Autoboxing
C.Unboxing
D.Polymorphism
Correct Answer: Autoboxing
Explanation:Autoboxing is the automatic conversion that the Java compiler makes between the primitive types and their corresponding object wrapper classes (e.g., int to Integer).
Incorrect! Try again.
26What 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: ... }
Correct Answer: switch(x) { case 1: ... }
Explanation:The standard syntax involves the keyword switch followed by the variable in parentheses, and case labels inside the block.
Incorrect! Try again.
27Which of these is NOT a Java keyword?
A.transient
B.volatile
C.sizeof
D.synchronized
Correct Answer: sizeof
Explanation:sizeof is a keyword in C/C++, but not in Java. Java does not expose the size of types directly to the programmer.
Incorrect! Try again.
28What is the decimal value of the octal literal 010?
A.10
B.8
C.2
D.16
Correct Answer: 8
Explanation:An integer literal starting with 0 is interpreted as octal (base 8). .
Incorrect! Try again.
29What is the return type of the assignment operator (e.g., a = 5) in Java?
A.void
B.boolean
C.The value assigned
D.null
Correct Answer: The value assigned
Explanation:The assignment expression evaluates to the value that was assigned. This allows chained assignments like a = b = 5.
Incorrect! Try again.
30Which of the following types is allowed in a switch case expression in Java 7 and later?
A.long
B.double
C.float
D.String
Correct Answer: String
Explanation:From Java 7 onwards, the switch statement supports String objects. It does not support long, float, or double.
Incorrect! Try again.
31What is the value of x after: int x = 5; int y = x++;?
A.5
B.6
C.4
D.Runtime Error
Correct Answer: 6
Explanation:The post-increment operator x++ returns the original value (5) to y, and then increments x. So y becomes 5, but x becomes 6.
Incorrect! Try again.
32Which 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.
Correct Answer: It stops the execution of the switch block.
Explanation:The break statement terminates the closest enclosing switch, while, or for statement. Without it, execution 'falls through' to the next case.
Incorrect! Try again.
33Java 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
Correct Answer: 16 bits
Explanation:Java char uses the UTF-16 encoding (originally intended for UCS-2), occupying 2 bytes or 16 bits.
Incorrect! Try again.
34What is the output of System.out.println(10 + 20 + "Java");?
A.1020Java
B.30Java
C.Java1020
D.Error
Correct Answer: 30Java
Explanation:Java evaluates from left to right. 10 + 20 (integers) results in 30. Then 30 + "Java" performs string concatenation.
Incorrect! Try again.
35Which operator is used to perform a bitwise Exclusive OR (XOR)?
A.|
B.&
C.^
D.!
Correct Answer: ^
Explanation:The ^ operator compares corresponding bits of two operands. If the bits are different, the result is 1; otherwise, 0.
Incorrect! Try again.
36What is the default value of an instance variable of type Object?
A.
B.undefined
C.null
D.Object()
Correct Answer: null
Explanation:Instance variables of reference types (classes, arrays, interfaces) default to null if not explicitly initialized.
Incorrect! Try again.
37Which 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()
Correct Answer: Integer.parseInt()
Explanation:Integer.parseInt("123") parses the string argument as a signed decimal integer primitive.
Incorrect! Try again.
38Identify the bitwise operator that preserves the sign bit during a right shift.
A.>>
B.>>>
C.<<
D.<<<
Correct Answer: >>
Explanation:>> is the signed right shift operator. It fills the new high-order bits with the value of the original sign bit (arithmetic shift).
Incorrect! Try again.
39If int a = 10;, what is the value of ~a (bitwise complement)?
A.-10
B.-11
C.9
D.5
Correct Answer: -11
Explanation:The bitwise complement ~x yields . So, .
Incorrect! Try again.
40Which syntax is correct to define a single-line comment in Java?
A.# Comment
B./ Comment /
C.// Comment
D.<!-- Comment -->
Correct Answer: // Comment
Explanation:Java uses // for single-line comments and /* ... */ for multi-line comments.
Incorrect! Try again.
41What 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
Correct Answer: To store command-line arguments
Explanation:The String[] args parameter captures arguments passed to the application from the command line when it is launched.
Incorrect! Try again.
42Which of these assignments causes a compilation error?
A.double d = 100;
B.float f = 10.5;
C.int i = 'A';
D.long l = 100;
Correct Answer: float f = 10.5;
Explanation:By default, decimal literals like 10.5 are treated as double. Assigning a double to a float requires a suffix f (e.g., 10.5f) or a cast, otherwise, it's a lossy conversion error.
Incorrect! Try again.
43What is the associativity of the assignment operator =?
A.Left to Right
B.Right to Left
C.Random
D.Center out
Correct Answer: Right to Left
Explanation:Assignment operators are associative from right to left. E.g., in a = b = c, b=c is evaluated first.
Incorrect! Try again.
44Can the main method be overloaded in Java?
A.Yes
B.No
C.Only in abstract classes
D.Only in interfaces
Correct Answer: Yes
Explanation:Yes, you can have multiple methods named main with different signatures (overloading), but the JVM will only call the specific public static void main(String[] args) signature to start the program.
Incorrect! Try again.
45Which 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
Correct Answer: switch-case
Explanation:The switch-case statement is designed for multi-way branching based on the value of a single variable, making it cleaner than many nested if-else statements.
Incorrect! Try again.
46Which data type has the widest range?
A.int
B.long
C.float
D.double
Correct Answer: double
Explanation:While long (64-bit integer) has a large range, double (64-bit floating point) can represent much larger numbers due to the exponent representation, though with less precision for large integers.
Incorrect! Try again.
47What 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
Correct Answer: Compile-time Error
Explanation:Static methods belong to the class context, while non-static methods need an object instance (this). A static context cannot access instance members directly.
Incorrect! Try again.
48What 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
Correct Answer: Both B and C
Explanation:3.14 is a double literal. You must append 'f' (3.14f) or explicitly cast it ((float) 3.14) to assign it to a float variable.
Incorrect! Try again.
49The J in J2SE stands for?
A.JavaScript
B.Junit
C.Java
D.JSharp
Correct Answer: Java
Explanation:J2SE stands for Java 2 Platform, Standard Edition (now generally referred to as Java SE).
Incorrect! Try again.
50Which 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.
Correct Answer: It executes only if no other case matches.
Explanation:The default block is optional and executes if none of the case constants match the switch expression. It does not strictly have to be the last case syntactically, though it usually is.
Incorrect! Try again.
Give Feedback
Help us improve by sharing your thoughts or reporting issues.