java基础-02标识符和关键字

一.关键字

学习一件东西,需要习惯从它官方文档里面学习。毕竟羊毛出在羊身上嘛。下面贴了一张官网图,看不清可以点击下方链接。
直达官网关键字链接
在这里插入图片描述
下面是对每个关键字的具体描述,我们需要习惯用英文去理解。所以没有特意翻译。

KeywordUsage
abstractSpecifies that a class or method will be implemented later, in a subclass
assertAssert describes a predicate placed in a Java program to indicate that the developer thinks that the predicate is always true at that place.
booleanA data type that can hold True and False values only
breakA control statement for breaking out of loops.
byteA data type that can hold 8-bit data values
caseUsed in switch statements to mark blocks of text
catchCatches exceptions generated by try statements
charA data type that can hold unsigned 16-bit Unicode characters
classDeclares a new class
continueSends control back outside a loop
defaultSpecifies the default block of code in a switch statement
doStarts a do-while loop
doubleA data type that can hold 64-bit floating-point numbers
elseIndicates alternative branches in an if statement
enumA Java keyword is used to declare an enumerated type. Enumerations extend the base class.
extendsIndicates that a class is derived from another class or interface
finalIndicates that a variable holds a constant value or that a method will not be overridden
finallyIndicates a block of code in a try-catch structure that will always be executed
floatA data type that holds a 32-bit floating-point number
forUsed to start a for loop
ifTests a true/false expression and branches accordingly
implementsSpecifies that a class implements an interface
importReferences other classes
instanceofIndicates whether an object is an instance of a specific class or implements an interface
intA data type that can hold a 32-bit signed integer
interfaceDeclares an interface
longA data type that holds a 64-bit integer
nativeSpecifies that a method is implemented with native (platform-specific) code
newCreates new objects
nullThis indicates that a reference does not refer to anything
packageDeclares a Java package
privateAn access specifier indicating that a method or variable may be accessed only in the class it’s declared in
protectedAn access specifier indicating that a method or variable may only be accessed in the class it’s declared in (or a subclass of the class it’s declared in or other classes in the same package)
publicAn access specifier used for classes, interfaces, methods, and variables indicating that an item is accessible throughout the application (or where the class that defines it is accessible)
returnSends control and possibly a return value back from a called method
shortA data type that can hold a 16-bit integer
staticIndicates that a variable or method is a class method (rather than being limited to one particular object)
strictfpA Java keyword is used to restrict the precision and rounding of floating-point calculations to ensure portability.
superRefers to a class’s base class (used in a method or class constructor)
switchA statement that executes code based on a test value
synchronizedSpecifies critical sections or methods in multithreaded code
thisRefers to the current object in a method or constructor
throwCreates an exception
throwsIndicates what exceptions may be thrown by a method
transientSpecifies that a variable is not part of an object’s persistent state
tryStarts a block of code that will be tested for exceptions
voidSpecifies that a method does not have a return value
volatileThis indicates that a variable may change asynchronously
whileStarts a while loop
sealedThe sealed keyword is used to declare a class as “sealed,” meaning it restricts which classes can extend it.
permitsThe permits keyword is used within a sealed class declaration to specify the subclasses that are permitted to extend it.

二.标识符

在 Java 中,标识符用于识别目的。Java 标识符可以是类名、方法名、变量名或标签。

public class Test
{
    public static void main(String[] args)
    {
        int a = 20;
    }
}
  • Test: 类名
  • main: 方法名
  • String: 预定义类名
  • args: 变量名
  • a: 变量名

标识符注意点:

1.所有的标识符只能以大小写字母(A-Z或a-z),美元符号($),或者下划线(_开头,首字符之后可以任意组合。但是不能以#,%等特殊字符结尾。(&可以)
在这里插入图片描述2. 不能使用关键字作为变量名或方法名,也就是第一大点讲到的图里的关键字。
3.标识符区分大小写,也就是大写字母的变量和小写字母的变量是完全不一样的。十分之敏感。在这里插入图片描述
4.养成习惯用英文方式命名。name就name,不要用mingzi代替,非常不规范。

这里顺便说一个快捷键:command + D 复制光标所在行内容。省事不少。(windows是ctrl+D)

三.关键字和标识符区别

在这里插入图片描述
较为潦草地说除了关键字图里的那些字母,其他符合规范的命名字符均为标识符。

最后,想啰嗦几句。我们在写代码之初,了解代码规范,养成良好的习惯是很重要。所有的理论需要投入实践,更准确的说是需要投入大量的实践。在实践中思考,在实践中总结,相信我们都会在混沌中找到一方属于自己的净土。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值