You are on page 1of 7

Java

Beginner to Guru

Keywords and Identifiers


Java Keywords
• A Java Keyword is a word in Java with special meaning
• Examples: public, class, void, static
• Keywords are reserved by the Java language. Meaning you cannot use these outside of their
purpose.
• Example: You cannot name a method ‘void’

• There are 51 Keywords in Java, 2 of which are not in use


Java Keywords
abstract if throws final native
continue private case interface super
for this enum static while
new break instanceof void _ (Underscore)
switch double return class
assert implements transient finally Other
default protected catch long
goto throw extends strictfp true
package byte int volatile false
synchronized else short const null
boolean import try float var
do public char
Java Identifiers
• Java Identifiers are names you define for methods, class names, variable names, constant names,
package names

• Pretty much anything you are assigning a name to in your program


• No Max length - 65,000 +
• Cannot be a Keyword

• Valid Examples: MyClass, MyVariable, my_variable, some_method, _someMethod, $uperMethod,


SUPER_METHOD, myVariable_123
Rules for Identifiers
• Can use any upper or lowercase letter or number (a-z, A-Z, 0-9)
• Can also use the underscore ‘_’ and dollar sign ‘$’
• Identifiers are case sensitive

• Cannot have spaces or other special characters


• Example: @, %, *, ! <— Not inclusive list!
Conventions
• Class names should be Pascal Case
• Camel case with starting capital
• Methods and variables should be Camel Case, with starting lower case

• Constants all upper case separated with underscores


• MY_CONSTANT_NAME
• Packages all lower case
• Reverse domain name is preferred

You might also like