销毁java类和示例_Java标识符的定义和示例

销毁java类和示例

A Java identifier is a name given to a package, class, interface, method, or variable. It allows a programmer to refer to the item from other places in the program.

Java标识符是为包,类,接口,方法或变量提供的名称。 它允许程序员从程序中的其他位置引用该项目。

To make the most out of the identifiers you choose, make them meaningful and follow the standard Java naming conventions.

要充分利用您选择的标识符,请使其有意义并遵循标准的Java命名约定

Java标识符示例 ( Examples of Java Identifiers )

If you have variables that hold the name, height, and weight of a person, then choose identifiers that make their purpose obvious:

如果您的变量包含一个人的姓名,身高和体重,那么请选择使其目的显而易见的标识符:

 String name = "Homer Jay Simpson";
 int weight = 300;
 double height = 6;
 System.out.printf("My name is %s, my height is %.0f foot and my weight is %d pounds. D'oh!%n", name, height, weight); 

关于Java标识符要记住的一点 ( This to Remember About Java Identifiers )

Since there are some strict syntax, or grammatical rules when it comes to Java identifiers (don't worry, they aren't hard to understand), make sure you're aware of these do's and don't:

由于涉及Java标识符时有一些严格的语法或语法规则(不用担心,它们不难理解),因此请确保您知道这些注意事项和不注意这些事项:

  • if 
    cannot be used.
  • "Java letters" is the term given to the acceptable letters that can be used for an identifier. This includes not only regular alphabet letters but also symbols, which just includes, without exception, the underscore (_) and dollar sign ($).

    “ Java字母”是赋予可用于标识符的可接受字母的术语。 这不仅包括常规字母,还包括符号,这些符号无一例外地仅包括下划线(_)和美元符号($)。
  • "Java digits" include the numbers 0-9.

    “ Java数字”包括数字0-9。
  • An identifier can begin with a letter, dollar sign, or underscore, but not a digit. However, it's important to realize that digits can be used so long as they exist after the first character, like

    标识符可以以字母,美元符号或下划线开头,但不能以数字开头。 但是,重要的是要意识到,只要数字出现在第一个字符之后, 可以使用它们,例如

    e8xmple
  • Java letters and digits can be anything from the Unicode character set, which means characters in Chinese, Japanese, and other languages can be used.

    Java字母和数字可以是Unicode字符集中的任何字符,这意味着可以使用中文,日文和其他语言的字符。
  • Spaces are not acceptable, so an underscore can be used instead.

    空格是不可接受的,因此可以使用下划线代替。
  • The length does not matter, so you can have a really long identifier if you choose.

    长度无关紧要,因此您可以选择一个很长的标识符。
  • A compile-time error will occur if the identifier uses the same spelling as a keyword, the null literal, or boolean literal.

    如果标识符使用与关键字,空文字或布尔文字相同的拼写,则会发生编译时错误。
  • Since the list of SQL keywords may, at some point in the future, include other SQL words (and identifiers can't be spelled the same as a keyword), it's usually not recommended that you use an SQL keyword as an identifier.

    由于SQL关键字列表在将来的某个时候可能会包含其他SQL词(并且标识符的拼写不能与关键字相同),因此通常不建议您使用SQL关键字作为标识符。
  • It's recommended to use identifiers that are related to their values so they're easier to remember.

    建议使用与其值相关的标识符,以便于记忆。
  • Variables are case-sensitive, which means

    myvalue 
    does not mean the same as

  • 变量区分大小写,这意味着

    myvalue 并不等同于 

Note: If you're in a hurry, just take away the fact that an identifier is one or more characters that come from the pool of numbers, letters, the underscore, and the dollar sign, and that the first character must never be a number.

注意:如果您着急的话,请忽略以下事实:标识符是一个或多个字符,它们来自数字,字母,下划线和美元符号池,并且第一个字符一定不能是数。

Following the rules above, these identifiers would be considered legal:

按照上述规则,这些标识符将被视为合法:

  • _variablename
  • _3variable
  • $testvariable
  • VariableTest
  • variabletest
  • this_is_a_variable_name_that_is_long_but_still_valid_because_of_the_underscores
  • max_value

Here are some examples of identifiers that are not valid because they disobey the rules mentioned above:

以下是一些无效的标识符示例,因为它们违反了上述规则:

  • 8example(this starts off with a digit)
  • exa+ple (the plus sign isn't allowed)
  • variable test (spaces are not valid)
  • this_long_variable_name_is_not_valid_because_of_this-hyphen(while the underscores are acceptable like in the example from above, even the one hyphen in this identifier renders it invalid)

翻译自: https://www.thoughtco.com/identifier-2034136

销毁java类和示例

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值