Monday, May 20, 2024

Java interview questions for 10 years Experienced

1. What are some of the important features that are introduced in Java 8?

There are many features important for development using Java that were

implemented in Java 8. Some of these features are as follows:

•Lambda expressions

•Default methods for interfaces

•Functional interface

•Stream API

•Date API

2. What is a lambda expression?

Within Angular, the view embodies the graphical user interface (UI) of an

application. Its primary role involves presenting the data sourced from the

component and managing user interactions. Constructed through HTML

templates, the view dynamically renders and adjusts its content in accordance

with the component’s data and the application’s logic.

The following is the structure of a lambda expression:

1 (Argument List) ->{expression;} or

2 (Argument List) ->{statements;}

3. What are the most important advantages of using Java 8?

The introduction of Java 8 has been proven to be very helpful for programmers

in the following ways:

•Code is now highly readable

•More reusability of code

•Code size is now very compact

•Minimum boilerplate code

•Easier testability methods

•Parallel execution and operations

4. What is the meaning of functional interfaces in Java 8?

Functional interfaces in Java 8 are interfaces having a single abstract method.

Following are the three types of methods that can be present:

•The static method

•The default method

•The overridden class method

5. What are the core API classes for date and time in Java 8?

There are three main core API classes for date and time in Java 8 as given

below:

•LocalDate

•LocalTime•LocalDateTime

6. What are PermGen and Metaspace in Java 8?

The Java Virtual Machine has been using PermGen for class storage until Java

7. It is now superseded by Metaspace.

Metaspace has a huge advantage over PermGen that makes the former grow

dynamically without any constraint, while PermGen has a fixed maximum size.

7. What is the use of the optional keyword in Java 8?

The optional keyword is used in Java 8 to avoid the occurrence of the

NullPointerException.

An optional object can be created easily using the empty() static method as

shown below:

@Test

public void whenCreatesEmptyOptional_thenCorrect() {

Optional<String> empty = Optional.empty();

assertFalse(empty.isPresent());

}

8. What is a supplier in Java 8?

A supplier is a simple functional interface in Java 8 that does not take in any

argument. It is used as an assignment target when making use of lambda

expressions.

The following is an example that denotes the usage of a supplier:

import java.util.function.Supplier;

public class Java8SupplierExample {

public static void main(String[] args) {

Supplier<String> supplier= ()-> "HelloLearners";

System.out.println(supplier.get());

}

}

9.What is a consumer in Java 8?

Similar to a predicate, a consumer is a functional interface with a single

argument in Java 8. However, unlike a predicate, a consumer does not return

any value and is commonly used for lambda expressions. Below is an example

code snippet that demonstrates the usage of the consumer interface to print a

string:

import java.util.function.Consumer;

public class Java8ConsumerExample {

public static void main(String[] args) {

Consumer<String>; consumerString = s -> System.out.println(s);

consumerString.accept("HelloWorld");}}

10. Can you name the common types of functional interfaces in the standard

library?

There are many functional interface types in the standard library, and some of

them are as follows:

•BiFuction

•BinaryOperator

•Consumer

•Predicate

•Supplier

•UnaryOperator

11. What are the similarities between map and flatMap stream operations in

Java 8?

Both the map and flatMap operations are types of intermediate stream

operations. They accept a function as input and utilize this function to perform

different actions on the stream elements.

12. Can you give examples of intermediate operations in Java 8?

The examples that are widely used in intermediate operations are:

•Distinct()

•Limit(long n)

•Filter(Predicate)

•Map(Function)

•skip(long n)

13. What are some of the examples of terminal operations in Java 8?

Following are some of the examples of terminal operations in Java 8:

•Count

•Min

•Max

•Reduce

•toArray

•anymatch

•allMatch

Spring Boot Questions

14. What annotations are used to create an Interceptor?

A prominent functionality of Spring Boot, Interceptor uses the annotated class

@Component, and it implements the interface HandlerInterceptor.

The interface contains 3 main methods, which are:

The preHandle() Method − preHandle() is used for intercepting the request prior

to the implementation of the handler. If preHandle() returns a “true” booleanvalue, developers can continue with handler execution. If preHandle() returns a

“false” boolean value, developers should stop the handler execution

15. What is a Swagger in Spring Boot?

Swagger is used for clearly detailing and documenting RESTful APIs in a

machine-readable and human-readable format, which is easily comprehensible for

testers and developers, as well as individuals having little knowledge of source

code.

Enabling hassle-free application discovery, development, and integration, Swagger

allows API consumers to interact with remote services with minimum

implementation logic.

16. What are Profiles in Spring Boot?

Profiles in the Spring framework enables users to map components and beans to

specific profiles, such as the Development (dev) profile, Production (prod)

profile, or the Test profile.

In Spring Boot, the annotation @Profile is used to map components and beans

to a certain profile.

What are the important features of Spring Boot?

Important features of Spring Boot are:

Web Development

Spring Application

Application occasions and listeners

Admin highlights

YAML Support

Type-safe Configuration

Externalized Configuration

Properties Files

Logging and Security

17.Is it possible to replace or override the Embedded Tomcat server in Spring

Boot?

