首页  >  文章  >  Java  >  Java关键字

Java关键字

王林
王林原创
2024-08-30 15:21:03243浏览

Java 关键字是编程语言中的保留字,不用作标识符。 Java 关键字称为保留字,因为它们是您所使用的语言“保留”的。它们具有在语言库中定义的特殊含义。

开始您的免费软件开发课程

网络开发、编程语言、软件测试及其他

Java 编程语言中的概念

与任何其他编程语言一样,Java 编程语言中的关键字是具有特殊含义的保留字。关键字是为内部流程保留的,并且具有一些预定义的操作。在 Java 中,如果以其他方式使用关键字,程序或代码将遇到“编译时错误”。为了便于程序员使用和识别关键字,通常在 Java 中将它们稍微“突出显示”。

Java 中的关键字列表

我们尝试按字母顺序列出下面 Java 中当前使用的重要关键字。您还可以按照给定的示例来观察每个关键字的工作原理。让我们一一看看这些关键词。

1. Abstract: Abstract The keyword is used to declare a class to be used later in the abstract program. Abstract used with a class declaration makes that class an abstract and specifies that the class will be implemented in a subclass at a later stage. Below is an example of the usage of the ‘Abstract’ keyword.Java关键字2. Assert: The ‘assert’ keyword was added to Java 1.4. This keyword allows a programmer to test his assumptions in the program.Java关键字3. Boolean: Boolean is a data type that can hold only two values; it’s either a ‘True’ or a ‘False’.Java关键字4. Break: This keyword helps the programmer want his code to jump out of a loop, for example, a For loop. It’s a control statement that breaks the current flow of the execution on a specific condition provided by the programmer.Java关键字5. Byte: Byte keyword is one of the data types that are able to store whole numbers. The numbers range from -128 to 127Java关键字6. Case: Case keyword is used in a switch statement. The ‘case’ keyword creates a block of code and marks it.Java关键字7. Catch: The ‘catch’ keyword catches the exceptions that were created by the ‘try’ statements. The catch block is used after Try block.Java关键字8. Char: The ‘char’ is one of the data types that is used to hold one character at a time.Java关键字9. Class: The class keyword is used to create a class in java. Everything that runs in Java programming resides inside a class.Java关键字10. Continue: The ‘continue’ keyword is used to skip the current execution and continues to the next step in a loop like a For loop or a While loop.Java关键字11. Default: The ‘Default’ keyword is used to create a default block of code containing a set of statements executed by default if the required case is not present.Java关键字12. Do: The ‘do’ keyword is used when creating a ‘do-while’ loop. The ‘do’ block is executed at least once before checking the condition in a while block.Java关键字13. Double: The ‘double’ keyword is one of the data types used for holding fractional numbers. The fractional numbers range from 1.7e – 308 to 1.7e + 308. While declaring a fraction, the value is ended with a ‘d’.Java关键字14. Else: The ‘Else’ keyword is used to create a block of code that will be executed if the condition is not ‘True’ in an ‘If’ statement.Java关键字15. Enum: The ‘enum’ keyword is used to create enumerations, unchangeable data types. The enum keyword defines a fixed set of constants.Java关键字16. Extends: Extends keyword is used to inherit properties of a superclass’s attributes and methods by a subclass.Java关键字17. Final: The ‘Final’ keyword is used to set a final value to a variable, making it impossible to overwrite or change altogether. If the value of a final variable is tried to change, it throws an error.Java关键字 When hovered over, it shows the following error.Java关键字18. Finally: Finally keyword is used along try and catch statements, which has a block that is executed even if the exception is not handled.Java关键字19. Float:float 关键字是一种数据类型,保存范围从 3.4e−038 到 3.4e+038 的小数。声明小数时,该值应以“f”结尾。Java关键字20。 For:‘For’关键字用于创建一个循环,一个for一个循环。 for 循环多次执行所包含的代码集,这些代码在 for 循环条件语句中定义。Java关键字21. If:“If”关键字用于创建在条件为“True”时执行的一组或代码块或语句。Java关键字22。 Implements:Implement 是另一个为声明接口而保留的关键字。它在类声明期间使用,并指定一个或多个接口。Java关键字23. Import:import 关键字用于导入包或一个或多个类,或者也可能是一个接口。Java关键字24。 Instanceof:‘instanceof’关键字用于检查相关对象是否是类或接口的实例。Java关键字25。 Int:‘int’关键字是声明整数类型的数据类型之一。Java关键字26。 Interface:interface关键字用于声明仅包含抽象方法的特殊类型的类。为了访问接口方法,接口必须被“实现”,就像我们通过使用“implements”关键字由另一个类使用继承概念一样。

Java关键字

27。 Long:“long”关键字又是保存整数的数据类型之一。它们的范围从 -9223372036854775808 到 9223372036854775808。整个数值应以“L”结尾。

Java关键字

28。 New:‘new’关键字用于创建对象。

Java关键字

29。 Package:‘package’关键字用于创建包。Java关键字30。 Private:‘private’关键字用于为私有模式类创建属性或方法。 “Private”是一个访问修饰符,仅允许声明的类使用私有属性或属性或方法。Java关键字31。 Protected:“Protected”是一个访问修饰符,允许属性或方法只能由相同的包或子类使用。Java关键字32。 Public:“public”关键字是另一个访问修饰符,它允许一个类在其自身内使用公共定义的类的属性或方法等。
下面是一个公共定义的类“test.java”和另一个类“Test2.java”,访问它。Java关键字类 – Test2.javaJava关键字33。 Return:return关键字可以作为方法的执行结束,也可以用来从方法返回一个值。Java关键字34. Short:‘short’关键字是一种数据类型,用于保存从 -32768 到 32767 范围内的整数。Java关键字35。 Static:‘static’关键字用于创建静态方法,这意味着可以在不创建其对象的情况下调用该方法。Java关键字36. Super:‘super’关键字用于调用父类或父类或对象。Java关键字37. Switch:‘switch’关键字用于在不同的情况下创建不同的场景,并用于从中选择一个。 switch 语句包含一个值或表达式,然后将其与所有存在的情况进行比较,并选择匹配的一个。Java关键字38. this:‘this’关键字用于引用方法或构造函数的当前对象。Java关键字39. Throw:“throw”关键字用于向用户在屏幕上抛出异常消息。Java关键字40。 Throws:当程序员想要决定并抛出异常类型时,可以使用“throws”关键字。41 特别是。 Try:“try”关键字启动“try-catch”块。 “try”块是测试异常的地方。Java关键字42。 Void:“void”关键字与方法一起使用时,指定该方法没有返回值。Java关键字43。 While:“while”关键字创建一个循环,其语句中带有条件。循环执行直到语句为真。Java关键字

关键字是Java编程语言中保留的、具有特殊含义的标记。它们在语言中具有保留的用途和预定义的操作。

以上是Java关键字的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn