Spring Boot is a Java framework that simplifies application development by providing a readymade structure with common rules, tools, and reusable code. The IOC (Inversion of Control) container is a memory space created in the JVM's heap area that manages application objects. When developers annotate classes with @Component, the Spring framework creates and manages these objects as 'beans' within the container, rather than developers creating them manually with the 'new' keyword. This inversion of control means the framework handles object creation, management, and destruction, providing advantages like easier dependency injection and lifecycle management. The @SpringBootApplication annotation combines @ComponentScan (which scans for @Component annotated classes), @EnableAutoConfiguration, and @Configuration to enable this automatic bean management.
Deep Dive
Prerequisite Knowledge
- No data available.
Where to go next
- No data available.
Deep Dive
Spring boot - IOC Container explained in detail - Class 2
Added:Okay, even before starting spring AI, I I want you to understand few things about spring boot. I will make you to get the basics. Then we will jump to uh spring AI. Okay, after completing one project in spring boot, we'll try to complete one one project in spring AI.
Okay. So what is a spring boot?
So what what does the definition says?
Spring boot is a Java framework.
Okay. So just focus here. Okay. makes it that makes it easy fast to create run and deploy spring applications with minimal minimal configurations.
If you want to create any Java project by using springboard is going to be very easy.
It is going to be very easy by using springboard. You will understand that with the one project. Okay, just keep it keep this definition in your mind. Okay.
What is a springboard? It is a Java framework. Again, what is a framework?
Okay, framework is a jargon. technical jargon that says a framework is a readym made structure that provides rules, tools and reusable code to help us build applications faster.
People who are new to uh this word framework, okay, think it up like this.
So when I say framework, let us take the house construction example. Okay. House construction. If house needs to be constructed.
So what are the things required? You depend on so many things, right? You depend on uh cement, you depend on soil, you depend on uh you know what we call as bricks, right? You depend on water, depend on pipes, you depend on uh cables. So many things are required to construct a house.
Right? And you construct the you construct the house step by step.
Right? The house construction happens step by step. And I say step by step, but the common things to construct an house is these are the raw materials.
Apart from this, what are the common thing for every house? Even if it is a small house or even if it is a very big house, even it is a skyscraper. Okay.
Foundation is very common.
Foundation is very common. you know the uh concrete uh the creating concrete is very common.
Okay. Uh you know the wall okay wall is very common. The windows are common.
Okay. You do not have to invest separate time on this. If you get everything ready made the the house construction is going to be very easy. So if you want to build the house from scratches you can you have to start from uh you know laying the foundation you know and you know constructing step by step this the one of the way if not you can directly if everything is available in advance if the uh you know things that is very basic to construct house if that is available in advance then the constructing an is going to be very easy right so there is a lot of difference is the time consuming right because you know you are also doing these things from the scratches. But if I give you these things in advance, those construction becomes very easy. Right?
The same analogy you can apply here.
Right? So when you have some readym made things in Java to develop a Java application, you require some basic things. So when I say basic things, okay, they are basic to all projects.
They are common to all projects, right? The rules are common to all projects, okay? The tools are common to all projects. The code that is common to all projects, these will be given to you in advance by the framework.
Right? The things that is common for any project. It could be a banking project.
It could be a you know enterprise application, big enterprise application.
It could be a you know simple uh the what we call as the midcap projects.
It could be a you know small enterprise project but some common course are going to be common for any kind of project that will be that will be given by what that will be given by a framework that is why the framework is a readym made structure right and this framework if you give a word like spring boot it becomes what spring boot framework spring boot is a framework that is going to help you to create run and deploy spring applications with minimal configuration which means 90% of the job will be done by the springboard. You have to do you have to concentrate only on the development.
Only 10% of job needs to be done from your side.
Are you getting the key difference between these two? Yes. No. Hello.
Are you getting this?
Can I get Yes.
Is my explanation is justified? Yes. I want to understand whether you're listening it or not.
>> Hello.
>> Yes, sir.
>> Okay. See, this is fine. Okay. I keep asking you. Just try to answer it to me because I need to I need to understand whether we both are in sync. Okay.
That's the reason why I'm asking. So, now see this is the STS tool. Okay. What I'm trying to do is I'm going to create a simple project file new project.
Okay. So I'm going to select what I'm going to select spring boot. Under spring boot there is a project called spring starter project. Click on next.
Okay. So here I'm going to select few things here. I'm choosing the version as Java 17. You can select just click drop down options to select the version of right and uh I am type I'm choosing it as maven I will tell you why we have to choose maven okay the package packaging is jar okay the language is java right and you know the group name you can give any meaningful name so the reverse of the domain name you can give me say com dot host application.
Okay. Artifact name any any meaningful name you can give first SP project or I can take it very simple com.ext any any uh domain name in the reverse direction you can give com test so that you keep it unique that's it. So this this is going to be a package. That's it. Artifact name is what? Artifact name is something like give any meaningful name. It is a kind of project name.
Okay. The package name is we'll go with SC dot register dot SFP or S SBF SVP spring boot project. Can click on next. Okay. And you can choose any version here. I'm going to choose the the latest one. Right. I'm just clicking on next. I'm going to hit the finish button.
So, so many things happens behind the scenes. Okay. Under the words I will tell you what is that in the future classes. Okay. First now focus your keep your concentration here.
Okay. So, we are not developing a ordinary Java project. We are developing a spring boot project.
If you see the project explorer, okay, Okay, it has created. Okay, the name has given us hacker rank two. Okay, I'm sorry about this name. The project is given as hacker rank. This one, this one, this our project.
Let me change the name.
Refactor refac spring boot project.
Okay. This is our project. It is getting built. Okay. So as soon as you do this you know uh you know it is going to add some configurations. It is going to add some readym made dependencies. You do not have to worry about this. Don't have to worry about this. Right? The first thing you have to do is you're able to see right source main java. Just open this folder. Okay? And you will find the package. The name of the package is the name which you have given at the time of creating this project.
Right? So this is the package name that you have given. Open this. And you know it is going to place the main method for you. Just open this.
Okay, it says the main method is there. Okay, this is you can recognize the main method. But what you do not recognize something like spring boot application, right? And some a line is here like line number 10. If you see, you know, it says spring application dot is calling run method. But you know what these things are, right? Right. Now, let's see if I just run this. Okay, right click here, run as spring boot app.
It is just going to uh we just going to run like this. You see the banner here spring, right? And it says spring uh spring boot application started in 2.8.11 seconds. Okay, it is running.
Right now what is the difference between ordinary Java application and this spring boot application to understand the difference what I'm trying to do here is so this is the main method right so I'm just adding a just focus here this is going to be very important I'm just adding a line like so just to check okay we just trying to debug okay like let me say post line and I am adding Another line here.
Second.
Look at I have just added two lines right in between this uh line number 11. Right. If I just run this, okay, it is not going to run like a Java application. I mean it is not going to run like a Java application. We know how the Java application usually runs. The main thread will be created.
Main thread gets access to the main method and you know all instructions inside the main main method gets executed. So here also it is going to follow the same thing but there is one one bit one little difference here.
Right? So let me copy this and put it in the paint.
Right. So this is our code.
So just remember the Java flow. So how the Java flow works when you start uh running the application right you know right there will be JVM.
So JVM comes into the picture. So this is the JVM.
Okay. So before JVM the doclass file will be created. Okay. You know those things. When JVM gets activated, main thread gets created.
Okay. This main thread gets access to the main method.
Call it as main.
It gets access to the main method. So it is it will execute all the instructions inside the main method. Right? So what is the very first instruction? The very first instruction is what? The first line. Okay. It is going to get displayed in the console. So we know these things.
Okay. Now focus on the second line. What is the second line? Second line says right that is spring boot I mean spring application dot it is calling a run method and this run method is having the argument of the dot class file. See let me wait here.
So this this run method has two arguments. Okay first argument if you look at the first argument it is you know we are passing what? We are passing the dot class file of the current class. So what is the name of the current class aer rank one application. So the file name that I have given right. So it is uh expecting what the dot class file of the current class I can say that the dot class file of the main method. So main method is here main method is part of aer rank one application. The first argument is expecting this. Okay. So this complete line will do what? Because of this line a container will be created. I will tell you what is a container. because of this line. Because of this line.
Okay. So I'm introducing a new word container. A container will be created in the E area. So you know right in JVM there is an area called E area. Inside the E area a small container will be created. For now think it of like a memory space.
Okay. Let me uh let me just uh you know uh zoom this out.
a container will be created.
So this container is called as what? Io container. I will tell you what is this IO container.
Right? And what is the next instruction?
Next instruction is what? Next instruction is the second line. Second end will be printed at the console and the program gets terminated.
Right? So one difference that you can notice here is uh when you start a spring boot application the main method will be executed from top to bottom.
Right? So if you see the spring boot main method okay you come across a special line a very special line called this line.
Okay I will tell you the purpose of this line for now. This line is what? This line is going to create a memory space in the E area of JVM. Okay, that memory space is called as what? The IOC container. Okay, for now just keep this thing in the map. I will tell you what is IOC contain error in the you know uh uh the coming uh explanation.
Right. So I just run this piece of code.
What happens? First line is getting printed. Okay. And you see something here. Something here like you know uh process uh running for 5.4 seconds. And second gets printed. In between the first and second line in the memory space a container is getting created.
The name of the container is what? The IOC container. Okay. So before understanding IOC content you should be asking sir what is this IOC container what is this IOC container what is the purpose of this IO container right so many of them will uh you know most of them they fail to answer this because of lack of understanding okay I will tell you the difference so let us say I have you know two classes we're going to deal with two classes class cat name of the class is cat.
Second class name is dog. So I have two classes here, right? So I am developing this. I'm developing a CL cat class. I'm developing a dog class. I want to create objects. How I can create object for the CL cat class? You know, right? Cat C equal to new cat. So we use the new keyword to create objects for the dog class. How to create an object.
So this is how you know you or me or any developer, any Java developer create an object for any Java classes, right? So these objects are created by developers.
It could be you, it could be me or it could be any developer. So developers are creating the object.
So when developers are creating an object, it is called as an object. Okay, it is very straightforward is called as what?
Right? Sometimes what happens you know if you give the job of creating an object to the framework.
Okay. So here the object is created by developers. But if you instruct the framework or if you direct the direct the framework to create object. Let me repeat this. If you express or direct the game work to create an object, right? So you uh you don't uh you know you no longer call them as an object.
Okay? You call them as what? Beings.
Right. So what is the difference between object and a brain? Now we got data.
Object is nothing but when the developer is creating an object by using the new keyword. Very simple. Okay. When you write this in your code which means you are creating you are creating an object right. So it means they are called as objects. But when you instruct or when you direct the framework you'll be like okay framework I I do not want to create the object can you create object for me.
You're asking the framework like can you create an object for me? Can you create objects for the class?
Okay. So framework is going to create objects for the dog class or the cat class. But you you no longer call them as an object. You call them as what? The right. So when the object is created by developer, it is called as object. So when when this objects are created by using the new keyword, you call them as an object. When the objects are created by the framework, you call them as what?
Beans. Have you understood the difference between object and a bin?
Hello.
I will tell you why how the framework is creating an object. First try to understand the meaning of object versus bean. When someone is asking you to create a bean. So what they mean is right they want you to instruct the framework to create an object. Bean is nothing but you are not creating an object. Okay. Framework framework is creating creating an object on behalf of you. Object is nothing but you are creating an object. I understood the key difference between these two.
Yes. No.
Yes.
>> Right. Very simple. Okay. If someone is asking what is a bean? A bean is nothing but uh if I if you instruct or direct the framework to create an object, you call them as it as simple as that. Okay.
The beans are okay. So why why are we lazy to create an objects? You can create an object very easily. But why we are asking the framework to create beans? Why we are asking the framework to create beans? When the framework is creating the beans, okay, it is going to it is going to have a lot of advantages that bean will have that bean or object understanding you can call it as being because framework will have a lot of inbuilt advantages. It becomes more powerful.
Okay, it is it is going to be very special.
Okay, because of those special characters that is going to possess that's why you are calling it as what bean right when you do it it is not special but when spring boot do does this okay it is going to become very special okay why it is going to become very special okay that is the next topic of discussion okay it is going to get some special benefit why it is going to become very special that is next topic of discussion okay now second question right so far so good if you are instructing or you know directing the framework to create an object you call them as main how we are going to instruct that is the question right okay where these objects will be created that is the question first question is where these objects gets created how are you going to instruct I mean instant framework to create objects.
Okay. To address this you need to understand something like OC. So this is where IOC comes. What is IO? I said no because of this line because of this line a container will be created in the uh E area. We don't know why this container is getting created for now. We don't know but simply it's going to create a container an extra space okay a special area special area that is called as IC container. What is this IOC container?
IOC expansion is what? Inversion of control.
Okay. So what IOC container says rather the developer takes me to create object to create manage destroy objects.
Okay.
Q will give the control to the control to the framework. So it is just like see if you have five classes right. I have class A, I have class B, I have class C, I have class C and class D and I have class C. We have P classes in the Java application. Right? So when you say a framework can you create object for this five classes right the objects will be created by the framework and and it is going to return those five objects to the developer okay there is a lot of advantages when you're giving this work to the framework I will tell you those advantages in the uh in the coming discussion okay objects will be created and these five objects will be given to the developer okay what is IO IOC is Rather the developer takes the responsibility to create, manage and destroy objects. You will give the control to the framework. Framework will be like okay I am happy to create objects for you. But they are not objects. They are called as what? They are called as the beans.
Why beans? These objects is coming with some special qualities. We'll understand this qualities in the discussion.
Now we understood what is inversion of control.
Right? What is the next thing we have to understand? Okay, we have to see this uh programmatically programmatically. Right? See, we have to address this question. How are you going to instruct the framework to create an object? This question needs to be addressed.
So, no, right? See, very simple.
Okay.
Right. So I have one class the name this is the main class. Right. In the same uh same file I'm taking another class. So for simplicity I love this example. The example is I have an engine class.
Car class.
I have two classes. Okay. Engine class and the car class.
Right.
Let me remove this. Not required.
Remove this. not required right in the engine class I am going to have a simple method void void start engine or start when I call this method okay this method is going to do a job what is the job engine is getting started very simple so the car class is going to have a similar method like this similar method like this so instead of engine Start. The method name is going to be car start right car start.
Now you see right now pay attention here.
How many classes do you have here? You have three classes. Right.
Right.
Okay. The next thing is if you want to call engine start method, if you want to call start method, okay, how I can do that? Okay, first you have to create an object for the engine.
Engine E equal to you know new engine, right? So and if you want to call the car start method okay you have to create an object for the car car equal to new car right so simply you can do what okay you have the uh objects here so these objects are created by the developer so these are the ordinary objects right what you can do with the help of this reference you can call the engine start method and you can call the car start method or key.
Okay. Now you know the control flow right? So what happens when I just execute this code? So behind the scenes, okay, this line is going to create a container in memory space. We don't know what is this container till now. We don't know.
See, it is going to create container.
This is going to create an object engine object you are creating here. This is going to create a car object.
With this reference, you can call engine start and you can call car start. Okay, we just done this.
You see engine started, car started, right? Engine started, the car started, right? Let me just replace this.
Right.
The main method and uh you know firstly JVM even though when I select this it is coming okay JVM gets activated. JVM is going to create a thread which is called as the main thread. So main thread get access to the main method right and uh the very first line of the main method I mean uh very first of the main method this okay there is a line called ring application dot it is calling run method which is accepting the dot class of the main uh dot class of the main method right so this is going to create a container in so this is the area in the area somewhere a memory space will be occupied that memory space is called as what? That memory space is called as the container. So the container will be created. This container is called as what? The OC container.
Okay, it's getting simply getting created. Then now what happens? You are creating a new key. By using new keyword, you are creating the engine object and you are creating the car object. Okay, these two objects will also be part of EI.
One is what? One is the engine object.
Second one is the car object. Right? And with these references you are you are calling what you are calling the engine start method.
So this is going to get displayed in the console right and you're calling the call start method. So this is going to get displayed in the control right? So objects are created. These objects are created by what? These objects are created by the developers.
They just the ordinary objects developers created this. So how how can you confirm that objects are created? So through the code how how can you confirm that objects are created? You can add a constructor here. So that is going to give you an idea that okay object is created for this class. Adding constructor for engine class engine object.
So this is the proof that object is created for the engine class. Let me add a constructor for car.
Okay. Okay, this is the proof that object is created for the car.
So we can confirm it. Okay, whether the object is getting created or not. How can we confirm it? If you place the constructor default constructor, if that is getting called, it means there is a complete confirmation that objects are getting created.
Right? So let me run this.
Okay. This engine object car object engine started car started.
Why? Because so you have created an object here and a car object here. So the constructor gets called, right? So that's why the instruction inside the constructor gets executed. And this is the ideal proof that you can uh use the constructor to confirm whether the objects are created or not. Okay, these objects are created by the developers.
The question is okay, we still we are not discussing. What is the question?
How are you instruct how are you going to instruct this framework to create objects, right? How are you going to instruct the framework to create? Very simple. Okay, just annotate every class. Okay, if you want the framework to create an object for the engine class, you want to instruct the framework to create an object for the engine class, just annotate this with the at component.
What is this component?
Okay, if you want the framework to create an object for the class car class, just annotate this with component.
Right?
So when you do this, when you just do this, you just add this component on top of every class. For example, class A. So if you have a class A, right? And uh if you do not want to create an object for this class A, right? If you want to uh give the instructions to the framework to create an object for this just say update component which means now the spring framework will know okay developer has instructed me to create an object how does it know because you're using a component which means spring framework is going to create an object on on your okay for see how how can I confirm this I have added at component on the engine class I have added at the rate component on the car class as well. Okay, so this new keyword is created by me.
Let me comment all this. Let me remove all this.
Right, let me remove all this. Why I have left with what? I left with only one line over here. And you know two classes they are with compar. Okay, if I just run this code, see uh let me expand this. See, I did not create any object. I did not use any keyword in the main method. Are you able to see the car objects and the engine objects?
This is the proof. Okay, I did not create an object by using the new keyword. But how this constructor is called?
Only the constructors will be called when the objects are really created in the memory. But I did not I did not create object by using the new keyword. Right? But if you see the console after running you see the console you are able to see the car object and engine objects. The car object constructor is called the engine object constru constructor is also called.
Why it is called? because I have instructed the framework to create the object.
Now framework has created the object on FB. This is the advantage of art component. If you just add this very simple springboard framework will be like I will create an object for you.
But how this is going to create an object that is the question right now. Now this is going to be interesting. Focus here.
this the main the main topic of discussion you're not understanding just stop me then and there right don't carry forward right you're able to see the screen and see the moment I start hitting the uh you know the run button right see I start hitting the run button. So many things will happen behind the scenes. I'm going to tell you the few things, okay, that is necessary for this class. I'm going to start hitting the run button, right?
So you know what are the basic things that will happen. See, JVM gets activated, right? Main thread gets created.
Right. So this main thread gets access to the main method. So far good. Right.
Focus.
Okay. Now main will check. Right. The main method is there. It is part of a rank aer rank one application which is annotated with add spring boot application.
It will identify this Right? It is going to identify this very simple right because this class has been annotated with art spring boot application. What does it mean? Again this arthrate spring boot application is a combination of three other annotations. I will tell you okay so we are going very slow. Okay. Because I just run I just explain it just like that it won't make any sense. Okay.
It's a combination of three. What are they?
Component auto configuration.
Enable auto.
Enable auto configuration.
Okay. So instead of placing these three right see sorry uh configuration I'm sorry other component scan configuration enable auto configuration. So these are the combination of you know this three com combines together to be called as oneation. Either you can use this or you can use these three.
Right?
This also fine. This also fine.
Import this.
Okay. Forget about these two. Forget about these two. Right? Think about this. Other component scan.
Okay. What is the job of component scan?
Arthrite component scan is just one of the annotations that is act under spring boot application. It's just one of the one among the three annotations. The job of this component scan is to scan. It is going to scan for classes going to scan for classes that is annotated with at the rate component. Okay. The component scan it is just scanning. We'll check it. Okay. in the current package or in the current package and the sub packages. It will check each and every class that is annotated with arate component. So this is one of the class annotated component. This another class annotated with component.
It has found two classes. So before that okay the main method you know the line is pointing to this spring boot spring application.run right. So for this uh eer will be created. Okay, in the area a container will be created, right? So this container is on top of JVM, right? Name of this container is what? IOC container, right?
After this, so it is going to this component scan annotation is going to scan for all the classes that is annotated with at the rate component. So you have engine class you have car class both areated with other component. So the framework will create it means the framework will understand right what what is going to understand okay developer has instructed me to create objects in the IOC container for the car class and the engine class. It will simply create an objects two objects.
Okay. And it is going to give the implicit references. You do not you do not have to worry about the references.
Okay. references will be taken care by itself.
Okay. Object for engine and object for car will be created. Why? Because you are using component on every class.
Okay. On whatever the class it is, right? It is just like giving the instruction to the framework to create an objects for you.
It is doing this. Let me repeat this once again. See previously there was anation called spring boot of don't get any confused here right so this is the combination of all you can use this or you can either use this or you can use this three right component scan configuration one of the rotation is component scan okay so this is going to create a container you know that container will be created that is called as IOC container Right. What happens after creating the container?
So this is not an ordinary class. This is the class that is placed with these three annotations. The job of this component can annotation. We are just discussing about this. We will be discussing about these two in the future classes. First understand this component is going to do what? It is going to scan for all the classes that is notated with other component.
Okay. Right. How many classes are there with other component? Engine class is there and car class is there. Now spring framework knows okay the developer has instructed the framework to create object for the engine where in the container this is the usage of container in the container when the objects are created inside the container they are called as what they called as beans when the objects are created inside the created by the developer outside the container they called as what objects you don't think uh you know uh don't take much here okay just try to understand the way the spring boot application works okay this is the way that we have to create we have to deal with the uh deal with developing the application this these words will be very new these are the framework words right it has own importance and this is going to make our job very simple going make our job very simple you know I know your questions are like you know sir we are very happy with the new keyword why we have to go for the earth component why we are giving the job to the framework okay those questions will be answered okay today the topic of discussion is what okay what is a frame what is springboard we have we have just I have given you a simple explanation on framework springboard what is a framework I given explanation what is I given the explanation right what is springboard application I have given the explanation okay we will we will understand these things in detail what is a component now we have understood it we will Now we will understand step by step right now. Okay, objects are created.
Now what?
Objects are created in the framework. I mean created in the container IOC container. Now what what is the next step?
How do you call these objects? How do you use these references? How do you use these references to create the methods?
Right? So the engine classes engine start method the car uh the car classes car start method. Okay. We have instructed the framework to create create an object. How we are going to call this?
Right. What is the way to call this? See now here again this IOC container has is further categorized into two types.
The first type is okay. Bean factory.
Please be informed that the IO container is further classified into two types. What are they? First one is you have something like bean factory.
So bean factory it's a legacy one. Second one is what application context two things bean factory. Why the name came bean factory is it has the factory.
It is a factory of beans. Beans means object. So that's why this bean factory.
This is the legacy one. These are the types of container. I mean uh of calling it like classification I can say these are the two types of containers. So in every product there will be a type right. So why there will be types. One type will have advantage other type will have some disadvantages. It depends upon our usage. Okay. Which type you like you can go with it. But this be impact is a legacy one. We are not using this anymore. This a new one application context.
Right. So when you can you can choose any two. We're going to choose application context. This IOC container I want to keep it as what? I want to keep it as application context.
How I can keep it as application context? Just open this. So this is the line that is creating a container.
Right? Okay. just assign this line to a variable. I'm just naming this variable as container.
Okay. And I am choosing my container as well. I don't want bean factory. I want application content.
Okay, so this line is creating a container. What I want to do, I want to assign this container to a meaningful variable container. Okay, I want to choose what? I want to choose the application context.
One minute.
application.
Okay.
And if you want you can choose beam factory also be factory also but it is a legacy one.
I want to choose what I want to choose application contract application.
Right? So now what happens behind the scenes, right?
Okay. Uh this IOC is going to have a reference of container because you are given the variable name as container. You can use this reference to call any of these beans. If you want to call engine object, you can call. If you want to call car object, you can call by using this reference. Right? So IOC is a container, right? So it has uh you can choose any container. I'm going with application context because it has some advantages, right? So what I'm doing in the code. So this line is creating a container. I'm assigning this line to the container variable which is called application context type.
Right?
So after this what you can use this reference to to get the beans. Okay for example if I want to get the engine mean if I want to get access to the engine bean I can I can use this reference variable container to get access to the bean engine to get access to this object.
Very simple use this container to get access to the object or get pin. What pin you want to get?
The pin is nothing but the object.
Okay, what you are saying? Okay, there are two pins. Okay, I want the bean of engine.
What you will pass here? We just say engine of engine engine class.
Okay, which means you are getting the reference of what? Reference of the engine class. When I say container getb internally, right? By using this reference you are getting the bean of engine. So this engine is of what class type? This engine is I mean this reference is of what engine class type right. So that is the reason why I am I am passing the engine. Which means get the reference of engine object or engine be and assign it to a variable any meaningful name variable engine.
Okay. This is of what type engine type again.
Right. So this is just giving you the reference reference of engine object reference of engine object object reference of engine object object reference of engine right now you are storing it to engine variable. So now by using this variable you can call the methods of engine class.
Run this car objects created engine object created because of component annotation and engine started. Okay, you are getting access to the you know references by using the get bean method. Right. So this reference can be used to call the respective methods of this of that particular class. I want to call the car start method. What I can do here very simple take the container reference dot get beam get be okay I want to pass the car class car okay and I want to store that in a meaningful variable name let me take it as car.
So now I have the reference bean reference of car class right by using this reference I can call the methods of car class car you see here I'm not using the new keyword here right I'm not using any new keyword here but still I'm able to know all the methods of the respective classes right but you might be thinking sir what is an advantage of this right so this reference is more powerful than if you create a reference by using what we give. I will tell you why. Let us understand this uh Good Remove this not required.
See now you have to think like a spring boot developer not not a Java developer.
Okay. So what happen the very first thing is what the JVM gets activated.
Right. That is the JVM. Let me keep the JVM here.
JVM get JVM is going to create the uh main uh thread. The main thread get access to the you know main method. So we know these things try to discuss over and over again right and it will encoder the first line okay right hand side okay it says spring application run now it comes to know okay it is developer is not creating a java application developer is creating a spring boot application okay you need to create a container in the e area so the e area a container nothing but a memory space guys when I say container just think it up like a memory space and this this is called as what the IC container. So what name I'm giving for this IOC container? I'm taking what I'm giving the reference as the container itself. Okay. Now all the beans will be stored in the inside this container reference.
This just like a reference variable.
Okay. And the name of this container is what I'm using application context.
So this line is going to do this after this okay it will just jump to the spring boot application this annotations okay it will find okay one of the annotation is what one of the annotation component scan which means it will check for all the classes that is annotated with other component there are two classes one is engine class and the car class okay this framework will create an object for these two okay one is what this is for engine and this is what we call is for car. So these are not called object these are called as beans why because framework is creating an object for you. So this is how you select framework to create objects on your behalf. IO inversion of control you're giving the control to the framework. So framework will create objects on your behalf in the container.
After doing this right what you're trying to say you're using the container reference. Okay, you're using the container reference to get the engine object reference and the car object reference. Right, for that you're using the container reference dot get bean means get object of engine class. This reference will be stored inside this engine variable. Right? And by using this engine reference, you're calling what? You're calling the engine start method will execute it. Likewise, container get bin get the bean of car class. We're storing that in the car reference variable. So by using this variable you're calling the part start class. So this is how we have to think about the framework in order when it comes to creating an object. You will not use new keyword not you will ask you you not use new keyword new keyword will create a tight coupling. I'll tell you about that in the coming classes. Right? You will give the instruction to the framer.
Right? What we have understood today we did not understand anything. understood about what is a springboard, what is a framework. Okay, what is IOC? IOC is nothing but inversion of control, inverting the control. Okay, means instead of your program creating and managing objects, the framework will create management objects for you. It is clear discuss about this tomorrow. Spring application, it is a combination of three annotations.
Configuration auto component scan. What is the job of component scan? It will scan for any classes that is with that component.
What is a function other component? It tells okay this class should be managed by spring IOC container. This IOC container will create objects for you.
We will discuss about tomorrow.
Related Videos

