Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

Which system property stores installation directory of JRE?(a) user.home(b) java.class.path(c) java.home(d) user.dirThe question was asked by my school principal while I was bunking the class.This interesting question is from Environment Properties topic in portion Exploring java.lang & java.io of Java

Answer»

Correct choice is (c) JAVA.home

To explain I WOULD SAY: java.home is the INSTALLATION directory of Java Runtime Environment.

2.

Java system properties can be set at runtime.(a) True(b) FalseI had been asked this question in an interview for internship.Question is taken from Environment Properties in section Exploring java.lang & java.io of Java

Answer»

Correct choice is (a) True

To explain I would say: Java SYSTEM PROPERTIES can be SET at RUNTIME using System.setProperty(name, value) or using System.getProperties().load() METHODS.

3.

Which of the following is true about Java system properties?(a) Java system properties are accessible by any process(b) Java system properties are accessible by processes they are added to(c) Java system properties are retrieved by System.getenv()(d) Java system properties are set by System.setenv()I had been asked this question by my college professor while I was bunking the class.I want to ask this question from Environment Properties in section Exploring java.lang & java.io of Java

Answer»

Right ANSWER is (B) Java system properties are accessible by PROCESSES they are ADDED to

For explanation: Java system properties are only USED and accessible by the processes they are added.

4.

Which object Java application uses to create a new process?(a) Process(b) Builder(c) ProcessBuilder(d) CreateBuilderThe question was asked by my college professor while I was bunking the class.My question is based upon Environment Properties in chapter Exploring java.lang & java.io of Java

Answer»

Right choice is (c) PROCESSBUILDER

The best I can explain: Java APPLICATION uses ProcessBuilder object to create a new process. By default, same set of ENVIRONMENT VARIABLES passed which are set in application’s virtual machine process.

5.

Which of this interface is implemented by Thread class?(a) Runnable(b) Connections(c) Set(d) MapConnectionsThe question was posed to me in semester exam.This is a very interesting question from Java.lang in portion Exploring java.lang & java.io of Java

Answer» RIGHT ANSWER is (a) Runnable

The EXPLANATION is: NONE.
6.

Which of these methods of a Thread class is used to suspend a thread for a period of time?(a) sleep()(b) terminate()(c) suspend()(d) stop()I had been asked this question in homework.My enquiry is from Java.lang topic in section Exploring java.lang & java.io of Java

Answer»

Right option is (a) SLEEP()

The best EXPLANATION: NONE.

7.

Which of the interface contains all the methods used for handling thread related operations in Java?(a) Runnable interface(b) Math interface(c) System interface(d) ThreadHandling interfaceThe question was asked in class test.I'd like to ask this question from Java.lang topic in section Exploring java.lang & java.io of Java

Answer»

Right ANSWER is (a) Runnable INTERFACE

Explanation: Runnable interface defines all the METHODS for handling THREAD OPERATIONS in Java.

8.

Which of these class is used to make a thread?(a) String(b) System(c) Thread(d) RunnableThe question was asked in a national level competition.This intriguing question comes from Java.lang topic in section Exploring java.lang & java.io of Java

Answer»

Correct choice is (c) THREAD

Best EXPLANATION: Thread CLASS is used to make threads in java, Thread encapsulates a thread of EXECUTION. To create a new thread the program will either extend Thread or IMPLEMENT the Runnable interface.

9.

Which of these methods return a class object given its name?(a) getClass()(b) findClass()(c) getSystemClass()(d) findSystemClass()I have been asked this question in an online interview.I would like to ask this question from Java.lang topic in division Exploring java.lang & java.io of Java

Answer» CORRECT choice is (d) findSystemClass()

Easiest explanation: findSystemClass() returnsa CLASS object GIVEN its NAME.
10.

Which of these methods returns the class of an object?(a) getClass()(b) Class()(c) WhoseClass()(d) WhoseObject()I had been asked this question by my college director while I was bunking the class.My enquiry is from Java.lang in portion Exploring java.lang & java.io of Java

Answer» RIGHT option is (a) GETCLASS()

The best explanation: NONE.
11.

