Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

View RSS Feed

JD1's Personal Development Blog

JD1's Personal Development Blog

Rate this Entry
Quote Originally Posted by KevinWorkman View Post
Just a few words of advice, take them or leave them:

Even if an if or a loop only consists of a single statement, you should still surround it with {brackets}. This is not only a standard Java convention, but I promise it'll save you a headache in the future.

And perhaps I can clear up some of your thoughts on the switch statement.

You use an if statement to test conditions, the operands of which you might not know at compile time, because they can change depending on program flow. But a subsection of those cases exists where you do know the value of one of the operands at compile time, and you're simply testing whether the other operand is equal to any of those known values. That's when you use a switch statement. It's not just more efficient, but once you're used to it, the syntax is also easier to read (easier to read than a bunch of if statements), which makes it easier to debug and harder to screw up.