您的位置:寻梦网首页编程乐园Java天地Core JavaJava Lecture Notes
Introduction
Content
Apply
Reflect
Extend
previous.gif
 (3087 bytes)
next.gif
 (2959 bytes)

 
 
Reflect Index
Reflect Page # 3

Discussion Topic 1 ?case-sensitivity issues

Misspelling of identifier names is a major source of error for novice (and other) programmers. For example, if I write

System.out.Println("hello");

where I really meant

System.out.Println("hello");

then this is an error, and the compiler will display an error message. Note that it does not say:

'You have `Println'

it says:

``method `Println(String)' not found in class ... ''

In other words, it interprets the change from lower case to upper case as representing a completely different operation.

Why is this? What disadvantages would there be to making Java a case-insensitive language, such that

println

was the same as 

Println ?

A much more serious problem is illustrated by this example. Suppose I am writing an applet, and I define the operation called `paint', but accidentally write `Paint' instead, like this:

public void Paint (Graphics g)

{

// More statements here

}

This appears superficially to be the same kind of error as the println/Println example earlier, but it is not. In the `Paint' example, the program will compile perfectly well, but it won't work. The Paint() operation is never called. This is a worse problem, because the compiler cannot give the programmer any guidance about where the error is. The compiler does not even know it is an error.

What is different about the first error (println/Println) that means the compiler spots it as an error, while the second error (paint/Paint) is undetected?
 
 

Back to top

basicline.gif (169 bytes)

RITSEC - Global Campus
Copyright © 1999 RITSEC- Middlesex University. All rights reserved.
webmaster@globalcampus.com.eg