6.2
Names and Identifiers
NAMES
In the example:
class Test {
public static void main(String[] args) {
Class c = System.out.getClass();
System.out.println(c.toString().length() +
args[0].length() + args.length);
}
}
the identifiers
Test
,
main
, and the first occurrences of
args
 and
c
 are not names;
rather, they are used in declarations to specify the names of the declared entities.
The names
String
,
Class
,
System.out.getClass, System.out.println
,
c.toString
,
args
, and
args.length
 appear in the example. The first occur 
rence of
length
 is not a name, but rather an identifier appearing in a method invo 
cation expression ( 15.11). The second occurrence of
length
 is not a name, but
rather an identifier appearing in a method invocation expression ( 15.11).
The identifiers used in labeled statements and their associated
break
 and
continue
 statements are completely separate from those used in declarations.
Thus, the following code is valid:
class TestString {
char[] value;
int offset, count;
int indexOf(TestString str, int fromIndex) {
char[] v1 = value, v2 = str.value;
int max = offset + (count   str.count);
int start = offset + ((fromIndex < 0) ? 0 : fromIndex);
i:
for (int i = start; i <= max; i++)
{
int n = str.count, j = i, k = str.offset;
while (n   != 0) {
if (v1[j++] != v2[k++])
continue i;
}
return i   offset;
}
return  1;
}
}
This code was taken from a version of the class
String
 and its method
indexOf
( 20.12.26), where the label was originally called
test
. Changing the label to
have the same name as the local variable
i
 does not hide the label in the scope of
the declaration of
i
. The identifier
max
 could also have been used as the statement
label; the label would not hide the local variable
max
 within the labeled statement.
80






footer




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

java hosting

 

Our partners: PHP: Hypertext Preprocessor Best Web Hosting Java Web Hosting Inexpensive Web Hosting  Jsp Web Hosting

Cheapest Web Hosting Jsp Hosting Cheap Hosting

Visionwebhosting.net Business web hosting division of Web Design Plus. All rights reserved