JAVA Updated Interview Tips

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 4

Java Developer - Interview Questions

1. Describe your experience and what are the technologies that you possess.
java
springboot
Oracle DataBase
2. Which are the feature in Java 8 that you are familiar with?
foreach and Iterator
3. Have you made use of any Java 8 feature? (Follow up questions regarding the
features that you will mention)

4. What are the concepts in J2EE/JEE that youa are familiar with?
Client Tier (Front End) -
Middle Tier (BackEnd / Business Logic) -
Data Tier (database) -

5. What are the differences between a LIST and a SET.


(Significant difference: You cannot put duplicate element in SET)
6. What is your experience in Spring boot?

7. What do you understand with Dependency Injection?


- Its responsibility is to inject dependencies using either setter or constructor
methods

(Possible follow up questions:


A. Is it possible to inject any object in to any class using the Autowired
Annotation?
- No, because the object may not be part of the component scan or there is no
spring anotation
B. Is it possible to inject a POJO object/Plain Old Java Object in to another class
using the Autowired Annotation?
- Answer is: NOT POSSIBLE)

8. Explain what is Autowired in Spring boot and why do we use it?


- Autowiring feature of spring framework enables you to inject the object
dependency implicitly(indirectly).
It internally uses setter or constructor injection

9. Why do we use Spring API?


- It allows you to create REST APIs with minimal configurations. A few benefits of
using Spring Boot for your REST APIs include: No requirement for complex XML
configurations.
Embedded Tomcat server to run Spring Boot applications.

10. Can you tell me the difference between GET and POST method in HTTP.

- Both GET and POST method is used to transfer data from client to server in HTTP
protocol but
Main difference between POST and GET method is that GET carries request parameter
appended
in URL string while POST carries request parameter in message body which makes it
more secure
way of transferring data from client to server.

REST API Part:

11. Let's imagine I have a Spring boot application with 2 REST API, defining the
controler class and 1 of them is a GET Method
and the other 1 is a POST Method, both these Methods have the same request mapping;

Let's call it /abc (both methods have the same endpoint, as in the request URI that
we used to access this API /abc) now, if I ran this application in my local machine
and I go to the web browser and in the URL part I type localhost:8080/abc will it
be GET Method be called or will it be POST Method that we called?
(Leave the Postman part aside and concentrate on the web browser, what will happen?

*Answer: It will execute a GET Method and it will return you a Image in JSON)

(Possible follow up question: If I remove this GET Method from my controler class
all together and I reroute the application and I again, go to the browser and type
localhost:8080/abc, what would happen?
(*Answer: Error 405 - Method not allowed)

12. If you are trying to call a POST method by sending a GET request, what kind of
error do we get?
If you write localhost:8080/abc, what the browser will do is look for methods
with /abc which is there;
however, it woould try to access it using GET which is not there, so, What kind of
error can we expect?

13. Are you familiar with Microservices Architecture? Define Microservices


Architecture and tell me what are the advantages of Microservices compared to the
Monolytic Architecture?
A microservices architecture is a type of application architecture where the
application
is developed as a collection of services. It provides the
framework to develop, deploy, and maintain microservices architecture diagrams and
services independently.

14. How does REST API's communicate with each other if I want to make an API called
from 1 REST API to another, how would I be able to do that? (By using REST Template
or Apache Kafka)

12. Give some advantages of Spring boot over the conventional Spring MVC
Architecture.
1)We need to setup the server explicitly(manually) while spring boot has an
embedded server.
2)Deployment descriptor is required for spring to work while it does need any
descriptor in spring boot
3)Faster to deploy since there is less time to configure spring boot
4)The lines of code is less in spring boot than in spring
5)Must define dependencies in pom.xml manually in spring while pom.xml
handles
the dependencies internally for springboot

13. How do Microservices communicate with each other?


Micro services can communicate using
Http communication(synchronous), message broker(Asynchronous) and Service
Mesh

Http communication(synchronous) - send each other http request between


endpoint and waits for response.
Message broker(Asynchronous) - publich message to message broker and the
broker fowards it to the other service.
Service Mesh - commonication logic the delegates communication between
services.
Disadvantage of Microservice
needs to be configured
hard to monitor which service is down

14. What are the diff between SOAP and REST API?
1)soap has predefined rules that must followed while rest api has loose
guidelines and recommendations
2)Soap is function driven (data is available as services ex. getuser())
while rest data driven (data is available as resources)
3)SOAP is by default stateless (possible to make it stateful) while rest is
stateless
4)SOAP cannot be cached while rest can be cached.
5)SOAP requires more bandwidth and computing while rest requires less.
6)SOAP only supports xml while rest supports like plain text,html,xml and
json.
7)SOAP works on HTTP,SMTP,UDP and others while rest only works on http.

Rest must be with limited bandwidth.


Rest can be used where state feature is not needed.
Rest must be used where caching is needed.

SOAP must be used asynchronous processing and security.


SOAP must be used when there is need in formal communication
SOAP must be used when stateful feature is needed

15. What are the ORM that you are familiar with? (For example: Hibernate or
MyBatis)

DATABASE Question:

16. Let's say I have a Table called Product and this product Table has 3 columns
which are: ID, Name, and Price. Now, if I have to find the product with the highest
Price, what would my SQL Query look like? (*Possible Answer: Select ID NAME comma
MAX PRICE from product)

(Possible follow up question: Is it possible for you to get the same result without
using the MAX Function? Tell me how your Query will look like. *Answer: Yes. Query
will look like: Order by Price decending then at the end you can just specify Limit
"What" Row)

OR

(Get the highest price with the ID and Name using MAX Functioction. *There are
several way that you can answer this but one is: Select ID Name Price from product
where Price =(Select Max (Price) From Product)

Abstraction is a process of hiding implementation details and exposes only the


functionality to the user.
In abstraction, we deal with ideas and not events.
This means the user will only know “what it does” rather than “how it does”.

There are two ways to achieve abstraction in Java

Abstract class (0 to 100%)


Interface (100%)
The practice of keeping fields within a class private, then providing access to
those fields via public methods.
Encapsulation is a protective barrier that keeps the data and code safe within the
class itself.
We can then reuse objects like code components or variables without
allowing open access to the data system-wide.

Inheritance is the process of one class inheriting properties and methods from
another class in Java.
Inheritance is used when we have is-a relationship between objects.
Inheritance in Java is implemented using extends keyword.

Allows programmers to use the same word in Java to mean different things in
different contexts.

You might also like