Blog Archives
1 2 3 4

01: 15 Spring Boot interview Questions & Answers

15 Spring boot interview questions & answers with tutorials for easy setup of new Spring applications. Spring boot helps you get started quickly with its auto-configuration ability, and Spring Cloud Microservices interview questions & answers extends Spring Boot with cloud & micro services architecture ready patterns. Q1. What is the…

Read more ...
Tags:

01: Q01 – Q07 Spring framework core interview Q&As

Spring framework interview questions are very common for the Java programmer jobs. This covers Spring framework beginner interview questions on the Spring core and more advanced Spring framework interview questions at Java microservices interview questions.

Q1. What do you understand by the terms Dependency Inversion Principle (DIP), Dependency Injection (DI) and Inversion of Control (IoC) container?
A1. The differences are very subtle and can be hard to understand. Hence, explained via code samples.

1) Dependency Inversion Principle (DIP): is one of the 5 OO design principles abbreviated as “SOLID”, and “D” stands for DIP meaning that we should always only rely on interfaces and not on their implementations. The idea of DIP is that higher layers of your application should not directly depend on lower layers. DIP is the principle that guides us towards DI pattern. You will see in the example below that the higher layer module “MyServiceImpl” depends on the lower layer module interface “Processor” and NOT on the implementations “XmlProcessor” & “JsonProcessor”. This is commented on the code shown in Q3 for “MyServiceImpl” as “// code to interface” for the understanding.

2) Dependency Injection (DI): is a design pattern where instead of having your objects create a dependency or asking a factory object to make one for you, you pass the needed dependencies into the constructor (i.e.… Read more ...

Tags:

01: Spring DI & IoC interview Q&As

Video: Spring DIP, DI, and IoC. This extends 13 Spring interview questions & answers.

Q1. What do you understand by the terms Dependency Inversion Principle (DIP), Dependency Injection (DI) and Inversion of Control (IoC) container?
A1. Dependency Inversion Principle (DIP) is one of the 6 OO design principles abbreviated as “SOLID“, and is in some ways related to the Dependency Injection (DI) pattern. The idea of DIP is that higher layers of your application should not directly depend on lower layers. Dependency Inversion Principle does not imply Dependency Injection. This principle doesn’t say anything about how higher layers know what lower layer to use. This could be done as shown below by

1) Coding to interface using a factory pattern or

2) Coding to interface and through “Dependency Injection” by using an IoC container like Spring framework, Guice, or JEE 6+.

The Dependency Inversion Principle (DIP) states that

– High level modules should not depend upon low level modules. Both should depend upon abstractions.

– Abstractions should not depend upon details. Details should depend upon abstractions.

When this principle is applied, the higher level classes will not be working directly with the lower level classes, but with an abstract layer (i.e. an abstract class or an interface). This gives us the flexibility at the cost of increased effort.… Read more ...



01: Spring MVC beginner tutorial step by step

This tutorial extends Getting started with Apache Tomcat application server by deploying a simple JEE Application to introduce Spring MVC.

Spring dependencies via Maven

Step 1: Modify the pom.xml file in the simpleWeb project to bring in the Spring web dependency jars.

Read more ...


01b: Q08 – Q13 Spring interview Q&As

This extends 13 Spring basics Q1 – Q7 interview questions & answers. Q8. Can you describe the high level Spring architecture? A8. A Spring Bean represents a POJO (Plain Old Java Object) performing useful operation(s). All Spring Beans reside within a Spring IoC Container. The Spring Framework hides most of…

Read more ...
Tags:

02: 8 Spring Boot interview Q&As

This extends 01: 15 Spring Boot interview Questions & Answers. Q1. What is a Swagger in Spring Boot? A1. Swagger is an open source set of rules, specifications and tools for developing and describing RESTful APIs. The Swagger framework allows developers to create interactive, machine and human-readable API documentation.Swagger allows…

Read more ...


02: Spring MVC form submission tutorial step by step

This tutorial extends Spring MVC beginner tutorial step by step.

Maven project structure

Model class to capture login form details

Step 1: Create a POJO “Login.java” in the package “com.mytutorial.model” under “src/main/java” to capture login form details like “user” & “password”.

Read more ...


02: Understanding Hibernate proxy objects and avoiding potential pitfalls

Q. How does hibernate support lazy loading? A. Hibernate uses a proxy object to support lazy loading. Basically as soon as you reference a child or lookup object via the accessor/getter methods, if the linked entity is not in the session cache (i.e. the first-level cache), then the proxy code…

Read more ...


03: Identifying and fixing NonUniqueObjectException in Hibernate

NonUniqueObjectException is thrown when there is an object already associated with the session with the same id (primary key) (i.e. a duplicate). It is important to understand the concept of a “detached” object in Hibernate. This is one of the most common errors, understanding why and when this error is thrown will save you time in identifying and fixing this issue.

Q. What is a detached object in Hibernate?

When you close an individual Hibernate Session, the persistent objects you are working with become detached. This means the objects are still in the application’s memory, but Hibernate is no longer responsible for tracking changes to those detached objects. If you then modify a detached object and want to update it, you have to reattach that object. During that reattachment process, Hibernate will verify if there are any other copies of the same object. If it finds any already in the session, it gets confused as to which one is the correct object, hence notifies you with a “NonUniqueObjectException” as opposed to saving any bad data.

LazyInitializationException” is another common error due to a detached object. This error occurs when you try to access properties or associated object of Detached object then it results in Lazy Initialization Exception. This means Hibernate “could not initialize the proxy” when there is no Session”.

Scenario 1: whilst update(..) or saveOrUpdate(..)

Step 1: Load an entity say a “Book” from the database into Hibernate session.… Read more ...

Tags:

03: Spring MVC with Java Configs instead of XML configs step by step

This tutorial extends Spring MVC form submission tutorial step by step. This tutorial gets rid of web.xml and applicationContext.xml files.

pom.xml changes

Step 1: Add “JSTL” (i.e. JSP Standard Tag Library ) jar dependency, and also override default “maven-war-plugin” by explicitly adding the plugin and setting the “failOnMissingWebXml” to false.

Read more ...


1 2 3 4

500+ Enterprise & Core Java programmer & architect Q&As

Java & Big Data Tutorials

Top