Showing posts with label Interviews. Show all posts
Showing posts with label Interviews. Show all posts

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!!

Tuesday, February 4, 2020

Java Interview @ OLX

Hi Friends,

I hope you all have read all my previous Java Interviews:




Here in this post, I'm sharing interview questions asked in OLX.



Question 1:

If you have three, you have three. If you have two, you have two, but if you have one, you have none. What is it?

Answer:

Choices


Question 2:

3 bulbs 3 switches problem:

There is a room with a door [Closed] and three light bulbs. Outside the room, there are 3 switches, connected to the bulbs. You may manipulate the switches as you wish, but once you open the door, you can't change them. Identify each switch with it's bulb.

Answer:

Turn on 1 switch and keep it on for 5 minutes. Now turn it off and turn on 2nd button and enter the room. Now the bulb which is ON  maps to ON switch.The hot bulb maps to previous  switch [which was turned on first]  and 3rd bulb maps to 3rd switch.


Question 3:

REST API must use HTTP. Is that true or false?

Answer:

FALSE



Question 4:

A resource in the context of REST is (or may be) which one of these:


  • Thing
  • Object
  • Real World Entity
  • An account
  • An Item
  • A Book
  • All of the above


Answer:

All of the above



Question 5:

Suppose you have a "Worker" table as shown below. You have to write a SQL query to find employees with different salary.

Show only 2 Columns in output: first_name and salary.




Answer:

select distinct w1.salary , w1.first_name
from Worker w1, Worker w2
where w1.salary = w2.salary
AND w1.worker_id = w2.worker_id;



Question 6:

Write SQL query to display first 5 records from the table shown above?

Answer:

select * from worker LIMIT 5;



Question 7:

What is the difference between UNION and UNION ALL?

Answer:

UNION removes duplicate records.  UNION ALL does not.

There is a performance hit when using UNION instead of UNION ALL, since the database server must do additional work to remove the duplicate rows. But usually , we don't want the duplicates especially when developing reports.


Question 8:

What are foreign key and super key?

Answer:

Foreign Key:

Foreign key maintains referential integrity  by enforcing a link between the data in two tables.
Foreign key in child table references the primary key in parent table.
The foreign key constraint prevents actions that would destroy the link between the child and parent table.

Super key : It is a column or a combination of columns which uniquely identifies a record in a table.

e.g.:

Super key stands for superset of a key. e.g. We have a table Book with columns:
Book (BookID, BookName, Author)

So, in this table we can have:


  • (BookID)
  • (BookID, BookName)
  • (BookID, BookName, Author)
  • (BookID, Author)
  • (BookName, Author)
as our super keys.

Each super key is able to uniquely identify each record.





That's all from this Interview.

Hope this post helps everybody in their job interviews.

Thanks for reading!!

Monday, February 3, 2020

Java Interview @ OrangeMantra

Hi Firends,

In this post, I'm sharing interview questions asked in OrangeMantra.

Also read Questions-Answers asked in other interviews:





Question 1:

List all types of HTTP Error code categories

Answer:

There are mainly 5 categories in HTTP Response codes:


  • 1XX : Informational
    • 100 : Continue
  • 2XX : Success
    • 200 : OK
    • 201 : Created
    • 202: Accepted
    • 204: No Content
  • 3XX : Redirection
  • 4XX : Client Side Error
    • 400 : Bad Request
    • 401 : UnAuthorized
    • 402 : Payment Required
    • 403 : Forbidden
    • 404 : Not Found
  • 5XX : Server Side Error 
    • 500 : Internal Server error
    • 501: Not Implemented
    • 502: Bad Gateway
    • 503: Web service not available


Question 2:

List all the features in Java 7

Answer:

There are multiple features which have been added in java 7:

  • String in switch
  • try with resources
  • Binary Literals
  • multiple Exception types in catch block


Question 3 :

Explain about one very typical designing/Coding situation which you have solved.

Answer:

I answered as per my experience.



Question 4:

Explain all differences between Stack and Heap?


