Lecture 6
Lecture 6
Scope of variables
Arrays
Symbolic constants
Operators
Expressions
SCOPE OF VARIABLES
Scope of a variable is the part of the program
where the variable is accessible. Like C/C++, in
Java, all identifiers are lexically (or statically)
scoped, i.e.scope of a variable can be determined
at compile time and independent of function call
stack.
Java programs are organized in the form of
classes. Every class is part of some package. Java
scope rules can be covered under following
categories.
ARRAYS
In Java, all arrays are dynamically allocated.
(discussed below)
Arrays may be stored in contiguous memory
[consecutive memory locations].
Since arrays are objects in Java, we can find their
length using the object property length. This is
different from C/C++, where we find length using size
of.
A Java array variable can also be declared like other
variables with [] after the data type.
The variables in the array are ordered, and each has
an index beginning with 0.
Java array can also be used as a static field, a local
variable, or a method parameter.
TYPES OF ARRAY
SYMBOLIC CONSTANTS
In Java, a symbolic constant is a named constant
value defined once and used throughout a
program. Symbolic constants are declared using
the final keyword.
Which indicates that the value cannot be
changed once it is initialized.
The naming convention for symbolic constants is
to use all capital letters with underscores
separating words.
SYNTAX OF SYMBOLIC CONSTANTS