Latest Government Jobs updates 2023
500+ Essay Ideas & Topics
500+ Advantages and Disadvantages Topics
500+Topics for Speech in English

Java MCQ with Answers [2023]

Rate this post
Java MCQ with Answers [2023]

1) Which of the following choices makes Java portable and secure?

  1. Use of exception handling
  2. Java code is made secure and portable by the applet.
  3. Bytecode is executed by JVM
  4. Dynamic binding between objects

Answer:  Bytecode is executed by JVM

2) Among the following, which are not Java features?

  1. Dynamic
  2. Architecture Neutral
  3. Use of pointers
  4. Object-oriented

Answer. Use of pointers

3) The \u0021 article termed to as a

  1. Unicode escape sequence
  2. Octal escape
  3. Hexadecimal
  4. Line feed

Answer. Unicode escape sequence

4) What one of the following qualifies as a proper char declaration?

  1. char ch = ‘\utea’;
  2. char ca = ‘tea’;
  3. char cr = \u0223;
  4. char cc = ‘\itea’;

Answer. char ch = ‘\utea’;

6) To locate and correct issues in Java programs, ____ is utilised.

  1. JVM
  2. JRE
  3. JDK
  4. JDB

Answer. JDB

7) Of the following, which is a legitimate long literal?

  1. ABH8097
  2. L990023
  3. 904423
  4. 0xnf029L

Answer. 0xnf029L

8) What type of value does the hashCode() method in the Object class return?

  1. Object
  2. int
  3. long
  4. void

Answer. Int

9) What is the result of the expression float a = 35 / 0?

  1. 0
  2. Not a Number
  3. Infinity
  4. Run time exception

Answer. Infinity

10) Which of the following tools is used to create HTML-formatted API documentation from source code doc comments?

  1. javap tool
  2. Java w command
  3. Javadoc tool
  4. Java h command

Answer. Javadoc tool

11) Which of the following statements for a for loop is invalid?

  1. for ( int i = 99; i >= 0; i / 9 )
  2. for ( int i = 7; i <= 77; i += 7 )
  3. for ( int i = 20; i >= 2; – -i )
  4. 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?

  1. Serialisation
  2. Variable Shadowing
  3. Abstraction
  4. Multi-threading

Answer. Variable Shadowing

13) Which statement regarding the anonymous inner class is accurate?

  1. It has only methods
  2. Objects can’t be created
  3. It has a fixed class name
  4. It has no class name

Answer. It has no class name

14) A _____ is a user interface that has no fields or methods.

  1. Runnable Interface
  2. Marker Interface
  3. Abstract Interface
  4. CharSequence Interface

Answer. Marker Interface

15) What do you mean by the term nameless objects?

  1. An item produced through the use of the new keyword.
  2. A superclass object produced by a subclass.
  3. An object without having any name but having a reference.
  4. An object that has no reference.
See also  Operating System MCQ (Multiple Choice Questions)

Answer. An object that has no reference.

16) Which of these classes directly derives from the Throwable class?

  1. RuntimeException and Error class
  2. Exception and VirtualMachineError class
  3. Error and Exception class
  4. IOException and VirtualMachineError class

Answer. Error and Exception class

17)The Panel class has which of the following as an immediate subclass??

  1. Applet class
  2. Window class
  3. Frame class
  4. Dialog class

Answer. Applet class

18) Which statement regarding the last keyword is untrue?

  1. A final method can’t be changed in a subclass.
  2. A final class cannot be extended.
  3. A final class cannot extend other classes.
  4. A final method can be inherited.

Answer. A final class cannot extend other classes.

19) What exactly do you mean by Java chained exceptions?

  1. Exceptions occurred by the VirtualMachineError
  2. An exception caused by other exceptions
  3. Chains of exceptions happen when the debugging data is discarded
  4. None of the above

Answer. An exception caused by other exceptions

20) What purpose does the intern() method serve?

  1. It returns the existing string from memory
  2. In the database, a new string is produced.
  3. It alters the string that already exists in the database.
  4. None of the above

Answer. It returns the existing string from memory

21) Which of the following corresponds to a Java reserved keyword?

  1. object
  2. strictfp
  3. main
  4. system

Answer. Strictfp

22) Jar refers for ___ in Java.

  1. Java Archive Runner
  2. Java Application Resource
  3. Java Application Runner
  4. None of the above

Answer. None of the above

23) To access a package’s functionalities, which term is used?

  1. package
  2. import
  3. extends
  4. export

Answer. Import

24) What function does \w serve in a regex?

  1. Used for a whitespace character
  2. Used for a non-whitespace character
  3. Used for a word character
  4. Used for a non-word character

Answer. Used for a word character

25) Of the following, which is untrue?

  1. The rt.jar stands for the runtime jar
  2. It is an optional jar file
  3. It contains all the compiled class files
  4. 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?

See also  [MCQ] Introduction to Computer Online Test

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


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

See also  Chemical Coordination And Integration MCQ

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

Leave a Comment

a to z