這是歷史版本頁面 — 看 Java Development Kit (64-bit) 最新版本

寫Java程式一直編譯失敗,JDK到底該不該裝

Java Development Kit (64-bit) 軟體圖示 Java Development Kit (64-bit) 9.0.4 (64-bit) 資料更新 2018-01-16 閱讀約 7 分鐘

你剛開始學Java,興沖沖地裝了Eclipse或IntelliJ IDEA,照著教學影片打了第一支Hello World,按下執行卻跳出「javac不是內部或外部命令」,或者直接顯示找不到Java執行環境。你上網查,有人說要裝JDK,有人說裝JRE就夠,還有人叫你改環境變數——但你連這些名詞在講什麼都還搞不清楚,只想知道為什麼寫個程式這麼麻煩。

多數人習慣直接裝一套IDE就開始寫,但IDE本身只是編輯器,真正負責把原始碼編譯成可執行檔、提供除錯工具和執行環境的,是底層那套開發工具包。沒有它,你寫的程式碼就只是一堆文字檔。這類工具的核心工作,就是補齊從「寫完程式」到「跑得起來」之間那段看不見的基礎建設——編譯、執行、除錯、看文件,全部靠它。

01JDK和JRE到底差在哪裡,我該裝哪一個?

JDK是完整的開發環境,包含編譯器、除錯工具、函式庫和JRE;JRE只是JDK的子集,只提供執行Java程式的必要元件。如果你要寫程式、編譯原始碼,必須裝JDK;如果只是要執行別人寫好的Java程式,裝JRE就夠了。以你的情況——會寫到javac指令——需要的是JDK。

02這套軟體裝完之後,具體能幫我做到哪些事?

它提供Java編譯器,把.java原始碼轉成可在JVM上執行的位元組碼;內含JRE讓你能在本機執行Java應用程式;附帶大量函式庫和API,涵蓋資料庫存取、網路通訊、GUI開發等;還有jdb、jstack等除錯工具,以及JConsole、VisualVM等效能分析工具。另外包含完整的Java API文件,查類別和方法用法時不必另外上網。

03它跟Eclipse、IntelliJ IDEA這些IDE是什麼關係?

它本身不包含IDE,但設計上就是為了跟這些工具搭配。Eclipse、IntelliJ IDEA、NetBeans等IDE在背後呼叫JDK的編譯器和工具來完成建置與執行。你裝好JDK後,在IDE裡指定JDK路徑,IDE就能用它來編譯和執行你的程式。兩者是互補關係,不是二選一。

0464位元版本跟32位元有什麼差別,我該怎麼選?

資料中沒有針對64位元與32位元差異的詳細說明。一般來說,64位元版本能使用更大的記憶體空間,如果你的作業系統是64位元,且需要處理大型專案或大量資料,通常會選擇64位元版本。但具體支援情況和安裝需求,建議到Oracle官方網站確認你的系統相容性。

05它的除錯工具實際上是怎麼用的?

它提供jdb(Java除錯器)和jstack(執行緒堆疊分析工具)。jdb讓你在命令列中設定中斷點、逐步執行、檢視變數值,適合不習慣用IDE內建除錯器的人;jstack則用來查看JVM執行緒狀態,可以找出死結或執行緒卡住的原因。另外JConsole和VisualVM提供圖形化介面,可以監看記憶體使用量、CPU負載和執行緒狀態。

06完全沒寫過程式的新手,適合直接碰這套軟體嗎?

可以裝,但要有心理準備。資料中明確提到,設定環境變數對初學者來說有挑戰性,安裝過程也需要手動設定。如果你只是跟著教學走,照步驟設定JAVA_HOME和PATH,通常能順利完成。但如果你對命令列操作不熟悉,第一次設定環境變數可能會卡一段時間。建議先找一篇完整的安裝教學照著做。

07商業用途可以免費使用嗎?

可以免費下載和使用,但商業使用時必須遵守Oracle的授權條款。資料中強調,JDK 20之後的版本在Oracle No-Fee條款下,可以在生產環境免費使用和重新散布,但授權條款細節需要自行審閱。如果你的公司要拿它來開發商業軟體,建議讓法務或主管確認授權內容,不要直接當作完全免費。

