Tuesday, 27 November 2018

Java - Lexical Issues

Java Programs are collection of white spaces, identifiers, literals, comments, operator, separator and keywords.

White space
White space is a space, tab, new line.

Identifiers
An identifier is the name of class, method and variable.
Identifiers can have uppercase, lowercase letter, numbers, underscore and dollar sign.
They must not begin with a number.
Keyword must not be an identifier, even though keyword can be a part of an identifier.
Example
·       int a
·       class A
·       void sum()
·       (a,sum,A are  identifiers)
Literals
A constant value in java can be known as literal.
Ex: int a=100(100 is a literal)
Literals can be written with underscores.(added in 1.7)
int x=12_34_56;

Comments
There are three types of comments defined by java
·      single line comment //
·      Multiline Comment /* … */
·      Documentation Comment /**……*/
Keywords
·         There are 50 keywords available in java.
·         48 keywords are in use.
·          2 keywords are reserved but not in use. These keywords are goto, const.
·         true, false, null are the values and not keywords.
·         enum keyword is added in J2SE 5
Separator
·        {} - braces
·        [] - brackets
·        () – parentheses
·        . – dot or period
·        , - comma
·        ; - semicolon
Escape Sequences
         \’                 Single quote
         \”                 Double quote
         \\                 Backslash
         \r                 Carriage return
         \n                 Newline
         \f                 Formfeed
         \t                 Tab
         \b                 Backspace

No comments:

Post a Comment

Note: only a member of this blog may post a comment.