Showing posts with label keyword. Show all posts
Showing posts with label keyword. Show all posts

Wednesday, 20 April 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.

Sunday, 17 April 2011

Using transient keyword in serialization

Serializable objects are much more convenient because everything is serialized there automatically. You can forbid serialization of any member variable object with the transient modifier. It tells the JVM: "Do not save and restore this field, please; somebody else will take care of this field." Listing D shows how it looks.

import java.io.*;
import java.util.*;

class LoginCredentials implements Serializable {

private String username;
private transient String password;

LoginCredentials(String name, String password) {
username = name;
this.password = password;
}

public static void main(String[] args)
throws IOException, ClassNotFoundException {
LoginCredentials = new LoginCredentials("peter","mikhalenko");
}
}

Sunday, 26 September 2010

Keywords in java

Reserved words are words that can't be used as identifiers. Many of them are keywords that have a special purpose in Java.

abstractbooleanbreakbytecasecatch
charclassconstcontinuedefaultdo
doubleelseextendsfinalfinallyfloat
forgotoifimplementsimportinstanceof
intinterfacelongnativenewnull
packageprivateprotectedpublicreturnshort
staticstrictfpsuperswitchsynchronizedthis
throwthrowstransienttryvoidvolatile
whileassertenum


A literal in Java technology denotes a constant value. So for example 0 is an integer literal, and
It is important to note the following
  1. const and goto are not currently in use.
  2. null, true, and false are reserved literals but can be considered as reserved words for the purpose of exam.
  3. It is important to understand that Java language is case-sensitive. So even though super is a keyword, Super is not.
  4. All the Java technology keywords are in lower case.
  5. strictfp is a new keyword added in Java 1.2. assert is added in Java 1.4 and enum in Java 5.0