08我只是想跑別人寫好的Java程式,不寫程式,需要裝這個嗎?

不需要。如果你不寫程式、不編譯原始碼,只需要執行Java應用程式,裝JRE就夠了。JDK包含了JRE,但體積更大、安裝更複雜。資料中明確指出JRE是JDK的子集,只提供執行所需的元件。先確認你的需求是「執行」還是「開發」,再決定要裝哪一個。

09我已經在用OpenJDK了,還需要換成這套嗎?

不一定。資料的FAQ中提到,OpenJDK、Amazon Corretto、IBM SDK for Java都是功能相近的替代方案。如果你目前的OpenJDK能正常編譯和執行你的專案,沒有必要更換。Oracle JDK和OpenJDK在核心功能上高度重疊,選擇哪一套通常取決於你對授權條款、更新頻率和技術支援的需求。

10這套軟體只有英文介面,看不懂英文的人該怎麼辦?

它的介面確實是英文,但實際使用上,你主要接觸的是命令列工具和IDE整合,不是圖形介面操作。javac、java這些指令的錯誤訊息是英文,API文件也是英文。如果你英文閱讀有困難,可以搭配中文教學網站或書籍學習,但長期寫Java程式,英文文件閱讀能力幾乎是必需的,這點要先有心理準備。

11我的電腦硬碟空間不多,裝這個會不會很佔空間?

資料中有提到,它的安裝套件相對較大,需要可觀的磁碟空間。具體需要多少空間,資料中沒有提供數字,建議到官方下載頁面查看安裝需求。如果你的硬碟空間有限,可以考慮只裝JRE(如果不需要開發),或選擇體積較小的OpenJDK發行版。安裝前先確認剩餘空間,避免裝到一半失敗。

12我朋友說用Android Studio寫Java也行,那我還需要另外裝這個嗎?

ndroid Studio本身是開發Android應用程式的IDE,它會綁定或要求安裝特定的JDK版本。資料中將Android Studio列為功能相近的軟體,但它的定位是Android開發,不是一般Java應用程式開發。如果你要寫的是桌面或伺服器端的Java程式,Android Studio並不適合;如果你要開發Android App,那Android Studio會處理JDK的配置,通常不需要手動另外安裝。

下載與官方連結

前往官方網站 下載 Java Development Kit (64-bit)

jdk-9.0.4_windows-x64_bin.exe · 375.56 MB · 連結指向軟體原廠

版本紀錄

再看 5 筆

看完整版本清單

這一版改了什麼

What's new in this version:

NEW FEATURES IN OpenJDK 9:
security-libs/java.security:
- Open source the root certificates in Oracle's Java SE Root CA program
- The OpenJDK 9 binary for Linux x64 contains an empty cacerts keystore. This prevents TLS connections from being established because there are no Trusted Root Certificate Authorities installed. As a workaround for OpenJDK 9 binaries, users had to set the javax.net.ssl.trustStore System Property to use a different keystore.
- "JEP 319: Root Certificates" [1] addresses this problem by populating the cacerts keystore with a set of root certificates issued by the CAs of Oracle's Java SE Root CA Program. As a prerequisite, each CA must sign the Oracle Contributor Agreement (OCA) http://www.oracle.com/technetwork/community/oca-486395.html, or an equivalent agreement, to grant Oracle the right to open-source their certificates.

NEW FEATURES:
- security-libs/javax.net.ssl:
- Negotiated Finite Field Diffie-Hellman Ephemeral Parameters for TLS
- The JDK SunJSSE implementation now supports the TLS FFDHE mechanisms defined in RFC 7919. If a server cannot process the supported_groups TLS extension or the named groups in the extension, applications can either customize the supported group names with jdk.tls.namedGroups, or turn off the FFDHE mechanisms by setting the System Property jsse.enableFFDHEExtension to false.

