PPL Lecture3
PPL Lecture3
(Lecture 3)
Implementation
ii) Java
In Java, strings are supported by the String class, whose values are
constant strings, and the StringBuffer class, whose values are changeable
and are more like arrays of single characters.
a) Enumeration types
An enumeration type is one in which the user enumerates all the possible
values, which are symbolic constants. In Ada a typical enumeration type is
shown as: type DAYS is ( M, T, W, R, F, Sa, S).
b) Subrange types
A subrange type is an ordered contiguous subsequence of an ordinal type.
These types were introduced by Pascal. For example: 12 . . . 16 is a subrange
of the integer type.
Array types
An Array is a Linear data structure which is a collection of data items having
similar data types stored in contiguous memory locations. By knowing the
address of the first item we can easily access all items/elements of an array.
Types of Arrays
The various types of arrays are as follows.
Multi-Dimensional Array
When the number of dimensions specified is more than one, then it is called as a
multi-dimensional array. Multidimensional arrays include 2D arrays and 3D
arrays.
Associative Arrays
An associative array is an unordered collection of data elements that are indexed
by an equal number of values called keys. In the case of non-associative arrays,
the indices never need to be stored (because of their regularity). In an associative
array, however, the user-defined keys must be stored in the structure.
So each element of an associative array is in fact a pair of entities, a key and a
value.
Example:
Record Types
The record type is a data type that you use to treat several different pieces of data
as one unit, for example, name and phone number. Each of these units is called
a variable of record type. Each piece of data is called an attribute. An attribute
can be a simple data type, another record type, or an array. A data value or a
variable for the record type is called a record.
To define a union, you must use the union statement in the same way as you did
while defining a structure. The union statement defines a new data type with more
than one member for your program. The format of the union statement is as
follows –
References
A reference variable is an alias, that is, another name for an already existing
variable. A reference, like a pointer, is also implemented by storing the
address of an object.
A reference can be thought of as a constant pointer (not to be confused with a
pointer to a constant value!) with automatic indirection, i.e., the compiler will
apply the * operator for you.
Example:
int i = 3;