Thursday, February 16, 2012

A list of ALL the Java Keywords & rules for variable names

Java Keywords:
abstract, boolean, break, case, catch, class, continue, char, const, default, do, double, else, extends, final, finally, for, if, implements, import, instanceof, int, interface, new, null, package, private, protected, public, return, static, super, this, throw, throws, try, void, while.

Rules for variable names:
Other than not using a keyword as a variable name, a name has to start with a letter, an underscore, or a $. A name cannot have any spaces or special characters.
 
Examples:
 Which of the following are valid identifiers in Java?
I. 2far
II. twoFar
III. TWO_FAR
A. I only    B. II only    C. III only    D. I and II    E. II and III
The answer is E because I has a number in the front.

Which of the following are Java keywords?
I. method
II. throws
III. foreach
A. I only    B. II only    C. III only    D. II and III    E. none of these
The answer is B since "throws" is the only java keyword out of the three.

-This post a direct result from the mind of Joshua Cannon

No comments:

Post a Comment