Test your knowledge of Java backend interview essentials, including Core Java, OOPs, Java 8 features, multithreading, SQL, and microservices. Prepare for Java interviews with beginner-friendly, real-world questions focused on core concepts and best practices.
Which of the following is NOT a core Object Oriented Programming concept in Java?
Explanation: Compilation is not an OOP concept; it's related to the process of converting source code into bytecode. Encapsulation, polymorphism, and inheritance are fundamental principles of object-oriented programming. Choosing 'Compilation' is correct while the others are integral to OOP.
If you create two String objects with the same value using String literals, how many objects are actually created in memory?
Explanation: Using String literals with the same value results in only one object in the string pool, as Java reuses string literals. Using 'new' keyword would create additional objects. Options '2' and '3' are incorrect as there’s only one object; '0' cannot be correct since at least one object is created.
What is a key characteristic that makes a Java class immutable?
Explanation: Immutability means the state of an object cannot be changed after creation, which is enforced by making fields final and private. Public fields or setters allow modification, breaking immutability. Implementing Runnable does not relate to immutability, so only the correct answer fits.
What is the main purpose of a marker interface in Java?
Explanation: Marker interfaces are empty and used to provide metadata, such as indicating a class has a special property. They do not mark methods for deprecation, declare constants, or provide default implementations. The other options describe unrelated functionalities.
Which statement accurately describes the 'finally' block in Java exception handling?
Explanation: The 'finally' block executes after try-catch blocks whether an exception occurs or not. It’s not required in every try-catch, and it may follow a try directly. The first, third, and fourth options reflect misunderstandings of the 'finally' block’s behavior.
Which statement best describes the difference between an abstract class and an interface in Java?
Explanation: Abstract classes can include implemented methods, whereas interfaces initially could only declare methods (though default/static methods are now allowed). Interfaces cannot have constructors or extend classes, and neither supports multiple inheritance of implementation the same way.
On what basis does a HashMap in Java decide where to store a key-value pair internally?
Explanation: HashMap uses the hashCode of the key to compute the storage index (bucket). Value's hashCode or toString output are irrelevant for determining position. Key's length is also not used; only the hashCode of the key matters.
What happens if you insert the same key into a HashMap with a new value?
Explanation: Inserting an existing key replaces its value with the new one; previous data is overwritten. No exception is thrown, and no duplicate or list is created. The other options misunderstand the core behavior of maps.
Which feature distinguishes fail-fast iterators from fail-safe iterators in Java?
Explanation: Fail-fast iterators detect structural modifications and throw exceptions. They do not create a copy, can be used with lists and other collections, and do in fact throw exceptions. The other options don't represent the unique behavior of fail-fast iterators.
Which of the following was introduced in Java 8?
Explanation: Functional interfaces and lambda expressions are key Java 8 features. Serialization and applets existed earlier, while synchronized methods have long been part of Java. Thus, the correct answer clearly highlights Java 8’s innovation.
In Java 8’s Stream API, what does the filter() method do?
Explanation: filter() selects elements that satisfy a given predicate, leaving others out. It doesn’t sort, transform types (like map()), or only remove nulls. The other options oversimplify or misrepresent what filter actually does.
Which intermediate method is used to sort a list using Java 8's Stream API?
Explanation: The sorted() method is used for sorting elements in a stream. filter() is for conditional selection, reverse() does not exist in Stream API, and findFirst() is a terminal operation to find an element. Only sorted() correctly achieves sorting.
What defines a functional interface in Java?
Explanation: A functional interface has only one abstract method, allowing instances to be provided by lambda expressions. Default methods don’t change that requirement. A class is not an interface, and implementing Runnable is just a use case, not a definition.
How can you create a new thread in Java?
Explanation: Threads are commonly created by extending Thread or implementing Runnable. Creating a new interface, overriding toString, or merely importing a package does not start a new thread. These alternatives do not relate to Java's threading model.
Which SQL query will find all students whose names start with the letter 'A'?
Explanation: Using 'LIKE 'A%'' finds names beginning with 'A'. Using '=' finds an exact match, '%A' looks for names ending with 'A', and '_A' looks for two-character names ending with 'A'. Only the correct answer matches the requirement.
Which annotation is commonly used in the main class to start a Spring Boot application?
Explanation: @SpringBootApplication enables configuration and component scanning for launching Spring Boot apps. @GetMapping is used for mapping web requests, @Entity defines persistence objects, and @ConfigurationProperties relates to externalized configuration. Only the correct annotation is used to start the application.