Mock Interview 3+ years experience | SDE-1 | Microservice | Java 8 | Spring boot | Code Decode |

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys welcome to codee decode for today's mock interview we have vami with us he is having three plus years of experience so let's get started with this interview also if you want to be the part of this interview series just add your details in the Google form which is whose link is given in the description below so now let's get started uh Hi vami how are you uh hi ma'am uh I am very good thank you thank you so much for connecting and sharing your knowledge to the committee can we get started with the mock now yeah sure okay so uh I'll start with uh very simple basic ones so I think you I can see Java it in your resume uh any clue what are the new features that were added in Java it which were not there previously uh some of the features introduced in Java uh related to functional interfaces and mostly Java they have introduced uh for functional program programming before Java uh there was no concept of functional programming in Java and also Lambda Expressions uh default and static methods in interfaces predefined interfaces uh like predicate function consumer and Method reference and Constructor reference uh in case of uh uh Lambda Expressions we can also use method reference and stream API date and time API and optional class okay and any reason why functional interface was introduced because I know that Java was pure object Orient almost objectoriented language not completely but then why functional interface used any clue why functional programming yeah functional programming was introduced such that we can pass a function as an argument to a method and also functional interface was introduced uh such that we can have only one abstract method in the interface we can make uh an interface as functional interface by forcing it as by forcing like we can use at functional interface annotation about the interface and we can have only one particular abstract method inside the interface awesome okay uh sounds good to me also why Java is not purely object oriented language so we have uh primitive uh data types like in short bite so use using those uh data types we can't say that Java is a complete object oriented language okay and how do you come across uh like what uh classes are around those particular Primitives which make them objectoriented we can use a concept of rer classes so which can convert the Primitive types into object oriented for example if it is int you can convert into integer reer class okay and why were these wrappers introduced why do you want to convert these Primitives to objects any reason specific reason why for example if you're using any collection data structure you are using list of integer instead of list of int so in that case we need to use Raper classes perfect sounds great uh okay any uh knowledge about the internal working of hashmap any changes that were done in java8 with the HH map changes yeah uh for example uh you're are uh adding value key and value uh into the map okay uh for example after some uh threshold value the link list will be converted into tree nice and why was that done uh in order to get the value from the map uh we know that the complexity uh time complexity uh to get the value from the map will be big of one but when we are iterating through the entire link list it could be big of one so when we convert the link list to three the time complexity will be reduced and how this could be the reason and what will be the worst time complexity with this tree maximum it could be big of login I'm not sure completely yes that's true it can be the verse complexity will change from order of a to order of log so that was a performance perfect perfect so uh yes that was done as a performance improvement with jav correct uh then any clue what changes were done with java8 in garbage collection with any Heap area memory area any changes that were done in case of uh garbage collection uh they have come up instead of uh there is one particular concept of perm gen so uh I think they have come up with the new concept of perm gen in Java so initially it was using something called as metaspace metaspace yeah from metaspace they have come up with the new concept of firm gen and any clue what changes were done there all the static members and the class definitions like all the metadata will be stored in the perm gen okay why was default methods introduced in interface with jav so default method if I talk about uh mainly it came into picture for solving the limitations of interfaces for adding more functionality to the methods in interface without breaking the implementation of classes for example I have a class called book and also I mean I have an uh book interface and this book interface is being implemented by two other classes called fictional books and also Forest books in fictional books books I want a separate method and in Forest books I want a separate method but I want these two method to these two classes uh to be implemented by one particular interface in such case I want a particular interface uh in the in that particular interface I'm writing some methods and I don't want all the methods to be implemented by both the classes right in such case I'll make the uh method as default in the interface and I'll write some logic inside that particular method and whatever class I want to override that particular method in that class I'll override it such that no other classes which is not requiring that particular inter method will not override it so if I want I can change its implementation in my own class can I yes yes you can override the implementation in the required class okay okay sounds good to me uh there are multiple type of inheritances right so which inheritance is not allowed in Java multiple inheritance is not allowed in Java okay and any way Java try to implement multiple inheritance using classes you cannot uh use multiple inheritance but using interfaces uh you can uh use the concept or implement the concept of inheritance multiple inheritance so how you can't extend two or more please you can't extend one or more classes but you can Implement two or more imple interfaces okay but then uh how it doesn't affect uh with interfaces me what why why are you able to do multiple inheritance with interfaces while you are not able to do it with classes why there could be same method inside the classes but there there couldn't be same method in the in inside the interfaces maybe that could be the reason okay so you you want to say that uh interfaces do not have implementations classes have so if my same method say U same method will be in the same classes so that is why since there's no implementation within the different classes okay okay but then the respective me but then with default methods you have the implementation now H correct we have the [Music] implementation any this this problem is called as Diamond problem so do you know about this diamond problem uh I heard it uh but not sure clearly no problem I'll help you with this so Diamond problem is when two classes have the same implementation and when you are extending it you are confused to take the implementation from home for example I have an animal class who has a method eat I have an uh fish class who whose method is eat and it just drinks water two implementations different implementations now if I extend both animal and fish you are confused I want to eat or I want to just drink water so this is the diamond problem that is the reason classes do not have it but initially with before java8 there was no interface as implementation so whatever method you take it will give its own implementation but with Java it now they have default methods so I can have interface one and interface 2 both can have method eat and drink now if you extend interface I Implement interface i1 and Implement interface I2 you have two methods eat and drink how will you decide from which interface to take this problem again arise with jav any clue how now this is solved you have inter and inside interfaces you have two different methods one is eat and drink in both the you're overriding for example so I'll give you one simpler example I have an animal I have a method legs uh so animal will have a default implementation I have four legs and then I have I'll have a interface as human I'll have a default methods legs and it will Implement I have two legs now now I have a particular class say mammals I'll Implement both animal and human both are mammals now I I'm uh like implementing the I'm taking it from the parent the number of legs method I have confusion it should have four legs or it should have two legs so how will I decide I have to take my legs the mammals have to take its legs from animal or from the human [Music] it is not having any input right so default has if it is having any default methods of implementation yeah based on the input you can pass you can get the implementation no no so I have my class members it implements I i1 comma I2 now it will give you an uh and then by default you will over uh extend everything and uh whatever you have as a default method in your particular class now you will have a problem so how will you fix this yeah we problem we implementing both I have read about it but I'll give you one not able to recall this this was change only done with Java 8 what they have done is they have used a super keyword so super. interface name do number of legs so you can say that uh this interface do super do four like uh like legs so four legs will come from anywh that's how you can do a super keyword just have a look and you a super keyword interface name and you will be good to go that was the change that was done with Java so uh that is done now any clue why optional was introduced with jav optional was introduced in order to avoid null pointer exceptions um there are different types of methods which was introduced in optional for example optional. empty optional do off and optional do off nullable mainly optional. empty this method returns an empty uh optional object and indicating that uh it doesn't contain any value and also it is mainly often used to initialize any optional object whenever like you know it should be empty and coming to optional do off uh this method creates an optional object and that contains a non- null value and it it basically throws null pointer exception if the provided value is null and in case of optional do off nullable this method basically creates optional object and that contains a value and which can also be null yeah these methods we are using as of an option and how do you check uh so in the if condition you'll pass that particular that is rather than checking the N pointer so can I directly do say optional o equals to something of optional and you have created your optional object and now you're checking o equals to equals to n is that a right implementation uh we can check optional dot empty so we can use optional do is empty or if present so using those methods we can pick so basically you should not check the optional with null directly because it will contain it will just n perfect sounds great n I'll I'll move to microservices as it is also written in your resume are you comfortable with it yeah yeah I'm comfortable good so I'll give you one small example I have my micros service application there are suppose 10 micros service application and one transaction spans across all 10 microservices like I'll give you one very very simple example of like swiigy or zato any food delivery application so what you do is you select something you put it in your cut you place the order you do the payment delivery partner is assigned and Order reaches to you what if the payment fails in between you have to roll back all you have to cancel the order right we need to roll back yeah so the this transaction you can see is not in one particular application it is across the whole micros services so what what kind of distributed transactions you can handle how how can you handle this particular distributed transactions in micr [Music] Services uh there is a concept called event driven architecture okay or inside the event driven architecture there is a pattern called Saga design pattern which solves this particular transaction distribution distributor transaction problem so here we are taking for example s or any food delivery app where we are sending uh different types of uh microservices where we are having order payments delivery Etc so once we have selected any uh service or any dish so we'll be adding into the cart so once we have added it to cart it should send an event or trigger an event so such that based on this triggering event the other microservice triggers okay and uh so you have you have done order you have added into the cart you have done order which is in the in the order microservice and this is also success when it is Success it will trigger an event and it will have the payment so now once the payment is down or something happened you got an exception and the payment is failed or cancelled so then uh it will trigger an event such that uh it will be moved to the I mean it will trigger uh such that the transaction will be rolled back okay and uh what is this communication mechanism you will have between multiple micros services like how many types of saga design patterns you have uh there are two types of saga design pattern one is the choreography design pattern one is the orchestration design pattern so in case of uh yeah I was asking how I would like to go with yeah I'd like to go with the orchestration design pattern uh because we have a centralized controller uh such that the Saga participants like Saga participants in in this case is like all the microservices uh what the local transactions will be having to execute and also the Saga orchestration handles all the transactions and and also it tells all the microservices which operation to perform based on the events It produced So based on the success and the failure events here agreed agreed so you you are saying that one person is going to uh handle all the success and failure regs and triggered accordingly yes any disadvantages you can but this is not the case in choreography okay yeah in orchestration design Saga design pattern uh additionally we require all the complexity like design complexity will be very high in case of orchestration and also any additional point of failure uh if there is any additional point the orchestration should manage the entire complete flow there could be these disadvantages orchestration Saga design pattern will have okay so what I can understand from this is that orchestration design in orchestration design pattern apart from 10 microservices you need 11th piece of code who is who will act as an administrator and manage all those right yeah now with single point of failure you want to say that that particular P of code if it fails everybody will be clueless what to do next yes correct yes okay I understood your point so yes this is a design complexity and additional thing to be added so we can use rather if there's a very simple application we can rather use codog choreography what's there in choreography so basically in choreography design pattern uh uh like it is a coordinate s like uh where participants exchange events without any centralized point of control we don't have any control and with choreography each microservices run its own local transaction and once the transaction is ready and it publish events to message broker whether it could be Kafka or any rabbit mq and then it trigger local transaction in other microservices so basically the advantages could be uh it is simple workflow you don't have any other uh microservice requirement or any other code requirement basically we push our messages to the broker system and and then it triggers the based on that particular message triggers the other microservices uh sounds great this is uh so basically there is one addition of messaging broker in between that's it broker system yes but there is one small disadvantage also it's it's good to have it for a small application that's nice but what is the disadvantage ages of this particular photography design um if there are many micros services and the workflow becomes very confusing right so when you're adding a new steps it's difficult for all the design I mean microservices to understand or to understand the different commands given by the particular broker and also you can have a cyclic dependency uh between the uh microservices which they consume uh all the commands like if I want to understand the a particular event if I'm listening the other event I may not work properly this could be one of the reason uh Target I mean this particular choreography design pattern will fail there if you are having many microservices I I recommend like if there are less microservices better to go with choreography design okay got your point uh this was a transaction that is being spanned across multiple microservices now if you have one single app how you manage transaction inside that Standalone micros service okay uh for example if you are having two tables inside one particular micros service and uh after one transaction you are adding uh into the second table you got some exception and you want to roll back the transaction which is happened in the first table as well over the method level you can have uh annotation called a transactional based on this annotation automatically the transaction will be rolled back from your database tables perfect sounds great uh so that was uh any clue about the propagation levels and isolation levels you can have with multiple transaction being spanned as a child transaction it's too much to ask for three years isolation do isolation. read isolation. write there are some propagation levels uh but not sure how it internally Works no problem now suppose I have 10 microservices and I have to hit these microservices from front end so how will you manage these 10 URLs who can dynamically change continuously so you will give this heck to front end guy or you will try to resolve it as a backend person on your own at the back end it shouldn't be given to front end guy this should be handled only in the back end so one one thing is related to once we get the reest directly we will not hit to the particular microservice it will be routed to a load balancer and the load balancer will route to that particular micros service so all the related URLs we will be storing in the service Discovery so service Discovery will store all the particular Ur URLs and based on that particular URLs it will be routed to that particular micros service I got confused I got confused uh uh okay can you tell me what is load balancing what does it do load balancer uh is nothing but based on the load it uh it particularly routes to particular instance of the same micros service of the same micros service so that is lo basically once you get the request once we get the request from the UI it will be mve to API Gateway and API Gateway routes to particular micros service cor so it should be API Gateway not the load balance not the L balancer so the routing thing has to be done with the API gway and service Bal load balance can rout it to particular instance of that particular micr service particular micros service perfect perfect sounds good okay and um how have you done logging in your application any loging Fring that you used how did you do that uh in case of logging uh we can since it is a distributed microservices we have used Zipkin and sluth in order to have uh logging centralized logging mechanism okay okay that is okay ID yes based on the trace ID and uh and we have added different types of dependencies for that based on that Trace ID we can understand to which Microsoft the flow is going so there's two things stce ID and span ID what is the difference between those what's the difference what Remains the Same across all micros servic and what changes with each micros service span ID will be same Trace ID will be changed okay sure yeah sure now my application is is in production or any particular involment where do you see all these logs okay in the current project I'm uh seeing in uh kibana and also observing all the metrics in uh promis and grafana so in kibana based on the time stamp uh you can filter it out or I want to see all the error messages so I can filter it using log. error uh so such that based on the time and based on the filtering you can see all the logs of a particular micros service so that's the GUI for monitoring monitoring yes any alerting system you have integrated with it that as soon as the production error is coming continuously that the system is low on memory or continuously the exception is coming 41 41 how do you alert yourself uh in AWS Cloud watch uh we have integrated with the cloud watch alarms so inside that particular alarm we have configured some properties So based on that properties if any AP is failing we'll get a notification to to a particular admin uh email so based on that uh will react accordingly perfect perfect uh okay and how do you log in your uh source code how do you make sure that your logs that you're logging in your source code reaches to so we are using a frame called log 4G or SL 4G uh uh we need to write for annotation and also that particular dependency in form. XML and you need to write log. info log. one or log debug So based on this particular uh log logging statements uh it will reach to the I how is kibana integrated to your particular application how do you make sure that yes you are written writing in your source code reaches all the logs will be moved to elastic search and from elastic search uh there is a concept of fluent D from fluentd it will be more to kibana this is the flow happening okay and uh where do you keep your so suppose I have 10 Micro Services I have many properties which are common so how do you place all these common properties do you replicate it in all the 10 microservices or do you keep it safely at some place and refer it from there basically we store it in a git REO or a local repo uh which is called Spring Cloud config server so we need to add one dependency called Spring Cloud config server and also one annotation called at enable config server uh inside the application. properties we maintain all this and uh like we need to write spring. cloud. config server and mention the URL of that particular uh Cloud base like whether it could be git or git lab anything okay automatically able to read all the we need to run that particular server and from uh all your applications will become its client config client config lines inside that particular also you need to write some annotations okay and what if I change anything in that git uh file how will it automatically it will be reflected to automatically it will be reflected to all the microservices so there must be some hook since it is reading from that particular spring. cloud. config do server it it it is switching the data from that particular uh file constantly fch so yeah it constant whenever it is when we are changing any value automatically it fetches the value okay that might there must be some hook which is created with that gith that's I'll go through this I'm not sure you are you are almost there it's it's almost there just just have one small look how it constantly dynamically PES the changed value okay uh nice uh with the m I'm good with the micros service part uh have you worked on git I can see that in the resum yeah I have worked on G okay so uh now suppose I'll give you an example I am a team with two frontend guys four backend Developers one tester one QA and all of them are working together so how do you follow your branching techniques your repository being either they foged or cloned what is the envirment what is profiling what is environments that you're using everything I would like to know so when I talk about the environments uh we have different environments like feature main Dev for developers both both feature M and develop uh develop will be for developers and QA will be for testers and we have po uh environment which is for product owners and and the production environment for the customers so this is about environments when I talk about the branching strategy uh initially the respective developer will start according to the user story they'll create a private branch and push it to FM so once everything they have tested in FM if it is fine uh they will push it to or merge merge the code to Dev so once the dev is also fine we give the uh demo to entire team so once they are satisfied with all the uh features automatically we will be triggering a night nightly build so it will be moved to QA okay so how is your envirment type deployment connected with your branches so it's like as soon as you merge it to your develop Branch the code goes to develop envirment is that how you're bounding the envirment with branching or how is the deployment done to particular envirment with your branches uh so once it is mov to FM or feature M we will raise a merge request and once it once it is approved uh will merge it but the code will not be reflecting in Dev it is an it build so once we have merged uh since it is a nightly build at around 11:30 the build will start and the changes will be reflected in the on the next day okay okay so you are saying that uh your code will be merged to develop Branch but the deployment is not done before your nightly building so deployment won't be done nightly build yeah so that brand that nightly build is actually the the deployment process from your branch to the inform yes okay any clue how the deployment is done in in so once we have done uh it will create a Docker file once the docker file is done uh it will create an image from the image uh it will pick the all the particular dependencies from a container registry okay uh all the all the images will be stored in the container registry and from the container registry it will be creating an uh I mean we are following kubernetes as of now so it will be moved to the kubernetes instance of of AWS of AWS so you're using eks as the yes automatically it pitches the uh file and it will create an instance there okay so basically you have multiple ports running and interacting with each other multiple port yes so okay so you are aware of Docker and kuet is also there yeah okay okay so uh I'll have a very simple questions on these so for the docker it is a way to create a containers and for kubernetes it is way for managing it so I have one application and second so B two microservices two micros servic basically two different containers how do they interact based on the IP address it should interact uh okay so if my container crashes and comes back again because container is something which crashes again and again so if it comes back again a new IP address is assigned so how will a know that b which was earlier alive was crashed is alive again is having a Dynamic IP how will it interact now directly it will not uh communicate with the container there is a concept of uh node so inside nodes uh the particular containers will run okay I mean pods inside pod pods containers will run and pod will be under nodes okay so anything something called as Services which will be used for interacting two parts yeah Services also will be used yeah publicly in order to uh communicate uh you need to use service s okay for the spring boot uh your application is currently uh using which springb spring boot spring boot okay 31.7 oh you move to three nice you migrated yeah recently we migrated yeah recently we migrated okay what changes did you see in Spring mod 3 compared to the Legacy EV the latest version of java we need to use is Java 17 that should be the least version of java and since it is using spring board 3 uh it is using spring six spring framework six and some of the dependencies they have moved from uh Jakarta e version I mean Java X2 Jakarta e version and also they have come up with the concepts of observability and micrometer and also spring Cloud na basically in order to provide lightweight executable files and such that it could be easily containerized uh these are the some of the features I can remember right now okay and what was micrometer introduced for micrometer mainly for uh your management of uh metrics or uh I think mainly for metrics they have introduced micrometer okay um what what web server are you using for your web applications Tomcat the default web server I don't want Tom how will I change it I want so if you want to change you want so uh inside inside the form. XML you need to exclude the Tomcat dependency initially and add the J dependency okay after excluding you have to add the dependency okay dependency yeah first you need to exclude because this is the default server right so you need to exclude that and add the jend uh any profiling you have done in your application spring profiling uh you'll not have only one particular environment right you'll be having Dev QA prod So based on each and every environment you need to take that particular property and execute your application so for that um you need to mention uh spring. profiles do active so inside active you need to mention which environment it should be whether it should be Dev QA or prod based on that it will fch that particular properties and execute your application okay so suppose I'm working with this particular profiling system in my local so I I'll go to my application. properties change my spring. profile. active to local and drive it in local how will I do it correct how will I do it in Dev how will I do it in QA how will I do it in prod every time I'll go change it in deploy it every time I do change in application prop deployed is this a feasible solution this is not feasible solu solution uh I think the devot team they have the idea of deploying it I'm not sure as a back end developer they don't no problem no problem there must be something because this is not how it has to be no problem there there's a centralized team like devops with every now and then with the organizations they might know no problem that's okay if you get a chance just have a word with them and see how they do it no problem yeah sure uh any design patterns that you have used in your code as of now uh I got a chance to work with all the three different types of design patterns one is the creational structural and behavioral design patterns in case of single uh creational I got a chance to work on single ter Factory and Abstract Factory as well as Builder and in case of structural uh flyweight facade and decorator design patterns and in case of Behavioral got a chance to work with Observer command iterator and State Design patterns nice uh okay so can you tell me why you have used Singleton single ton when we talk about it is for creation it is one of the creational design pattern only one particular instance of the class should be existing mainly we use this particular design pattern in case of logging or when we want to Cache any any systems or any data we use this particular design pattern um when we when we talk about the implementation uh the Constructor of that particular class should be private and method which is ring the instance of the class should be public and the instance whatever you are creating that particular instance type should be private and static there are different types of uh initializations uh in this single turn design pattern which could be eager and lazy and and also For Thread safety uh there is thread uh thread safe method initialization and thread safe block initialization in case of eager initialization uh even there is no particular check directly return the inance and in case of lazy initialization we need to check whether the object is being initialized or not and then uh I mean using uh equal to null condition you can just check and then if it is null then only create the new object so this is the lazy initialization and else you can directly return it return it is this thread yeah so two threads so no this is not this is so this is not thread safe in order to have thread safety uh for entire method you can use a keyword called synchronized along with the method since we are writing public static synchronized and and the method name and inside the method we need to check whether that particular object is equal to null or not then uh since we are making it is synchronized only one particular thread will be accessing the method at once nice uh but one problem I can see here is if you make the whole method synchronized you are losing the performance so any other way rather than using synchronized since the method is entirely method is being synchronized performance will be decreasing so whichever code you think that uh you need better performance and you I mean multiple threads can cause thread safety make that particular piece of block as [Music] synchronized synchronized and inside the synchronized yeah so which which line of code will you put into that synchronize uh so this uh checking of uh Singleton class I mean Singleton equal to dou double equal to null so that particular piece of block block I'll keep it in uh synchronized block so what you will do is synchronize block you will check if this equals to equal to null and then what you will do you will return no no if if it is null then we need to create the new instance okay if it is null you will create create new instance uh that's how so this this is called double check Singleton something like that right double check locking yeah double check yeah double check locking yes so there'll be two null checks in this particular scenario before the synchronized block we need to have one more null check and why was why will that be done uh I have gone through but I'm not able to recall right now no problem it's true but but good job I in the middle of the interview i' say good job okay is the uh how many score how many types of Scopes are there for the bean and spring so there are four types of Scopes or five types of Scopes I think five five one is uh the single turn yeah one is the single turn scope uh if I talk about single turn scope this is the default scope okay um so this is the default scope uh if even if you're not mentioning it um only one particular instance of The Bean uh is being created in the spring container and the same instance is written whenever the bean is being requested and all the subsequent request for that particular Bean will receive the same object reference since you are calling the same Bean again and again and in case of prototype scope a new instance of the be is created each time and and it means the spring container does not manage the life cycle of the be and the developer should be responsible for managing all the resources and also we should make make it clean if it is necessary and request scope uh we have request scope session scope and Global session scope so all these are related to http requests so whenever I call any request scope a new instance of The Bean Is created for each HTTP request and also it is specific to web applications and each user request receives a separate instance of the beam isolated from the other request and in case of session scope a new instance of The Bean Is created for each user user session and also it is specific to web application and each user can spam multiple HTTP requests and in case of global session scope uh this scope is similar to session score but it is specific to portless based web application and also it represents a global session that can spawn multiple portlets nice okay uh for the single you said it's a default scope right yeah default scope so if I have that been in one uh particular Auto in one class Auto in another particular class suppose I have a been for your name and I'm changing your name okay from VY to something else will that be visible to all the other classes where it is being autoed can you repeat okay uh I have a class uh it has a attribute called his name I'm setting that particular to W sheet now uh I'm changing that name uh to XY Z so will that beam which is Auto in different classes can see the effect of this change no since you're making the scope uh as XY Z it will be visible to only that particular class scope is single I have not CH I'm not changing the scope I'm just changing the property of that class say a person is the class the attribute is name the name has a value Oney okay I'm changing VY to XYZ I'm not changing the scope scope I going to remain it as default scope so will the other classes be able to see the change you have a class and you have a property name and its value is okay and you are creating a bean out of this so person the class person is a bean which is completely managed by your spring container now I'm Auto wiring Class A and Class B so Auto wire Auto wire person and adate autowire person now I'm trying to and creating two instance P1 and P2 now I I'll change P1 do name from vamy to XY Z so P2 instance will also see the change or it will be only be able to see the change no it will be able to see the change because it is managed by the spring container oh single time Very Yes since it is single it will be visible to all the classes where it is being a classes Auto yeah perfect perfect I have a query about the Singleton uh when I was doing the coding in Java code Java it was like Singleton Singleton and then I'm when I'm again coding with spring I'm still learning about Singleton so how the Singleton in Java for Java is different from a Singleton in Spring you need to write your own logic in case of spr when you are writing only Java based applications but in case of spring only annotation is sufficient so automatically spring configures all the single ter so you have to put I think at scope you can no no no automatically spring manages the single T scope in uh spring board based applications but in case of normal Java it's the responsibility of developer to manage all this okay uh true that I have a person class in code Java which you are creating as your own Singleton and I have a person class which is Singleton and it is automatically defined as Singleton by default scope of beam in Spring how is this person how this instance of this uh Singleton notion is is different in core Java and his notion is different in spring so there will Singleton is one instance per something in Java and one instance per something a bit confusing I I'll give you one one small hint uh single tenders one instance per spring container you said that so ining means one instance per container but in it will be one instance for jvm for JV okay that's how it is so if I have two different spring containers I can have same instance with different things so that will not be Singleton with two different spring containers but we run these applic uh I mean we are running we are using Java and as well as spring so in this case how it will be it's it's mostly the same if you are running using a container your application runs with a spring container right so it will be one per spring yeah not not one per [Music] jvm okay good so even if I have two uh containers with application context I can have two uh spring containers also then I'll have two instances and that won't be single any yes okay so um okay that was all about my spring spring boot questions uh I'll I can see the tdds in your uh resume so how do you unit test your Cod yeah so once we start any feature we follow bdd and tdd approaches so bdd is nothing but behavioral driven development so product owner developer and the tester sits and understand all the senior of a particular feature here and we use cucumba framework uh to write the bdd files in ging language so it's nothing but when given when then we need to write all the three scenarios I mean all the scenarios uh using this particular framework and once all the three persons uh they have understood all the scenarios the developer will start writing the test cases test cases is like PDD is nothing but test driven development initially we'll write all the scenarios using junit 5 and moo and initially all the test cases will fail so the developer will start writing all the Logics inside his class so automatically one by one test case will pass okay so all the corner cases also you write as a test case that's how yes yes yes yes and with your business logic they starts getting green getting past yeah that's test perfect uh so you said you use junit 5 and mock yeah so what do you Mo what do you inject mock uh all the classes which are required we'll be mocking them using at Mock Bean for example uh I'm using any service class I I should mock them and the data which I'm getting from the repository layer I'll not be uh able to get directly from the database right I should not hit the database directly I I should not save anything directly to the database when I'm uh calling the test class so for that I need to mock them so you will mock your business class also and your repository also if you testing your business class so suppose I have a service class so okay uh and then that service class gives a call to a repository and that repository gives a database call and my database is actually in AWS and each uh database call will give me a burn in my pocket I don't want that so you said right that all the database calls will be moed and what about the service class that you are testing service class will not be mocked there you will inject only database um we we are injecting the particular class which are required we'll be injecting and only the database calls will be mocking them because directly we should not hit the database because these are costly operations so you inject mock your business class and you mock your repository class okay repository classes correct uh now before each of the J unit that is running I want to initiate my product with some values likeu product is going to have something like and attributes the color the product name the subcategory category how will I will I will I create product which new product for each and every test class test cases or how how can I do it at once uh in inside the class inside the test class there is a method called setup and there is an annotation called Ed before so inside the setup method you can create the object of product and once the test class is being run uh the product uh object will be created so the same object can be used in any test method okay and have we used before each and before all what is the difference between before each and before all at before each before calling any test class uh test method this particular method will be called setup method which is annotated with at before which will be called and at before all will be called at the start of executing all the methods all the test class methods okay so you mean to say before each is Method level before each method it is called and all is class level before the class clevel only once it is called for n number of methods only once n number of methods yeah understand and what is the tear down method have you used for mocking uh sorry for unit testing te down uh not sure no just just like finalize you remove all the K all the garbage so tear down also will remove everything as tear down it's just that my method is done the after method is run uh done you will tear it down whatever things you want to so I want to garbage collect this particular so I'll make my product P equals to n so that my memory is not used by my product anyway any cleanup thing you can do with the down any clue what is a test suit I heard about it but uh didn't use any time no problem set of all these test cases which can run together becomes a test that's okay okay also I can see you have worked with solid principles so can you give me a real time example how you are working with solid principles and implementing that in your uh solid principles these are very important concept of uh while developing any code so s stands for single responsibility principle basically it states that every class should have only one particular functionality and implementation of all multiple functionalities in a single class will match up your code and in case of open and closed uh it states that according to the new requirements the module should be open for ex extension but should be closed for the new modification and in case of lisco substitution um it states that according to the uh class P for example there is a parent class and it should be replaceable by the child class and no business logic should be affected and in case of interface aggregation principle all the larger interfaces should be splitted into smaller one such that all the concrete classes uh will use the required methods only it should not we should not force all the concrete methods to implement all the unnecessary methods and in case of dependency inversion uh basically we have a concept of abstraction and it states that we should use abstraction concept instead of concrete implementations we can use abstract classes and interfaces uh to achieve this particular principle that is dependency verion dependency inversion inversion of dependency okay uh how how have you used the single responsibility principle in your code in real time for example you'll be having many classes right so we shouldn't have only one particular logic inside one particular class you need to separate them into different classes and use it so also I'll I'll get some example like suppose I have an entity class I should not write business logic repository everything into that class then that is what you okay understood understood and anywhere you have used open close principle anywhere for example I'm having some logic uh for example I'm building any payment Gateway systems in my application uh currently I'm having credit card and debit card and I I have PayPal uh after that I want to implement any other payment Gateway system which was introduced my code should be such that it should be extended but it should not be it should be having extension but you shouldn't modify the existing code existing logic so what I will do uh I'll create an interface and based on those uh interfaces I can uh extend it okay so you saying that you will create an interface called payment methods and you will create classes as debit card payment method implementing payment credit card and payal yes correct perfect perfect I'm good with that um also I can see that you have written jpa in your resume yeah and how do you write queries for connecting the DS with jpa and what is [Music] jpa jpa is nothing but uh Java persistence API okay and uh it is connecting it is for connecting to the databases it is similar to one omm tool object relation mapping okay so you you should connect to the database previously there was a concept of jdbc and it's the responsibility of developer there will be lot of boiler plate code you need to manage to connect to the database so in order to reduce them they have come up with the concept of hbnet and JP so for connecting to the jpa you need to add springing data jpa dependency and in um application. yml or in application. properties you need to mention spring data jpa and username password driver name so all these you need to mention perfect perfect okay uh now I would ask you that uh there are some inbuilt queries in jpa and then you can write your own queries so how do you uh like how how many ways you can do that for example there are nbu queries like find by ID okay find by name so these are the inbuilt uh queries and if you want to write your custom queries yeah we can directly use the inbuilt queries but if you want to use your custom query uh in the repository class you can extend the jpa repository mention the primary key of The Entity and also you need to mention the entity which you using and inside the class we write s query and convert the SQL query which have written to jpql query but if you want to use the same query which you have written in the SQL uh you can use named queries or native queries inside the query once you have written the query comma you can mention it and Native query equal to true so these are the three types I have used correct what are named [Music] queries uh I think named queries and Native queries are the same okay I don't think named queries you can no worries no worries named queries we basically write we don't write in the repository layer we write it in the entity layer nice yes you do that so we can have multiple multiple named queries as well uh inside the entity ler entity perfect perfect yes true that uh also you said that you are going to extend a JP repository and give a primary key of the entity okay primary key of the entity yeah okay I have a class person I have uh an attribute name as Mami I have an attribute ID so int ID int so uh you will put it as jpa repository int comma ID comma int that's how no integer comma person integer comma person so why not in because they using object are not allowed there since they using object we need to use integer there yes per correct uh now uh you you you have an application okay what is happening in your current application is that your DB calls are taking very long so your performance overall performance of your production application is getting down so how will you make this better uh before understanding the scenario I'll check the logs to understand which particular method is taking long time okay based on the logs I'll be understanding which particular query is taking long time perfect I'll go to that particular table I'll understand how much data is available right now okay if indexing is required I need to index the table and even if even if even this is taking time I need to chart the data or if it is required to partition the data I need to do the partitioning as well nice and this is this is apart from the database uh if it is required to have multip if there is multiple uh operations happening in the business logic you can use multi-threading concept and you can submit different task to the thread pool you can use completable future and as synchronous programming and based on that you can improve the the performance of the APA so basically you will introduce an execute a framework execute a framework and we can submit the task to it based on it it can parall process your business logic perfect perfect sounds great um okay you said something about shredding so can you tell me anything uh you know about shredding how do you do it how many types of shredding is there uh can you repeat strategy Str how do you do the strategy so in in case of databases uh there is a concept of sharding which is nothing but you'll be dividing your data into more than one particular uh physical databases okay uh there are basically two types of uh sharding uh basically we'll be dividing uh the data into three different uh different databases one is we have vertical sharding one is the horizontal sharding based on the the data you can uh divide them okay uh and how do you do the partitioning so there are different types of partitioning one is the vertical partitioning the second thing is the horizontal partitioning for example there is a table called employee table and you have uh different columns and I want to uh partition them so using when you're are using um based on the columns like I have five columns and I want to store three columns in one table and two other columns in another table so this is based up basically ver vertical partitioning and in case of horizontal partitioning for example I have 10,000 records I want to store 5,000 records in one table second 5,000 records in another table this is called as horizontal partition so basically with rows that's horizontal with columns that's vertical perfect horizontal vertical yeah okay and okay that is also good uh types of mappings in jpa hynet any clue so there is one to many mapping one to one mapping many to one yeah I think these are the types many to many many to many many to one one to one one to many okay and in many to many how many tables are there if two tables I'm uh mapping with each other how many tables will be created total in physical database I think three tables will be created in total and third table will have what the common records of both the table common records or the unique memory Keys unique records I mean unique unique memory keys of both the tables for example ID in both the tables oh uh uh okay I can see you have used Kafka also yeah uh as we are using uh currently is a um small microservices uh pattern We are following so it's choreography design pattern we are using So based on the request of uh based on the event of one microservices it is pushed to the Kafka and all the other microservices it subscribes to this particular topic and uh it performs its actions so we are pushing our data to Kafka and and then it subscribed to other microservices it subscribed to this particular topic okay so public subscribe model so one publisher multiple subscribers that's yeah and multiple subscribers uh any clue about the architecture of Kafka so basically when I talk about Kafka uh you have partition concept so you have have different types of partition and inside partition you have different types of basically one is uh broker and inside broker uh you'll be having different types of topics inside topics you'll be having different types of partitions okay for for example uh for example I have one particular topic uh inside that I'll be having four partition first two partitions uh for example two microservices you have so two microservices will be subscribed to that part particular topic and uh we have four partitions so first two partitions will be assigned to microservice one and second two partitions will be assigned to microservice 2 okay so we creating consumer groups out of your consumers consumers group yeah correct okay and this will help you in parallel reading from your topic topic correct okay and how is the Fault tolerance done with in kka somewhere you have one leader broker you have multiple follower Brokers if one follower dies we have a concept ofo we have a concept of Zookeeper zookeeper basically manages all the topics and So based on that it will create a new broker automatically out of the follow yeah out of the for other Brokers okay okay okay uh I think some has to be done with the architecture of uh no problem no problem uh I I I can see there's also uh also one more thing on Kafka any knowledge around uh how the consumers do acknowledgement and it marks the opposite that no not sure completely no no problem no problem no problem uh I'll move to another topic that is security so so uh what what kind of token have you used for your security implementation in your project uh I have used uh JWT JWT is nothing but Json web token so once the token is being uh created uh based on the response I mean we'll be having also expiry time so once the expiry time is expired like uh of that particular token again a new token will be generated okay and so inside the Json the J toen consist of three particular parameters one is the header the payload and the signature if I talk about the header we'll be having the algorithm which is required for example HS 256 and the type we'll be using the JW so the type will be JWT and in case of payload we'll be having a registered claims which are nothing but uh like which are not mandatory but these are recommended to provide uh for examp um which are set set of usable and uh interoperable claims okay and for example you'll be having isser expired time and what is the subject and who are all the audience like AUD all these things will be mentioned in the like there are two claims one is the P public claims the second one is the private claims so in the public claims you'll be having uh all the defined will all all these will be defined by using the JWT to avoid all the collisions basically and in the private claims these are all the custom claims to create the shared information and in case of signature it's nothing but uh to create the signature you have to take the encoded header the encoded header have a payload and a secret message and algorithm like which is the algorithm um So based on this the JWT token uh I mean the JWT uh will be able to generate the signature So based on the signature and U we'll be encoding them um in the application and based on the username and the password we get we'll be checking whether the token is valid or not so uh and the J to Bally we are using using a particular uh topic called OCTA so using OCTA we'll be generating the JWT token so OCTA becomes your authorization server authorization server okay it will provide you JDP tocs uh now I am allowed to add anything in your claims so can I add my password in the claim in the body it is a you can you can have uh custom values as well but I'm not sure whether you can have password inside the claims okay and uh how do you handle the course issue have you faced the course C is cross or sharing issue in your application connecting front to back how do you resolve it so back end will be running in one particular server and front end will be running in another server so in order to manage them we need to have one particular dependency sorry one particular annotation called at course you need to add that particular annotation inside the uh application which which you want to integrate with the front end so CS is nothing but course Orin resource sharing so you need to share your resource from the back end to the front end so in order to resolve this particular error you need to add that particular dependency called Ed Course and where do you addite this particular annotation uh inside the application where you are writing at Spring boot application we can add at course there okay uh how about the filter where all the HP request comes and goes uh I'm not clear with your question okay so question be more clear okay no problem so from front end your request is coming to back end so there is one filter security filter which is before uh the backend a layer just before the backend so all the request will intercept with this particular filter so why not add the course at this filter you can uh mention Star as well in the course or you want to filter some of the apis or some of the URL based on that particular Ur URL you want to filter inside the course you can mention the URL there okay okay fine fine sounds good if it is a local development we mention it as star but if it is a production based application we need to mention the filters okay and where do you mention that all the request coming for H HTM just pass it and all the request which is coming for my uh so I just want to have a few requests completely passing out and few post request to be uh properly tested for authentication authorization so where is that logic WR you can have a separate uh class uh inside the class you can write your own logic and how that class will intercept each and every HTTP request you need to have enabled enable web security and based on web security you'll be extending web security adapter and inside that uh you you can have HTTP security method and inside that you can write your own law perfect so basically with extending your web security configuration adapter you can configure an interceptor vors perfect s scre I think I am good with this uh last thing maybe you know or not uh any any knowledge about about configuration continuous integration continuous deployment cicd have you worked upon it so yeah see I didn't work on it like I have the uh working experience like uh once the code is uh build uh using your m in local we'll push it to get and automatically once it is pushed we have CI pipeline which is nothing but continuous integration we'll be having different stages one is the unit test stage integration test stage sonar and code coverage so all these four stages will be passed and depends upon the project these stages will be different okay so once uh all the all the four stages passed you'll be creating a merge request to that particular envir onment you want to push so then then next CD pipeline will start so again the four stages will be common uh integration test unit test case Sona code coverage and then publish and then deploy okay okay and you deploy using any particular deployment Tool uh in the previous project I got a chance to work on Jenkins and currently we are using gitlab so no third party tool as of now uh Jenkins is for continuous integration I think we have used Jenkins for both CI and CD okay so I think I'm going to stop this interview here I am good uh with this particular part yes so I'll start with my feedback now I have not I interviewed such a great like person since for 3 years of experience even these many questions were not being answered by five seven years of experience also so such a great interview man I mean a heads off heads off I think 95 96% uh questions you were able to answer perfectly fine only thing I can see is a problematic thing is Kafka architecture there uh Kafka architecture is a lot a lot I mean uh it has too many things into it techn knowledgement is there uh lagging is there if partitions are having lags how will you face it how will you handle it so Kafka has a lot of things into it so you can uh yeah uh just have a look like how the architecture works because zookeeper is also there who who handles the leaders Brokers the only thing I can find in the whole interview which is problematic is kakka apart from that uh okay for three years of experience you were good you were perfect so very nice interview no no uh also I covered everything no um so one thing you need to have a look at is Diamond problem for Java that was one thing I want to remind you about okay and what all I have written so I was just taking down notes where you have to a taste suit you might have to look at it once I think that is it that is all the feedback I can give you only two three points here and there and you were perfectly fine so thank you so much for sharing your knowledge with the community man I would say go ahead with all your interviews you're good to go you don't need a mock at all you are completely ready for companies go ahead have fun yeah thank you so much thankk you so much for connecting thank you so much FY for for taking your time out and help helping the community by sharing your knowledge with all of us this was such an awesome interview uh also if you guys want to be the part of this interview series just add your details in the Google form below and we will uh give you a call as as soon as possible thank you so much again and have a nice day we will be meeting next in the uh another mock interview thank you that
Info
Channel: Code Decode
Views: 80,162
Rating: undefined out of 5
Keywords: java interview 3 years experience, java mock interview for 3 years experience, code decode mock interview, mock interview for java developer 3 years experience, sde mock interview, sde 1 interview questions, java interview questions and answers, java interview questions and answers for 3 years experience, spring boot interview questions code decode, microservice interview questions code decode, java 8 interview questions code decode, codedecode
Id: ekLB9t9DBAk
Channel Id: undefined
Length: 83min 35sec (5015 seconds)
Published: Wed Jan 17 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.