other-libs/corba:
- Add additional IDL stub type checks to org.omg.CORBA.ORBstring_to_object method
- Applications that either explicitly or implicitly call org.omg.CORBA.ORB.string_to_object, and wish to ensure the integrity of the IDL stub type involved in the ORB::string_to_object call flow, should specify additional IDL stub type checking. This is an "opt in" feature and is not enabled by default.

To take advantage of the additional type checking, the list of valid IDL interface class names of IDL stub classes is configured by one of the following:
- Specifying the security property com.sun.CORBA.ORBIorTypeCheckRegistryFilter located in the file conf/security/java.security in Java SE 9 or in jre/lib/security/java.security in Java SE 8 and earlier.
- Specifying the system property com.sun.CORBA.ORBIorTypeCheckRegistryFilter with the list of classes. If the system property is set, its value overrides the corresponding property defined in the java.security configuration.
- If the com.sun.CORBA.ORBIorTypeCheckRegistryFilter property is not set, the type checking is only performed against a set of class names of the IDL interface types corresponding to the built-in IDL stub classes.

Changes:
security-libs/javax.crypto:
- RSA public key validation
- In 9.0.4, the RSA implementation in the SunRsaSign provider will reject any RSA public key that has an exponent that is not in the valid range as defined by PKCS#1 version 2.2. This change will affect JSSE connections as well as applications built on JCE.
- security-libs/javax.crypto
- Provider default key size is updated
- This change updates the JDK providers to use 2048 bits as the default key size for DSA instead of 1024 bits when applications have not explicitly initialized the java.security.KeyPairGenerator and java.security.AlgorithmParameterGenerator objects with a key size.
- If compatibility issues arise, existing applications can set the system property jdk.security.defaultKeySize introduced in JDK-8181048 with the algorithm and its desired default key size.
- security-libs/javax.crypto
- Stricter key generation
- The generateSecret(String) method has been mostly disabled in the javax.crypto.KeyAgreement services of the SUN and SunPKCS11 providers. Invoking this method for these providers will result in a NoSuchAlgorithmException for most algorithm string arguments. The previous behavior of this method can be re-enabled by setting the value of the jdk.crypto.KeyAgreement.legacyKDF system property to true (case insensitive). Re-enabling this method by setting this system property is not recommended.
- security-libs/javax.net.ssl
- Disable exportable cipher suites
- To improve the strength of SSL/TLS connections, exportable cipher suites have been disabled in SSL/TLS connections in the JDK by the jdk.tls.disabledAlgorithms Security Property.
- core-svc/javax.management
- JMX Connections need deserialization filters
- New public attributes, RMIConnectorServer.CREDENTIALS_FILTER_PATTERN and RMIConnectorServer.SERIAL_FILTER_PATTERN have been added to RMIConnectorServer.java. With these new attributes, users can specify the deserialization filter pattern strings to be used while making a RMIServer.newClient() remote call and while sending deserializing parameters over RMI to server respectively.
- The user can also provide a filter pattern string to the default agent via management.properties. As a result, a new attribute is added to management.properties.
- Existing attribute RMIConnectorServer.CREDENTIAL_TYPES is superseded by RMIConnectorServer.CREDENTIALS_FILTER_PATTERN and has been removed.

Bug fixes:
- deploy webstart:JNLP files won't launch from IE11 on Windows 10 Creators Update
- hotspot runtime: s390: Some java boolean checks are not correct
- javafx media: Provide media support for libav version 57
- javafx web: Underscore not visible in HTML combo box options inside webview
- javafx web: Possible crash due to use-after-free
- security-libsjava.security: Open-source the Oracle JDK Root Certificates
- security-libs javax.crypto: A comment in the java.security configuration file incorrectly says that "strong but limited" is the default value
- security-libs javax.net.ssl:Negotiated Finite Field Diffie-Hellman Ephemeral Parameters for TLS
- security-libs javax.net.ssl: Transport Layer Security (TLS) Session Hash and Extended Master Secret Extension
- security-libs javax.net.ssl: Restrict the use of EXPORT cipher suites
- security-libs javax.net.ssl: Increase the number of clones in the CloneableDigest