CORE JAVA Interview Questions You'll Most Likely Be Asked
3.5/5
()
About this ebook
- 290 CORE JAVA Interview Questions
- 77 HR Interview Questions
- Real life scenario based questions
- Strategies to respond to interview questions
- 2 Aptitude Tests
CORE JAVA Interview Qu
Read more from Vibrant Publishers
Operations and Supply Chain Management Essentials You Always Wanted To Know: Self Learning Management Rating: 0 out of 5 stars0 ratingsHR Analytics Essentials You Always Wanted To Know: Self Learning Management Rating: 0 out of 5 stars0 ratingsStakeholder Engagement Essentials You Always Wanted To Know: Self Learning Management Rating: 5 out of 5 stars5/5Business Strategy Essentials You Always Wanted To Know: Self Learning Management Rating: 5 out of 5 stars5/5Digital SAT Reading and Writing Practice Questions: Test Prep Series Rating: 5 out of 5 stars5/5Diversity in the Workplace Essentials You Always Wanted To Know: Self Learning Management Rating: 5 out of 5 stars5/5GMAT Analytical Writing: Solutions to the Real Argument Topics: Test Prep Series Rating: 4 out of 5 stars4/5Core Java Interview Questions You'll Most Likely Be Asked: Job Interview Questions Series Rating: 4 out of 5 stars4/5GRE Reading Comprehension: Detailed Solutions to 325 Questions: Test Prep Series Rating: 5 out of 5 stars5/5Financial Accounting Essentials You Always Wanted to Know: 5th Edition: Self Learning Management Rating: 0 out of 5 stars0 ratingsGRE Master Wordlist: 1535 Words for Verbal Mastery: Test Prep Series Rating: 4 out of 5 stars4/5Business Law Essentials You Always Wanted To Know: Self Learning Management Rating: 0 out of 5 stars0 ratingsHR Interview Questions You'll Most Likely Be Asked: Job Interview Questions Series Rating: 0 out of 5 stars0 ratingsGRE Words In Context: The Complete List: Test Prep Series Rating: 5 out of 5 stars5/5GRE Text Completion and Sentence Equivalence Practice Questions: Test Prep Series Rating: 4 out of 5 stars4/5GRE Analytical Writing: Solutions to the Real Essay Topics - Book 1: Test Prep Series Rating: 5 out of 5 stars5/5Writing Impressive College Essays: Test Prep Series Rating: 0 out of 5 stars0 ratingsGRE Verbal Reasoning Supreme: Study Guide with Practice Questions: Test Prep Series Rating: 4 out of 5 stars4/5Organizational Behavior Essentials You Always Wanted To Know: Self Learning Management Rating: 3 out of 5 stars3/5Time Management Essentials You Always Wanted To Know: Self Learning Management Rating: 0 out of 5 stars0 ratingsHuman Resource Management Essentials You Always Wanted To Know: Self Learning Management Rating: 0 out of 5 stars0 ratingsProject Management Essentials You Always Wanted To Know: Self Learning Management Rating: 0 out of 5 stars0 ratingsMarketing Management Essentials You Always Wanted To Know: Self Learning Management Rating: 0 out of 5 stars0 ratingsDigital Marketing Essentials You Always Wanted To Know: Self Learning Management Rating: 0 out of 5 stars0 ratingsData Analytics Essentials You Always Wanted To Know: Self Learning Management Rating: 0 out of 5 stars0 ratingsSales Management Essentials You Always Wanted To Know: Self Learning Management Rating: 0 out of 5 stars0 ratingsPrinciples of Economics Essentials You Always Wanted To Know: Self Learning Management Rating: 0 out of 5 stars0 ratingsWinning Strategies For ACT Essay Writing: With 15 Sample Prompts: Test Prep Series Rating: 5 out of 5 stars5/5Financial Management Essentials You Always Wanted to Know: 5th Edition: Self Learning Management Rating: 0 out of 5 stars0 ratingsLeadership Essentials You Always Wanted To Know: Self Learning Management Rating: 0 out of 5 stars0 ratings
Related to CORE JAVA Interview Questions You'll Most Likely Be Asked
Titles in the series (33)
SQL Server Interview Questions You'll Most Likely Be Asked Rating: 0 out of 5 stars0 ratingsC & C++ Interview Questions You'll Most Likely Be Asked Rating: 0 out of 5 stars0 ratingsAdvanced JAVA Interview Questions You'll Most Likely Be Asked Rating: 0 out of 5 stars0 ratingsCORE JAVA Interview Questions You'll Most Likely Be Asked Rating: 4 out of 5 stars4/5C# Interview Questions You'll Most Likely Be Asked Rating: 0 out of 5 stars0 ratingsData Structures & Algorithms Interview Questions You'll Most Likely Be Asked Rating: 1 out of 5 stars1/5Hibernate, Spring & Struts Interview Questions You'll Most Likely Be Asked Rating: 0 out of 5 stars0 ratingsJava / J2EE Interview Questions You'll Most Likely Be Asked Rating: 0 out of 5 stars0 ratingsPython Interview Questions You'll Most Likely Be Asked Rating: 2 out of 5 stars2/5Hadoop BIG DATA Interview Questions You'll Most Likely Be Asked Rating: 0 out of 5 stars0 ratingsSAP HANA Interview Questions You'll Most Likely Be Asked Rating: 0 out of 5 stars0 ratingsJSP-Servlet Interview Questions You'll Most Likely Be Asked Rating: 0 out of 5 stars0 ratingsAutomated Software Testing Interview Questions You'll Most Likely Be Asked Rating: 0 out of 5 stars0 ratingsORACLE PL/SQL Interview Questions You'll Most Likely Be Asked Rating: 5 out of 5 stars5/5Software Testing Interview Questions You'll Most Likely Be Asked Rating: 0 out of 5 stars0 ratingsAdvanced SAS Interview Questions You'll Most Likely Be Asked Rating: 0 out of 5 stars0 ratingsAdvanced C++ Interview Questions You'll Most Likely Be Asked Rating: 0 out of 5 stars0 ratingsBase SAS Interview Questions You'll Most Likely Be Asked Rating: 0 out of 5 stars0 ratingsCCNA Interview Questions You'll Most Likely Be Asked Rating: 0 out of 5 stars0 ratingsJavaScript Interview Questions You'll Most Likely Be Asked Rating: 0 out of 5 stars0 ratingsSAS Programming Guidelines Interview Questions You'll Most Likely Be Asked Rating: 0 out of 5 stars0 ratingsAdministrator & Helpdesk Interview Questions You'll Most Likely Be Asked Rating: 0 out of 5 stars0 ratingsIBM WebSphere Application Server Interview Questions You'll Most Likely Be Asked Rating: 0 out of 5 stars0 ratingsOperating Systems Interview Questions You'll Most Likely Be Asked Rating: 0 out of 5 stars0 ratingsLinux System Administrator Interview Questions You'll Most Likely Be Asked Rating: 0 out of 5 stars0 ratingsJava/J2EE Design Patterns Interview Questions You'll Most Likely Be Asked: Second Edition Rating: 0 out of 5 stars0 ratingsUNIX Shell Programming Interview Questions You'll Most Likely Be Asked Rating: 0 out of 5 stars0 ratingsSAS Interview Questions You'll Most Likely Be Asked Rating: 0 out of 5 stars0 ratingsCloud Computing Interview Questions You'll Most Likely Be Asked: Second Edition Rating: 0 out of 5 stars0 ratings
Related ebooks
Java Core Interview Questions and Answers. Tech interviewer’s notes Rating: 1 out of 5 stars1/5Hibernate, Spring & Struts Interview Questions You'll Most Likely Be Asked Rating: 0 out of 5 stars0 ratingsJava Core Interview in Australia. Questions and Answers. Tech interviewer’s notes Rating: 0 out of 5 stars0 ratingsJava: Best Practices to Programming Code with Java Rating: 0 out of 5 stars0 ratingsJava: Tips and Tricks to Programming Code with Java Rating: 0 out of 5 stars0 ratingsJavaScript Interview Questions You'll Most Likely Be Asked Rating: 0 out of 5 stars0 ratingsJava: Best Practices to Programming Code with Java: Java Computer Programming, #3 Rating: 0 out of 5 stars0 ratingsJava 8 Programmer II Study Guide: Exam 1Z0-809 Rating: 4 out of 5 stars4/5CODING INTERVIEW: 50+ Tips and Tricks to Better Performance in Your Coding Interview Rating: 0 out of 5 stars0 ratings120 Advanced JavaScript Interview Questions Rating: 0 out of 5 stars0 ratingsUnleashing the Power of TypeScript Rating: 0 out of 5 stars0 ratingsJava: Tips and Tricks to Programming Code with Java: Java Computer Programming, #2 Rating: 0 out of 5 stars0 ratingsJava for Black Jack: Learn the Java Programming Language in One Session by Writing and Running a Java-Based Card Game Simulation Rating: 0 out of 5 stars0 ratingsUNIX Shell Programming Interview Questions You'll Most Likely Be Asked Rating: 0 out of 5 stars0 ratingsAdvanced JAVA Interview Questions You'll Most Likely Be Asked Rating: 0 out of 5 stars0 ratingsJava Multithreading Interview Questions And Answers Rating: 0 out of 5 stars0 ratingsPractical Java 8: Lambdas, Streams and new resources Rating: 5 out of 5 stars5/5Java/J2EE Design Patterns Interview Questions You'll Most Likely Be Asked: Second Edition Rating: 0 out of 5 stars0 ratingsSpring and Spring Boot Interview Questions and Answers. Tech interviewer’s notes Rating: 5 out of 5 stars5/5Java Coding Problems: Improve your Java Programming skills by solving real-world coding challenges Rating: 0 out of 5 stars0 ratingsJava / J2EE Interview Questions You'll Most Likely Be Asked Rating: 0 out of 5 stars0 ratingsRESTful Java Web Services Interview Questions You'll Most Likely Be Asked: Second Edition Rating: 0 out of 5 stars0 ratingsBrush-up java for Interview Rating: 5 out of 5 stars5/5Grokking the Java Interview Rating: 0 out of 5 stars0 ratingsSpring Boot and Single-Page Applications: Securing Your API with a Single-Page Application Frontend - Second Edition Rating: 0 out of 5 stars0 ratingsJava and Java EE Interview Preparations Rating: 0 out of 5 stars0 ratingsBuilding a RESTful Web Service with Spring Rating: 5 out of 5 stars5/5Java 9 Data Structures and Algorithms Rating: 0 out of 5 stars0 ratingsSpring Boot Cookbook Rating: 0 out of 5 stars0 ratings
Programming For You
Learn to Code. Get a Job. The Ultimate Guide to Learning and Getting Hired as a Developer. Rating: 5 out of 5 stars5/5SQL QuickStart Guide: The Simplified Beginner's Guide to Managing, Analyzing, and Manipulating Data With SQL Rating: 4 out of 5 stars4/5Learn PowerShell in a Month of Lunches, Fourth Edition: Covers Windows, Linux, and macOS Rating: 5 out of 5 stars5/5Python Programming : How to Code Python Fast In Just 24 Hours With 7 Simple Steps Rating: 4 out of 5 stars4/5Coding All-in-One For Dummies Rating: 4 out of 5 stars4/5Excel 101: A Beginner's & Intermediate's Guide for Mastering the Quintessence of Microsoft Excel (2010-2019 & 365) in no time! Rating: 0 out of 5 stars0 ratingsHTML in 30 Pages Rating: 5 out of 5 stars5/5Visual Studio Code: End-to-End Editing and Debugging Tools for Web Developers Rating: 0 out of 5 stars0 ratingsPython QuickStart Guide: The Simplified Beginner's Guide to Python Programming Using Hands-On Projects and Real-World Applications Rating: 0 out of 5 stars0 ratingsHTML & CSS: Learn the Fundaments in 7 Days Rating: 4 out of 5 stars4/5Excel : The Ultimate Comprehensive Step-By-Step Guide to the Basics of Excel Programming: 1 Rating: 5 out of 5 stars5/5Spies, Lies, and Algorithms: The History and Future of American Intelligence Rating: 4 out of 5 stars4/5Grokking Algorithms: An illustrated guide for programmers and other curious people Rating: 4 out of 5 stars4/5JavaScript All-in-One For Dummies Rating: 5 out of 5 stars5/5SQL: For Beginners: Your Guide To Easily Learn SQL Programming in 7 Days Rating: 5 out of 5 stars5/5Unreal Engine from Zero to Proficiency (Foundations): Unreal Engine from Zero to Proficiency, #1 Rating: 3 out of 5 stars3/5Python for Data Science For Dummies Rating: 0 out of 5 stars0 ratingsRaspberry Pi Electronics Projects for the Evil Genius Rating: 3 out of 5 stars3/5Linux: Learn in 24 Hours Rating: 5 out of 5 stars5/5Python: Learn Python in 24 Hours Rating: 4 out of 5 stars4/5
Reviews for CORE JAVA Interview Questions You'll Most Likely Be Asked
11 ratings0 reviews
Book preview
CORE JAVA Interview Questions You'll Most Likely Be Asked - Vibrant Publishers
Core Java
Interview Questions
You'll Most Likely Be Asked
Job Interview Questions Series
www.vibrantpublishers.com
*****
Core Java Interview Questions You'll Most Likely Be Asked
Copyright 2021, By Vibrant Publishers, USA. All rights reserved. No part of this publication may be reproduced or distributed in any form or by any means, or stored in a database or retrieval system, without the prior permission of the publisher.
This publication is designed to provide accurate and authoritative information in regard to the subject matter covered. The author has made every effort in the preparation of this book to ensure the accuracy of the information. However, information in this book is sold without warranty either expressed or implied. The Author or the Publisher will not be liable for any damages caused or alleged to be caused either directly or indirectly by this book.
Vibrant Publishers books are available at special quantity discount for sales promotions, or for use in corporate training programs. For more information please write to bulkorders@vibrantpublishers.com
Please email feedback / corrections (technical, grammatical or spelling) to spellerrors@vibrantpublishers.com
To access the complete catalogue of Vibrant Publishers, visit www.vibrantpublishers.com
*****
Table of Contents
1. Flow Controls and Assertions
2. Wrapper Classes, Garbage Collection, and Exception Handling
3. Threads
4. Object Oriented Programming Concepts
5. Declarations and Access Controls
6. Java Assignments
7. Java Operators
8. Inner Classes and String Handling
9. Streams
10. Collections
HR Questions
INDEX
*****
Core Java
Interview Questions
Review these typical interview questions and think about how you would answer them. Read the answers listed; you will find best possible answers along with strategies and suggestions.
*****
Flow Controls and Assertions
1: What would be the output if boolA is false and boolB is true?
public void foo( boolean boolA, boolean boolB) /* Line 1 */
{
if(boolA ) /* Line 3 */
{
System.out.println(X
); /* Line 5 */
}
else if(boolA && boolB) /* Line 7 */
{
System.out.println( X && Y
); /* Line 9 */
}
else /* Line 11 */
{
if ( !boolB ) /* Line 13 */
{
System.out.println( notY
) ; /* Line 15 */
}
else /* Line 17 */
{
System.out.println( In here
) ; /* Line 19 */
}
}
}
Answer:
Output: In hereIf boolA is false line 5 will never happen and X will not be printed. If boolA is false line 7 will also be false so X && Y will also not be printed. So the next option is line number 13. If boolB is true the condition is wrong and control goes to the else part and print In here
.
2: What will be the output?
public class SwitchTrial
{
final static short caseVal = 2;
public static void main(String [] abc)
{
for (int iterNo=0; iterNo < 3; iterNo ++)
{
switch (iterNo)
{
case caseVal: System.out.print(a
);
case caseVal -1: System.out.print(b
);
case caseVal -2: System.out.print(c
);
}
}
}
Answer:
Output: c b c a b c
Since caseVal is declared as a final variable, it can be evaluated at compile time. When interVal = 0, the 3rd case is true, caseVal – 2 = 0 so it prints c. Then in the 2nd iteration, iterVal becomes 1 so the 2nd case iterVal = caseVal – 1 is true so it prints B and the next one C. The 3rd time interval is 2 and the 1st case iterVal = caseVal = 2. So all a, b and c are printed. Then the loop exits.
3: What is an assertion in Java? How is it different from if – else conditions?
Answer:
An assertion is a Boolean expression which is assumed by the programme. If true it executes the next statement and if false the program throws an exception and ends. If - else conditions are different from the assertions as if the condition is false the else part takes over in if-else but in case of assertions, if the assert expression is false, the program ends throwing an error but will execute the second expression in assert statement.
Example:
public static void main(String [] abc)
{
int var = 0;
System.out.println(Enter a value bigger than 20 :
);
var = in.nextLine();
assert var / 2 >5 : System.out.println(Please try again and enter the correct value
);
System.out.println(Good Choice!
);
}
Case 1:
Enter a value bigger than 20:10
Exception in thread main
java.lang.AssertionError: Please try again and enter the correct value
Case 2:
Enter a value bigger than 20:30
Good Choice!
When Case 1 executes the output will be - Exception in thread main
java.lang.AssertionError: Please try again and enter the correct value. Case 2 will not throw any exception as the assumption or assertion is true and hence the next line in program will execute and the output is Good Choice!
4: Name the decision structures used in Java.
Answer:
The Decision statement is a statement which evaluates a given expression and based on the logical result, performs the execution. There are two decision statements in Java. They are:
a) if
b) switch
5: What are the looping constructs in Java?
Answer:
Looping constructs are statements which are executed again and again based on the logical result. Java has three types of looping constructs. They are
a) for
b) while
c) do
6: How will you legally define if else
statement. Give an example.
Answer:
The valid format of if else
statement is described below:
If(iValue > 1000) {
System.out.println(iValue is > 1000
);
}
else {
System.out.println(iValue is < 1000
);
}
7: What happens when you execute the code below? If it compiles, what will be the output?
int iValue1 = 100;
int iValue2 = 200;
boolean isTrue() {
return true;
}
if(((iValue1 > iValu2) && (iValue2 < 50)) | isTrue()) {
System.out.println(This is True
);
}
else {
System.out.println(This is False
);
}
Answer:
The code compiles just fine and it displays the below output:
This is True
It is because, isTrue() method returns TRUE and the && expression returns FALSE. The | returns TRUE for FALSE TRUE combination.
8: What is the use of break
and continue
statements?
Answer:
As the name implies, the keyword break
is used to stop executing the statement and come out of the loop.
The continue
keyword is used to stop executing the next statement and continue executing the first statement below the loop.
9: What happens when you compile and execute the code below? What will be the output?
for(int iValue=0; iValue<5; iValue++) {
System.out.println(iValue);
continue;
System.out.println(iValue + 1);
}
Answer:
The code compiles and on executing it displays the below output:
0
1
2
3
4
It is because continue
statement will stop executing the next statement and start executing the first statement of the loop.
10: What happens when you compile and execute the code below? What will be the output?
for(int iValue=0; iValue<5; iValue++) {
System.out.println(iValue);
break;
System.out.println(iValue + 1);
}
Answer:
The code compiles and on executing it displays the below output:
0
It prints just 0 because the break statement will stop executing the next statement and push you out of the loop.
11: What happens when you compile and execute the code below? What will be the output?
for (;;) {
System.out.println(Will this get printed?
);
}
Answer:
The above mentioned code compiles fine but it never stops executing. This is because it is an infinite loop and keeps on printing the output Will this get printed?
.
12: What happens when you compile and execute the code below? What will be the output?
int iValue = 50;
for (;iValue < 100;) {
System.out.println(iValue);
}
Answer:
In the above code, the iValue is never incremented. So, this becomes an infinite loop; it infinitely prints the value 50
.
Output:
50
51
...
99
13: What is the benefit of an enhanced for
loop?
Answer:
The enhanced for
loop is mainly used to loop through an array object or a collection object. It is introduced in Java 5 and the valid format is described as below:
for ( Declaration : Expression)
The Declaration must be a type that you assign based on the expression type.
The Expression can be of the following:
a) Array variable
b) Call to a method that returns an array
Also, the array can be a primitive, an object or an array of arrays.
14: How will you declare a valid enhanced for
loop?
Answer:
A valid enhanced for
loop is described below:
Integer [] integerArray = {10, 100, 1000};
for(Integer integer : integerArray) {}
int [] iValue = {10, 100, 1000};
for(int iValue1 : iValue) {}
Electronics [] electronics = {new Camera(), new Laptop()};
for(Electronics e : electronics) {}
15: What will be the output of the following code?
for(int iValue = 0; iValue < 10; iValue++) {}
System.out.println(iValue);
Answer:
The above mentioned code will not compile. It is because the variable ‘iValue’ scope is available only within the for
loop and not beyond the for
loop.
16: Which lines of below code will compile and which will not?
while (iValue) {} //Line 1
while (false) {} //Line 2
while (iValue = 5) {} //Line 3
while (iValue == 5) {} //Line 4
Answer:
Line 1 and Line 3 will not get compiled.
Line 2 and Line 4 gets compiled.
It is because the return type of an expression must be a boolean.
17: Look at the code below. What will happen when you execute the below code? If it compiles fine, what will be the output?
int iValue = 10;
switch(iValue) {
case 5: System.out.println(5
);
case 8: System.out.println(5
);
default: System.out.println(This is Default
);
case 9: { System.out.println(9
); break; }
case 11: System.out.println(11
);
}
Answer:
The above mentioned code compiles fine and displays the below output.
This is Default
9
Although 10 is not available, default
it gets executed and executes the next statement as well. The code will not print 11. It’s because of the break
statement.
18: What are the benefits of assertions?
Answer:
Below are the benefits of Assertions:
a) It is used to test your logical assumptions when you develop your code.
For example:
if(intNumber >= 0) {
invokeMethod(intNumber);
}
We are not supposed to make assumptions. It is not the case when you write code. So, the above piece of code can be written as
assert(intNumber >= 0);
invokeMethod(intNumber);
b) It is also useful to write the code clean and we have the option of turning the assertions on and off. i.e., if we know that the above assumption is correct in all the scenarios, then we don’t need to write the exception handling code.