Transcript for:
Java Spring Boot and Microservices Insights

hey guys today we have shivar engineer and she's having six year of experience in Java spring Boot and microservices and those who want to give same free mock interview please fill out the form below in the description so let's get started hey hello Hi shivaranjani how are you I'm good how about you yes I am also good uh shall we start yeah sure okay uh can you please first introduce yourself and your recent project in brief okay as you know my name is sh I have six plus years of experience as developer and completely back end now I'm working in Enterprise applications and it's internet based applications okay right okay this is related to something um government related projects official have to update their details in their uh in our systems that's it like they want to keep the track of all IND histories and all uh they will use the systems uh they will they will go into the uh place and investigate and take the photographs videos and take someid and then just upload it into our base I mean our systems so have you worked with uh in your project have you worked with hashmap or hash set hashmap um yeah okay so uh what happens when two different Java objects have the same hash code and how do you handle such a scenario yeah actually Coalition happens uh you yeah when you are trying to actually if it is different uh key keyword uh then different same keyword the Collis won't happens because the value will be overrated but two different Keys generating the same hash code then the C happens right for this um first uh we can override the uh hash code method in ex class then here you should use the unique hash code algorithm um then only yeah each time it will give you the unique index so so that uh collisions will ction occurs will be reduced and uh link list actually it's internally already there uh in the hashmap uh for example uh each index you consider is an array of array the array will have the linked list for example on key will be stored the another key which is having the same index will be so when there are lot of collisions happen so what actually happened internally uh like do you know after Java version do we use red black tree as well some yeah balance actually after java8 they have converted into I mean uh instead of using link list they are using now uh red black tree yeah okay okay okay uh and uh uh do you know about the difference between comparable and uh uh comparator yes yeah go compar yeah yeah comparable actually is interface uh which is having with um compared to it's interface F uh if you want to do uh sorting operations depending on the natural sorting order then you can go with comparator I mean comparable and uh if you want to customize your assorting operations then you can go for the um comparator which is having a method uh called uh compare so have you customized sorting uh before yes and if yes for what purpose you have done um to sh the application uh based on the uh person who is so this is related to your recent project or some different project yeah different before that I I have us okay okay yeah okay uh so uh before moving ahead I will like to share one important thing so hey guys uh if you are not able to crack your interviews then you can check our interview preparation kit uh it has help thousands of candidates in cracking their interviews uh in this we give the job support and referrals as well uh basically this kit has four parts the first part is complete interview preparation material this contains 16 documents step by step with practice quizzes where all the content is organized and available in one place the second part is two real Enterprise projects one based in Sweden and the other in the USA uh there will be video explanation prototype source code PDF documents and quizzes for each project if someone already has projects and they can take this as a reference and prepare accordingly the third part is 7 Days of chat support for all your doubts on projects preparation material or any other Guidance the fourth part is job support and referrals for the deserving candidates I have provided the link to get this uh Below in the description please check out once and it may change your life literally so now uh moving to our question so uh do you know uh the difference between finalize method and finalize keyword uh finalize keyword you mean uh final finalize method and finally keyword or finally block sorry uh to be precise finally block yeah finally blocks which is comes with the exception handling like uh whatever you are opening resources inside the tri block you have to close it in uh when you outside the tri block right for that you you can use the tri block to close the resources or clean up the resources so if any exception happens or not happen uh however whe the finalized block will be executed to clean up process and the finalize method right so it will be executed uh this is also the same purpose to clean up the process but it is called by the uh carbage collector before uh you destroy the object you need to clean up the resources who are attached with that object right uh to do the purpose we are use uh internally uh garbage collector uh using the finalized method yeah so do we still use finalized method or it is deicated nowadays uh I heard uh we nowadays gc1 uh introduced the modern um modern yeah yeah introduced after that we not using it okay okay so how how does jvm handle memory leaks and what tools or techniques would you use to identify and fix a memory leak in your application about the memory leaks uh first thing is so first thing is I mean first question is did you face any memory leag in your career now actually I faced uh object uh o error only uh okay of memory error and this one memory Le I never faced but I know certain uh things can do can lead to the memory leaks uh first thing is uh if any other variables I mean any uh thing it's not related to the object you should make it at Statics so it will be under the class level uh and any unused don't create so many objects which is not used in futes so it can do a memory and especially the hashmap right hashmap hashmap it dominates the carbage collections because even if it is not attached with um any references it dominates the um garbage collector so garbage collector cannot connect uh I mean collect the um hashmap so better um properly use the hashmap I would suggest it yeah okay and what do we have any tool tool have you heard about J profiler visual uh VM Eclipse memory analyzer oh yeah okay uh do you know the difference between Class loader and class. for name method yes uh you mean class loader first is it yeah yeah class loader class loader uh okay class. for name to load the uh class I mean uh at the run time yeah at the run time you don't know what's the object is coming I mean you are going to create an object you you are not sure about the class name then by using the new instance you will create the object for it and before that uh you need to load right uh for that you can use class. for name and uh system. class loader system. class loader to load the I think Native uh n native libraries to load the native libraries system. classer class. for name class. for name yeah it also loads yeah driver class to load the driver class yeah yeah driver class okay uh have you worked with the string Builder string buffers uh string string yes uh can you discuss a scenario where uh string Builder is preferable over string buffer string buffer actually is a synchronized all methods are synchronized uh it's the same as same like um string and uh string is immutable string buffer is uh not immutable and yeah string buffer is uh I mean sting buffer is a thread safe string Builder is not a thread safe uh yeah the objects is keep on changing and uh the scenario is um what we can see yeah the user informations if you want to keep the data uh consistent then you should go for the string puffer and uh string Builder um scenario okay uh okay so do you know about Java memory model Java memory model uh yeah it's fine uh okay go let's go ahead uh have you heard about generational garbage collection yes generational garbage colle yeah uh what's that uh can you give us an overview okay uh in the Heap R uh we have uh we are spading into two space one is younger generation and it's older generation so when you initially uh when you initially uh create the object the objects will be stored in the um younger generation especially the hiden space once uh yeah it will be stored in the idden space uh so for multiple carbage collection process takes place then then after also the object is still exist it's alive then it will go for the Survivor phase here the Survivor phase it will have the two two phases on s s z and S1 then here also yeah now here also uh there is a cbas collection process will take so here also the object still exist then it will move to the uh older generation uh here uh yeah it's like uh in older generation uh here also that garbage collection process takes place but the thing is here it's a cost person costliest process uh it won't happen um so so quickly compared to the generation yeah MH okay uh like I asked you uh one question about class loader so uh there are three things in class loader uh bootstrap extension and system do you know about those stuff class loader uh bootst class loader yeah bootst class load I remember it um if you are not aware yeah actually um and yeah when inside the J jdk jbm is there right I mean rtime en along with we will we will have the some libraries those libraries are [Music] to yeah yeah it's fine uh okay so uh tell me what makes an object immutable in Java first thing and second thing uh provide a scenario where using immutable objects would be advantageous over mutable ones okay um immutable you mean first I want to tell how to create the immutable object yeah yeah yeah uh uh to make object is immutable first uh you need to uh provide the final for the class and uh yeah class should be final and variables should be of private and Fin and you have the parameter Constructor which initialize all the parameters and you should not include any Setter methods you can have set getter method but you should not have the setter method and by this way uh yeah you can make the object is immutable and the scenario is like uh some scenarios for example um when emplo is there and uh I didn't get you come again yeah this is how we can create the um yeah that's what I understood in the second part uh what the scenario right yeah yeah scenario immutable object scenarios okay um uh I think in concurrent application uh can we use imitable uh objects concurrent objects is it yeah that do not require synchronization something like that a copy on right or Le copy on right or is it uh yeah it uses the synchronization okay okay so the answer is yeah like we can I mean the scenario might be uh in concurrent application so I think we should use uh okay immutable objects okay yeah yeah okay so uh have you heard about Java serialization yes okay and Ja serialization attacks civilization attacks no civilization attacks okay so what is Java calization okay to uh whenever you are trying to pass the object through the network right you need to convert the object um into binary uh so the process of converting object into binary it's called cation and we have the marker interface for to achieve that that is serializable interface okay and the the reverse process is called detalization and yeah and we have one um modifier called uh volatile if you don't want to uh if you don't want to uh serialize by a particular variable you can mention it volatile and it will be provided with the default value when you send over the network yeah okay okay uh do you know the difference between error runtime exception and exception yes um so the throw is um top no Ro rootless for the uh every exceptions and throw further is splitted into exception and um error error which something we cannot handle it's related to um system resources right and exceptions is something we can handle it it's unwanted event that happens and if if the exception happens the rest of the program will won't work so to to smooth process of um program execution we should handle it either by cat or through keyw and runtime exceptions um runtime exceptions comes under the um exception only and uh runtime exceptions like exception AR index of bound exceptions and index of the wounds exception pointer and yeah much more IO exceptions yeah okay do you know about composition over inheritance uh principle composition yeah yeah please go ahead uh inheritance is all about reusability right for example yeah parent class properties and behaviors you can you can Acure by the um class it's called I relationship and we have composition uh it is called hasher relationship like uh you don't want to have every um methods or every properties from the parent class you need specific methods then you can go for the composition you just create it's uh like for the inhance you can achieve by the extance keyword but in in case of composition we don't have the specific keywords like by using the key uh keyword called new I could say like create the object inside the work class and use whatever method you want yeah nice okay so moving ahead uh if you need to secure rest API in Spring boot application what security methods would you consider and why uh I would say um um first JW token jwd okay and or yeah and uh jwd actually for the first time if you got the authentication success each time you when you send the request you just need token to verify your authentication okay for authorization you should go for the uh What uh to or what provider like it will have your user details and the permissions also so each time uh when you send the requests and it will check your roles and permissions if you have a permission send it will check everything uh yeah okay okay and uh uh how does spring boot Auto configuration mechanism work or can we overwrite this yes we can do um first thing is uh when you yeah when when your application starts it's combination of the uh spring board application it com of three uh annotations right one is at uh enable auto configurations config Auto configurations another one is component scan so first first annotation itself unable uh configurations this will do the um uh whatever uh it will provide automatic setup for your spring boot applications like then it will look for the conditions also like uh we can override uh by using the condition classes like at condition at conditional class conditional missing bin at condition properties kind of conditional beans we can use scenarios and we can use the profilers also to make things and yeah we can customize those things and at Auto configuration and it will do um yeah for example before the spring board we need to uh tell every dependencies explicitly but uh after the spring Bo you don't need to consider about those things it spring automatically uh I mean yeah discover and register the beans and uh the life cycle will be handed okay okay okay so moving ahead if you were to scale an application for high traffic what spring boot features would you uh leverage um spring boot Cloud actually uh we have um Cloud balanced is there it will do the uh client client side load balancing for us M based on the whenever us send request which instances has requests then requ to the correct instances okay and yeah and other than spring Cloud spring Cloud um spring Cloud other than spring Cloud this horizontal scaling uh horizontal scale so we can do this All I think under SP cloud and this is cloud related stuff right yeah yeah okay okay so moving ahead uh can you please explain uh spring Bean life cycle spring being left cycle okay um spring being left cycle okay actually um in Spring um yeah stuff the uh beans are um Bean Scopes are uh single T and yeah uh spring scope I know what spring cycle uh actually I I couldn't remember right not there yeah it's fine no worries uh okay so it's I mean uh first initialization something like that resource allocation implementing cleanup okay yeah these kind of stuff so okay moving ahead if you were uh tasked with ensuring High availability for a spring boot e-commerce application during peak times what architectural decisions would you make uh it going to handle large number of users is it make concurrent actions yeah yeah yeah then I think we should go for the beux and Kafka okay yeah and uh can we use some other stuff uh uh and anything else okay uh okay so imagine you are developing a spring boot application that handle sensitive customer data so how would you securely manage and store this data uh okay for example for to store the you um okay uh uh for this we can use a spring uh spring Cloud config server so whatever you want to whatever you want to uh secure the data that it should not it should not be in the code it should be away from the code it should be externalized okay so for this we can use uh git repo G repo also you just have one file and whatever you can use the key value pair also um for the sensitive data and you just write it and uh you committed to the G G repo and uh whenever you need uh then you can um you can access it from the uh G directly uh this is the best way and uh we can for the password and or any other stuffs sometimes if it is treatable by the users we can um scramble it like the user who who is access to the sensitive data they can able to read it right so we can do that cor correct okay so moving ahead what testing strategies do you recommend for spring boot application what okay um strategies dist one you mean uh kind of okay um first uh I don't know currently uh we are following the same like develop and uh do the testing first we should start with unit test cases [Music] right yeah yeah okay then we can go for integration and some other stuff okay yeah okay so have you integrated with the have you integrated your application with any no SQL database no SQL uh I have used R for a cach implementation okay so how can we Implement RIS in our project okay for this we have um dependency radies uh dependency uh and you just need to include the dependencies and we have then you need to enable the caching by using enable caching and uh whenever you are trying to get the data on the top of the method you should put a catchable and uh uh uh if do we have default caching mechanism in Spring boot I think uh there think there okay there yeah and what logging uh things you would suggest uh logging methods default one or SL SL 4J okay there is one default logging mechanism also right yeah log log log back I think oh okay yeah so which one would you suggest log back or log 4 J2 uh log 4 J2 why we uh we can categories right uh this one like info info level cannot we do this in log back I didn't use it and yeah yeah it's fine uh okay so [Music] okay so can you describe a scenario where we can Implement a synchronous uh messaging synchronous messaging okay asynchronous messaging asynchronous yes uh yeah this is like uh when you want to communicate uh email when you want to send the email or notifications to that users then in this case you I mean whenever we are making the order if you want to send the notifications to the user then we can go for the uh this and um any other scenario like um the email notifications only for for me thing anything else I think that's it for me okay okay so let's say you noticed that a spring boot application you are working on is slightly lower in production than in the development environment so how would you go about fixing the problem coming in uh let's say you observed your application is slower in production environment uh but it's good in development environment so how would you fix this issue um okay first um we can use actuator uh actually it's a tool we can use for monitoring and managing the applications okay and to to check the uh statuses in case of it is microservices environment we can use Zipkin or um Zipkin yeah zipin to know it is a distributed uh systems we can track where the services is getting slow like that okay then um first we can do yeah we can verify by using the actuator and what are the St then we can um verify with the locks anything any patterns any errors which logging to sorry which logging visualizing tool would you prefer uh visualizing tool okay um we have spung and gra gra yeah so which one would you prefer and why let's say if client approached you to work on some project and you are leading that project and client ask you which one should we use for visualizing because in the end client need to uh purchase a subscription or license so which one would you uh uh prefer or why uh actually uh currently we are using AWS Cloud watch to verify the logs and uh I heard about this uh Gana I mean gra is okay you heard about only you haven't worked on this spun and grafana okay you worked on this AWS s asws CL Cloud so how how does that work AWS Cloud watchat actually it's a configurable one and okay when you deploy the applications uh it will be splited into a many buckets like uh app blcks bad of blcks and uh middle middleware locks everything will be splited and yeah it will be configured um uh and another thing is it will provide you the insect like like you can search search using the insect and we can use the Lambda Expressions also on there to search effectively um uh I think apart from that yeah the based on the time and date we can specify and search for it uh okay yeah okay so uh let's say uh so how would you handle a situation where a merged conflict occurs in a critical piece of code just before your production deployment okay father this first uh um merge conflict right you were saying mge conflict yeah yeah merge conflicts yeah first uh in your local you have to take uh you need to check uh what where are the conflicts occurs and you need to talk to the developers who are who worked in the file also then uh you compare both files and um first thing is both codes should be there who are all working there both code should be there then at locally once you have done the changes and you should test it in local first before moving to me or commit uh to the protections you should test this is what uh I will I will follow okay and also uh tell me let's say you guys are working on some feature and you successfully tested in your local and in Dev environment right but now it's time to release that feature in production okay but in production you guys are facing some issue so how do you encounter this we can use the active profile in Spring boot right we we can yeah we can uh chase the um environment I mean active profile to the production uh then from the local you can uh try to debug it no no I'm saying it's working on local and uh Dev environment but as soon as you release in the production environment it's it it is not working uh first maybe uh first we need to check the dependencies a verions if it is any conflicts need to check versions conflicts Then I then I will verify the logs only first I would check the Vlogs uh and in case uh if the bean is not discoverable then those things we need to check and okay okay all okay how would you optimize a maven build for a large project with multiple modules you optimize okay um this one optimize before you uh build you need to clean up the you need to clean first uh then okay have you faced any uh dependencies conflict in your M project dependency no as of now I never fa the dependency compl okay okay so uh now I will share uh two uh I mean a few coding problems and uh you need to share your screen and uh you have to solve in any editor okay yeah please go ahead M yeah uh I think couldn't share it why disabl attende screening sharing H host disabled the uh screen sharing I get yeah make host make now try yeah I think is it visible yes yes it's visible okay so uh the first question is uh you are given a list of employee objects H each with property name and salary okay name is is string and salary is double you have to use a stream API to find the employee with the second highest salary and return its name okay and assume employee uh is the object name of employee employees object yeah small case employee is the name of the object of the employee okay yeah uh just uh do one thing uh just write code uh don't write this employee object and all just I just want to check the logic only okay yeah yeah or you can say you can assume a list of an integer and just find the second highest uh uh number in the list just yeah first declare a list declare and initialize a list and then just find the second highest number in the list okay for second what s okay okay now let's move to the second question uh second question is uh you are uh given a list uh that is that contains uh salaries of the employees okay just assume you are given a list of numbers and you have to uh count how many salaries uh have uh greater than 1,000 okay or assume 10,000 greater than 10,000 okay yeah just initialize a list and just assume 6,000 7,000 12,000 uh add one more uh add 12,000 because you have to find the great who are greater than and change 9,000 to uh some greater than 10,000 okay yeah count right yeah yeah count okay yeah please and share your screen it's not sharing is it oh okay yeah yeah sh you are sharing I'm saying okay so yeah shivaani it's done from my end