Java Is Case Sensitive



Java Is Case Sensitive

  • Java is a case-sensitive language, which means that the upper or lower case of letters in your Java programs matter.

About Case Sensitivity

  • Case sensitivity enforces capital or lower case in text. For example, suppose you have created three variables called "endLoop", "Endloop", and "EndLoop". Even though these variables are composed of the exact same letters in the same exact order, Java does not consider them equal.
  • This behavior has its roots in the programming language C and C++, on which Java was based, but not all programming languages enforce case sensitivity. Those that do not include Fortran, COBOL, Pascal and most BASIC languages.

The Case For and Against Case Sensitive Programming Languages

  • The "case" for the value of case sensitivity in a programming language is debated among programmers, sometimes with an almost religious fervor.
  • Some argue that case sensitivity is necessary to ensure clarity and accuracy for example, there is a difference between Polish (being of Polish nationality) and polish (as in shoe polish), between SAP (an acronym for System Applications Products) and sap (as in tree sap), or between the name Hope and the feeling hope.
  • Further, the argument goes, a compiler should not try to second-guess the intent of the user and should rather take strings and characters exactly as entered, to avoid unnecessary confusion and introduced errors.
  • Others argue against case sensitivity, citing that it is harder to work with and more likely to result in mistakes while providing little gain. Some argue that case-sensitive languages negatively impact productivity, forcing programmers to spend untold hours debugging issues that end up as simple as the difference between "LogOn" and " logon."

Case Sensitive Tips for Working in Java

  • If you follow these tips when coding in Java you should avoid the most common case sensitive errors.
    • Java keywords are always written in lowercase. You can find the full list of keywords in the reserved words list.
    • Avoid using variable names that differ only in case. Like the example above, if you had three variables called “endLoop”, “Endloop”, and “EndLoop” it would not take long before you mistype one of their names. Then you might find your code changing the value of the wrong variable by mistake.
    • Always make sure the class name in your code and java filename match.
    • Follow the Java naming conventions. If you get into the habit of using the same case pattern for different identifier types, then you improve your chances of avoiding a typing mistake.
    • When using a string to represent the path of a filename, i.e. "C:\JavaCaseConfig.txt" make sure you use the right case. Some operating systems are case insensitive and don't mind that the filename isn't exact. However, if your program is used on an operating system that is case sensitive it will produce a runtime error.

Related Searches to Java Is Case Sensitive