Sunday, 28 August 2011

Declaration and Access Control

Array Fundamentals
Arrays are used to represent fixed number of elements of the same type. The following are legal syntax for declaring one-dimensional arrays.

int anArray[];
int[] anArray;
int []anArray;

It is important to note that the size of the array is not included in the declaration. Memory is allocated for an array using the new operator as shown below.
anArray = new int[10];
The declaration and memory allocation may be combined together as shown below.
int anArray[] = new int[10];
The elements of the array are implicitly initialized to default values based on array types (0 for integral types, null for objects etc.). This is true for both local arrays as well as arrays which are data members. In this respect arrays are different from normal variables. Variable defined inside a method are not implicitly initialized, where as array elements are implicitly initialized.

Array Initializations
Arrays are initialized using the syntax below
int intArray[] = {1,2,3,4};
The length operator can be used to access the number of elements in an array (for example - intArray.length).

Operators and Assignments

Operators and Assignments

Commonly used operators
Following are some of the commonly used JavaTM technology operators - Multiplication (*), Addition (+), Subtraction (-), logical and (&&) Conditional Operator ?:, Assignment (=), left shift (<<), right shift (>> and >>>), Equality comparison (==), Non-equality comparison (!=).

Conversion rules in Assignments
In the description below, I am giving basic conversion rules for assignment when source and destination are of different types.

LANGUAGE FUNDAMENTALS

Language Fundamentals


  1. Identifiers are names of variables, functions, classes etc. The name used as an identifier must follow the following rules in JavaTM technology.
    • Each character is either a digit, letter, underscore(_) or currency symbol ($,¢, £ or ¥)
    • First character cannot be a digit.
    • The identifier name must not be a reserved word.
  2. A keyword or reserved word in Java technology has special meaning and cannot be used as a user defined identifier. The list of keywords in Java technology is given below. It is important to completely remember this list as you can expect a question in Java Certification exam related to this.
    abstractbooleanbreakbytecasecatch
    charclassconstcontinuedefaultdo
    doubleelseextendsfinalfinallyfloat
    forgotoifimplementsimportinstanceof
    intinterfacelongnativenewnull
    packageprivateprotectedpublicreturnshort
    staticstrictfpsuperswitchsynchronizedthis
    throwthrowstransienttryvoidvolatile
    whileassertenum