Java關鍵字
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.2. Assert: The ‘assert’ keyword was added to Java 1.4. This keyword allows a programmer to test his assumptions in the program.
3. Boolean: Boolean is a data type that can hold only two values; it’s either a ‘True’ or a ‘False’.
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.
5. Byte: Byte keyword is one of the data types that are able to store whole numbers. The numbers range from -128 to 127
6. Case: Case keyword is used in a switch statement. The ‘case’ keyword creates a block of code and marks it.
7. Catch: The ‘catch’ keyword catches the exceptions that were created by the ‘try’ statements. The catch block is used after Try block.
8. Char: The ‘char’ is one of the data types that is used to hold one character at a time.
9. Class: The class keyword is used to create a class in java. Everything that runs in Java programming resides inside a class.
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.
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.
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.
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’.
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.
15. Enum: The ‘enum’ keyword is used to create enumerations, unchangeable data types. The enum keyword defines a fixed set of constants.
16. Extends: Extends keyword is used to inherit properties of a superclass’s attributes and methods by a subclass.
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.
When hovered over, it shows the following error.
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.
19. Float:float 關鍵字是一種資料類型,保存範圍從 3.4e−038 到 3.4e+038 的小數。聲明小數時,該值應以“f”結尾。
20。 For:‘For’關鍵字用來建立一個循環,一個for一個迴圈。 for 迴圈多次執行所包含的程式碼集,這些程式碼在 for 迴圈條件語句中定義。
21. If:「If」關鍵字用於建立在條件為「True」時執行的一組或程式碼區塊或語句。
22。 Implements:Implement 是另一個為聲明介面而保留的關鍵字。它在類別聲明期間使用,並指定一個或多個介面。
23. Import:import 關鍵字用於匯入套件或一個或多個類,或者也可能是一個介面。
24。 Instanceof:‘instanceof’關鍵字用來檢查相關物件是否為類別或介面的實例。
25。 Int:‘int’關鍵字是聲明整數型別的資料型態之一。
26。 Interface:interface關鍵字用於聲明僅包含抽象方法的特殊類型的類別。為了存取介面方法,介面必須被“實現”,就像我們透過使用“implements”關鍵字由另一個類別使用繼承概念一樣。
27。 Long:「long」關鍵字又是儲存整數的資料型別之一。它們的範圍從 -9223372036854775808 到 9223372036854775808。整個數值應以“L”結尾。
28。 New:‘new’關鍵字用於建立物件。
29。 Package:『package』關鍵字用來建立套件。 30。 Private:‘private’關鍵字用於為私有模式類別建立屬性或方法。 「Private」是一個存取修飾符,僅允許聲明的類別使用私有屬性或屬性或方法。
31。 Protected:「Protected」是一個存取修飾符,允許屬性或方法只能由相同的套件或子類別使用。
32。 Public:「public」關鍵字是另一個存取修飾符,它允許一個類別在其自身內使用公共定義的類別的屬性或方法等。
下面是一個公共定義的類別“test.java”和另一個類別“Test2.java”,存取它。 類別 – Test2.java
33。 Return:return關鍵字可以當作方法的執行結束,也可以用來從方法傳回一個值。
34. Short:‘short’關鍵字是一種資料類型,用於保存從 -32768 到 32767 範圍內的整數。
35。 Static:‘static’關鍵字用於建立靜態方法,這意味著可以在不建立其物件的情況下呼叫該方法。
36. Super:‘super’關鍵字用來呼叫父類別或父類別或物件。
37. Switch:‘switch’關鍵字用於在不同的情況下創建不同的場景,並用於從中選擇一個。 switch 語句包含一個值或表達式,然後將其與所有存在的情況進行比較,並選擇一個符合的值。
38. this:‘this’關鍵字用來引用方法或建構函數的目前物件。
39. Throw:「throw」關鍵字用來向使用者在螢幕上拋出異常訊息。
40。 Throws:當程式設計師想要決定並拋出異常類型時,可以使用「throws」關鍵字。 41 特別是。 Try:「try」關鍵字啟動「try-catch」區塊。 “try”區塊是測試異常的地方。
42。 Void:「void」關鍵字與方法一起使用時,指定方法沒有傳回值。
43。 While:「while」關鍵字建立一個循環,其語句中帶有條件。循環執行直到語句為真。
關鍵字是Java程式語言中保留的、具有特殊意義的標記。它們在語言中具有保留的用途和預先定義的操作。
以上是Java關鍵字的詳細內容。更多資訊請關注PHP中文網其他相關文章!

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