Yes, it is possible to replace the Embedded Tomcat with any other servers by

using the starter dependencies. For that, you can use spring-boot-starter-jetty or

as a dependency for according you to your need.

18. What is the difference between Spring and Spring Boot?

Difference between Spring and Spring boot are as follows:

Spring –

1.Is a dependency injection framework.

2.It is basically used to manage the life cycle of java classes (beans). It

consists of a lot of boilerplate configuration.

3.Uses XML based configuration.

4.It takes time to have a spring application up and running and it’s mainly

because of boilerplate code.Spring boot-

1.It is a suite of pre- configured frameworks and technologies which helps to

remove boilerplate configuration.

2.Uses annotations.

3.It is used to create a production-ready code.

Hibernate Interview Questiions

19. What are fetching strategies? Which strategies do Hibernate support?

Hibernate uses a fetching strategy for retrieving associated objects when the

application has to navigate the association. The strategies can be declared in the

O/R mapping metadata or overridden by a particular HQL or criteria query.

Hibernate supports the following fetching strategies:

Join fetching

Batch fetching

Immediate fetching

Select fetching

Subselect fetching

Lazy collection fetching

"No-proxy" fetching

"Extra-lazy" collection fetching

Proxy fetching

Lazy attribute fetching(Naming Directory Interface)

Database - MySQL, PostgreSQL, Oracle

20. What are the main elements of the hibernate framwork?

hibernate framwork consists of the following main elements:

SessionFactory: It gives a factory method to create session objects and

get clients of ConnectionProvider. It is immutable and holds a second-

level cache (optional) of data.

Session: A short-lived object acting as an interface between the Java

application objects and database data. It is usually used to generate query,

transaction, and criteria objects. It has a first-level cache (mandatory) of

data.

Transaction: An object specifying the atomic unit of work. It has

methods for transaction management and is optional.

TransactionFactory: A factory of transaction objects. It is optional.

ConnectionProvider: A factory of JDBC connection objects. It is optional

and gives abstraction to the application from the DriverManager.

21. Can we define an entity class final in Hibernate?

No, we should not declare the entity class final because Hibernate employs

objects for lazy loading of data and proxy classes and hits the database only ifit is absolutely necessary. You can achieve the same by extending the entity

bean. However, if you declare the entity class (or bean) final, then it can't be

extended. As a result, lazy loading won't be supported

22.What is a view in SQL? How to create a view?

A view is a virtual table based on the result-set of an SQL statement. We can

create it using create view syntax.

CREATE VIEW view_name AS

SELECT column_name(s)

FROM table_name

WHERE condition

23.What are the uses of view?

1. Views can represent a subset of the data contained in a table; consequently,

a view can limit the degree of exposure of the underlying tables to the outer

world: a given user may have permission to query the view, while denied

access to the rest of the base table.

2. Views can join and simplify multiple tables into a single virtual table.

3. Views can act as aggregated tables, where the database engine aggregates

data (sum, average, etc.) and presents the calculated results as part of the data.

4. Views can hide the complexity of data.

5. Views take very little space to store; the database contains only the

definition of a view, not a copy of all the data which it presents.

6. Depending on the SQL engine used, views can provide extra security.

24. What is a Trigger?

A Trigger is a code associated with insert, update or delete operations. The

code is executed automatically whenever the associated query is executed on a

table. Triggers can be useful to maintain integrity in the database.

25. What is a transaction? What are ACID properties?

A Database Transaction is a set of database operations that must be treated as

a whole, which means either all operations are executed or none of them.An

example can be a bank transaction from one account to another account. Either

both debit and credit operations must be executed or none of them.ACID

(Atomicity, Consistency, Isolation, Durability) is a set of properties that

guarantee that database transactions are processed reliably.

26. What are indexes?

A database index is a data structure that improves the speed of data retrieval

operations on a database table at the cost of additional writes and the use ofmore storage space to maintain the extra copy of data.Data can be stored only

in one order on a disk. To support faster access according to different values,

faster search like binary search for different values is desired, For this purpose,

indexes are created on tables. These indexes need extra space on the disk, but

they allow faster search according to different frequently searched values.

27. What are clustered and non-clustered Indexes?

Clustered indexes are the index according to which data is physically stored on

a disk. Therefore, only one clustered index can be created on a given database

table.

Non-clustered indexes don’t define the physical ordering of data, but logical

ordering. Typically, a tree is created whose leaf point to disk records. B-Tree

or B+ tree are used for this purpose.

28. What is a Live Lock?

Livelock situation can be defined as when two or more processes continually

repeat the same interaction in response to changes in the other processes

without doing any useful work These processes are not in the waiting state, and

they are running concurrently. This is different from a deadlock because in a

deadlock all processes are in the waiting state.

29.What are temporary tables? When are they useful?

Temporary tables exist solely for a particular session, or whose data persists for

the duration of the transaction. The temporary tables are generally used to

support specialized rollups or specific application processing requirements. Unlike

a permanent table, space is not allocated to a temporary table when it is

created. Space will be dynamically allocated for the table as rows are inserted.

The CREATE GLOBAL TEMPORARY TABLE command is used to create a

temporary table in Oracle.

No comments:

Post a Comment