InterviewSolution
Saved Bookmarks
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.
| 251. |
Which of these operators can be used to concatenate two or more String objects?(a) +(b) +=(c) &(d) || |
|
Answer» Right choice is (a) + For explanation I would say: Operator + is used to concatenate strings, Example String s = “i ” + “like ” + “java”; String s contains “I like java”. |
|
| 252. |
Which of these have highest precedence?(a) ()(b) ++(c) *(d) >> |
|
Answer» Right choice is (a) () The best I can explain: Order of precedence is (highest to lowest) a -> b -> c -> d. |
|
| 253. |
Which of these are selection statements in Java?(a) if()(b) for()(c) continue(d) break |
|
Answer» The correct choice is (a) if() Explanation: Continue and break are jump statements, and for is a looping statement. |
|
| 254. |
Which of these selection statements test only for equality?(a) if(b) switch(c) if & switch(d) none of the mentioned |
|
Answer» Correct option is (b) switch The explanation: Switch statements checks for equality between the controlling variable and its constant cases. |
|
| 255. |
Which of these is returned by “greater than”, “less than” and “equal to” operators?(a) Integers(b) Floating – point numbers(c) Boolean(d) None of the mentioned |
|
Answer» Correct answer is (c) Boolean The best I can explain: All relational operators return a boolean value ie. true and false. |
|
| 256. |
Which of these statement is incorrect?(a) A thread can be formed by implementing Runnable interface only(b) A thread can be formed by a class that extends Thread class(c) start() method is used to begin execution of the thread(d) run() method is used to begin execution of a thread before start() method in special cases |
|
Answer» Correct choice is (d) run() method is used to begin execution of a thread before start() method in special cases To explain: run() method is used to define the code that constitutes the new thread, it contains the code to be executed. start() method is used to begin execution of the thread that is execution of run(). run() itself is never used for starting execution of the thread. |
|
| 257. |
What is true about protected constructor?(a) Protected constructor can be called directly(b) Protected constructor can only be called using super()(c) Protected constructor can be used outside package(d) protected constructor can be instantiated even if child is in a different package |
|
Answer» Right choice is (b) Protected constructor can only be called using super() The best explanation: Protected access modifier means that constructor can be accessed by child classes of the parent class and classes in the same package. |
|
| 258. |
Servlet are used to program which component in a web application?(a) client(b) server(c) tomcat(d) applet |
|
Answer» Correct answer is (b) server To explain: A servlet class extends the capabilities of servers that host applications which are accessed by way of a request-response programming model. |
|
| 259. |
How are java web applications packaged?(a) jar(b) war(c) zip(d) both jar and war |
|
Answer» Correct option is (d) both jar and war To explain I would say: war are deployed on apache servers or tomcat servers. With Spring boot and few other technologies tomcat is brought on the machine by deploying jar. |
|
| 260. |
Which component can be used for sending messages from one application to another?(a) server(b) client(c) mq(d) webapp |
|
Answer» The correct answer is (c) mq To elaborate: Messaging is a method of communication between software components or applications. MQ can be used for passing message from sender to receiver. |
|
| 261. |
How many copies of static and class variables are created when 10 objects are created of a class?(a) 1, 10(b) 10, 10(c) 10, 1(d) 1, 1 |
|
Answer» Correct option is (a) 1, 10 The best I can explain: Only one copy of static variables are created when a class is loaded. Each object instantiated has its own copy of instance variables. |
|
| 262. |
A single try block must be followed by which of these?(a) finally(b) catch(c) finally & catch(d) none of the mentioned |
|
Answer» The correct option is (c) finally & catch To explain I would say: try block can be followed by any of finally or catch block, try block checks for exceptions and work is performed by finally and catch block as per the exception. |
|
| 263. |
Which of these are types of multitasking?(a) Process based(b) Thread based(c) Process and Thread based(d) None of the mentioned |
|
Answer» Correct option is (c) Process and Thread based Explanation: There are two types of multitasking: Process based multitasking and Thread based multitasking. |
|
| 264. |
Which of the following is not an inheritance mapping strategies?(a) Table per hierarchy(b) Table per concrete class(c) Table per subclass(d) Table per class |
|
Answer» The correct option is (d) Table per class For explanation: Table per class is not an inheritance mapping strategies. |
|
| 265. |
What is not type of inheritance?(a) Single inheritance(b) Double inheritance(c) Hierarchical inheritance(d) Multiple inheritance |
|
Answer» Right option is (b) Double inheritance The best explanation: Inheritance is way of acquiring attributes and methods of parent class. Java supports hierarchical inheritance directly. |
|
| 266. |
Using which of the following, multiple inheritance in Java can be implemented?(a) Interfaces(b) Multithreading(c) Protected methods(d) Private methods |
|
Answer» Right option is (a) Interfaces Easy explanation: Multiple inheritance in java is implemented using interfaces. Multiple interfaces can be implemented by a class. |
|
| 267. |
What is true of final class?(a) Final class cause compilation failure(b) Final class cannot be instantiated(c) Final class cause runtime failure(d) Final class cannot be inherited |
|
Answer» Right answer is (d) Final class cannot be inherited For explanation: Final class cannot be inherited. This helps when we do not want classes to provide extension to these classes. |
|
| 268. |
Which of the following is used to rollback a JDBC transaction?(a) rollback()(b) rollforward()(c) deleteTransaction()(d) RemoveTransaction() |
|
Answer» Correct answer is (a) rollback() To explain: rollback() method is used to rollback the transaction. It will rollback all the changes made by the transaction. |
|
| 269. |
Which of the following is method of JDBC batch process?(a) setBatch()(b) deleteBatch()(c) removeBatch()(d) addBatch() |
|
Answer» The correct answer is (d) addBatch() To explain: addBatch() is a method of JDBC batch process. It is faster in processing than executing one statement at a time. |
|
| 270. |
Which of these class contains the methods used to write in a file?(a) FileStream(b) FileInputStream(c) BUfferedOutputStream(d) FileBufferStream |
|
Answer» Correct answer is (b) FileInputStream The explanation is: None. |
|
| 271. |
Which of these methods are used to read in from file?(a) get()(b) read()(c) scan()(d) readFileInput() |
|
Answer» Right choice is (b) read() To explain: Each time read() is called, it reads a single byte from the file and returns the byte as an integer value. read() returns -1 when the end of the file is encountered. |
|
| 272. |
Which of these functions is called to display the output of an applet?(a) display()(b) paint()(c) displayApplet()(d) PrintApplet() |
|
Answer» The correct answer is (b) paint() Easiest explanation: Whenever the applet requires to redraw its output, it is done by using method paint(). |
|
| 273. |
Which of the following is used to limit the number of rows returned?(a) setMaxRows(int i)(b) setMinRows(int i)(c) getMaxrows(int i)(d) getMinRows(int i) |
|
Answer» Correct answer is (a) setMaxRows(int i) To explain: setMaxRows(int i) method is used to limit the number of rows that the database returns from the query. |
|
| 274. |
Which of these values is returned by read() method is end of file (EOF) is encountered?(a) 0(b) 1(c) -1(d) Null |
|
Answer» Right option is (c) -1 The best explanation: Each time read() is called, it reads a single byte from the file and returns the byte as an integer value. read() returns -1 when the end of the file is encountered. |
|
| 275. |
What is the range of numbers returned by Math.random() method?(a) -1.0 to 1.0(b) -1 to 1(c) 0 to 100(d) 0.0 to 1.0 |
|
Answer» Right option is (d) 0.0 to 1.0 Explanation: Math.random() returns only double value greater than or equal to 0.0 and less than 1.0. |
|
| 276. |
What is the value of double consonant ‘E’ defined in Math class?(a) approximately 3(b) approximately 3.14(c) approximately 2.72(d) approximately 0 |
|
Answer» The correct answer is (c) approximately 2.72 Easiest explanation: None. |
|
| 277. |
Which of the following classes can catch all exceptions which cannot be caught?(a) RuntimeException(b) Error(c) Exception(d) ParentException |
|
Answer» Correct choice is (b) Error To elaborate: Runtime errors cannot be caught generally. Error class is used to catch such errors/exceptions. |
|
| 278. |
If an expression contains double, int, float, long, then the whole expression will be promoted into which of these data types?(a) long(b) int(c) double(d) float |
|
Answer» Correct choice is (c) double The explanation: If any operand is double the result of an expression is double. |
|
| 279. |
Which of the following is not a decision making statement?(a) if(b) if-else(c) switch(d) do-while |
|
Answer» Correct choice is (d) do-while The best explanation: do-while is an iteration statement. Others are decision making statements. |
|
| 280. |
Which of the following is used with the switch statement?(a) Continue(b) Exit(c) break(d) do |
|
Answer» Right option is (c) break The best explanation: Break is used with a switch statement to shift control out of switch. |
|
| 281. |
Which of this class can be used to format dates and times?(a) Date(b) SimpleDate(c) DateFormat(d) textFormat |
|
Answer» The correct choice is (c) DateFormat Explanation: DateFormat is an abstract class that provides the ability to format and parse dates and times. |
|
| 282. |
Which of these is necessary condition for automatic type conversion in Java?(a) The destination type is smaller than source type(b) The destination type is larger than source type(c) The destination type can be larger or smaller than source type(d) None of the mentioned |
|
Answer» Right option is (b) The destination type is larger than source type To elaborate: None. |
|
| 283. |
How to get difference between two dates?(a) long diffInMilli = java.time.Duration.between(dateTime1, dateTime2).toMillis();(b) long diffInMilli = java.time.difference(dateTime1, dateTime2).toMillis();(c) Date diffInMilli = java.time.Duration.between(dateTime1, dateTime2).toMillis();(d) Time diffInMilli = java.time.Duration.between(dateTime1, dateTime2).toMillis(); |
|
Answer» The correct option is (a) long diffInMilli = java.time.Duration.between(dateTime1, dateTime2).toMillis(); For explanation I would say: Java 8 provides a method called between which provides Duration between two times. |
|
| 284. |
Which of these can be returned by the operator &?(a) Integer(b) Boolean(c) Character(d) Integer or Boolean |
|
Answer» Right choice is (d) Integer or Boolean Best explanation: We can use binary ampersand operator on integers/chars (and it returns an integer) or on booleans (and it returns a boolean). |
|
| 285. |
Which of these is a process of writing the state of an object to a byte stream?(a) Serialization(b) Externalization(c) File Filtering(d) All of the mentioned |
|
Answer» Right answer is (a) Serialization To elaborate: Serialization is the process of writing the state of an object to a byte stream. This is used when you want to save the state of your program to a persistent storage area. |
|
| 286. |
Which of these is long data type literal?(a) 0x99fffL(b) ABCDEFG(c) 0x99fffa(d) 99671246 |
|
Answer» Right choice is (a) 0x99fffL To explain: Data type long literals are appended by an upper or lowercase L. 0x99fffL is hexadecimal long literal. |
|
| 287. |
What is the range of byte data type in Java?(a) -128 to 127(b) -32768 to 32767(c) -2147483648 to 2147483647(d) None of the mentioned |
|
Answer» Right choice is (a) -128 to 127 The best I can explain: Byte occupies 8 bits in memory. Its range is from -128 to 127. |
|
| 288. |
An expression involving byte, int, and literal numbers is promoted to which of these?(a) int(b) long(c) byte(d) float |
|
Answer» Right choice is (a) int For explanation I would say: An expression involving bytes, ints, shorts, literal numbers, the entire expression is promoted to int before any calculation is done. |
|
| 289. |
Which of these literals can be contained in float data type variable?(a) -1.7e+308(b) -3.4e+038(c) +1.7e+308(d) -3.4e+050 |
|
Answer» The correct answer is (b) -3.4e+038 Easy explanation: Range of float data type is -(3.4e38) To +(3.4e38) |
|
| 290. |
What does MIME stand for?(a) Multipurpose Internet Messaging Extension(b) Multipurpose Internet Mail Extension(c) Multipurpose Internet Media Extension(d) Multipurpose Internet Mass Extension |
|
Answer» The correct choice is (b) Multipurpose Internet Mail Extension To elaborate: MIME is an acronym for Multi-purpose Internet Mail Extensions. It is used for classifying file types over the Internet. It contains type/subtype e.g. application/msword. |
|
| 291. |
How to get prints of shared object memory maps or heap memory maps for a given process?(a) jmap(b) memorymap(c) memorypath(d) jvmmap |
|
Answer» Right choice is (a) jmap Explanation: We can use jmap as jmap -J-d64 -heap pid. |
|
| 292. |
Which of these methods is used to make raw MIME formatted string?(a) parse()(b) toString()(c) getString()(d) parseString() |
|
Answer» Right answer is (a) parse() Easiest explanation: None. |
|
| 293. |
Which of these is a standard for communicating multimedia content over email?(a) http(b) https(c) Mime(d) httpd |
|
Answer» Correct answer is (c) Mime Explanation: MIME is an internet standard for communicating multimedia content over email. The HTTP protocol uses and extends the notion of MIME headers to pass attribute pairs between HTTP client and server. |
|
| 294. |
What data structure should be used when number of elements is fixed?(a) Array(b) Array list(c) Vector(d) Set |
|
Answer» Right choice is (a) Array For explanation I would say: Array list has variable size. Array is stored in contiguous memory. Hence, reading is faster. Also, array is memory efficient. |
|
| 295. |
Which of below is not a dependency management tool?(a) Ant(b) Maven(c) Gradle(d) Jenkins |
|
Answer» The correct choice is (d) Jenkins Explanation: Jenkins is continuous integration system. Ant, Maven, Gradle is used for build process. |
|
| 296. |
What does Liskov substitution principle specify?(a) parent class can be substituted by child class(b) child class can be substituted by parent class(c) parent class cannot be substituted by child class(d) No classes can be replaced by each other |
|
Answer» The correct answer is (a) parent class can be substituted by child class Explanation: Liskov substitution principle states that Objects in a program should be replaceable with instances of their sub types without altering the correctness of that program. |
|
| 297. |
Which of the following is not a maven goal?(a) clean(b) package(c) install(d) debug |
|
Answer» The correct option is (d) debug Explanation: clean, package, install are maven goals. Debug is used finding and resolving of defects. |
|
| 298. |
How can we filter lines based on content?(a) lines.filter()(b) filter(lines)(c) lines.contains(filter)(d) lines.select() |
|
Answer» Right choice is (a) lines.filter() Easy explanation: lines.filter(line -> line.contains(“===—> Loaded package”)) can be used to filter out. |
|
| 299. |
Which file is used to define dependency in maven?(a) build.xml(b) pom.xml(c) dependency.xml(d) version.xml |
|
Answer» The correct answer is (b) pom.xml For explanation I would say: pom.xml is used to define dependency which is used to package the jar. POM stands for project object model. |
|
| 300. |
Which environment variable is used to specify the path to maven?(a) JAVA_HOME(b) PATH(c) MAVEN_HOME(d) CLASSPATH |
|
Answer» Right answer is (c) MAVEN_HOME The explanation: MAVEN_HOME should be set to the bin folder of maven installation. |
|