Showing posts with label lexical structure. Show all posts
Showing posts with label lexical structure. Show all posts

Thursday, April 21, 2011

Lexical Structure in java

The lexical structure of a programming language is the set of elementary rules that define what are the tokens or basic atoms of the program. It is the lowest level syntax of a language and specifies what is punctuation, reserved words, identifiers, constants and operators. Some of the basic rules for Java are:
  • Java is case sensitive.
  • Whitespace, tabs, and newline characters are ignored except when part of string constants. They can be added as needed for readability.
  • Comments in java are used for documentation, but they don't change code execution.
  • Statements terminate in semicolons! Make sure to always terminate statements with a semicolon.
  • Commas are used to separate words in a list
  • Round brackets are used for operator precedence and argument lists.
  • Square brackets are used for arrays and square bracket notation.
  • Curly or brace brackets are used for blocks.
  • Keywords are reserved words that have special meanings within the language syntax.
  • Identifiers are names for constants, variables, functions, properties, methods and objects. The first character must be a letter, underscore or dollar sign. Following characters can also include digits. Letters are A to Z, a to z, and Unicode characters above hex 00C0. Java styling uses initial capital letter on object identifiers, uppercase for constant ids and lowercase for property, method and variable ids.
    Note: an identifier must NOT be any word on the Java Reserved Word List.

Friday, April 2, 2010

Syntax and Grammar of Java

  1. Identifiers are names of variables, functions, classes etc.
  2. A keyword or reserved word 
  3. Java technology supports three type of comments
  4. Read about full lexical structure of java
  5. Integer literals can also be specified as octal (base 8), or hexadecimal (base 16). Octal and hexadecimal have 0 and 0x prefix respectively. So 03 and 0x3 are representation of integer three in octal and hexa-decimal respectively.
  6. Java technology supports the primitive types - boolean (for representing true or false), a character type called char, four integer types (byte, short, int and long) and two floating point types (float and double). Click here for more.
  7. Corresponding to all the primitive type there is a wrapper class defined. These classes provide useful methods for manipulating primitive data values and objects. See here. 
  8. Limits of these datatypes
  9. Default values of primary datatypes 
  10. Variables 
  11. A Java source file format
  12. The Java interpreter executes a method called main, defined in the class specified in command line arguments. The main method is the entry point for execution of a class. In Java technology the main method must have the following signature -
    public static void main(String args[])
    The java interpreter is invoked with the name of the class as an argument. The class name is followed by possible set of arguments for the main function of the class. When a Java program is invoked then the Java interpreter name "java" and the class name are not passed to the main() method of the class. The rest of the command line arguments are passed as an array of String. For example invoking java Sky blue gray
    would invoke main method of Sky class with an array of two elements - blue and gray. 
    args[0]=blue , args[1] = gray


Chitika