Blog Archives

01: ♥ What is wrong with this code? Auto-unboxing, switch, short circuit & exception

Auto-unboxing, switch, short circuit logical operators & exception handling are core Java basics that sometimes lead to obscure errors if not understood well & often tested in coding tests.

Q1. What is wrong with this code?

A1. compile-error at switch(i) as switch works only with “int”

Read more ›



02: ♥♦ What is wrong with this code? Heap Vs Stack, Thread safety & Synchronized

This post covers must know Java Multithreading basics – Heap Vs Stack, Thread-safety & Synchronization. When you have a multithreaded Java application, you need to code in a thread-safe manner. Java interviewers may ask you to detect thread-safety issues as discussed in “What is wrong with this code?

Read more ›

Tags: ,

03: What is wrong with this code? Data types & equals( ) Vs, hashCode( ) contract

Q6. What is wring with this code? A6. Infinite loop at due to sum != 1.0. Using floating point variables like float or double in loops to compare for equality can lead to infinite loops. Comparing for “” or “ … Read more ›...

Members Only Content

This content is for the members with any one of the following paid subscriptions:

45-Day-Java-JEE-Career-Companion, 90-Day-Java-JEE-Career-Companion, 180-Day-Java-JEE-Career-Companion, 365-Day-Java-JEE-Career-Companion and 2-Year-Java-JEE-Career-Companion Log In | Register | Try free FAQs | Home


04: What is wrong with this code? Java Collection & ConcurrentModificationException

Q9. What is wring with this code? A9. throws a Runtime exception called “java.util.ConcurrentModificationException” The output will be: Fix 1: Use iterator.remove() instead of collection.remove Output: Fix 2: Use java.util.… Read more ›...

Members Only Content

This content is for the members with any one of the following paid subscriptions:

45-Day-Java-JEE-Career-Companion, 90-Day-Java-JEE-Career-Companion, 180-Day-Java-JEE-Career-Companion, 365-Day-Java-JEE-Career-Companion and 2-Year-Java-JEE-Career-Companion Log In | Register | Try free FAQs | Home


05: What is wrong with this code? Deep Vs Shallow comparison & multithreading

Q10 What is wring with this code? A10. date1 == date2 only compares the references and not the actual dates. Since both the references are different objects, they will never be the same, and nothing will be printed. This is also known as the “ … Read more ›...

Members Only Content

This content is for the members with any one of the following paid subscriptions:

45-Day-Java-JEE-Career-Companion, 90-Day-Java-JEE-Career-Companion, 180-Day-Java-JEE-Career-Companion, 365-Day-Java-JEE-Career-Companion and 2-Year-Java-JEE-Career-Companion Log In | Register | Try free FAQs | Home


06: What is Wrong with this code? Multithreading & wait/notify

An excellent written test question to assess your Java multi-threading knowledge. Please practice it by doing it yourself. Q. Review the code shown below and then answer the following questions. Q1. What does the above code do? Q2. What are the issues with the above code? … Read more ›...

Members Only Content

This content is for the members with any one of the following paid subscriptions:

45-Day-Java-JEE-Career-Companion, 90-Day-Java-JEE-Career-Companion, 180-Day-Java-JEE-Career-Companion, 365-Day-Java-JEE-Career-Companion and 2-Year-Java-JEE-Career-Companion Log In | Register | Try free FAQs | Home


07: What is wrong with this code? Multithreading & locks

Q. What is wrong with the following Java code? Explain what does the following code do? Explain if there is anything wrong with the following code? If there is something wrong, how will you go about fixing it? A. … Read more ›...

Members Only Content

This content is for the members with any one of the following paid subscriptions:

45-Day-Java-JEE-Career-Companion, 90-Day-Java-JEE-Career-Companion, 180-Day-Java-JEE-Career-Companion, 365-Day-Java-JEE-Career-Companion and 2-Year-Java-JEE-Career-Companion Log In | Register | Try free FAQs | Home


08: What is wrong with this code? Generics

Q. Can you review the following code and see if it has any issues? A. The “MyStack” class is not properly using “generics”. It only works with “String” class. Here is the revised solution using generics to work with any object type. … Read more ›...

Members Only Content

This content is for the members with any one of the following paid subscriptions:

45-Day-Java-JEE-Career-Companion, 90-Day-Java-JEE-Career-Companion, 180-Day-Java-JEE-Career-Companion, 365-Day-Java-JEE-Career-Companion and 2-Year-Java-JEE-Career-Companion Log In | Register | Try free FAQs | Home


09: What is wrong with this code? HashMap & Race condition

Q. What is wrong with the following code snippet? A. It is NOT thread-safe as a “HashMap” is not thread-safe as per the Java API, and race conditions can leave the “map” in “inconsistent state“. It is very hard to detect or reproduce race conditions. … Read more ›...

Members Only Content

This content is for the members with any one of the following paid subscriptions:

45-Day-Java-JEE-Career-Companion, 90-Day-Java-JEE-Career-Companion, 180-Day-Java-JEE-Career-Companion, 365-Day-Java-JEE-Career-Companion and 2-Year-Java-JEE-Career-Companion Log In | Register | Try free FAQs | Home


10: What is wrong with this code? ConcurrentHashMap & Atomic operations

Q. What output is expected from the following code? What does it actually output? A. It is expected to output counts from 100,001 to 100,010, but actually the output will be as shown below missing counts. Output with missing counts Why does the output miss counts?… Read more ›...

Members Only Content

This content is for the members with any one of the following paid subscriptions:

45-Day-Java-JEE-Career-Companion, 90-Day-Java-JEE-Career-Companion, 180-Day-Java-JEE-Career-Companion, 365-Day-Java-JEE-Career-Companion and 2-Year-Java-JEE-Career-Companion Log In | Register | Try free FAQs | Home


By topics – 800+ Q&As ♥ Free ♦ FAQ

open all | close all

Java 200+ FAQs – Quick Brushup

open all | close all

100+ Java Tutorials step by step

open all | close all

13+ Tech Key Areas to standout

open all | close all

Java coding exercises

open all | close all
Top