首頁  >  文章  >  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
上一篇:Java 中的私有下一篇:Java 中的私有