r/learnjava • • Feb 10 '26
Is it okay to not understand stuff like IOC, injection, beans in beginning and move forward or should I wait and get hold of these first?
Need to get myself familiar for spring boot and as I need to start working on it from next week. So what would be your advice
0
Upvotes
•
u/AutoModerator Feb 10 '26
Please ensure that:
If any of the above points is not met, your post can and will be removed without further warning.
Code is to be formatted as code block (old reddit/markdown editor: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.
Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.
Code blocks look like this:
You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.
If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.
To potential helpers
Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
1
u/VegGrower2001 Feb 10 '26 edited Feb 11 '26
You'll manage to get started and follow some tutorials etc, just fine. For the rest, here's a short explanation.
In current usage, a bean is simply an instance of a Java class, with all its required configuration elements.
When you first discover Spring, you'll probably think of it as a web framework. And it is. But the heart of Spring is really a system for creating, holding, using, and eventually destroying beans. Some of these beans are ones that Spring provides, depending on your configuration. But you can also ask Spring to manage your own beans, then it will automatically create them and use them, too.
Very often, one bean will depend on one or more others. Spring will help you here because , when it goes to create a new bean and finds that it needs some other beans which it already has, it will automatically make them available to the new bean. This is one of the main parts of dependency injection. Spring will helpfully inject any dependencies that it can. That's work that your own code then doesn't need to do.
Inversion of control means simply that, instead of writing code where A controls B, you write code where B controls A. How does that apply here? Normally, you might write code that loads a java library and uses it. In this case, your code is controlling the provided library. But Spring works differently. When you run Spring, it's going to be in control and it's going to use the code that you supply to it. Ultimately, you can still get Spring to do what you want, but you need to understand that Spring is in control and supply it with all the configuration etc that it needs in order to achieve what you want.
1
u/vudureverso Feb 11 '26
How to Learn Spring Boot Fast (Using AI Properly)
1: Use ChatGPT in "Study & Learn" Mode
Instead of asking for answers, use it as a mentor:
Use it interactively. Don't just consume explanations — test yourself.
2: Use Gemini NotebookLM to Process Documentation
NotebookLM is powerful because it works directly on source material.
You can:
The key: feed it high-quality sources. High-Quality Sources include official materials you can upload or paste and books.
Good luck!
1
u/Ok-Dance2649 Feb 12 '26
These are part of the core spring framework. Everything else in spring frameworks family relies upon that. If you can live without that, fine, but questions related to understanding DI are rising frequently. And besides, it is not such terrible thing to learn these concepts, one by one.
IoC and dependency injection are tools for inverting depnendencies when necessary. It's a design matter if you want to have a good code organisation with modularity in place. This is all part of the sound architecture/design as an enabler to the evolutionary aproach in agile world.
Dependencies matters, separation of concerns matters, cohesion matters, modularity matters!
0
u/severoon Feb 10 '26
It's fine to ignore beans. These were a curiosity in the early days pushed by Sun that were supposed to allow simple POJOs that follow this JavaBeans pattern to plug in as a component in a larger component object model. The larger model never really took off. However, the pattern gave new Java developers some rules to follow, and follow them they did, even though there was no reason or purpose to it.
For IoC, you absolutely should learn this as it's not really Spring-specific but just good OO design. Learn the SOLID principles, especially the Dependency Inversion Principle. Keep in mind that most people conflate "dependency inversion" and "dependency injection" and use the abbreviation DI to refer to both when they should be talking about one or the other.
To clarify the difference, dependency inversion is the way you design your code to break a chain of dependency. Dependency injection is the act of instantiating a class and handing it to another class so the receiving class doesn't have any dependency on the instantiated class, and this is often done using a dependency injector like Spring, Guice, or Dagger (but can be done manually).
For example, let's say you have your own DB connection class that wraps the standard one because you have some specific DB setup you need to manage:
This is bad because in order to compile this class, you need
MySqlDatabaseConnectionon the classpath. Since dependency is transitive, if this database connection class requires 120 other things on its classpath, now you need those things on your classpath as well. YourQueryExecutordoesn't really care about any of that, though. It runs standard JDBC statements against any old database and returns a JDBC result set, so for all it cares it could be querying any DB.To invert this dependency, just abstract your MySQL-specific stuff:
Now you can compile
QueryExecutorand only haveDatabaseConnectionon its classpath. This is because the dependency graph went from:QueryExecutor ‒> MySqlDatabaseConnection ‒> …to:
QueryExecutor ‒> DatabaseConnection <‒ MySqlDatabaseConnection ‒> …See how the dependency chain gets broken? Now everything depends on
DatabaseConnectioninstead of dependency transiting endlessly along the chain.The key thing that many new devs get wrong when doing IoC is that they do the dependency inversion, and then they go ahead and package the
DatabaseConnectioninterface up with both, or either, of its dependencies. So, in theory, you can compileQueryExecutorwithoutMySqlDatabaseConnection, but in practice since it depends onDatabaseConnectionandDatabaseConnectionis packaged up withMySqlDatabaseConnection, there's no way to depend on it without also having all of the MySQL-specific stuff on the classpath as well.If you're not going to take the time to actually break the compilation dependency chain, don't bother inverting the dependency in the first place. It's pointless to do this as a design exercise if you're not actually going to take advantage of it because, remember, you still have to deliver the created instance of the connection to the executor, and it's very possible to get that wrong and end up in a situation where that part of the process ends up spoiling the inversion. No, if you invert a dependency, then make sure you don't bundle the interface with its implementation.
The other way is problematic too. If you bundle the interface with its client, now you have a situation where you cannot compile the implementation without having the interface and everything it's packaged with on the classpath. You don't want implementations to depend upon their clients.
I've heard a lot of people complain about DI tools over the years, "Guice sucks because it makes the codebase impossible to navigate!" Every last time I've looked at these codebases to see what's so bad about Guice, all I've ever discovered is incorrectly inverted dependencies.
Anyway, now that you know the secret, you should be able to avoid the pitfalls. Just remember: If you can't compile code with the actual dependency graph you're trying to create by inverting deps, then you didn't invert the deps. Compiling the code with the deps you design is the unit test for your design, and you have to make sure you "write" that unit test by having only the correct deps available to the compiler to ensure the inversion is done correctly.