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

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

Java Development Kit (64-bit) 軟體圖示 Java Development Kit (64-bit) 141 (64-bit) 資料更新 2017-07-19 閱讀約 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-8u141-windows-x64.exe · 197.78 MB · 連結指向軟體原廠

版本紀錄

再看 5 筆

看完整版本清單

這一版改了什麼

What's new in this version:

IANA DATA 2017b:
- JDK 8u141 contains IANA time zone data version 2017b

CERTIFICATE CHANGES:
- Let's Encrypt certificates added to root CAs. One new root certificate has been added

NEW FEATURES:
security-libs/java.security. Improved algorithm constraints checking:
- With the need to restrict weak algorithms usage in situations where they are most vulnerable, additional features have been added when configuring the jdk.certpath.disabledAlgorithms and jdk.jar.disabledAlgorithms security properties in the java.security file.
- jdk.certpath.disabledAlgorithms: The certpath property has seen the most change. Previously it was limited to two Constraint types; either a full disabling of an algorithm by name or a full disabling of an algorithm by the key size when checking certificates, certificate chains, and certificate signatures. This creates configurations that are absolute and lack flexibility in their usage. Three new Constraints were added to give more flexibility in allowing and rejecting certificates.
- "jdkCA" examines the certificate chain termination with regard to the cacerts file. In the case of "SHA1 jdkCA". SHA1's usage is checked through the certificate chain, but the chain must terminate at a marked trust anchor in the cacerts keystore to be rejected. This is useful for organizations that have their own private CA that trust using SHA1 with their trust anchor, but want to block certificate chains anchored by a public CA from using SHA1.
- "denyAfter" checks if the given date is before the current date or the PKIXParameter date. In the case of "SHA1 denyAfter 2018-01-01", before 2018 a certificate with SHA1 can be used, but after that date, the certificate is rejected. This can be used for a policy across an organization that is phasing out an algorithm with a drop-dead date. For signed JAR files, the date is compared against the TSA timestamp. The date is specified in GMT.

"usage" examines the specified algorithm for a specified usage. This can be used when disabling an algorithm for all usages is not practical. There are three usages that can be specified:
- TLSServer' restricts the algorithm in TLS server certificate chains when server authentication is performed as a client
- TLSClient' restricts the algorithm in TLS client certificate chains when client authentication is performed as a server
- SignedJAR' restricts the algorithms in certificates in signed JAR files. The usage type follows the keyword and more than one usage type can be specified with a whitespace delimiter
- For example, "SHA1 usage TLSServer TLSClient" would disallow SHA1 certificates for TLSServer and TLSClient operations, but SignedJars would be allowed
- All of these constraints can be combined to constrain an algorithm when delimited by '&'. For example, to disable SHA1 certificate chains that terminate at marked trust anchors only for TLSServer operations, the constraint would be "SHA1 jdkCA & usage TLSServer"
- jdk.jar.disabledAlgorithms: One additional constraint was added to this .jar property to restrict JAR manifest algorithms
- "denyAfter" checks algorithm constraints on manifest digest algorithms inside a signed JAR file. The date given in the constraint is compared against the TSA timestamp on the signed JAR file. If there is no timestamp or the timestamp is on or after the specified date, the signed JAR file is treated as unsigned. If the timestamp is before the specified date, the .jar will operate as a signed JAR file. The syntax for restricting SHA1 in JAR files signed after January 1st 2018 is: "SHA1 denyAfter 2018-01-01". The syntax is the same as that for the certpath property, however certificate checking will not be performed by this property

CHANGES:
core-svc/java.lang.management. JMX Diagnostic improvements:
- com.sun.management.HotSpotDiagnostic::dumpHeap API is modified to throw IllegalArgumentException if the supplied file name does not end with “.hprof” suffix. Existing applications which do not provide a file name ending with the “.hprof” extension will fail with IllegalArgumentException. In that case, applications can either choose to handle the exception or restore old behavior by setting system property 'jdk.management.heapdump.allowAnyFileSuffix' to true.

security-libs/javax.net.ssl. Custom HostnameVerifier enables SNI extension:
- Earlier releases of JDK 8 Updates didn't always send the Server Name Indication (SNI) extension in the TLS ClientHello phase if a custom hostname verifier was used. This verifier is set via the setHostnameVerifier(HostnameVerifier v) method in HttpsURLConnection. The fix ensures the Server Name is now sent in the ClientHello body.

xml/jax-ws. Tighter secure checks on processing WSDL files by wsimport tool:

The wsimport tool has been changed to disallow DTDs in Web Service descriptions, specifically:
- DOCTYPE declaration is disallowed in documents
- External general entities are not included by default
- External parameter entities are not included by default
- External DTDs are completely ignored

To restore the previous behavior:
- Set the System property com.sun.xml.internal.ws.disableXmlSecurity to true
- Use the wsimport tool command line option –disableXmlSecurity
- NOTE: JDK 7 and JDK 6 support for this option in wsimport will be provided via a Patch release post July CPU

BUG FIXES:
- JFileChooser with Windows look and feel crashes on win 10
- Race Condition in java.lang.reflect.WeakCache
- java.nio.Bits.unaligned() doesn't return true on ppc
- After updating to Java8u131, the bind to rmiregistry is rejected by registryFilter even though registryFilter is set
- sun.management.LazyCompositeData.isTypeMatched() fail for composite types with items of ArrayType
- SafePointNode::_replaced_nodes breaks with irreducible loops
- NPE when JavaFX loads default stylesheet or font families if CCL is null
- WebEngine.getDocument().getDocumentURI() no longer returns null for loading a String of HTML
- Failed to load RSA private key from pkcs12
- Improved algorithm constraints checking
- Custom HostnameVerifier disables SNI extension