case sensitive : Java Glossary

go to home page C words local find full screen, hide local find menu Google search web for more information on this topic jump to foot of page translate this page with Babelfish punctuation 0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z (all) ©1996-2009 2007-05-18 Roedy Green, Canadian Mind Products
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 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 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
CMP logofeedback Please email your feedback for publication, errors, omissions, typos, formatting errors, ambiguities, unclear wording, broken/redirected link reports, suggestions to improve this page or comments to Roedy Green : feedback email
mindprod.com IP:[65.110.21.43]
view BlogYour face IP:[38.107.191.101]
You are visitor number 18,298.