Two Java Beginner Coding Tips

DZone 's Guide to

Two Java Beginner Coding Tips

Write your code as temporary comments and remove syntax errors as soon as you see them.

· Java Zone ·
Free Resource

Here are a few tips I’ve been verbally passing on when teaching new develops at my Java-For-Testers, face-to-face training.

  • Write the code you want to see as comments first
  • Remove syntax errors as soon as you see them

Write the Code You Want to See as Comments First

For example, creating a blog comment, such as:

iterate over the list and print the name of each object in the list
and assert that when I call getAge for each object it is greater than 18

The reason for doing this is that learning Java is hard enough. You find yourself with all kinds of questions:

  • What short cut keys in the IDE do I use?
  • What was that loop construct again?
  • How do I get the age?
  • What does the if statement look like?

You are trying to remember a whole bunch of stuff.

Writing down what you are trying to achieve means that you don’t have to keep that in your head at the same time.

Eventually, you will stop doing this. And you will want to delete the comments when you are finished.

But, I’ve seen this help people because this it stops people from getting too far lost.

Remove Syntax Errors as Soon as You See Them

When people don’t do this, they end up writing a bunch of code, and then, none of it works. And, it can be hard to resolve.

As soon as you see a syntax error, fix it. This will allow you to write code and harness code completion.

Sometimes, that means I’ll write "" because I just want the syntax error to go away and I haven’t decided on the data yet.

Sometimes, that means I’ll pass the null as the argument because I don’t know what it should be yet, but I know it needs to be there.

Then, when the line of code is syntactically correct, I make it semantically correct.

This also helps when you are using the IDE to write code with “Alt+Enter,” the more syntactically correct it is, the more the IDE will generate the code you want to see.

And using the IDE to write your code can help avoid syntax errors.


Those are the first two tips that come to mind. I’ll try to make another list the next time I teach the training. This is just a list of simple things that can avoid the enormous, cognitive workload associated with learning code.

This article was syndicated from blog.eviltester.com. Author Alan Richardson is an Agile Software Development and Testing Consultant he has written 4+ books including Dear Evil Tester, Automating and Testing a REST API, Java For Testers. He has created 6+ online training courses covering Technical Web Testing, Selenium WebDriver and other topics. He is a prolific content creator on his blog, Youtube and Patreon.

coding, comments, java, java for beginners, syntax error

Published at DZone with permission of Alan Richardson , DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}