[Go to site: main page, start]

0% found this document useful (0 votes)
14 views4 pages

Essential Java Interview Questions

This document outlines a comprehensive list of Java interview questions covering various topics such as differences between Java and C++, object-oriented programming concepts, exception handling, multithreading, JDBC, collection frameworks, Java 8 features, and Spring framework. It includes specific questions about key concepts like inheritance, polymorphism, arrays, strings, and dependency injection in Spring. Additionally, it addresses Spring Boot and REST API development, providing a thorough preparation guide for Java interviews.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views4 pages

Essential Java Interview Questions

This document outlines a comprehensive list of Java interview questions covering various topics such as differences between Java and C++, object-oriented programming concepts, exception handling, multithreading, JDBC, collection frameworks, Java 8 features, and Spring framework. It includes specific questions about key concepts like inheritance, polymorphism, arrays, strings, and dependency injection in Spring. Additionally, it addresses Spring Boot and REST API development, providing a thorough preparation guide for Java interviews.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Java Interview Questions

● Difference between C++ and Java


● Difference between JDK, JVM and JRE
● What is data type in java and its types?
● What is variable?
● What are different operators?
● What are Keywords?
● What are control statements?
○ Conditional statements( if, if-else, switch)
○ Loop statements (for, while, do-while)
○ Jump statements (break, continue)

OOP(Most IMP)

● What is Class?
● What is an Object?
● What is IS-A Inheritance?
○ Single level
○ Multi level
○ Hierarchical
○ Multiple (Not possible in java, Need to implement using Interface) IMP
○ Hybrid
● What is HAS-A inheritance?(Aggregation)
● What is Polymorphism and its types?
● Difference between method overloading and method overriding
● What is Runtime polymorphism and Compile time polymorphism?
● What is Dynamic binding?
● What is super, this, static, final and instanceOf keyword?
● What are wrapper classes?
● What is Object class?
● What is Encapsulation?
● What are packages and subpackages in java?
● What are Access modifiers in java?
○ public
○ private
○ default
○ Protected
● What is Abstraction?
● In how many ways abstraction can be achieved?
● Difference between interface and abstract class
● Implement Multiple inheritance using interface

Arrays/Strings

● What is an array? And its types (1D and 2D)


● What is String?
○ Why are strings immutable?
■ What is String constant pool?
○ What are different methods of string?
● What is StringBuffer?
● What is StringBuilder?
● What is the difference between StringBuffer and StringBuilder?
● What is the StringTokenizer class?

Exception Handling

● What is Exception handling?


● How will you handle exceptions?
● Difference between Compile time exception(Checked exception) and Runtime
exception(Unchecked Exception)
● Difference between throw and throws keyword?
● Difference between final, finally and finalize()

Multithreading

● What is Multithereading?
● In how many ways multithreading can be implement?
● Difference between multithreading and multitasking
● Difference between yield(), slep() and join() methods
JDBC

● Steps to implement JDBC


● What is Statement?
● What is PreparedStatement?
● What is ResultSet?

Collection framework

● Difference between Collections and Collection


● Difference between Array and ArrayList
● What are different collections available in java
○ List (ArrayList, LinkedList, Stack etc.)
○ Queue (LinkedList, PriorityQueue etc.)
○ Set (HashSet, TreeSet etc.)
○ Map (HashMap etc.)

Regular expressions(Just go through once)

Java 8 features

● What is Date and Time API?


● What is Functional interface?
● What is Lambda expression?
● What is Stream API (filter(), map() and reduce() functions)
● Static and default methods in interface
● What is marker interface (Serializable, clonable)

Spring Core

● What is Maven Project and Maven Repository?


● What is Spring framework?
● Difference between Spring, Spring MVC and Spring Boot
● Need of Spring framework
● What is dependency?
● What is dependency injection?
● What is Tight coupling?
● What is Bean?
● Life Cycle of bean (@PostConstruct, @PreDestroy)
● What is IOC Container?
● Types of IOC Container
● Different ways to inject dependency (Setter injection, Constructor injection,
Proxy object)
● Different ways of Autowiring (BY_NAME, BY_TYPE)
● What are Scopes in spring framework(Singleton, Prototype)?
● Use of @Value and @PropertyScouce?

Spring BOOT

● What is MVC Pattern?(Model, View and Controller)


● What is REST API?
● What is DispatcherServelet?
● What is @Controller?
● What is @Service ?
● What is @Configuration?
● What is @Repoitory?
● What is ORM?
● What is JPA?
● Wh do we use [Link]?
● Procedure to create REST APIs using Spring boot
● How will you test the REST API? (Using Postman)

Common questions

Powered by AI