Which of these methods returns the total number of bytes of memory available to the program?(a) getMemory()(b) TotalMemory()(c) SystemMemory()(d) getProcessMemory()I had been asked this question during an internship interview.My question comes from Java.lang in division Exploring java.lang & java.io of Java

Answer»

Right option is (B) TotalMemory()

To ELABORATE: TotalMemory() returns the TOTAL number of BYTES AVAILABLE to the program.

12.

Which of these classes encapsulate runtime state of an object?(a) Class(b) System(c) Runtime(d) CacheThis question was posed to me during a job interview.My query is from Java.lang topic in division Exploring java.lang & java.io of Java

Answer» CORRECT CHOICE is (a) Class

The EXPLANATION is: NONE.
13.

Which of the following exceptions is thrown by every method of Runtime class?(a) IOException(b) SystemException(c) SecurityException(d) RuntimeExceptionI had been asked this question in an interview for job.My question comes from Java.lang in division Exploring java.lang & java.io of Java

Answer»

The correct ANSWER is (C) SecurityException

The best I can EXPLAIN: EVERY method of Runtime class THROWS SecurityException.

14.

Which of these classes encapsulate runtime environment?(a) Class(b) System(c) Runtime(d) ClassLoaderI had been asked this question in a job interview.This is a very interesting question from Java.lang in chapter Exploring java.lang & java.io of Java

Answer»

The CORRECT ANSWER is (C) Runtime

Easiest EXPLANATION: NONE.

15.

toRadian() and toDegree() methods were added by which version of Java?(a) Java 1.0(b) Java 1.5(c) Java 2.0(d) Java 3.0The question was asked in an interview for job.Question is from Java.lang in portion Exploring java.lang & java.io of Java

Answer»

The CORRECT choice is (c) JAVA 2.0

Easiest explanation: toRadian() and TODEGREE() methods were ADDED by Java 2.0 before that there was no method which could directly convert degree into radians and vice VERSA.

16.

Which of these method converts radians to degrees?(a) toRadian()(b) toDegree()(c) convertRadian()(d) converDegree()I got this question in semester exam.Origin of the question is Java.lang in chapter Exploring java.lang & java.io of Java

Answer» CORRECT choice is (B) TODEGREE()

The EXPLANATION: None.
17.

Which of these method returns the remainder of dividend / divisor?(a) remainder()(b) getRemainder()(c) CSIremainder()(d) IEEEremainder()I had been asked this question during an internship interview.My enquiry is from Java.lang topic in division Exploring java.lang & java.io of Java

Answer»

The correct CHOICE is (d) IEEEremainder()

EXPLANATION: IEEEremainder() returns the REMAINDER of DIVIDEND / DIVISOR.

18.

Which of these method return a pseudorandom number?(a) rand()(b) random()(c) randomNumber()(d) randGenerator()I had been asked this question in an interview.I need to ask this question from Java.lang topic in section Exploring java.lang & java.io of Java

Answer»

Correct OPTION is (B) RANDOM()

BEST explanation: NONE.

19.

Which of these class contains all the methods present in Math class?(a) SystemMath(b) StrictMath(c) Compiler(d) ClassLoaderThe question was posed to me by my college director while I was bunking the class.Enquiry is from Java.lang topic in section Exploring java.lang & java.io of Java

Answer»

The correct choice is (b) StrictMath

Easy EXPLANATION: SystemMath class defines a complete set of MATHEMATICAL methods that are parallel those in Math class. The DIFFERENCE is that the StrictMath version is guaranteed to GENERATE precisely identical results across all Java implementations.

20.

Which of these methods is used to know whether a string contains “true”?(a) valueOf()(b) valueOfString()(c) getString()(d) none of the mentionedI got this question by my college director while I was bunking the class.My enquiry is from Java.lang topic in section Exploring java.lang & java.io of Java

Answer» RIGHT answer is (a) valueOf()

Best explanation: valueOf() RETURNS true if the specified string contains “true” in lower or UPPERCASE and FALSE OTHERWISE.
21.

Which of these methods return string equivalent of Boolean object?(a) getString()(b) toString()(c) converString()(d) getStringObject()This question was addressed to me in my homework.My query is from Java.lang topic in portion Exploring java.lang & java.io of Java

