r/javahelp • • Dec 14 '21

Experienced Java Programmers, what are your tips to become better at Java?

Any key tips will be appreciated! Also, if you are going to say practice please expand on it, thanks!

33 Upvotes

32 comments sorted by

•

u/AutoModerator Dec 14 '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:

public class HelloWorld {

    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

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.

42

u/_Atomfinger_ Tech Lead Dec 14 '21

Continue to write more Java. Practice makes perfect.

6

u/Health_45 Dec 14 '21

What type of practice do you do to get better at it?

16

u/_Atomfinger_ Tech Lead Dec 14 '21

Just writing applications. Keep doing better and bigger stuff and you'll learn a ton.

4

u/[deleted] Dec 14 '21

java programmer is a big ecosystem.

there are methodologies and tools as well.

besides core java language, you can also advance yourself in using tools that are used to build and test java stuff.

being good at tools will help you being a better java developer.

with the help of tools much of the best practices can be standardised and your growth will already be on the fastest path

4

u/LazyGamble Dec 14 '21

Do a lot of real projects, don't try to learn by learning it explicitly but learn from your actual work and the problems you overcome and see what works and what doesn't.

3

u/khooke Extreme Brewer Dec 14 '21

Build apps with different libraries and frameworks that you haven't used before. It's useful to practice doing what you're already familiar with, but part of practicing is to grow your skills and knowledge in other areas that you may be less familiar with.

24

u/maethor Dec 14 '21

Besides writing more Java (which really is the best way to get better at it) read Effective Java by Joshua Block.

11

u/timotomat0 Dec 14 '21

Look at job postings for java devs and research buzzwords in the job listing surrounding java.

8

u/Cap-Ten-Bill Dec 14 '21 edited Dec 23 '21
  • Learn Clean Code

  • Learn Design Patterns

    • Implement them

  • Learn technologies and Libraries Used

  • Monitor Java Release Notes

    • Try new idea

  • Find Open Source Projects you can help out with