In Java, 'throw' and 'throws' serve different purposes in exception handling. The 'throw' keyword is used within a method to explicitly throw an exception, allowing a specific error to be flagged when an exceptional situation occurs. It is typically used with instances of the Exception class or its subclasses. In contrast, 'throws' is used in a method signature to declare that the method might throw one or more exceptions, passing responsibility to handle them to the method's caller. Proper use involves 'throw' for raising exceptions when conditions require it and 'throws' for letting calling methods know about exceptions that need to be managed further up the call stack .

In the Spring Framework, beans are managed components that are instantiated, configured, and assembled by the IoC (Inversion of Control) container. The lifecycle starts with bean instantiation, followed by property setting and post-initialization processing (@PostConstruct). Beans may undergo custom init methods and eventually are ready for use until the application context is destroyed. During this destruction phase, pre-destroy callbacks (@PreDestroy) or custom destroy methods are invoked. Proper management of the bean lifecycle ensures resources are allocated and cleaned efficiently, which is vital for the agile performance and stability of applications, particularly in stateful or resource-intensive scenarios .

The Stream API in Java 8 provides a functional programming approach to processing sequences of elements, offering the advantage of concise and readable code. It supports operations like filter, map, and reduce, enabling lazy evaluation and efficient performance improvements. Stream operations can be parallelized easily, which takes advantage of multi-core architectures, leading to improved performance in processing large datasets. The API's ability to chain operations without the need for boilerplate code simplifies complex data-processing queries. Utilizing Streams reduces the risk of bugs and helps with maintaining clean and modern-code paradigms .

The MVC (Model-View-Controller) pattern helps in developing scalable web applications by separating the application logic into three components, which increases modularity and allows for parallel development. The Model represents the data and business logic of the application; it responds to requests for information and updates data according to the commands. The View is responsible for displaying data and represents the user interface. The Controller handles user interactions, works with the model, and selects the view to render. By separating these concerns, changes in user interfaces or business logic can be made independently, improving maintainability and scalability .

The JDK (Java Development Kit) is a complete software development environment used for developing Java applications. It includes the JRE (Java Runtime Environment), an interpreter/loader (Java), a compiler (javac), an archiver (jar), a documentation generator (Javadoc), and other tools needed in Java development. The JVM (Java Virtual Machine) is a part of the JRE, responsible for executing the Java bytecode by converting it into machine-specific code. Essentially, the JDK is used for development, the JRE for execution, and the JVM for the complete run time of the program .

Polymorphism in Java allows for methods to do different things based on the object it is acting upon, which increases flexibility and reusability. The two main types of polymorphism are compile-time (or method overloading) and runtime (or method overriding). Compile-time polymorphism occurs when a class has multiple methods with the same name but different parameters, allowing for different usages within the same method name. Runtime polymorphism is achieved through method overriding, where a subclass provides a specific implementation for a method that is already defined in its super class. This mechanism allows dynamic method lookup and helps in designing more flexible and easily maintainable software .

Dependency Injection (DI) enhances flexibility and testability in Java applications by decoupling object creation from business logic. Within the Spring Framework, DI allows for defining the dependencies of classes through configuration, aiding in loose coupling by managing object creation and destruction. This approach facilitates easier testing, as dependencies can be mocked or stubbed; and changes to required classes mean modifying configurations rather than changing class code. Spring uses different types of injection such as constructor injection and setter injection, which simplifies application enhancements and maintenance .

Proper exception handling in Java is crucial as it ensures that runtime errors are managed and the application continues to function without crashing. Best practices include using specific exceptions rather than catching generic ones to handle different error cases distinctly and effectively; logging exceptions to help with debugging and application monitoring; avoiding the swallowing of exceptions, which makes debugging difficult; using finally blocks to clean up resources; and avoiding the use of exceptions for control flow logic. Proper exception handling contributes to an application's robustness and reliability, increasing user trust and satisfaction .

In Java, interfaces and abstract classes both provide a way to achieve abstraction but serve different purposes. Interfaces declare methods that implementing classes must define, ideal for defining capabilities that may be shared across different classes. They support multiple inheritances, meaning a class can implement multiple interfaces. Abstract classes, however, can have method implementations and fields, providing a base class with some common functionality that derived classes can use or override. They only support single inheritance. When designing an application, use interfaces to define common behavior across unrelated classes, and use abstract classes for sharing code among related classes .

Multi-threading in Java enhances application performance by allowing simultaneous execution of two or more threads, which is ideal for tasks that can run concurrently, such as I/O operations or computations. This approach optimizes CPU idle time and enhances application responsiveness, particularly in environments that support parallel processing. Unlike multitasking at OS level, which switches between processes, multi-threading keeps context-switching within a single process, reducing overheads and memory usage. However, challenges include synchronizing shared resources to prevent data inconsistency, handling thread interference, deadlocks, and ensuring that thread coordination is efficiently managed. These challenges require careful design and consideration of thread safety in application development .

You might also like