Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Accenture II

Download as pdf or txt
Download as pdf or txt
You are on page 1of 13

Accenture Round I

1 Introduction
2 Java 8
3 Functional Interface
3 LambdaFuntions
4 Streams
5 How map collection work in the background /Hashmap
6 Concurrent modification exception
7 Course error
8 Swagger
9 Json response
10 Maintain code quality
11 Create springboot project
12 How change the default configuration
13 What is Microservices and difference between web services
14 How u connect mysql
15 Saving bulk records in mysql

16 scheduling processes in Springfield


17 @ scheduled/@enable
18 AOP
19 excel api
20 @query for custom query
21 hibernate relationship mapping

22 Hibernate Transaction Example

1-so i have been actually working into a micro service based architecture where almost all services
most of them are actually there into spring boot itself and for the inter-service communication part we
are using kafka for the ui to actually fetch the data configure some kind of data or interact with backend
services and for storing the data we are using mysql over here apart from that we are using git as a
versioning tool uh we are also using uh docker for blocker containers for testing and deploying and the
build purpose we are using Jenkins as the tool for creating user stories and um different kind of bugs
so my roles and responsibilities are basically the discussions and apart from that majorly involved into
implementation of changes along with unit testing and bug fixing for unit testing we are using j unit and
mocking purpose we are using Mockito framework

2 Java 8

2-yes i actually am using java version 8 over here in this particular project so how many of functions

3 Functional Interface
3-Java 8 introduces a new category of Interface called Functional Interface. They are special cases of regular interfaces that
have only one abstract method and one or more default methods.
interface Calculator {
int doOperation(int num1, int num2);

default boolean checkValues(int num1, int num2) {


return (num1 > 0 && num2 > 0);
}
}
This interface is a functional interface. But by chance, if we add one or more abstract methods in this interface compiler will not
complain. The compiler will simply consider this as any normal interface.
In order for the compiler to restrict the addition of more abstract methods, we need to use annotation @FunctionalInterface.
@FunctionalInterface
interface Calculator{
int operation(int num1, int num2);
}

Now, if by chance we add another abstract method compiler will show an error.
Functional Interfaces are very useful for defining Lambda Expressions which we will study later in this course.
There are many inbuilt functional interfaces given by Java. You can read more about Function Interfaces here.

3 LambdaFuntions
3a- yes yes basically lambda functions are actually used to provide the implementation of you can
say abstract methods into a functional interface here these are anonymous functions into which you
can actually using like for example uh it starts with a curly brace and then you can provide okay this this
particular suppose for each employee you are writing so e and then you can provide like dash and
arrow symbol and inside the curly braces you can actually write provide the method uh function body
basically so so likewise this we actually write a particular lambda function

4 Streams
4-streams are basically so you can actually process the collections yeah so streams are actually
introduced as part of java 8 which you can actually process a particular collection um into java 8 so you
can use the stream method for that which actually uh converts it into stream and further you can
provide like intermediate operations there are two types of operations intermediate and ternary
operations or i think for terminal operations it is so with intermediate operations like your filter you have
map like for processing the the stream data we use intermediate operations and for like returning for
example you want to use a list you want to return set you want to find the average you want to find the
sum for that we use actually terminal operations which so so collect method minimum maximum
average these are actually terminal operations into a stream

5 How map collection work in the background /Hashmap


5- yeah so basically map have key value where keys are unique values can be duplicate so as soon as
you do a put on map so what happens is initially when you create a map it has a bucket size of 16. so as
soon as you do a dot put it actually gets the hash code from the object class or if you have overridden
the hashcode it and apart from that it will do a mod by capacity like like initial capacity 16 so it does a
hash for mod 16 so anything that will be the resultant will actually land up between 0 to 15 so suppose it
lands upon 2 the hash for mod 16 is actually 2 so on the second um the second bucket it will actually it
will first check equals if there is already a key with that it will replace that if it is not there it will actually
create a new node for a linked list and add a particular node on the second second bucket position

6 Concurrent modification exception


6-yeah so basically we get that in fail first collections so basically like for example i have a list and i am
trying to iterate through that list and while i iterating i try to modify that list as well so in that case that
will throw concurrent modification exception so we can use like safe collections in that case or maybe
modify it before or after but do not modify it while iterating over them

What is course error


7-yeah so basically suppose you have a ui and you have your backend services so when your ui tries to
communicate to the backend service there are certain course filters which you need to enable where
you provide okay my request will be coming from this particular place from this particular ui and it
should be authorized so if you do not provide that you will not be able to actually hit your back end so at
the back end you need to provide i think there is an annotation @ allow origin so into that you have to
actually provide the origin from this the request is coming that you will consider as mandated otherwise
if you do not provide that you get the course error

8 Swagger

