I'm new to Java but I'm not new to programming and I'm wondering what areas of Java programming do rookie Java programmers tend to overlook or not give enough attention to?
This question is aimed at Java programmers who have experience with the language and writing real Java programs.Hopefully the answer will help us rookies on certain overlooked topics.
If I had to choose one area that surprised me with its lack of coverage in the intro materials -> the class path. I'm surprised how much(implicitly and explicitly) class path shows up in real java programs. Its everywhere but intro materials don't really emphasize its importance.
I find that many people don't pay attention to testing that much. This is an extremely important part of development. Developers who don't know how to test their code tend to produce poor quality code and designs.
From what I've seen here (okay, maybe not a representative sample) a lot of programmers will start working on a part of Java which they haven't seen before, and their modus operandi is to just start writing code. And then they code themselves into a corner which they can't get out of. Whereas if they had starting by reading a tutorial, and downloading some of its code and playing around with it, they wouldn't be in that mess.
And it's not like the Internet is short of tutorials. There's plenty of them out there and some of them are even not bad.
Beginners should be writing tons of code snippets. Reading the Javadocs on a class and method often leads you to make a lot of assumptions about it's real behavior (e.g. Scanner). Taking a bit of time out to write a few lines of code to exercise a method or methods to assure yourself that it indeed works the way you thought will save you lots of head scratching later. Snippets can also be the source for examples that you can cut and paste into projects.
That became much easier with Java9 when JShell was introduced. You can run one line of code and see it go wrong. I firmly believe that you can learn more from code going wrong than from code working beautifully first time.
Campbell Ritchie wrote:You only need it after you have started using external resources.
I think that one of the first lessons should be how to set up a project directory structure, including how to compile your classes into a different directory than where your source files are. To prevent you from having to switch between directories all the time, you would then need to specify the class path when you tell java or jar to run your application.
Also I'd say, try not to mess around when writing a code. Meaning, make sure formatting is consistent, code is well indented. No excessive amount of empty lines between the code blocks, at the same time, code is not squeezed onto fewer lines as possible. Variables names are chosen carefully, so they tell exactly what they represent.
These things aren't difficult to get them right right from the beginning (except maybe it will take some time to name variables in an optimum way..), and they do help a lot.
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop