Blog Archives
1 2 3 4 5 15

01: 15+ Java multithreading interview questions & answers

Multithreading is one of the important features of Java, and multithreading interview Q&As can reveal a lot about your depth of core Java knowledge. Most importantly, it is not easy to grasp multithreading concepts without lots of hands-on experience. Let’s start with the beginner basics & then get into Java concurrency management interview Q&As for the experienced.

What is a thread?

Q1. What is a thread?
A1. It is a thread of execution in a program. The JVM (i.e. process) allows an application to have multiple threads of execution running concurrently. In the Hotspot JVM there is a direct mapping between a Java Thread and a native operating system (i.e. OS) Thread. When a thread terminates, all resources for both the native and Java thread are released.

Q2. What are the JVM created threads?
A2. The main thread and a number of background threads.

1) main thread, which is created as part of invoking the main(…) method

2) VM background thread to perform major GC (i.e. Garbage Collection), thread dumps (e.g. kill -QUIT in Unix), thread suspension, etc.… Read more ...


01: 19 Java 8 Functional Programming (FP) Interview Q&As

Java 8 Functional Programming Interview questions focusing on FP. Getting a good handle on Java OOP concepts and FP concepts are very important NOT only from writing quality code perspective, but also from job interviews perspective to be able to do well in written tests & technical interviews.

Q1. Can you explain your understanding of Functional Programming (FP)?
A1. In a very simplistic approach FP means:

#1 Programming without assignments: For example, in imperative style programming like OOP, you can say “x = x + 5”, which is an assignment, but in mathematical or functional programming you need to say f(x) -> x + 5. If, x were to be 2, it is mathematically incorrect to say “2 = 2 + 5”. In imperative style you are assigning a new value of 7 to x by saying “x = x + 5”. So, imperative programming has state and you can assign a new state. FP treats computation as the evaluation of mathematical functions and avoids storing state and mutating data.

#2 FP focuses on WHAT to be done, and NOT on HOW to be done: For example, in the ‘functional style loop’ you’ll focus only on the action of what to do on each element and you don’t have to concentrate on how to go through each element. The “forEach” function will take care of it.

Here is a simple example that shows imperative (e.g.… Read more ...


01: 7 rules to remember on Java Generics for better understanding

Here are 7 rules to remember regarding Java Generics to understand Generics and handle interview and coding questions on Core Java. Object <– Fruit <– (Orange, Mango, etc siblings) Rule 1: Java generics differ from C++ templates. Java generics (at least until JDK 8), generate only one compiled version of…

Read more ...

01: Java 8 FP interview Q&As on Function, Supplier, Consumer & Predicate

The java.util.function package provides the below functional interfaces. These are used in lambda functions & saves you time by you not having to create your own. You will often find one of these below serve your requirement. Why Function, Supplier, Consumer & Predicate? We know that Java 8 introduced an…

Read more ...

01: Java 9+ modules interview Q&As

Q01. What is a module in Java?
A01. You can think of the Java Platform Module System (JPMS) as a higher level of aggregation above packages. A Java module is a set of packages that declares which of them form an API accessible to other modules and which are internal and encapsulated, which is similar to how a class defines the visibility of its members. A Module allows you to organise a few packages into one single logical unit and to distribute them as a one whole system. A Java module is packaged as a modular JAR file. is one of the resources introduced in Java & resides in the base folder of a package. A Java module can specify which packages it contains that should be visible to other Java modules, which uses this module. A Java module must also specify which other Java modules it requires to do its job. When you create this file, you have to know 2 things:

1) What it will export: A module can export its packages to the outside world so that other modules can use them.

2) What the module will depend on: A module can import or use other modules packages.… Read more ...

01: Java data types interview Q&As

Q1. How would you go about choosing the right data types for your application?
A1. Java is what is known as a strongly typed language. This means Java only accepts specific values within specific variables or parameters. Some languages, such as JavaScript, PHP, and Perl are weakly typed languages.

1. Know the data limits to prevent any data overflow

2. Prefer immutable wrapper objects to primitives.

Each primitive data type has a corresponding wrapper class like Integer, Long, Character, Float, Double, etc. There are 8 primitive variables and as many wrapper objects. In Java 5, additional wrapper classes like AtomicInteger, AtomicLong, AtomicBoolean and AtomicReference were introduced to provide atomic operations for addition, increment, and assignment. These additional classes are mutable and cannot be used as a replacement for regular immutable wrapper classes.

Q2. What are wrapper classes, and why do you need them?
A2.… Read more ...

01: jvisualvm tutorial to sample Java heap memory

Java does not have a sizeof operator like C++ does. Java uses automatic memory management known as the Garbage Collection, hence it is not that important to evaluate size of various objects. But, for the purpose of learning & fixing any potential memory issues, I have used “jvisualvm”, which is…

Read more ...

01: OOP vs FP with Java example – placing a trade

A Trade goes through 3 state changes – placed, filled, and settled. Let’s solve this simple problem using both OOP & FP approaches.

Place –> Fill –> Settle

OOP approach by mutating the state

State changes are maintained via a variable named “status“, which is mutable.… Read more ...

02: 10 Java String class interview Q&As

Java Collection interview questions and answers and Java String class interview questions and answers are must know for any Java developer as these two APIs are the most frequently used in your Java application code. You can’t write any decent Java application without these 2 APIs. Q1. What will be…

Read more ...

02: 5 Java multithreading scenarios interview Questions & Answers

Java interview questions & answers on multithreading scenarios to judge your experience in building applications with concurrency in mind. Q1. Can you give some scenarios where you built concurrent systems? A1. In a concurrent system different threads run concurrently, whereas in a distributed system different processes often in separate machines…

Read more ...

1 2 3 4 5 15

500+ Enterprise & Core Java programmer & architect Q&As

Java & Big Data Tutorials