06 May 2026

Java top 30 in 2026

 Question 1. What are the key features of Java 17 and later LTS versions? Modern Java focuses on conciseness, safety, and readability. Java 8 introduced Streams and Lambdas. Java 11 added the HTTP Client. Java 17 brought Records for immutable data classes, Sealed Classes for controlled inheritance hierarchies, Pattern Matching to reduce boilerplate, Switch Expressions for cleaner conditional logic, and Text Blocks for multi-line strings. These features make Java more expressive and closer to modern language design.  Question 2. Explain JVM Architecture. The Java Virtual Machine is the engine that runs your Java programs. It has three main components. The ClassLoader loads your compiled bytecode into memory. The Runtime Data Areas include the Heap, Stack, Method Area, and PC Registers. The Execution Engine runs the bytecode using either an Interpreter for quick startup or the JIT Compiler for optimized performance. Understanding JVM architecture is essential for writing performant Java applications.  Question 3. What is the difference between Heap and Stack memory? The Stack stores method call frames and local variables. It is thread-specific and automatically cleaned up when a method returns. It is fast but limited in size. The Heap stores all objects created with the new keyword. It is shared across threads and managed by the Garbage Collector. The Heap is much larger but involves GC overhead. Stack overflow errors and OutOfMemoryErrors are the typical failure modes for each.  Question 4. What is Garbage Collection in Java? Garbage Collection is Java's automatic memory management system. The JVM periodically identifies objects that are no longer reachable from any live reference and reclaims their memory. This prevents memory leaks and reduces the burden on developers. The GC uses algorithms like Mark and Sweep, Copying, and Generational collection to efficiently manage memory across the Young Generation and Old Generation heap spaces.  Question 5. What are the different types of Garbage Collectors in Java? Java offers several GC implementations. Serial GC is single-threaded and suited for small applications. Parallel GC uses multiple threads for throughput-focused workloads. G1 GC, the default since Java 9, balances throughput and latency by dividing the heap into regions. ZGC is a low-latency collector introduced in Java 11, targeting pause times under one millisecond. Shenandoah is another low-pause collector available in OpenJDK. Concurrency & Memory  Question 6. What is Multithreading in Java? Multithreading allows a Java application to execute multiple threads concurrently, making better use of CPU cores. Each thread is an independent path of execution. Java supports multithreading via the Thread class, the Runnable interface, and higher-level abstractions in the java.util.concurrent package. Multithreading improves responsiveness in UI applications, throughput in server applications, and enables parallel computation.  Question 7. What is the difference between Runnable and Callable? Both Runnable and Callable represent tasks to be executed by a thread. Runnable's run method returns void and cannot throw checked exceptions, making it simpler for fire-and-forget tasks. Callable's call method returns a typed value and can throw checked exceptions. Callable is used with ExecutorService and returns a Future object, allowing you to retrieve the result or handle exceptions asynchronously.  Question 8. What is Synchronization in Java? Synchronization controls concurrent access to shared resources, preventing race conditions and data corruption. The synchronized keyword can be applied to methods or blocks. When a thread enters a synchronized block, it acquires a lock on the object. Other threads attempting to enter the same block are blocked until the lock is released. Proper synchronization ensures thread safety but must be used carefully to avoid deadlocks and performance bottlenecks.  Question 9. What is the Volatile keyword? The volatile keyword ensures that a variable's value is always read from and written to main memory, not from a thread's local CPU cache. This guarantees visibility of the latest value across all threads. Volatile is useful for simple flags and state variables but does not provide atomicity for compound operations like increment. For atomic compound operations, use classes from java.util.concurrent.atomic.  Question 10. What is the Java Memory Model? The Java Memory Model defines how threads interact with memory. It specifies when changes made by one thread become visible to another. The JMM introduces the happens-before relationship: if action A happens-before action B, then A's effects are visible to B. Synchronized blocks, volatile reads and writes, and thread start and join operations all establish happens-before guarantees. Understanding the JMM is critical for writing correct concurrent programs. Collections, Generics & OOP Question 11. What is the Stream API? The Stream API, introduced in Java 8, enables functional-style processing of data collections. A stream is a sequence of elements supporting operations like filter, map, sorted, distinct, and collect. Streams can be sequential or parallel. They promote declarative programming, making code more readable and concise. Streams are lazy — intermediate operations are not executed until a terminal operation like collect, forEach, or reduce is invoked. Question 12. What is the difference between HashMap and ConcurrentHashMap? HashMap is not thread-safe. Concurrent modifications can cause data corruption or infinite loops. ConcurrentHashMap is designed for concurrent access. In Java 8 and later, it uses CAS operations and synchronized blocks at the bucket level, avoiding full-table locks. It allows multiple threads to read and write simultaneously with high throughput. Use ConcurrentHashMap whenever a map is shared across threads. Question 13. What are Java Generics? Generics allow you to write type-safe, reusable code by parameterizing classes, interfaces, and methods with type parameters. For example, List of String ensures only strings can be added, eliminating casts and preventing ClassCastException at runtime. Generics use type erasure, meaning type parameters are removed at compile time. Wildcards provide flexibility in generic API design. Question 14. What is the difference between Abstract Class and Interface? An Abstract Class can have both abstract and concrete methods, instance variables, and constructors. A class can extend only one abstract class. An Interface defines a contract. Since Java 8, interfaces can have default and static methods. A class can implement multiple interfaces, enabling multiple inheritance of behavior. Use abstract classes for shared state and behavior; use interfaces for defining capabilities and contracts. Design Patterns & Architecture Question 15. What is the SOLID Principle? SOLID is a set of five object-oriented design principles. Single Responsibility: a class should have one reason to change. Open-Closed: classes should be open for extension, closed for modification. Liskov Substitution: subtypes must be substitutable for their base types. Interface Segregation: clients should not depend on interfaces they don't use. Dependency Inversion: depend on abstractions, not concrete implementations. Following SOLID leads to maintainable, flexible, and testable code. Question 16. What are Design Patterns? Design patterns are reusable solutions to common software design problems. They are categorized into three groups. Creational patterns like Singleton, Factory, and Builder manage object creation. Structural patterns like Adapter, Decorator, and Proxy deal with composition. Behavioral patterns like Observer, Strategy, and Command define communication between objects. Knowing design patterns helps you write cleaner, more maintainable code. Question 17. What is the Singleton Pattern? The Singleton pattern ensures a class has only one instance and provides a global access point to it. Common implementations include eager initialization, lazy initialization with double-checked locking, and the enum-based approach, which is the most concise and thread-safe. The Singleton is used for shared resources like configuration managers, connection pools, and logging utilities. Question 18. What is Dependency Injection? Dependency Injection is a design pattern where an object receives its dependencies from an external source rather than creating them itself. This promotes loose coupling, testability, and separation of concerns. DI is commonly implemented via constructor injection, setter injection, or field injection. Frameworks like Spring manage DI using an IoC container that automatically wires dependencies based on annotations like Autowired and Component. Spring & Microservices Question 19. What is Spring Boot and how does it differ from Spring? Spring is a comprehensive framework for enterprise Java development. Spring Boot is an opinionated layer on top of Spring that simplifies setup through auto-configuration, embedded servers like Tomcat, and starter dependencies. With Spring Boot, you can create a production-ready application with minimal configuration. It is ideal for building microservices and RESTful APIs quickly. Question 20. What are Microservices? Microservices is an architectural style where an application is structured as a collection of small, independently deployable services, each responsible for a specific business capability. Services communicate via REST APIs, messaging queues, or gRPC. Benefits include independent scaling, technology diversity, and faster deployment cycles. Challenges include distributed system complexity, network latency, and the need for service discovery tools like Kubernetes. Question 21. What is RESTful API design? REST is an architectural style for designing networked APIs. RESTful APIs use standard HTTP methods: GET for reading, POST for creating, PUT for updating, and DELETE for removing resources. Resources are identified by URIs. Responses are typically in JSON format. REST principles include statelessness, uniform interface, and client-server separation. Good REST design uses proper HTTP status codes, versioning, and consistent resource naming. Advanced Java Question 22. What is Exception Handling in Java? Java uses a try-catch-finally mechanism for exception handling. Checked exceptions must be declared or caught at compile time. Unchecked exceptions extending RuntimeException do not require explicit handling. The finally block always executes, making it ideal for cleanup. Java 7 introduced try-with-resources for automatic resource management and multi-catch blocks for handling multiple exception types concisely. Question 23. What is Java Reflection? Reflection allows Java code to inspect and manipulate classes, methods, and fields at runtime. You can dynamically create objects, invoke methods, and access private members using the java.lang.reflect package. Reflection is widely used in frameworks like Spring, Hibernate, and JUnit. However, it bypasses compile-time safety and can impact performance, so it should be used judiciously. Question 24. What is the difference between Comparable and Comparator? Comparable defines the natural ordering of a class by implementing the compareTo method within the class itself. It is used for the default sort order. Comparator defines an external ordering strategy implemented in a separate class or lambda. Comparator is more flexible, allowing multiple sort orders for the same class. Java 8 enhanced Comparator with methods like comparing, thenComparing, and reversed for fluent, composable sorting. Question 25. What are Java Annotations? Annotations are metadata markers applied to classes, methods, fields, or parameters. They do not directly affect program logic but provide information to the compiler or runtime. Built-in annotations include Override, Deprecated, and SuppressWarnings. Framework annotations like Spring's Autowired, JPA's Entity, and JUnit's Test drive behavior through reflection and annotation processors. Question 26. What is the Optional class? Optional, introduced in Java 8, is a container object that may or may not hold a non-null value. It is designed to replace null returns and make the absence of a value explicit in APIs. Common methods include isPresent, ifPresent, get, orElse, orElseGet, and map. Using Optional reduces NullPointerExceptions and encourages explicit handling of absent values. It should be used as a return type in APIs. Question 27. What is the Fork-Join Framework? The Fork-Join Framework, introduced in Java 7, is designed for parallel computation by recursively splitting tasks into smaller subtasks and combining results. It uses a work-stealing algorithm where idle threads steal tasks from busy threads' queues, maximizing CPU utilization. The main class is ForkJoinPool. Tasks extend RecursiveTask for result-returning tasks or RecursiveAction for void tasks. Java 8's parallel streams use the Fork-Join Framework under the hood. Question 28. What is Java NIO? Java NIO provides non-blocking, channel-based IO operations. Key components include Channels for reading and writing, Buffers for data storage, and Selectors for monitoring multiple channels with a single thread. NIO is ideal for high-performance network applications handling thousands of concurrent connections. It contrasts with traditional blocking IO where each connection requires a dedicated thread. Question 29. What are Functional Interfaces? A Functional Interface is an interface with exactly one abstract method, making it eligible as a lambda expression target. Java 8 introduced the java.util.function package with built-in functional interfaces: Function maps input to output, Predicate tests a condition, Consumer accepts input without returning a value, Supplier provides output without input, and BiFunction works with two inputs. Question 30. What are CompletableFuture and Reactive Programming? CompletableFuture, introduced in Java 8, enables asynchronous, non-blocking programming with chainable operations. You can compose async tasks using thenApply, thenCompose, thenCombine, and handle exceptions with exceptionally. Reactive Programming treats asynchronous data streams as first-class citizens with back-pressure support. Libraries like Project Reactor and RxJava implement reactive principles. Spring WebFlux builds on Project Reactor to enable fully non-blocking, reactive web applications essential for high-throughput microservices. Wrap Up And that wraps up the Top 30 Java Interview Questions for 2026. From JVM internals to reactive programming, mastering these topics will set you apart in any senior Java interview. Keep practicing, keep building, and good luck.

18 January 2020

K8S

Kubernetes cluster manages the containers for
1.Deployment
2.Maintenance
3.Scaling.


Steps to create a deploy a spring boot application to google cloud with kubernetes cluster
1.Create a spring boot app and push it to git.
2.Login to google cloud console and create a docker image by pulling application
3.Deploy container image to kubernetes cluster.
4.Allow traffic
5.Test it by  adding additional containers and changing versions.