Answer:

  • Heap is very large in size while Stack is small in size as compared to Heap.
  • Every thread has it's own Stack while Heap is shared among all threads.
  • When Heap gets full, java.lang.OutOfMemoryException is thrown. While in case of Stack, java.lang.StackOverflowException is thrown.
  • Heap is mainly used to store the objects, while Stack is used for storing local data, method body , method return values etc.
  • Heap is tuned by using -Xmx and -Xms options. While Stack size is tuned by -Xss.
  • In Heap, data is stored in random order. While in  Stack , data is stored in LIFO [Last-In-First-Out] order.


Question 5:

What is the contract between natural ordering and equals() method in java?

Answer:

Contract between natural ordering or ordering provided by comparator interface and equals() method is that the output returned by natural ordering / comparator interface should be consistent with value returned by equals() method.

If these values are not consistent, then it will lead unexpected results in TreeMap and TreeSet Collections.



Question 6:

What is the use case of Marker interface ? How to write custom marker interface?

Answer:

Marker interface is used to indicate something special to JVM/Compiler so that it can perform necessary actions on the class implementing marker interface.

Examples of marker interfaces are : Serializable, Cloneable, Remote

Custom marker interface:

public interface Ingestible{
    //nothing
}

public interface Edible extends Ingestible{


}


public interface Drinkable extends Ingestible{

}


public class Food implements Edible{

}


public class Drink implements Drinkable{

}


public class Person{

    public void ingest(Ingestible something){
        
         if(something instanceof Edible){

              System.out.println("something can be eaten");

         }
    }
}

In above example, we are telling JVM that the class implementing Ingestible interface can be ingested.

Use case:

A marker interface is used for Identification purpose.



Question 7:

Why to use BigDecimal over Float or Double?


Answer:

Float and Double cannot be used for precise values: e.g.:

double d1 = 131.44;
double d2 = 130.34;

System.out.println("d1 - d2 = "+ (d1-d2));

Output:  1.10000000000013

That's why in financial applications, where while doing calculations , scale and rounding mode for the numbers is an important aspect . So it's a better choice to go with BigDecimal.


Using BigDecimal:
BigDecimal bd1 = new BigDecimal("131.44");
BigDecimal bd2 = new BigDecimal("130.44");

System.out.println(bd1-bd2);  gives 1.10







That's all for this interview post.

Hope this post helps everybody in their java interviews.

Thanks for reading !!


Monday, January 27, 2020

Interview @ NexGen Solutions

Hi Friends,

I'm sharing my recent interview @ NexGen Solutions. It was for the  position of Technical Architect and was very simple one.

You can also go through my other real time interviews:

Interview @ Dew Solutions
Interview @ RBS
Interview @ Aricent



Question 1: What is the benefit of Executor framework?


Answer:

Executor Framework provides separation of Command submission from Command execution.
It has several interfaces. Most important ones are:


  • Executor
  • ExecutorService
  • ScheduledExecutorService
Executors is Factory methods class used in this framework.




Question 2: Asked me to write custom ArrayList.

//You can write your own implementation


Question 3: In your Custom ArrayList, there are multiple methods. How will you provide synchronization?

Answer:

We have two ways of providing synchronization in this source code:


  • Make each method synchronized by placing synchronized keyword before return type of method
  • Use synchronized block inside method body.



Question 4:

How did you use Amazon EC2?

Answer:

I installed EC2 instance using Amazon Management console after login into it.
I used General instance for my purpose, as in my application I needed to send multiple emails to client very fast.



Question 5:

What is the benefit of Generics in java?

Answer:

Generics provides Compile-time safety. And it also avoids ClassCastException. It was introduced in Java 5.



Question 6:

How Generic code written in java 5 runs in Java 4 compiler?

Answer:

Java compiler uses type check information at compile time and after all validation it generates type erased byte code which is similar to the byte code generated by Java 4. So, it provides backward compatibility.


Question 7: Asked about my last project.

Answer:

I explained it.


Question 8:

Why we can't pass List<String> to List<Object> in java?

Answer:

String is a subclass of Object, but List<String> is not a subclass of List<Object>.

If it would be allowed, then look at below code:

List<Object> listO = new ArrayList<String>();
listO.add("String");
listO.add(new Object());

Now, in the same List , we have both a String and Object object. Which is wrong.





That's all from this interview.
Hope this post helps everybody in their job interviews.

Thanks for reading.




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...