8-swagger is basically used for providing api documentation and apart from that you can also hit like
usually use postman to hit your end apis however if you configure swagger into your particular
application so what you can do is it will provide you the documentation okay these are my list of apis
and it actually you can like hit it for a particular service suppose your host name colon your port
suppose it is running on 8080 you do a slash swagger ui.html so in html you will be able to see where it
will show you okay these many endpoints are there these are get the these are put these are post end
points and when you click on it you will be actually able to see that in the request payload you have to
this kind of a schema will be there that you have to provide as part of the request and you can hit the
request from there as well it will also list you down that uh for this particular end point you can have
these many kind of responses suppose it is a create first endpoint so you will have 201 created the 400
things like that it will also show you and you can definitely hit the end point and get the response as
well from there

9 Json response
9-yeah so jason is basically like into a spring boot application if you're using rest controller so your auto
configuration basically um you know maps like suppose i return a bean so what auto configuration
does is auto configuration automatically using a jackson object mappers it automatically configures
that into json and returns you so at the time of returning those object mappers are actually used and
internally using the auto configuration spring does that when you are returning a pojo it will get
converted into json and you will be able to see at the client time that this particular json you have got so
json is basically a schema that you can get from from any particular endpoint in json body you can have
arrays json objects things like that
can you tell us how you maintain code quality
10-so we are actually using sonar cube for that it does the static analysis over the code and apart from
that it actually uh also calculate the code coverage we have so we are actually writing j units and we
are maintaining almost 95 percent of uh coverage in all our services so as soon as like you create a pull
request it runs jenkins jobs onto which it is it is doing it is executing the j units and it is also doing the
sonar cube does the static analysis like there are critical major minor issues whatever are there there
for the static analysis part and it also measures like complexity that a particular method can have these
many number of if else checks so likewise that it actually does the static analysis and also calculates
your code coverage uh so if if your code coverage is beyond 95 it will uh automatically uh you know
your build will pass then only you will be able to merge your code otherwise you will not be able to
merge your code bill will actually fail

okay so uh can you just tell me if i want to create a spring boot project uh how do you go about
it what are the configurations and springboot projects
11-yeah so basically in order to create a spring root project what you can do is uh you can either use uh
spring dot initializer dot io there you can actually you know provide the initial set of dependencies
whatever you want suppose db you want mysql so you can have it and it can actually create a
springboot project for it you can download from there you can provide a group id artifact id and
everything uh likewise it will actually you know create a springboot project for you and you can
download and start importing it into your intellij or sts whatever you are using that will actually create a
basic application for you

okay so so uh how do you change the default configurations that are already there like you
know if i don't want to use the embedded db how do you change those settings the people
12-So in case by default it runs on 8080 and you want to run in another port so you change server.port
in application.properties as soon as your application starts it will start on that particular port apart
from this you mentioned like changing the default server uh usually we have tomcat server onto which it
gets deployed so if you want to use some other servers so you can use other server in your pom.xml
which your application to be deployed there you can actually provide that as a dependency in pom.xml
and then as soon as your application starts it will deploy on that particular server that you have
provided as the additional dependency

What exactly Microservices and difference web services


13-yeah so web services basically an you know independent application that you
can use for some kind of you know performing some kind of business you know
implementation or logic suppose i have an application that returns me some
employee related

data it maintains it and it returns me stores creates employees so that is a web


service which can be accessible over web and that is independent in itself if you
talk about microservice microservice is actually a combination of small services
which are

independent in itself but they can communicate with one another to form a
particular application the major advantage with microservice that comes into
picture is scalability so suppose for instance i am not sure what uh flipkart is using
like suppose uh
there is this application of flipkart and we have like multiple micro services
different services into it like for example one is for product catalog one is for order
related uh data one is for uh you can say some kind of user user related data which
deals with all

the accounts of the users and and their related details so if i log in so basically i
will be able to see the product catalog i can see my own personal information
which will be coming from some user related service i can see whatever orders
have placed so that will

be something that user service will actually get from order service okay this is a
these are the previous past 10 orders that this person has placed so something like
this so this this kind of an architecture where multiple independent applications
are actually

talking to each other to solve a particular business purpose this is um basically a


micro service so suppose i have like for example daily i have for instance one
million users that actually hit this particular flipkart application and they they
browse through it and
place orders now there is some big billion sales coming in so the for instance
those 1 million users actually call up to 4 million users now what happens is um
definitely there will be a lot of load that will be put so they have anticipated okay in
our big billion sale

there will be around four million users so at run time so you can actually configure
that at runtime you can actually increase the number of instances of a particular
application suppose my user application is going to get a lot of hits so at runtime i
can actually

scale that particular application so that it it maintains the load in a proper way and
it doesn't you know stop responding or there is some issue because of heavy load
so this is what the micro service is all about