    • Or at least try it yourself on a fork..

3

u/techieguy009 Dec 16 '21

This needs to go up!!

4

u/kwinabananas Dec 14 '21

Practice, then practice more. Then when you've done that, practice some more.

4

u/fluffytme Java dev Dec 14 '21

Learn how to effectively use a debugger. It makes things sooo much easier if you know how to properly debug an application, hell you can even attach a debugger to a remote process and see what's going on (e.g. hook it into a webapp running on a Tomcat server and debug away)

3

u/manuelpimen Dec 14 '21

Implement what you read, don't just read stuff but put in practice as you read it!

2

u/akuma-_-8 Dec 14 '21

Read, practice! Practice and read! Try also other programming languages. Having a side project where you can do everything you want is also really helpful.

2

u/mit74 Dec 14 '21

Learn design patterns and when to use them. I still make the mistake of forgetting to use them when they should be used.

2

u/severoon pro barista Dec 15 '21

The number one thing you can do to become a better programmer in general, and specifically a better OO / Java programmer, is to learn how to structure code in a way that organizes dependencies sensibly.

This is at the same time the most useful and useless advice you'll ever get. It's useful in the sense that, if you can do it, there's almost no limit to how high you can technically go. You'll be a better programmer, designer, and architect, you'll be able to understand other packages that are well written very quickly, you'll be able to insulate your projects from bad design decisions made in other projects you have to depend upon, etc. It's useless in the sense that, without specific guidance, it's too vague to actually use (it's like saying "practice" … but practice what, exactly? :-) ).

Everything in programming—and I mean everything—can be viewed in terms of how it affects dependencies. That's the problem with learning to view things this way: There's always some other valid point of view, and how do you decide which is better? Sometimes you can't, and that's fine. The main thing is to be able to recognize bad points of view on it.

A brief review of what I mean when I say everything…

Why is a procedural language like C better than programming in assembly? Because it introduces concepts like for-loops and other language constructs that allow you to abstract away details. But not all abstractions are equal, procedural languages provide abstractions that help you structure your code in a way that helps you control dependencies. If you ever write a decent-sized project in assembly, you quickly end up with spaghetti, and then you take a more mature pass at it and organize all that assembly into modules, and before you know it you've spent probably more code supporting this modular approach than actual business logic that executes your app.

Similarly, why is an OO / functional / etc language better than procedural language? Again, it introduces more abstractions that allow you to control dependencies better.

What's so great about component object models like model-view-controller (MVC)? They give you a way of coding that structures dependencies in a way that is robust in the face of change.

Why are the Gang of Four design patterns so well respected? What differentiates them from the raft of design patterns that followed which are all mostly terrible? They got the dependencies right; the also-rans didn't.

So for OO, what does it mean to manage dependencies well? Learn the Dependency Inversion Principle. Most everything you read on it will exclusively address OO, and that's fine, but really try to understand the essence of it and the point and how to manually construct it in other non-OO applications too. Above all, do not confuse dependency injection with dependency inversion! These are both abbreviated DI and frequently used interchangeably when they are not interchangeable. Dependency injectors like Guice and Dagger are tools that assist good design that has properly inverted dependencies, but they do not tell you what dependencies to invert, and in fact don't even invert any, they just inject. If you don't understand the dependency inversion principle and you are using a dependency injector, it's like taking a bad carpenter's hammer away and giving them a nail gun. Will they work faster? Yes. Will they build something better? No, it will be worse. It will be bigger and more rickety and worse in every way.

All of the other SOLID principles you learn about (interface segregation, stability abstraction, Liskov substitution, etc) can, and should, be viewed through the lens of how they support good dependencies. So that's all well and good, but what is a good dependency? How do you know if a dependency is good or bad?

This is one of those questions that's impossible to answer in a vacuum, but in general you want to have a good understanding of the problem domain that your application is addressing. For instance you're building a chess game, or an app that allows customers to book a cruise for a cruise line, etc. First understand how you are going to model the different elements in that problem domain. This is going to be different for different programming paradigms because the "atom" of a functional program isn't the same as for OO. But let's take the chess game for instance.

You have a board, various pieces, and a player. Those are the fundamental objects, and all other objects you're going to build when you write your chess game should model these objects as such. The very first way most designs go wrong is that the board is designed so that it is a piece container, which means now you cannot compile Board.java without having ChessPiece.java on the class path. Is this a good dependency?

No! A chess board in real life exists on its own, it is not contingent upon chess pieces being present. In fact you can play checkers on it if you want. So you should not need anything on the classpath to compile it. A piece is only associated with a particular square on a chess board in the context of a game of chess, so later on when you design your object that models an actual game, that class can depend on both.

Such a simple and fundamental mistake immediately sets you up for working around this bad dependency as long as you work on this chess game project, and it all stems from not understanding how to mirror the dependencies that actually exist in the problem domain in code.

Hope this helps!

P. S. Dependencies should always be a DAG, and long dependency chains are bad. Circular dependencies are not allowed.

P. P. S. Google MVC implementations in Java right now—how many examples can you find where there are circular dependencies between the different components? You can immediately rule those out as being worthwhile, they got it wrong. (Most of them get it wrong.)

2

u/OMWasap Dec 26 '21

Is it the Java language you’re looking for? Or Object Oriented Programming specifically?

Regardless, if you don’t know already, I would recommend learning object oriented programming via Java! I’d like to believe that’s the best way to get into Java.

Make a “pizza store” program. Where you have a Pizza object, and in the Main/driver class, make a series of questions for the Pizza class. Questions like “how many pizzas” “what toppings” “what size” etc. then make it more difficult on yourself by implementing data structures like Arrays or linked lists etc.

But this is very “beginner” type of stuff. I thought I’d throw it out there just in case a beginner was interested.

1

u/new_one_7 Dec 14 '21

People say practice I think beside that, you should read good example of coding and understand it.

1

u/cerntain Dec 14 '21

Practice making some Spring APIs

1

u/AceroAD Dec 14 '21

Read documentation and implement it

1

u/wakuku Dec 14 '21

practice writing java code without using an IDE. I wish I did that. IDE makes things easier but you tend not to remember shit after you finish your homework. Like I can do the a a java homework by searching stuff up but on my last test, i have to do the same homeworks again and I didnt do well because I panic and dont remember shit anymore

1

u/Vezqi Dec 15 '21 edited Dec 20 '21

Using the Stream API can simplify the need for loops in most cases. They're much cleaner to write and can be more efficient.

1

u/11timesover Dec 15 '21

Github or bitbucket, lang: java. Looking at source code is very enlightening.

1

u/jppp2 Dec 15 '21

I think the other suggestions have better tips than I could provide, but we don’t know your current level so:

What is your current experience in Java? How about other languages or programming concepts?

What do you need Java for? Do you want to build an gui application, cli application, simple in-&output, database, or?

1

u/AngelVzla Dec 15 '21

Keep doing coding exercises, study books from time to time (certification books gives you a lot of insight) and keep an eye on the whole spring framework, most likely every single job you land will be using that thing.

1

u/Typiqally Dec 26 '21

I decided to get into Java reverse engineering, messing with bytecode increased my understanding of Java by a ton!

1

u/JoshAlex Dec 27 '21

One realization you should consider is that the things the separate good programmers from medium and bad ones are never language specific. A good java programmer is going to also be good in Python or C++ or Javascript. A bad one will be bad across the board.

With practice, everyone will learn the basic syntax of each language in short order, the differentiator from good & bad code however is language agnostic.

One great blog out there is Robert Martins (Uncle Bob) which is not Java specific, but has generally good advice.

1

u/[deleted] Dec 14 '21

Use System.out.println() instead of Log4j

0

u/[deleted] Dec 14 '21

Just....be better