![Java MCQ with Answers [2023]](https://edukar.in/wp-content/uploads/2022/12/Java-MCQ-1024x640.webp)
1) Which of the following choices makes Java portable and secure?
- Use of exception handling
- Java code is made secure and portable by the applet.
- Bytecode is executed by JVM
- Dynamic binding between objects
Answer: Bytecode is executed by JVM
2) Among the following, which are not Java features?
- Dynamic
- Architecture Neutral
- Use of pointers
- Object-oriented
Answer. Use of pointers
3) The \u0021 article termed to as a
- Unicode escape sequence
- Octal escape
- Hexadecimal
- Line feed
Answer. Unicode escape sequence
4) What one of the following qualifies as a proper char declaration?
- char ch = ‘\utea’;
- char ca = ‘tea’;
- char cr = \u0223;
- char cc = ‘\itea’;
Answer. char ch = ‘\utea’;
6) To locate and correct issues in Java programs, ____ is utilised.
- JVM
- JRE
- JDK
- JDB
Answer. JDB
7) Of the following, which is a legitimate long literal?
- ABH8097
- L990023
- 904423
- 0xnf029L
Answer. 0xnf029L
8) What type of value does the hashCode() method in the Object class return?
- Object
- int
- long
- void
Answer. Int
9) What is the result of the expression float a = 35 / 0?
- 0
- Not a Number
- Infinity
- Run time exception
Answer. Infinity
10) Which of the following tools is used to create HTML-formatted API documentation from source code doc comments?
- javap tool
- Java w command
- Javadoc tool
- Java h command
Answer. Javadoc tool
11) Which of the following statements for a for loop is invalid?
- for ( int i = 99; i >= 0; i / 9 )
- for ( int i = 7; i <= 77; i += 7 )
- for ( int i = 20; i >= 2; – -i )
- for ( int i = 2; i <= 20; i = 2* i )
Answer. for ( int i = 99; i >= 0; i / 9 )
12) Which of the following processes has a local variable with the same name as an instance variable?
- Serialisation
- Variable Shadowing
- Abstraction
- Multi-threading
Answer. Variable Shadowing
13) Which statement regarding the anonymous inner class is accurate?
- It has only methods
- Objects can’t be created
- It has a fixed class name
- It has no class name
Answer. It has no class name
14) A _____ is a user interface that has no fields or methods.
- Runnable Interface
- Marker Interface
- Abstract Interface
- CharSequence Interface
Answer. Marker Interface
15) What do you mean by the term nameless objects?
- An item produced through the use of the new keyword.
- A superclass object produced by a subclass.
- An object without having any name but having a reference.
- An object that has no reference.
Answer. An object that has no reference.
16) Which of these classes directly derives from the Throwable class?
- RuntimeException and Error class
- Exception and VirtualMachineError class
- Error and Exception class
- IOException and VirtualMachineError class
Answer. Error and Exception class
17)The Panel class has which of the following as an immediate subclass??
- Applet class
- Window class
- Frame class
- Dialog class
Answer. Applet class
18) Which statement regarding the last keyword is untrue?
- A final method can’t be changed in a subclass.
- A final class cannot be extended.
- A final class cannot extend other classes.
- A final method can be inherited.
Answer. A final class cannot extend other classes.
19) What exactly do you mean by Java chained exceptions?
- Exceptions occurred by the VirtualMachineError
- An exception caused by other exceptions
- Chains of exceptions happen when the debugging data is discarded
- None of the above
Answer. An exception caused by other exceptions
20) What purpose does the intern() method serve?
- It returns the existing string from memory
- In the database, a new string is produced.
- It alters the string that already exists in the database.
- None of the above
Answer. It returns the existing string from memory
21) Which of the following corresponds to a Java reserved keyword?
- object
- strictfp
- main
- system
Answer. Strictfp
22) Jar refers for ___ in Java.
- Java Archive Runner
- Java Application Resource
- Java Application Runner
- None of the above
Answer. None of the above
23) To access a package’s functionalities, which term is used?
- package
- import
- extends
- export
Answer. Import
24) What function does \w serve in a regex?
- Used for a whitespace character
- Used for a non-whitespace character
- Used for a word character
- Used for a non-word character
Answer. Used for a word character
25) Of the following, which is untrue?
- The rt.jar stands for the runtime jar
- It is an optional jar file
- It contains all the compiled class files
- The JVM is aware of all the classes in rt.jar.
Answer. It is an optional jar file
26) Which of these elements is used for the compilation, debugging, and execution of a Java program?
a. JDK
b. JVM
c. JRE
d. JIT
Answer: JDK
27) Which of these literals can be stored in a variable with the float data type?
a. -3.4e+050
b. +1.7e+308
c. -3.4e+038
d. -1.7e+308
Answer: -3.4e+038
28) BigDecimal.ONE: What is it?
a. it is a custom-defined statement
b. it is a wrong statement
c. It is a static variable with a value of 1 on a scale of 0
d. It is a static variable with a value of 1 on a scale of 10.
Answer: It is a static variable with a value of 1 on a scale of 0
29) When an expression contains the data types int, double, long, and float, the entire expression will be converted into one of the following data types:
a. float
b. double
c. int
d. long
Answer: double
30) Which of the subsequent operations is applicable to boolean variables?
A. &&
B. ==
C. ?:
D. +=
a) C & B
b) A & D
c) A, B & D
d) A, B & C
Answer: A, B & C
31) Which of these is the proper approach for the subclass B to call the constructor of the superclass A that has no parameters?
a. superclass.();
b. super(void);
c. super();
d. super.A();
Answer: super();
32) Which of these Object class methods is capable of cloning an object?
a. Object clone()
b. clone()
c. Object copy()
d. copy()
Answer: Object clone()
33) Which one of these packages includes an abstract keyword?
a. java.util
b. java.lang
c. java.system
d. java.io
Answer: java.lang
34) Which of these techniques can be used to turn a String’s whole character set into an array of characters?
a. both getChars() & toCharArray()
b. both charAt() & getChars()
d. charAt()
d. all of the mentioned
Answer: both getChars() & toCharArray()
35) In the event where the initiating string is longer than the compared string, what result is returned by the compareTo() function?
a. a value that is greater than 0
b. a value that is less than 0
c. zero
d. none of the above
Answer: a value that is greater than zero
36) Which one of the following exceptions is thrown by the double-wrapped compareTo() method?
a. SystemException
b. ClassCastException
c. IOException
d. CastException
Answer: ClassCastException
37) What place is the String Pool kept?
a. Metaspace
b. Java Stack
c. Java Heap
d. Permanent Generation
Answer: Java Heap
38) Which of these HttpResponse class data elements is used to store the response received from a http server?
a. address
b. status
c. statusCode
d. statusResponse
Answer: statusCode
39) Which of these techniques produces the raw MIME formatted string?
a. toString()
b. getString()
c. parse()
d. parseString()
Answer: parse()
40) Which of these exceptions is thrown by the remover() method:
a. ObjectNotFoundException
b. IllegalStateException
c. IOException
d. SystemException
Answer: IllegalStateException
41) Which of the following contains all exceptions type classes as its superclass?
a. String
b. RuntimeExceptions
c. Catchable
d. Throwable
Answer: Throwable
42) What occurs when we request that two threads with the same priority run simultaneously?
a. Both of the threads will be simultaneously executed
b. Lexically, any one of the threads may be run first.
c. It Depends on the OS
d. There won’t be any thread execution.
Answer: It Depends on the OS
43) Which of these classes is used to read strings and characters from the console into Java?
a. StringReader
b. BufferedReader
c. InputStreamReader
d. BufferedStreamReader
Answer: BufferedReader
44) Which of these operations can be used to obtain an object’s run-time information?
a. Info
b. getInfo
c. getinfo of
d. instanceof
Answer: instanceof
45) Which of these classes permits the user to specify their own formatting style for times and dates?
a. UsersDateFormat
b. ComplexDateFormat
c. SimpleDateFormat
d. DefinedDateFormat
Answer: SimpleDateFormat
46) Which approach is appropriate for an applet’s output of a string?
a. transient()
b. drawString()
c. print()
d. display()
Answer: drawString()
47) What does the public int start() return?
a. starting with the previous match’s start index
b. the current match’s starting index
c. the input string’s starting index
d. None of the above
Answer: starting with the previous match’s start index
48) Which action variable facilitates the JSP’s inclusion of a file?
a) jsp:plugin
b) jsp:include
c) jsp:getProperty
d) jsp:setProperty
Answer: jsp:include
49) Maven defines dependencies in the _____ file.
a) dependency.xml
b) build.xml
c) version.xml
d) pom.xml
Answer: pom.xml
50) Closeable and AutoCloseable are distinguished primarily by the following features:
a) AutoCloseable throws IOException; Closeable throws Exception
b) Closeable is a notion, while AutoCloseable is an implementation of it.
c) AutoCloseable throws Exception; Closeable throws IOException
d) Closeable is an interface, while AutoCloseable is a concrete class.
Answer: AutoCloseable throws Exception; Closeable throws IOException