TOP 15 Data compression Interview Questions and Answers 2019 Part-2 | Data compression | Wisdom jobs
wisdomjobs
281 views•2019-06-28

CTS 158: 802.11w Management Frame Protection
ClearToSend
4K views•2019-02-04

NDSS 2019 Send Hardest Problems My Way: Probabilistic Path Prioritization for Hybrid Fuzzing
NDSSSymposium
496 views•2019-04-02

How realistic is Cities: Skylines?
CityBeautiful
159K views•2019-02-14

GUIs & TUIs: Choosing a User Interface for Your Python Project | Real Python Podcast
realpython
2K views•2025-04-04

The OSI Model - Explained by Example
hnasr
225K views•2019-05-12

Cloud Computing - Introduction
elithecomputerguy
98K views•2019-10-07

From Traveler's Dilemma to Dynamic Routing | Demystifying Networking
IITBombayJuly
5K views•2019-08-04
Trending

WOW! Judge TURNS THE TABLES on Trump in His OWN $10B LAWSUIT!!!
MeidasTouch
197K views•2026-07-23

Playstation NO DISC/NO BUY Fight Is Over...
DavidJaffeGames
4K views•2026-07-23

Steam and Xbox Just Dropped The Hammer On PlayStation
OhNoItsAlexx
9K views•2026-07-23

Americans Confused in Australia for 17 Minutes Straight
IWrocker
17K views•2026-07-23