case sensitive : Java Glossary

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 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
logo
Please email your , 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, your name or email kept confidential, not considered for public posting, please explicitly specify that. Unless you state otherwise, I will treat your message as a letter to the editor that I may or may not publish in the feedback section. After that, it will be too late to retract it. If you disagree with something I said, please quote it and cite the web page where you found it, tell me why you think it is wrong, and, if possible, provide some supporting evidence. Threatening to kill me or spouting obscenities has yet to persuade me to change my mind.
mindprod.com IP:[65.110.21.43]
view BlogYour face IP:[38.107.179.211]
You are visitor number 24,241.