[ Pobierz całość w formacie PDF ]
help you win friends and influence people. Here goes:
% class comments
% package declaration
% import statements
% class declaration
% static variables
% instance variables
% constructors
% methods
Location and Initialization
The following guidelines should be considered when making Java declarations:
% Within methods:
% Declare and initialize local variables before other statements (whenever
possible).
% Declare and initialize block variables before other block statements
(when possible).
% Declare only one member per line.
% Avoid shadowing variables. This occurs when an instance variable has
the same name as a local or block variable. While the compiler will allow
it, shadowing is considered very unfriendly towards the next co-worker
(remember: potentially psychopathic) who has to maintain your code.
Color profile: Generic CMYK printer profile
CertPrs8(SUN) / Sun Certified Programmer & Developer for Java 2 Study Guide / Sierra / 222684-6 / Chapter 12
CertPrs8(SUN) / Sun Certified Programmer & Developer for Java 2 Study Guide / Sierra / 222684-6 / Chapter 12
Composite Default screen
Use Sun Java Coding Standards
13
Capitalization
Three guesses. You better use capitalization correctly when you declare and use
your package, class, interface, method, variable, and constant names. The rules
are pretty simple:
% Package names The safest bet is to use lowercase when possible:
com.wickedlysmart.utilities
% Class and Interface names Typically they should be nouns; capitalize the
first letter and any other first letters in secondary words within the name:
Customer or CustomTable
% Method names Typically they should be verbs; the first word should be
lowercase, and if there are secondary words, the first letter of each should
be capitalized:
initialize(); or getTelescopicOrientation();
% Variable names They should follow the same capitalization rules as
methods; you should start them with a letter (even though you can use _
or $, don t), and only temporary variables like looping variables should
use single character names:
currentIndex; or name; or x;
% Constant names To be labeled a constant, a variable must be declared static
and final. Their names should be all uppercase and underscores must be used
to separate words:
MAX_HEIGHT; or USED;
Key Points Summary
% This is the easiest part of the exam, if you are careful and thorough you
should be able to do very well in this area.
% Always indent four spaces from the previous level of indentation.
% Break long lines at around the 65 character mark:
% Break after a comma
% Break before an operator
Color profile: Generic CMYK printer profile
CertPrs8(SUN) / Sun Certified Programmer & Developer for Java 2 Study Guide / Sierra / 222684-6 / Chapter 12
Composite Default screen
Chapter 12: Coding Standards
14
% Try not to break inside inner parens.
% Use single blank lines between constructors, methods, logic segments, before
comments, and after your last instance variable.
% Use blank spaces between binary operators, after commas in argument lists,
after for expressions, between a keyword and a paren.
% Place opening curly brace on the same line as the declaration or statement.
% Put closing curly brace on a new line.
% Closing curly brace shares a line with else, else if, do, catch, and finally.
% Block comments start and end with /* and */, * in the middle.
% Single line comments use /* */
% End of line comments use //
% Masking comments use //
% File declaration sequence is this: comments, package, import, class, static,
instance, constructors, methods.
% Initialize variables at the top of blocks; avoid variable name shadowing.
% Package names are lowercase: com.wickedlysmart.utilities.
% Classes and interfaces have capitalized nouns for names: Inventory.
% Methods and variables names start lowercase and capitalize secondary
words, as in
doRiskyStuff(); or currentIndex;.
% Constant names are all caps with underscores: MAX_HEADROOM.
[ Pobierz całość w formacie PDF ]