case sensitive : Java Glossary

case sensitive  case sensitive
If you compare two strings in acase sensitive  case sensitive way, e.g. with String. compareTo, they are considered different if they differ only in capitalisation.

If you compare two Strings in a case insensitive case insensitive way, e.g. withString.compareToIgnoreCase, then they are considered equal if they differ only in capitalisation.

Java, the language, is case sensitivecase sensitive. Capitalisation must be precise in class, method and variable names. avar is not the same variable as aVar. However, the underlying operating system may be case insensitive, e.g. Windows. To Java, MyApp. class and Myapp. class are totally different files, but to Windows they are the same. To avoid problems, never name two different classes (or any other entities for that matter) with names differing only in capitalisation. The one possible exception is to name a local variable the same as its class, with the leading cap change to lower case, e.g. MyApplet myApplet = new MyApplet(); The OS (Operating System) never sees these local variable names.

Resources, resource bundles, jar members generally and images all need the correct capitalisation. Again for safety, file names should be correct too, though Windows permits sloppiness.

Gotchas

Even if your OS is case insensitivecase insensitive, it is best to treat as if it were case insensitive. Otherwise, the following nasty things will eventually happen to you. On some operating systems it gets even hairier, with parts of the file system being case sensitive and others case-insensitive. The way I handled the problem in BackupToZip was to convert all filenames to canononical form withFile.getCanonicalPath. Then I always compare with a case-sensitive compare. If you think about it, you will see this works in either a case-sensitive or case-insensitive file system. It fobs the problem of how sloppy you can let the user be on getCanonicalPath.

Converting Case

String.toUpperCase, String. toLowerCase, Character. toUppercase and Character. toLowerCase are much more complicated internally than you would imagine with all manner of coded cultural lore on how caps are done for various symbol sets, including chars that change length. If you are just dealing with English, you can use the much faster version part of the StringTools package.

CMP homejump to top You can get the freshest copy of this page from: or possibly from your local J: drive (Java virtual drive/mindprod.com website mirror)
http://mindprod.com/jgloss/casesensitive.html J:\mindprod\jgloss\casesensitive.html
logofeedback Please email your feedback for publication, letters to the editor, errors, omissions, typos, formatting errors, ambiguities, unclear wording, broken/redirected link reports, suggestions to improve this page or comments to Roedy Green : feedback email If you want your message kept confidential, not considered for posting, please explicitly specify that.
mindprod.com IP:[65.110.21.43]
view BlogYour face IP:[38.107.179.212]
You are visitor number 23,859.