Answer» RIGHT OPTION is (B) TOSTRING()

The explanation: None.
22.

Which of the following constant are defined in Boolean wrapper?(a) TRUE(b) FALSE(c) TYPE(d) All of the mentionedThis question was posed to me in my homework.This interesting question is from Java.lang topic in section Exploring java.lang & java.io of Java

Answer»

Correct OPTION is (d) All of the mentioned

Explanation: Boolean wrapper defines 3 constants – TRUE, FALSE & TYPE.

23.

Which of these methods is used to know whether a given Character object is part of Java’s Identifiers?(a) isIdentifier()(b) isJavaIdentifier()(c) isJavaIdentifierPart()(d) none of the mentionedI had been asked this question during an internship interview.My question is based upon Java.lang topic in portion Exploring java.lang & java.io of Java

Answer»

The CORRECT CHOICE is (C) isJavaIdentifierPart()

For EXPLANATION: NONE.

24.

Which of these is a super class of Character wrapper?(a) Long(b) Digits(c) Float(d) NumberI have been asked this question in an interview.Asked question is from Java.lang topic in section Exploring java.lang & java.io of Java

Answer»

Right choice is (d) Number

Explanation: Number is an abstract CLASS containing SUBCLASSES DOUBLE, FLOAT, Byte, Short, CHARACTER, Integer and Long.

25.

Which of these methods of Boolean wrapper returns boolean equivalent of an object.(a) getBool()(b) booleanValue()(c) getbooleanValue()(d) getboolValue()I had been asked this question during an online interview.My question is taken from Java.lang in portion Exploring java.lang & java.io of Java

Answer» CORRECT OPTION is (B) booleanValue()

For EXPLANATION: NONE.
26.

Which of these methods of Character wrapper can be used to obtain the char value contained in Character object.(a) get()(b) getVhar()(c) charValue()(d) getCharacter()The question was posed to me during an interview for a job.Asked question is from Java.lang in section Exploring java.lang & java.io of Java

Answer»

Correct ANSWER is (c) charValue()

Easy explanation: To obtain the CHAR VALUE CONTAINED in a Character OBJECT, we use charValue() method.

27.

Which of the following constant are defined in Character wrapper?(a) MAX_RADIX(b) MAX_VALUE(c) TYPE(d) All of the mentionedI had been asked this question in an online quiz.My question is from Java.lang in division Exploring java.lang & java.io of Java

Answer»

The correct choice is (d) All of the mentioned

The best EXPLANATION: Character wrapper DEFINES 5 constants – MAX_RADIX, MIN_RADIX, MAX_VALUE, MIN_VALUE & TYPE.

28.

Which of these methods of Byte wrapper can be used to obtain Byte object from a string?(a) toString()(b) getString()(c) decode()(d) encode()The question was asked at a job interview.My question is based upon Java.lang in chapter Exploring java.lang & java.io of Java

Answer»

Right option is (c) DECODE()

Explanation: decode() methods returns a Byte OBJECT that CONTAINS the value SPECIFIED by string.

29.

Which of the following methods Byte wrapper return the value as a double?(a) doubleValue()(b) converDouble()(c) getDouble()(d) getDoubleValue()The question was posed to me in examination.My question is from Java.lang in section Exploring java.lang & java.io of Java

Answer» CORRECT ANSWER is (a) doubleValue()

For explanation: doubleValue() RETURNS the value of invoking OBJECT as double.
30.

Which of these is a super class of wrappers Byte and short wrappers?(a) Long(b) Digits(c) Float(d) NumberThe question was asked in my homework.I'd like to ask this question from Java.lang in division Exploring java.lang & java.io of Java

Answer» RIGHT answer is (d) Number

Explanation: Number is an ABSTRACT class CONTAINING subclasses DOUBLE, Float, BYTE, Short, Integer and Long.
31.

Which of these methods return a smallest whole number greater than or equal to variable X?(a) double ceil(double X)(b) double floor(double X)(c) double max(double X)(d) double min(double X)This question was posed to me in an interview.This intriguing question originated from Java.lang topic in chapter Exploring java.lang & java.io of Java

