java 区分大小写_Java区分大小写

2023-02-18 00:00:00 java 区分 大小写

java 区分大小写

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

Java是区分大小写的语言,这意味着Java程序中字母的大小写很重要。


关于区分大小写 ( About Case Sensitivity )

Case sensitivity enforces capital or lower case in the 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. It will treat them all differently.

区分大小写在文本中强制使用大写或小写。 例如,假设您创建了三个变量,分别称为“ endLoop”,“ Endloop”和“ EndLoop”。 即使这些变量以完全相同的顺序由完全相同的字母组成,Java也不认为它们相等。 它将以不同的方式对待他们。

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.

此行为起源于Java所基于的编程语言C和C ++,但并非所有编程语言都强制区分大小写。 不包含Fortran,COBOL,Pascal和大多数BASIC语言的语言。


区分大小写的理由 ( The Case For and Against Case Sensitivity )

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. 

有人认为,区分大小写对于确保清晰度和准确性是必要的,例如,波兰语(属于波兰国籍)和波兰语(如鞋油),SAP(系统应用产品的缩写)和sap(如树液),或在希望和感觉希望之间。 此外,争论的焦点是,编译器不应试图再次猜测用户的意图,而应准确输入所输入的字符串和字符,以避免不必要的混乱和引入的错误。

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.”

其他人则反对区分大小写,理由是这种做法更难处理,更容易导致错误,同时却几乎没有收益。 一些人认为,区分大小写的语言会对生产率产生负面影响,迫使程序员花费大量时间来调试问题,而这些问题的解决之道就像“登录”和“登录”之间的区别一样简单。

The jury is still out on the value of case-sensitivity and it may be able to pass final judgment. But for now, case sensitivity is here to stay in Java.

陪审团仍不区分大小写,可以通过最终裁决。 但是就目前而言,区分大小写在Java中仍然存在。


使用Java的区分大小写的技巧 ( 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进行编码时遵循这些提示,则应该避免最常见的区分大小写的错误:

  • Java keywords are always written in lowercase. You can find the full list of keywords in the reserved words list.

    Java关键字始终以小写形式编写。 您可以在保留字列表中找到关键字的完整列表 。

  • 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.

    避免使用仅大小写不同的变量名。 像上面的示例一样,如果您有三个名为“ endLoop”,“ Endloop”和“ EndLoop”的变量,那么不久您就可以输错它们的名称之一。 然后,您可能会发现代码错误地更改了错误变量的值。

  • Always make sure the class name in your code and java filename match.

    始终确保代码中的类名和Java文件名匹配。

  • 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.

    遵循Java命名约定 。 如果您习惯对不同的标识符类型使用相同的大小写模式,则可以避免输入错误。

  • When using a string to represent the path of a file name, 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.

    当使用字符串表示文件名的路径时,即“ C:\ JavaCaseConfig.txt”,请确保使用正确的大小写。 某些操作系统不区分大小写,并且不介意文件名不正确。 但是,如果您的程序在区分大小写的操作系统上使用,则会产生运行时错误。

翻译自: https://www.thoughtco.com/java-is-case-sensitive-2034197

java 区分大小写

    原文作者:cumao2792
    原文地址: https://blog.csdn.net/cumao2792/article/details/108575566
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。

相关文章