1 / 3

Best Practices for Java Variable Naming and Layout Style

This guide outlines effective Java style conventions for variable naming and code layout. Variable names should start with a lowercase letter, using camel case for multiple words (e.g., `audioSystem`). Constants should be in all caps with underscores (e.g., `MAX_ITERATIONS`). Large scope variables can have longer names, while boolean variables should follow the `isX` format (e.g., `isVisible`). Code layout should maintain clarity with proper indentation, whitespace around operators, and blank lines between logical blocks. These practices enhance readability and maintainability of Java code.

jill
Télécharger la présentation

Best Practices for Java Variable Naming and Layout Style

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Java Style • Variables: • Variable names start with lower case character and separate words by raising the first letter of successive words, e.g. line, audioSystem. • Names for constants use all capital letters and underscore “_” to separate words, e.g., MAX_ITERATIONS. • Variables with larger scope use longer names and otherwise use shorter names. • Boolean variables has the format isX, e.g., isVisible, isSet. • Abbreviations of words should be avoided. • Avoid using magic numbers; define constants instead. • Variables should be declared where they are used and localized in a small scope.

  2. Java Style • Layouts: • Use indentation to increase clarity. • Put white spaces around operators and colons; put one white space after key words and commas; • Insert blank rows between logic statement blocks. • While statements use the following two styles: while (condition) { statements; } while (condition) { statements; } or if (condition) { statements; } else if (condition) { statements; } else { statements; } 6. If statements 5. Do-while Statements do { statements; } while (condition);

  3. Java Style 7. Do-while Statements for (initialization; condition; update) { statements; }

More Related