14 How u connect mysql


14-yeah so basically um into our application.properties we actually provide the host and port on to
which the mysql has to connect to apart from that you can also provide a database name if you want
and
creating an interface the repository interface and annotating with @repository annotation and we
extend the repository similarly we have like a CRUD repository or JPA repository we have specific to
MYSQL we have repository over there so as soon as you extend it so JPArepository you get like
default methods for example save save all or delete by id delete and apart from that you can find find all
find by id so all these default methods actually come come along with that
15 Saving bulk records in mysql
15-So you can provide saveall and you cal also provide list of all your entities at you actually want to
save

so you have also written in your cv uh that you have worked on cassandra and what is difference
between Cassandra and mongodb
A-yeah yeah you can say into mongodb if you have suppose a high availability kind of a setup and you
have one as master master and other working as slaves so when master will go down anyone will
actually become the any one slave will be elected as the master and likewise that actually the entire
replication concept is there in mongodb whereas in cassandra db in the cluster itself you have um
almost all the there is no concept of master slave all of them are actually working as master itself so
you can actually in the data replication is quite fast so if you talk about speed and scalability so in that
case because of this reason cassandra is better than mongodb both are no sequel but performance-
wise Cassandra is better

16 scheduling processes in Springfield

so with respect to spring have you used any scheduling processes in springfield like patch
you know about batches and you know about schedules right which run probably likely pins or some
prawn jobs have you come across something like that
16-yes yes i have used schedulers basically

17 @ scheduled/@enable
but what does it do and how do you configure them
17- yeah so we can do it using @ scheduled annotation so into that basically you can provide the
fixed delay or something like whatever whatever delay with which delay you want to actually run that
yeah so basically here we use @ schedule annotation and you can annotate it over a method you can
define the fixed delay inside that with which delay suppose i want to run it within every one hour so i
can give the delay over there and apart from that i can define whatever my functionality is like usually
we delete the scale entries um into the database um which which actually elapse a particular time
period uh on to which that particular thing has to be processed if that is elapsed we usually delete it
from the database for cleaner processes we basically use it and you can also use @ enable scheduling
annotation to enable your scheduling basically

have you used any related apis i have only still reading for reporting

A- yeah i have used apache boy for that

18 AOP
18-Not very much onto it but yes i have like used basic point cuts i have created for suppose i have a
logging purpose or some other different purposes so we usually create point cuts and in the around
advice basically we actually execute some particular logic and then we execute other things onto our
controllers we are actually using certain kind of point cuts

you said you used excel api or apache pi


19-yeah actually we have like uh you can say a very huge excel file that actually gets imported into our
application so that is bulk device import so so using that excel there are multiple devices into it a very
huge number of thousands of devices are there so for you know passing logic on those devices we
have used apache

so uh i have a question i have a scenario um and in the organization i have some basic things like
organization name organization id okay organization location like where the organization is situated and
inside that i have a huge array of all the employee data just exactly which i'm giving okay it can be tacky
right you know there can be an array inside the talking right yeah yeah so it's the collection is very huge
now there is a dashboard in which i just want to display uh details of organization like id name and
where is the organization currently situated i don't want uh to prevent the details of the employees
which is stored inside this collection yeah okay uh but when i am displaying the data on the dashboard
it's taking a lot of time because i have used find by id and it is getting me the whole data set of the
collection of one full document so how do i improve the performance
20 @query for custom query
20- so your problem is that it is taking a lot of time off for fetching the data from the database right okay
yes because the collection size is too huge i cannot say collection i should say document size is too
huge okay so uh document size is too huge and there are a lot of streams in this document but i may
not be requiring all of the scenes but i have used find by training so i think it will written all the things
right okay yeah if you ever if you have actually done fine by id it will actually return you all the fields you
can say use custom query for that like i can provide the @query annotation to just you know find the
query to just get me the name location etc for this particular id basically what you can do is you have
some kind of you know default methods like find by idea things like that which are already defined in
the repository but if you want to you know provide your custom queries you can use @ query annotation
and inside double quotes you can actually provide the entire query which you want to hit so i can do
simply like select you know name this name id location from whatever is your collection name
organization where id is equal to this so if that will just return me that particular data only

21 21 hibernate relationship mapping

22 22 Hibernate Transaction Example

An-so a high documents i haven't actually written those documents but high-level documents are
basically you know kind of high-level description of all your services like for example i have um you
know one of my service suppose for example i have a user service so in hld basically we will have we
will define whatever functionality that service will do and what will be the basic things that it will do and
apart from that uh this uh these many endpoints it is going to expose to the user and low level is
basically how you are actually going to implement that particular thing into more detail and technical
terms

You might also like