Java 8引入了Stream API,提供了一種強大且表達力豐富的處理數據集合的方式。然而,使用Stream時,一個常見問題是:如何從forEach操作中中斷或返回? 傳統循環允許提前中斷或返回,但Stream的forEach方法並不直接支持這種方式。本文將解釋原因,並探討在Stream處理系統中實現提前終止的替代方法。 延伸閱讀: Java Stream API改進 理解Stream forEach forEach方法是一個終端操作,它對Stream中的每個元素執行一個操作。它的設計意圖是處

PHP是一種廣泛應用於服務器端的腳本語言,特別適合web開發。 1.PHP可以嵌入HTML,處理HTTP請求和響應,支持多種數據庫。 2.PHP用於生成動態網頁內容,處理表單數據,訪問數據庫等,具有強大的社區支持和開源資源。 3.PHP是解釋型語言,執行過程包括詞法分析、語法分析、編譯和執行。 4.PHP可以與MySQL結合用於用戶註冊系統等高級應用。 5.調試PHP時,可使用error_reporting()和var_dump()等函數。 6.優化PHP代碼可通過緩存機制、優化數據庫查詢和使用內置函數。 7

PHP和Python各有優勢,選擇應基於項目需求。 1.PHP適合web開發,語法簡單,執行效率高。 2.Python適用於數據科學和機器學習,語法簡潔,庫豐富。

PHP適合web開發,特別是在快速開發和處理動態內容方面表現出色,但不擅長數據科學和企業級應用。與Python相比,PHP在web開發中更具優勢,但在數據科學領域不如Python;與Java相比,PHP在企業級應用中表現較差,但在web開發中更靈活;與JavaScript相比,PHP在後端開發中更簡潔,但在前端開發中不如JavaScript。

PHP和Python各有優勢,適合不同場景。 1.PHP適用於web開發,提供內置web服務器和豐富函數庫。 2.Python適合數據科學和機器學習,語法簡潔且有強大標準庫。選擇時應根據項目需求決定。

膠囊是一種三維幾何圖形,由一個圓柱體和兩端各一個半球體組成。膠囊的體積可以通過將圓柱體的體積和兩端半球體的體積相加來計算。本教程將討論如何使用不同的方法在Java中計算給定膠囊的體積。 膠囊體積公式 膠囊體積的公式如下: 膠囊體積 = 圓柱體體積 兩個半球體體積 其中, r: 半球體的半徑。 h: 圓柱體的高度(不包括半球體)。 例子 1 輸入 半徑 = 5 單位 高度 = 10 單位 輸出 體積 = 1570.8 立方單位 解釋 使用公式計算體積: 體積 = π × r2 × h (4

PHP成為許多網站首選技術棧的原因包括其易用性、強大社區支持和廣泛應用。 1)易於學習和使用,適合初學者。 2)擁有龐大的開發者社區,資源豐富。 3)廣泛應用於WordPress、Drupal等平台。 4)與Web服務器緊密集成,簡化開發部署。

Java是熱門程式語言,適合初學者和經驗豐富的開發者學習。本教學從基礎概念出發,逐步深入解說進階主題。安裝Java開發工具包後,可透過建立簡單的「Hello,World!」程式來實踐程式設計。理解程式碼後,使用命令提示字元編譯並執行程序,控制台上將輸出「Hello,World!」。學習Java開啟了程式設計之旅,隨著掌握程度加深,可創建更複雜的應用程式。
