case-sensitive : Java Glossary

*0-9ABCDEFGHIJKLMNOPQRSTUVWXYZ (all)

case-sensitive  case-sensitive
If you compare two strings in a  case-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. with String.compareToIgnoreCase, then they are considered equal if they differ only in capitalisation.

Java, the language, is case-sensitive  case-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-insensitive  case-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 with  File.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 ST package.

This page is posted
on the web at:

http://mindprod.com/jgloss/casesensitive.html

Optional Replicator mirror
of mindprod.com
on local hard disk J:

J:\mindprod\jgloss\casesensitive.html
Canadian Mind Products
Please the feedback from other visitors, or your own feedback about the site.
Contact Roedy. Please feel free to link to this page without explicit permission.

IP:[65.110.21.43]
Your face IP:[18.191.186.84]
You are visitor number