Saturday, August 8, 2020

Java Technical interview @ ThalesGroup : Round-2

Hi Friends,

In this post, I am sharing interview questions and answers asked in ThalesGroup : Round-2.


Question 1:

What are the tools available for testing web services?

Answer:

  • SOAP UI Tool
  • Poster for Firefox Browser
  • The Postman extension for Chrome

Question 2:

Which java API helps in developing a RESTful web service?

Answer:

There are many frameworks and libraries that a developer can use to create Restful web services in java.

For example , the JAX-RS library is standard way to develop a REST web service.


Also Jersey is another most popular implementations of JAX-RS which offers more than what the specs recommended. There are others like  RESTEasy, RESTLet and Apache CFX.



Question 3:

What is the difference between REST and RESTful?

Answer:

REST based services/architecture vs RESTFul services/architecture:

To differentiate or compare these two, we should know what is REST.

REST [Representational State Transfer]: Is basically an architectural style of development having some principles:

  • It should be stateless
  • It should access all the resources from the server using only URI.
  • It does not have inbuilt encryption
  • It does not have session
  • For performing CRUD operations , it should use HTTP verbs, such as GET, POST, PUT, DELETE, PATCH.
  • It should return the result only in JSON format or XML , atom etc. (lightweight data)


REST based services follow some of the above principles and not all.

RESTFUL services means, it follows all the above principles.

 


Question 4:

Write a sample GET request using Jersey.

Answer:

@GET

@Path("/{empId}")

Employee getEmployee(@PathParam("empId") String empId, @QueryParam("empName") String empName)


Question 5:

Is Spring initializer the only way to create Spring boot projects?

Answer:

No

We can use two approaches:

  • The first one is start.spring.io
  • The other one is : Setting up a project manually
Setting up a maven project manually:

  • In Eclipse, Use File-> New Maven project to create a new project
  • Add dependencies
  • Add the maven plugins
  • Add the Spring boot Application class


Question 6:

Why do we need spring-boot-maven-plugin?

Answer:

Spring-boot-maven-plugin provides a few commands which enable us to package the code as a jar or run the application.

Command in spring-boot-maven-plugin are:

  • Spring-boot: run - Runs the spring boot application
  • Spring-boot : repackage - Repackages the jar/war to be executable
  • Sprint-boot: start and spring-boot: stop - To manage the lifecycle of spring boot application.
  • Spring-boot: build-info - Generates build information that can be used by the Actuator.



Question 7:

How can I enable auto reload of  Spring application with spring boot? 

Answer:

We can enable auto reload of spring application by using spring boot developer tools.

Adding spring boot developer tools to the project is very simple.

Add this dependency to pom.xml:


<dependency>

    <groupId> org.springframework.boot</groupId>

    <artifactId>spring-boot-devtools</artifactId>

    <scope>runtime</scope>

</dependency>

Restart the application.


Question 8:

What is the use of Embedded servers?

Answer:

Think about what you would need to be able to deploy the application on a virtual machine:

  • Step 1: Install Java
  • Step 2: Install the web/application server
  • Step 3: Deploy the application war
What if we want to simplify it?
How about making the server a pat of the application?

We just need a virtual machine with java installed and we would be able to directly deploy the application on the virtual machine.

This idea is the genesis of Embedded servers.
When we create an application deployable , we would embed the server (for example tomcat or jetty) inside the deployable.

Embedded server is when the deployable unit contains the binaries of the server (example tomcat.jar)


 
Question 9:

How can we use profiles to configure environment specific configuration with spring boot?

Answer:

Profile is nothing but a key to identify an environment.

In this example, we will use two profiles

  • dev
  • prod

The default application configuration is present in application.properties. Let’s consider an example.

application.properties

  • basic.value= true
  • basic.message= Dynamic Message
  • basic.number= 100

We would want to customize the application.properties for dev profile. We would need to create a file with name application-dev.properties and override the properties that we would want to customize.

application-dev.properties

basic.message: Dynamic Message in DEV


Similarly you can configure properties for prod profile.

  • application-prod.properties
  • basic.message: Dynamic Message in Prod

Once you have profile specific configuration, you would need to set the active profile in an environment.

There are multiple ways of doing this:

  • Using -Dspring.profiles.active=prod in VM Arguments
  • Use spring.profiles.active=prod in application.properties



Question 10:

Which file is required for application configuration with spring boot?

Answer:

The file name is application.properties.

application.properties can reside anywhere in classpath of the application.



Question 11:

How does spring boot reduces configuration?

Answer:

A Web Application using Spring MVC and JPA (Hibernate):

·         Pom.xml

·         Configure Service/DAO Layer Beans using JavaConfig

·         Application.properties file

·         Log4j.properties file

·         Configure Spring MVC Web Layer Beans

·         Register Spring MVC FrontController Servlet DispatcherServlet

·         Create JPA Entity

·         Create Spring Data JPA repository

·         Create a SpringMVC Controller

·         Create a Thymeleaf View /WEB-INF/views/index.html

 

Using Spring Boot:

·         Pom.xml 

·         Application.properties file

·         Create JPA Entity

·         Create Spring Data JPA repository

·         Create Thymeleaf view

·         Create SpringBootEntryPoint class



That's all for this post.
Thanks for reading!!

No comments:

Post a Comment

CAP Theorem and external configuration in microservices

 Hi friends, In this post, I will explain about CAP Theorem and setting external configurations in microservices. Question 1: What is CAP Th...