Answer»

The correct answer is (a) double ceil(double X)

Explanation: ceil(double X) RETURNS the SMALLEST WHOLE number greater than or EQUAL to variable X.

32.

Which of these method returns a largest whole number less than or equal to variable X?(a) double ceil(double X)(b) double floor(double X)(c) double max(double X)(d) double min(double X)This question was addressed to me in quiz.Question is from Java.lang in chapter Exploring java.lang & java.io of Java

Answer»

The correct CHOICE is (b) double FLOOR(double X)

Best explanation: double floor(double X) returns a largest whole NUMBER less than or equal to VARIABLE X.

33.

Which of these exceptions will be thrown if we use null reference for an arithmetic operation?(a) ArithmeticException(b) NullPointerException(c) IllegalAccessException(d) IllegalOperationExceptionI had been asked this question by my school principal while I was bunking the class.I'd like to ask this question from Java’s Built in Exceptions topic in chapter Exploring java.lang & java.io of Java

Answer»

Right CHOICE is (b) NullPointerException

For explanation: If we USE null REFERENCE ANYWHERE in the code where the value stored in that reference is used then NullPointerException occurs.

34.

Which of these class provides various types of rounding functions?(a) Math(b) Process(c) System(d) ObjectThis question was addressed to me in an online quiz.This interesting question is from Java.lang topic in division Exploring java.lang & java.io of Java

Answer»

The CORRECT CHOICE is (a) Math

The BEST EXPLANATION: NONE.

35.

Which of these packages contain all the Java’s built in exceptions?(a) java.io(b) java.util(c) java.lang(d) java.netI got this question in homework.My doubt is from Java’s Built in Exceptions topic in portion Exploring java.lang & java.io of Java

Answer» RIGHT OPTION is (C) java.lang

Best EXPLANATION: NONE.
36.

Which of these exceptions handles the situations when an illegal argument is used to invoke a method?(a) IllegalException(b) Argument Exception(c) IllegalArgumentException(d) IllegalMethodArgumentExcepetionThe question was posed to me in my homework.My doubt stems from Java’s Built in Exceptions in chapter Exploring java.lang & java.io of Java

Answer» RIGHT answer is (c) IllegalArgumentException

The BEST EXPLANATION: NONE.
37.

Which of these exceptions will be thrown if we declare an array with negative size?(a) IllegalArrayException(b) IllegalArraySizeExeption(c) NegativeArrayException(d) NegativeArraySizeExeptionThe question was posed to me in a job interview.Asked question is from Java’s Built in Exceptions topic in portion Exploring java.lang & java.io of Java

Answer»

Right choice is (d) NegativeArraySizeExeption

Easiest EXPLANATION: Array size must always be positive if we declare an array with NEGATIVE size then BUILT in exception “NegativeArraySizeException” is thrown by the java’s RUN TIME system.

38.

Where is String Pool stored?(a) Java Stack(b) Java Heap(c) Permanent Generation(d) MetaspaceThe question was asked in an interview.The doubt is from Memory Management topic in section Exploring java.lang & java.io of Java

Answer»

Correct CHOICE is (b) JAVA Heap

Easy EXPLANATION: When a string is created; if the string already exists in the pool, the reference of the EXISTING string will be RETURNED, else a new object is created and its reference is returned.

39.

Classes and Methods are stored in which space?(a) Eden space(b) Survivor space(c) Tenured space(d) Permanent spaceI had been asked this question in a job interview.Enquiry is from Memory Management topic in section Exploring java.lang & java.io of Java

Answer»

Right answer is (d) Permanent space

To elaborate: The permanent generation holds objects which JVM finds CONVENIENT to have the garbage COLLECTOR. Objects DESCRIBING classes and methods, as WELL as the classes and methods themselves,are a part of Permanent generation.

40.

What is the Java 8 update of PermGen?(a) Code Cache(b) Tenured Space(c) Metaspace(d) Eden spaceThis question was addressed to me in homework.Question is taken from Memory Management in section Exploring java.lang & java.io of Java

Answer»

The correct answer is (C) Metaspace

