Java, Database, Spring Boot, Microservices, and CI/CD: Key Concepts and Examples
What are the features introduced in Java 8?
Java 8 introduced several key features, including:
- Lambda Expressions
(a, b) -> a + b;
- Stream API
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5);
numbers.stream().filter(n -> n % 2 == 0).forEach(System.out::println);
- Functional Interfaces
@FunctionalInterface
interface Addable { int add(int a, int b); }
- Optional Class
Optional<String> name = Optional.of('Java');
name.ifPresent(System.out::println);
- Date-Time API
LocalDateTime now = LocalDateTime.now();
System.out.println(now);
What is Stream API?
The Stream API allows functional-style operations on streams of elements.
It supports operations like map, filter, reduce, etc., to process data.
Example:
List<String> names = Arrays.asList('John', 'Alice', 'Bob');
names.stream().filter(name -> name.startsWith('A')).forEach(System.out::println);
What are Lambda Expressions and Functional Interfaces?
Lambda expressions allow you to pass a block of code as a parameter to a method or store it in a
variable.
Functional interfaces are interfaces with only one abstract method.
Example:
interface MathOperation {
int operate(int a, int b);
MathOperation add = (a, b) -> a + b;
System.out.println(add.operate(5, 3));
What are Multithreading and Lock Strategies?
Multithreading allows concurrent execution of multiple threads.
Lock strategies like ReentrantLock or synchronized help manage thread safety.
Example:
ReentrantLock lock = new ReentrantLock();
lock.lock();
try {
// Critical section
} finally {
lock.unlock();
What is the String Class in Java?
In Java, the String class is immutable and stored in the String Pool.
Methods like concat(), substring(), and equals() are commonly used.
Example:
String str1 = 'Java';
String str2 = str1.concat(' 8');
System.out.println(str2); // Java 8
What is the usage of the static keyword?
The static keyword is used to declare variables, methods, blocks, or inner classes that belong to the
class rather than instances.
Example:
class Counter {
static int count = 0; // Global
static void increment() {
count++;
Counter.increment();
System.out.println(Counter.count); // 1
What are Global and Instance Variables?
Global variables are declared at the class level and shared by all instances, whereas instance
variables belong to each object.
Example:
class Car {
static int globalCount = 0; // Global
int speed = 0; // Instance variable
What is the Java Memory Model?
The Java Memory Model (JMM) defines how threads interact with memory.
It involves the heap (for storing objects), stack (for method execution), and method area (for class
metadata).
What are Collections in Java, and how does HashMap work?
Collections in Java include interfaces like List, Set, and Map. HashMap stores key-value pairs.
To use custom objects as keys, we need to override equals() and hashCode().
Example:
class Person {
String name;
Person(String name) { this.name = name; }
@Override
public boolean equals(Object obj) {
return this.name.equals(((Person) obj).name);
@Override
public int hashCode() {
return name.hashCode();
HashMap<Person, String> map = new HashMap<>();
map.put(new Person('John'), 'Developer');
What are common Design Patterns in Java?
Common design patterns include Singleton, Factory, and Observer.
Example (Singleton Pattern):
public class Singleton {
private static Singleton instance;
private Singleton() {}
public static Singleton getInstance() {
if (instance == null) {
instance = new Singleton();
return instance;