Java Lexical Structure Published: July 24, 2007 PrintEmail
Unicode provides a unique number for every character, no matter what the platform, no matter what the program, no matter what the language.You can use Unicode characters anywhere in a Java program, including comments and identifiers such as variable names.
Case-Sensitivity and Whitespace Java is a case-sensitive language. Its keywords are written in lowercase and must always be used that way. Java white space is defined as the ASCII space, horizontal tab, and form feed characters.Java ignores spaces, tabs, newlines, and other whitespace, except when it appears within quoted characters and string literals.
Keywords The following words are reserved in Java:
abstract const final int public throw assert continue finally interface return throws boolean default float long short transient break do for native static true byte double goto new strictfp try case else if null super void catch enum implements package switch volatile char extends import private synchronized while class false instanceof protected this
The keywords const and goto are reserved, even though they are not currently used.
Comments There have two types of comments in Java.The first type is a single-line comment, A end-of-line comment: all the text from the ASCII characters // to the end of the line is ignored
int i = 0; // Initialize the loop variable
The second type is a multiline comment. It begins with the characters /* and continues, over any number of lines, until the characters */. Any text between the /* and the */ is ignored by the Java compiler.
/* * text */
Comments do not nest.
/* and */ have no special meaning in comments that begin with //. // has no special meaning in comments that begin with /* or /**.
Identifier An identifier is an unlimited-length sequence of Java letters and Java digits, the first of which must be a Java letter. An identifier cannot have the same spelling (Unicode character sequence) as a keyword , boolean literal, or the null literal
Literals A literal is the source code representation of a value of a primitive type, the String type , or the null type. For example, the following are all literals:
2.4 '6' "two" true false null
Punctuation Java uses a number of punctuation characters as tokens. The Java Language Specification divides these characters (somewhat arbitrarily) into two categories, separators and operators. Separators are: