Master Spring Boot Interviews — 50 Questions in One Shot !

The Curious Coder3,662 words

Full Transcript

Hello and welcome to my channel, The Curious Coder. If you're preparing for Spring Boot interviews, then you are at the right place because this video is a complete gold mine. I have packed 50 of the most important interview questions from short answers to MCQs to fill in the blanks and match the following. We have different variety of questions. It's fast-paced, interactive, and designed to test how well you actually know Spring Boot. Okay, so let's get started. Question one, what is an IoC container? Define beans. The IOC container is basically the part of Spring Framework that takes care of creating and managing all the objects your application needs. These objects are called beans. Now, IOC stands for inversion of control. That is instead of you manually creating objects using new keyword, spring boot does it for you and saves these objects/beans in the IOC container. Once these objects are there in the container, you can just use them anywhere in your project as many times as you want. Question two, what is autoiring? Now, autowiring is a concept that lets you use the beans that you already created inside the IOC container into your project. So you just need to add the add the rate auto add annotation on a field and spring boot will automatically inject the matching bean into that field. You can use auto add on multiple fields in different classes and spring boot will simply reuse the same bean from the container. Okay. Question three. What is the difference between add component and add the rate bean? Both at the rate component as well as at the rate bean are used to create a bean but they are used in different ways. Component is placed directly on a class. So spring automatically detects it and creates its bean. Whereas add bean is used on a method and in the method you return the object of the class. This method is written inside a configuration class that is a class which has add configuration annotation on it. Now it is mandatory to write add configuration on a class where you want to use add bean otherwise it won't work. Okay. Now generally add component is an easy way of creating a bean but we need to use add bean for third party classes because if we want to create a bean of a third party class we can't edit that class and add at the rate component on it right since we don't own it. Okay. So add bean is used in that case. Question four. Which of the following are correct differences between Spring and Spring Boot? A. Spring Boot has auto configuration mechanism. Spring doesn't. B. Spring Boot has embedded Tomcat server. Spring doesn't. C. Spring Boot supports inmemory database named H2 whereas Spring doesn't or D all of the above. So the correct answer is D all of the above. All these are important differences that you must share in an interview when asked about them. Okay. Question five. Which of the following is not a part of at the rate spring boot application annotation? A at the rate enable auto configuration. B at the rate configuration. C at the rate component or D at the rate component scan. So the correct answer is C add the rate component. Add spring boot application is an annotation that is used on the main class and it comprises of these three annotations enable auto configuration configuration and component scan. Question six what is the purpose of at enable auto configuration. Now spring boot has a concept of auto configuration. It means that there are some classes and beans that are required for an application to run. For example, classes related to dispatcher serlet or classes related to Tomcat. So, Spring Boot automatically configures these classes for you. You don't have to write any code yourself for them. Now, let's say if you want to connect your application with a database. So, at your end, you'll just add a dependency for it in the pom.xml file. Then all the data source related configuration classes will be created by Spring Boot itself. This beautiful concept of spring boot is called auto configuration and it is enabled using this annotation add the rate enable auto configuration. Okay. Question seven. What is the purpose of add the rate component scan? Now when you run your application at the rate component scan scans your project and looks out for all the beans that you have declared. It then creates their objects in the IOC container. So when you use at the rate component and at the rate bean you just declare beans. Okay. Actually those beans were registered in the IOC container at the time of project startup when they were scanned by add component scan. Okay. Now question eight. What is the purpose of add configuration on the main class? It means that main class can also be considered as a configuration class. That is you can declare beans inside this class. Just keep on adding the methods with add the rate bean on it and they will be declared as beans. Okay. Question nine. Which of the following statements are correct? A. Add the rate entity and add the rate ID are both used on a field level. B. Add the rate table is where you give the name of the table with whom you want to map your class. C. Add the rate entity means that the class is a visual representation/mapping of a table. or D. It is mandatory to use at the rate column on every field to map that field with the SQL column. Okay. So, A is not correct because ID is used on a field. It marks that field as the primary key. But entity is not used on a field. It's used on a class level. Now, B is correct because add table is where you give the name of the table. C is also correct because entity tells spring boot that this class will be a mapping of some table. Now D is not correct. Yes, add the rate column maps Java fields with columns. But if the column name and Java field name is exactly same, then there is no need to add at the rate column on it. Okay. Question 10. Fill in the blank. Dash can be considered as the traffic controller/ nervous system of any spring boot application. The most appropriate answer would be dispatcher serlet. Why? Because all the incoming API requests first lands on the dispatcher serlet. Then it decides which controller method should handle that request based on the URL of the request. Okay. The response sent back from the controller also reaches the dispatcher serlet first before going back to the client. Question 11. Which of the following interfaces work alongside with dispatcher serlet? A. Multipart resolver, B local resolver, C handler mapping, D view resolver or E all of the above. Now the correct answer is E all of them. These are multiple interfaces that perform different responsibilities for dispatcher serlet. Multipart resolver comes into play when you want to upload a file in your API. It converts raw file data into a proper multipart Java object. Local resolver figures out the language and region of your API request. It is used a lot when your application is global. Handler mapping contains all the mappings of URLs against controller methods. This is the one that helps dispatch a serlet in routing the API request to the correct controller method. View resolver decides which view to render. It could be HTML, JSP, JSON or something else. Okay. Question 12. Fill in the blank. Add the rate controller plus at the rate response body is equal to dash. The correct answer is add the rate rest controller. Rest controller is actually a combination of controller and response body. When you use at the rate controller without addate response body, it means that controller will not return data from the API. Okay, it will return a view name. Then that view name is resolved by dispatcher serlet using view resolver. it finds the appropriate view against that name and returns the same to the client. But if you use add response body as well, then view resolution is bypassed and whatever is returned from the controller, it's considered as proper data and sent directly to the client by default in the JSON format. Okay. Question 13. What are bean scopes? Name few of them. Now a scope of a bean defines when the bean is created, how long the bean will live and how many instances will be created for that bean. Now different bean scopes are singleton, prototype, request and session. Singleton bean is created at the time of project startup and as the name suggests it has a single instance only. Rest all of them are created at runtime whenever they are needed. It's called lazy initialization and they can also have multiple instances in the IOC container. Question 14. Where do you define the environment properties in your application? A application.properties, B pom.xml, C application.yamel or D spring application.class. Now the correct answer is A and C. You can define environment properties in both these classes. Okay. Question 15. Map the following annotations with their respective dependencies. We have annotations like at the rate component, at the rate data, add the rate entity, add the rate service, add the rate auto, add the rate id, add the rate getter and add the rate spring boot application. Now these annotations we get from some dependencies that we add in our pom.xml file. So here we have spring boot starter web, we have Lombok and we have spring boot starter data jpa. So the question is that we have to map these annotations with the dependencies from which we got these annotations. Okay. So first we have at the rate component we got it from spring boot starter web. Then we have at rate data. It's a Lombog annotation. Add entity is is an annotation that we got from Spring Boot Starter data JPA. Addit service also we got from Spring Boot Starter web. Add Autoad also from Spring Boot Starter web. Addit ID we got from Spring Boot Starter data JPA. Getter is an annotation of Lombok. And at the rate spring boot application again we got from Spring Boot Starter web. Okay, question 16. What is spring boot actuator? Spring Boot Actuator is a productionready feature of Spring Boot that helps you monitor your application. It provides endpoints to check metrics, health, environment properties and other runtime information. You just add this dependency in your pom.xml file and you get multiple endpoints like /actuator/halth/actuator/matrix/jvm.threads threads.live/actuator/matrix/system.cpu. usage or/actuator/ environment? There are many other endpoints as well. Okay. Question 17. Which application property is used to change the default port of your spring boot application? A. Spring. B. Server. C. Spring. D. Application. So correct answer is B server. port. You can define your port using this property in your application.properties file. Question 18. What is the main purpose of spring profiles? A to create multiple beans. B to separate configurations for different environments. C to define multiple main classes or D to manage dependencies. So the correct answer is B to separate configurations for different environments. Spring profiles are used widely in your projects as generally in our companies we work on multiple environments like dev, test and prod. Okay. Question 19. Which property is used to activate a profile in spring boot? A. Spring.profiles.active, B. Spring.profiles.enable, C. Spring.active.profiles or D. Spring.Environment.profile. So the correct answer is A. Spring.profiles.active. You use this property in your application.properties to activate a profile for a particular environment. Okay. Question 20. Can you connect multiple databases with your Spring Boot application? Yes or no. So the correct answer will be yes. Yes, you can. You just have to give both their database properties in application.properties file and create separate configuration classes for them. Question 21. Which of the following is Spring Boot's default server? A. Jetty, B, Tomcat, C. Underdo, or D none of the above? The correct answer is B. Tomcat. Question 22. What is context path? How do you define it? In Spring Boot, the context path is basically the base URL under which your application runs. So, all the APIs will start with this base URL. You can define context path by adding this property in your application.properties file. Question 23. Can you disable a particular class from spring boot auto configuration? Yes or no? Correct answer is yes. Yes, you can. Just use exclude in the add spring boot application annotation. Question 24. What is spring boot's default serialization format? A. XML using jaxb. B JSON using Jackson library, C YAML using snake AML or D binary using protocol buffers. Correct answer is B JSON using Jackson library. Question 25. Which of the following is the default JPA implementation used by Spring Boot? A Eclipse link, B Hibernate, C Open JPA or D top link. Correct answer is B. Hibernate. Question 26. What does the add rate generated value annotation do? A. It sets the default value for a column. B. It declares a transient property. C. It specifies a default column length or D. It defines how the primary key should be generated. So the correct answer is D. It defines how the primary key should be generated. Question 27. Which of the following best describes the relationship between JPA and Spring Data JPA? A. Spring Data JPA replaces JPA. B. Spring Data JPA implements the JPA specification. C. Spring data JPA uses JPA underneath and builds additional abstractions over it. Or D. They are completely independent technologies. So the correct answer is C. Spring Data JPA uses JP underneath it. and builds additional abstractions over it. Question 28, match the following. In the first column, we have classes and interfaces. We have JP repository and entity manager. And in the second column, we have the technologies that they belong to. Okay. So, JPA repository belongs to Spring Data JPA and entity manager belongs to JPA. Question 29. What is the main purpose of Lombog in a springboard project? A to handle dependency injection. B to reduce boilerplate code like getters, setters and constructors. C to manage application configuration or D to handle database migrations. So the correct answer is B to reduce boilerplate code like getters, setters and constructors. Question 30. Which Lombok annotation automatically generates getters and setters for all the fields? A add rate getter setter, B addors, C add data or D add auto methods. So the correct answer is C add data because at the rate data contains both annotations add getter as well as add rate setter inside it. Okay. Question 31. Which of the following is the correct syntax to use at the rate value? A add rate value with a dollar sign. B add the rate value without any sign directly server. C add the rate value with a hash sign or D add value with an and sign. So the correct answer is A add the rate value with a dollar sign. Question 32. How do add value and add the rate configuration properties differ in usage? A add rate value is used for a single property whereas add configuration properties is used for a group of related properties. Both work only with YAML files. C add configuration properties doesn't require getters and setters or D add value can only be used once. So the correct answer is A. Add value is used for a single property whereas add configuration properties is used for a group of related properties. Question 33. What is the purpose of pagination in spring data JPA? A to fetch all records at once. B to fetch data in smaller chunks or pages instead of the entire data set. C to update records in batches. or D to cache the query results. So the correct answer is B to fetch data in smaller chunks instead of the entire data set. Question 34 fill in the blank. Dash is the interface used for pagination. So the correct answer is pageable. Pageable is the interface which we use for pagination. Question 35. Fill in the blank. Dash is the class used for sorting. So the correct answer is sort. Sort is the class that we use for sorting our data. Now question 36 match the following. In the first column we have filters and interceptors and in the second column we have one is part of the spring framework and one is part of the serlet API. Okay. So filters are part of the serlet API and interceptors are part of the spring framework. Question 37. Which method in an interceptor is executed before the controller method is called? A pre-andle, B postandle, C after completion or D hand handle request. So the correct answer is A pre-andle. Question 38. Which method in an interceptor is called after the response is returned to the client? A pre-andle, B postandle, C after completion or D finalize. So the correct answer is C after completion. Question 39. What is the main purpose of an interceptor in Spring Boot? A to intercept requests that reach the dispatcher serlet and perform logic before and after the controller methods. B to intercept request before they reach the dispatcher serlet. C to handle only authentication failures or D to process JSP rendering. So the correct answer is A to intercept requests that reach the dispatcher serlet and perform the logic before and after controller methods. Question 40. What is the correct order of execution? A. Dispatch a serlet then filter then interceptor. B interceptor then filter then controller. C controller then interceptor then filter or D filter then dispatcher serlet then interceptor and then controller. So the correct answer is D filter then dispatch a serlet then interceptor and then controller. Question 41. Which annotation is used to enable spring security in a spring boot application? A add at the rate enable security B add enable web security C adding security or D add security config. So the correct answer is B add enable web security. Question 42. What is the default authentication mechanism in spring security? A ooth 2, B basic authentication, C JWT or D LDAP. So the correct answer is B. Basic authentication. Question 43. What is the difference between authentication and authorization? Authentication verifies who the user is whereas authorization determines what the user can access. B authentication is done after authorization. C authorization is about password hashing. Or D authentication is optional. So the correct answer is A. Authentication verifies who the user is and authorization determines what the user can access. Question 44. Which of the following is a stateless authentication method commonly used with Spring Security? A basic authentication, B JWT, C session authentication or D form based authentication. So the correct answer is B JWT. It's the most popular security mechanism these days as it is very lightweight and stateless. Question 45. Which annotation is used to enable caching in a spring boot application? A add at the rate enable cache, B at the rate caching config, C at the rate cachable or D at the rate enable caching. So the correct answer is D at the rate enable caching. Question 46. Which annotation is used to cach the result of a method? A at the rate cache result, B at the rate cachable, C at the rate cache put or D at the rate cache event. So the correct answer is B at the rate cashable. Question 47. What is the default cache provider used by Spring Boot if none is explicitly configured? A radius, BH cache, C simple in memory cache or D mem cacheed. So the correct answer is C simple in memory cache. Question 48 match the following. In the first column we have add rate enable scheduling, add rate scheduled with a fixed rate, add rate scheduled with a fixed delay and add rate scheduled with a chron expression. In the second column, we have runs a task repeatedly with a fixed time interval after the previous execution finishes, enables scheduling in a spring boot application, runs a task repeatedly with a fixed interval from the start of the previous execution, and runs a task based on a chron expression. Okay, so the correct matches at the rate enable scheduling enables scheduling in a spring boot application. At the rate scheduled when used with a fixed rate, it runs a task repeatedly with a fixed interval from the start of the previous execution. And at the rate scheduled when used with a fixed delay, it runs a task repeatedly with a fixed time interval after the previous execution finishes. Okay. And when we use add scheduled with a chrome expression, it runs a task based on a chron expression. Okay. Question 49. Which thread pool is used by default for add schedule tasks? A single threaded exeutor, B cache thread pool, C fork join pool or D fixed thread pool with 10 threads. So the correct answer is A singlethreaded exeutor. Now the last question is that how would you define spring boot in three lines. Okay. So I would define spring boot like this. Spring Boot is a framework that simplifies Spring application development by providing auto configuration and sensible defaults. Okay. It removes boilerplate setup, embeds servers like Tomcat and supports production ready features like actuator and matrix. So developers can quickly build standalone production grade applications with minimal configuration. Okay. So these are the top 50 questions that I wanted to share with you. I hope you liked the video and I hope you understood all these questions. Okay.

Need a transcript for another video?

Get free YouTube transcripts with timestamps, translation, and download options.

Transcript content is sourced from YouTube's auto-generated captions or AI transcription. All video content belongs to the original creators. Terms of Service · DMCA Contact

Master Spring Boot Interviews — 50 Questions in One Shot ...