Easiest explanation: Metaspace is the REPLACEMENT of PermGen in Java 8. It is very similar to PermGen EXCEPT that it resizes itself dynamically. THUS, it is unbounded.

41.

Which of the following is not a memory classification in java?(a) Young(b) Old(c) Permanent(d) TemporaryI got this question during an online interview.My question is based upon Memory Management topic in division Exploring java.lang & java.io of Java

Answer»

Right OPTION is (d) Temporary

To explain: Young generation is further CLASSIFIED into Eden space and Survivor space. Old generation is ALSO the tenured space. The PERMANENT generation is the non HEAP space.

42.

Which class loader loads jar files from JDK directory?(a) Bootstrap(b) Extension(c) System(d) HeapI had been asked this question in semester exam.This is a very interesting question from Memory Management topic in section Exploring java.lang & java.io of Java

Answer»

The CORRECT answer is (B) Extension

To explain: Extension loads jar files from lib/ext directory of the JRE. This gives the BASIC functionality AVAILABLE.

43.

Which one of the following is a class loader?(a) Bootstrap(b) Compiler(c) Heap(d) InterpreterI had been asked this question by my college director while I was bunking the class.This intriguing question comes from Memory Management in section Exploring java.lang & java.io of Java

Answer»

Correct ANSWER is (a) BOOTSTRAP

For explanation I WOULD SAY: Bootstrap is a CLASS loader. It loads the classes into memory.

44.

Does code Segment loads the java code?(a) True(b) FalseI had been asked this question in a job interview.I need to ask this question from Memory Management in portion Exploring java.lang & java.io of Java

Answer»

Right option is (a) True

The EXPLANATION: Code Segment loads COMPILED JAVA bytecode. Bytecode is platform independent.

45.

What is JVM?(a) Bootstrap(b) Interpreter(c) Extension(d) CompilerThis question was addressed to me in homework.My doubt is from Memory Management topic in section Exploring java.lang & java.io of Java

Answer»

Right option is (b) Interpreter

Best explanation: JVM is Interpreter. It READS .CLASS FILES which is the byte code GENERATED by COMPILER line by line and converts it into native OS code.

46.

Which of the following is not a segment of memory in java?(a) Stack Segment(b) Heap Segment(c) Code Segment(d) Register SegmentThe question was asked in an interview.My question is based upon Memory Management in portion Exploring java.lang & java.io of Java

Answer»

Correct answer is (d) Register Segment

Explanation: There are only 3 types of MEMORY segment. STACK Segment, Heap Segment and CODE Segment.

47.

Which of these class can be used to implement the input stream that uses a character array as the source?(a) BufferedReader(b) FileReader(c) CharArrayReader(d) FileArrayReaderThis question was addressed to me in an interview for job.My enquiry is from Java.io Character Streams topic in portion Exploring java.lang & java.io of Java

Answer»

Correct choice is (c) CharArrayReader

Best EXPLANATION: CharArrayReader is an implementation of an INPUT stream that USES character array as a source. Here array is the input source.

48.

Which of these class is used to read characters in a file?(a) FileReader(b) FileWriter(c) FileInputStream(d) InputStreamReaderThe question was asked during an internship interview.I need to ask this question from Java.io Character Streams in chapter Exploring java.lang & java.io of Java

Answer» CORRECT ANSWER is (a) FileReader

Explanation: NONE.
49.

Which of these method of FileReader class is used to read characters from a file?(a) read()(b) scanf()(c) get()(d) getInteger()I got this question during an interview for a job.I would like to ask this question from Java.io Character Streams topic in section Exploring java.lang & java.io of Java

Answer» CORRECT OPTION is (a) READ()

For EXPLANATION: NONE.
50.

Which of these stream contains the classes which can work on character stream?(a) InputStream(b) OutputStream(c) Character Stream(d) All of the mentionedI had been asked this question in a national level competition.My question comes from Java.io Character Streams topic in division Exploring java.lang & java.io of Java

Answer»

The correct answer is (C) CHARACTER Stream

Easiest explanation: InputStream & OutputStream classes under byte stream they are not streams. Character Stream CONTAINS all the classes which can WORK with Unicode.