r/javahelp • u/vhacbao_vn • Jan 06 '21
Algorithm in Java Spring
I am Java self-taught, I just learned algorithms and spring framework. I want to master web programming using Java. I am still a student, I have never participated in real projects so I have many questions I want to be answered. I would be more than happy to receive an answer from someone.
-In Java Spring practical projects, algorithms such as recursion, backtracking, BFS, DFS, binary tree search, etc are used and used a lot? When Spring Data JPA has a search function, are search algorithms such as binary tree search, BFS, DFS, etc important and used?
- Between the algorithm and the framework, which one should I learn more deeply?
Hope someone will answer these of my problems. Thanks very much
14
u/King5lay3r Jan 06 '21
Let me get this straight. You'd only be using Algorithms you've mentioned when needed, which is very rare. You'd be applying the business logic of the application or service you are building. You have been blessed with all the required Data Structures and their APIs that using these algorithms from scratch is not necessary. When developing project your focus should be getting the business logic right and delivering a working component. All the required operations are provided through APIs so you'd focus more on actual development. Although no one is stopping you from using Searching and Sorting algorithms if its for the learning purpose.
About your second question; they both have their own place. Learn Algo and DS for problem solving and interviews, Learn framework for actual project development.
8
u/LiteratureStriking Jan 06 '21 edited Jan 06 '21
Honestly, with basic web apps and most business apps, they are not going to be algorithm heavy. You'll be using libraries that implement the algorithms. This is true unless you are going into a very specialized field, such as machine learning or data analytics. It's good to have background knowledge though, because the need might turn up every now and again.
While framework knowledge is good, more practical knowledge would be architecture, testing and tuning. You don't want to let the framework do the thinking for you and you don't want to become a slave to the framework.
Learn how to structure apps so that they are easy to maintain and test. (for example: Clean Architecture, SOLID).
Learn testing techniques, to ensure code quality and ease of maintenance (for example Test Driven Development).
Learn code tuning so you can get an instinct for what is not a good idea to do (for example, not writing horrible SQL or the dreaded N + 1 SELECT problem), while at the same time knowing when the code is good enough vs. when you need to write more sophisticated code to improve performance (premature optimization is the root of all evil).
Also, some basic code quality skills is good, especially when working on a team (code formatting, when and how to comment, etc.) (see Clean Code).
1
1
u/dastardly740 Jan 07 '21
Also, even when you use search and sort algorithms they are embedded in your data store, and you trust the data store to do things right. Whether that is a relational database, elasticsearch, Cassandra, Mongo, or others.
I will also add one of the most annoying things I run into is people writing code that should be handled by a library. For example: I caught multiple people writing the code to copy an InputStream to an OutputStream instead of using Apache IOUtils. I also ran into quite a bit of String manipulation that Apache StringUtils handles.
So, one more...
Learn to recognize what should be generic code, that you shouldn't have to write. Then, google for the library. You won't always be right, and there might be reasons not to use what you find. But, when you get good the vast majority of the time you will find yourself writing less code and just adding maven dependencies.
2
Jan 06 '21
" I have never participated in real projects " - You can always fix this by participating in real projects. There are plenty of open opportunities in open source community, build your git profile, try to contribute something everything daily.
If not enough time or not getting enough knowledge to do something, just mimic some and see if some one has contributed any code, how they have done, what they have done it.
As already posted by others, it should be a balance between algorithm and framework. If you are master of algorithm but you don't know basics of framework, you are of no use. I will suggest go slowly in parallel in both.
At the same time, algorithm is important as most of interview questions are based on it, so it is not only important to know the basics, but you must have hands-on experience of implementation of most of algorithms so that you can answer better the practical questions of interview also.
May be you can try to create your own repository of implementation of each algorithm and play around with code.
Hope it helps feel free to DM me or ask here more.
2
u/evils_twin Jan 06 '21
Memorizing how to code these algorithms isn't really needed when you actually start working, but you will probably be tested on these things in an interview.
What you should understand is the strengths and weaknesses of each of the algorithm so when you are trying to solve a problem you can choose most efficient algorithm and data structure that will solve your problem.
1
1
Jan 06 '21
it's important to understand the theory behind things but typically you'd just use a library, instead of your own homegrown solution, for these algos
1
u/sweetno Jan 06 '21
It depends on what's the problem domain. The damning majority of problems in web development, whether they use any advanced algorithms or not, have already been solved, so it's uncommon to write algo code for such projects.
However, if you develop something that is conceptually new, knowing algorithms and data structures will decide who wins the competition.
1
u/dastardly740 Jan 07 '21
Also, understanding time complexity analysis (i.e. Oh of) can be a good thing. So, when you find out that a Java LinkedList get(int index) has to traverse the list to get to the element. You don't do this...
for(int i == 0; i < mylist.size(); i++) { Object item = mylist(i); item.doSomething(); }O(n2) use an ArrayList if you really need to do that...
Of course the right way because we should program to interfaces and not implementations, so your code shouldn't know what kind of List it is working on...
for(Object item : mylist) { item.doSomething(); }O(n)
•
u/AutoModerator Jan 06 '21
Please ensure that:
Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions
You include any and all error messages in full
You ask clear questions
You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.
Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar
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: empty line before the code, each code line indented by 4 spaces, new reddit: https://imgur.com/a/fgoFFis) 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.