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

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

Java Development Kit (64-bit) 軟體圖示 Java Development Kit (64-bit) 112 (64-bit) 資料更新 2016-10-18 閱讀約 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-8u112-windows-x64.exe · 195.13 MB · 連結指向軟體原廠

版本紀錄

再看 5 筆

看完整版本清單

這一版改了什麼

What's new in this version:

CHANGES:

security-libs/java.security:
- SunPKCS11 Provider no longer offering SecureRandom by default
- SecureRandom.PKCS11 from the SunPKCS11 Provider is disabled by default on Solaris because the native PKCS11 implementation has poor performance and is not recommended. If your application requires SecureRandom.PKCS11, you can re-enable it by removing "SecureRandom" from the disabledMechanisms list in conf/security/sunpkcs11-solaris.cfg
- Performance improvements have also been made in the java.security.SecureRandom class. Improvements in the JDK implementation have allowed for synchronization to be removed from the java.security.SecureRandom.nextBytes(byte[] bytes) method.

BUG FIXES:
- client-libs 2d GraphicsDevice.getConfigurations() is slow taking 3 or more seconds
- client-libs 2d Xrender: Class cast exception in 2D code running an AWT regression test
- client-libs 2d java/awt/Window/WindowsLeak/WindowsLeak.java fails
- client-libs 2d Wrong glyph is displayed for a derived font
- client-libs 2d [win10] Some unicode characters do not display any more after upgrading to Windows 10
- client-libs 2d ClassCastException: sun.font.CompositeFont cannot be cast to PhysicalFont
- client-libs 2d CCE: sun.java2d.NullSurfaceData cannot be cast to sun.java2d.opengl.OGLSurfaceData
- client-libs java.awt java.awt.SplashScreen.getSize() returns incorrect size for high dpi splash screens
- client-libs java.awt:i18n Caps Lock doesn't work as expected when using Pinyin Simplified input method
- client-libs javax.accessibility [macosx] sun.lwawt.macosx.CAccessible leaks
- client-libs javax.accessibility Uninitialised memory in WinAccessBridge.cpp:1128
- client-libs javax.accessibility Jaws reads wrong values from comboboxes when no element is selected
- client-libs javax.swing Selection in JList is drawn with wrong colors in Nimbus L&F
- client-libs javax.swing javax.swing.text.html.parser.Parser parseScript incorrectly optimized
- client-libs javax.swing JComboBox prevents wheel mouse scrolling of JScrollPane
- client-libs javax.swing Personalized Windows Font Size is not taken into account in Java8u102
- client-libs javax.swing JEditorPane.createEditorKitForContentType throws NPE after 6882559
- core-libs java.lang Annotations with lambda expressions has parameter result in wrong behavior.
- core-libs java.lang.invoke MHs.Lookup.findConstructor returns handles for array classes
- core-libs java.nio (se) Selector.select(long) uses wrong timeout after EINTR (lnx)
- core-libs javax.naming LDAP "follow" throws ClassCastException with Java 8
- core-libs javax.naming com.sun.jndi.ldap.SimpleClientId produces wrong hash code
- core-libs javax.naming Non-synchronized access to shared members of com.sun.jndi.ldap.pool.Pool
- core-libs javax.script ReferenceError in 1.8.0_72
- core-libs jdk.nashorn streamline input parameter of Nashorn scripting $EXEC function
- core-libs jdk.nashorn "ant test" fails to complete on Windows when run under cygwin shell
- core-libs jdk.nashorn Negative lookahead in RegEx breaks backreference
- core-libs jdk.nashorn Simplify Nashorn's Context class loader handling
- core-libs jdk.nashorn Nashorn shebang argument handling is broken
- core-libs jdk.nashorn Regression: two tests fail on Windows with "ant test" target
- core-libs jdk.nashorn fix Nashorn shebang argument handling on Mac/Linux
- core-libs jdk.nashorn arguments are handled differently in apply for JS functions and AbstractJSObjects
- core-libs jdk.nashorn Parsing issue with automatic semicolon insertion
- core-libs jdk.nashorn Script stack trace should display function names
- core-libs jdk.nashorn JSON.stringify does not work on ScriptObjectMirror objects
- core-libs jdk.nashorn Callback parameter of any JS builtin implementation should accept any Callable
- core-libs jdk.nashorn TypeError when a java.util.Comparator object is invoked as a function
- core-libs jdk.nashorn AccessControlException is thrown on public Java class access if "script app loader" is set to null
- core-svc Tests in com/sun/jdi fails intermittently with "jdb input stream closed prematurely"
- core-svc debugger com/sun/jdi/OptionTest.java test times out again
- deploy [macosx] Java Control Panel unable to perform tasks requiring admin privileges
- deploy [macos] JVM continuously throw a NullPointerException on new MacOS 10.12
- deploy javafx FXUIToolkit.showFileChooser() fails when jre is below 7u21
- deploy javafx FXUIToolkit.showSandboxSecurityDialog fails when running jre below 7u21
- deploy javafx FXUIToolkit.showMessageDialog() fails when running jre below 7u55
- deploy webstart Add a URL scheme handler to reliably launch .jnlp files - Mac registration part
- deploy webstart Change JavawsLauncher.app to use NSTask or execv
- deploy webstart Desktop shortcut is not updated after JNLP is changed in deployment cache
- deploy webstart Allow always checkbox in security dialog when jnlp location is unknown
- deploy webstart Signed JWS application unexpectedly asks for permission to open a socket
- hotspot compiler Math.pow yields different results upon repeated calls
- hotspot compiler Need to bailout cleanly if creation of stubs fails when codecache is out of space
- hotspot compiler CastII/ConvI2L for a range check is prematurely eliminated
- hotspot compiler PPC64: unaligned Unsafe.getInt can lead to the generation of illegal instructions
- hotspot compiler Partially initialized string object created by C2's string concat optimization may escape
- hotspot gc G1: UseSHM in combination with a G1HeapRegionSize > os::large_page_size() falls back to use small pages
- hotspot gc Confusing message in "Current rem set statistics"
- hotspot gc allocating heap with UseLargePages and HugeTLBFS may trash existing memory mappings (linux)
- hotspot gc Long response times with G1 and StringDeduplication
- hotspot gc Test gc/ergonomics/TestDynamicNumberOfGCThreads.java fails
- hotspot jvmti Crash in Method::checked_resolve_jmethod_id(_jmethodID*)
- hotspot jvmti Fix for JDK-8147451 failed: Crash in Method::checked_resolve_jmethod_id(_jmethodID*)
- hotspot runtime Null ProtectionDomain in JVM can cause NPE because principals field is not initialized to an empty array
- hotspot runtime vm/mlvm/anonloader/stress/byteMutation failed with: assert(index >=0 && index < _length) failed: symbol index overflow
- hotspot runtime ConstantPool::release_C_heap_structures not run in some circumstances
- hotspot runtime Convert an assert in ClassLoaderData to a guarantee
- hotspot runtime Zero: Better byte behaviour
- hotspot runtime SIGSEGV: Metadata::mark_on_stack
- infrastructure release_eng 8u112 template file need to be updated
- install install jdk 8u71 fails to install with no error message
- install install ent msi does not have double-click support
- javafx application-lifecycle Passing objects between JavaScript (JavaFX / WebKit) and Java causes a memory leak
- javafx base SortedList wrapping a FilteredList causes AIOOBE
- javafx controls TreeTableView's selectedItems reports include null items.
- javafx controls [TreeTableView] graphic property of TreeItem is still visible after collapsing tree
- javafx controls Enhance CustomColorDialog to have flexibility to hide 'Opacity', 'Use' and 'Save' Button
- javafx graphics Scene content shows too large on Retina display, when a regular screen attached
- javafx graphics Print jobs do not finish when using a page range
- javafx graphics javafx print jobs take 60 times longer than javax.print
- javafx graphics Generated temp files (+JXF...temp) for custom fonts not deleted on exit.
- javafx graphics changes to compile under Visual Studio 14.0
- javafx graphics Crash while running imported/w3c/canvas/2d.gradient.interpolate.overlap2.html
- javafx graphics ContextMenu shown at wrong position on Windows10 with Extended Screen
- javafx graphics Revert fix for JDK-8150181 to push it with the correct commit message
- javafx graphics JavaFX Path drawing appears to leak native memory
- javafx web Javascript Timing Events stop work on system clock changes at past
- javafx web WebView Tooltip position no longer changes in 8u60
- javafx web WebView can't alert from a timer
- javafx web Debug build is not working after new WebKit upgrade
- javafx web NullPointer exception in WebView
- javafx web SQL Server Reporting Services in WebViews shows 401
- javafx web [WebView] Icon font doesn't work if single page application will be loaded from jar
- javafx web Need to document that JavaScript to Java bindings use weak references
- javafx web Update to newer version of WebKit
- javafx web DRT crash at fast/css-generated-content/initial-letter-basic.html
- javafx web Update java-wrappers for WebKit generated classes following WebKit update
- javafx web Linux: Javascript Timing Events stop work on system clock changes at past
- javafx web Linux: libjfxwebkit.so has hard-coded path
- javafx web Char value is set as integer, not as character
- javafx web Add timestamp to WebView Keyboard Event
- javafx web Can't get file size with javascript
- javafx web the JVM for our Swing application crashes, once we login into our application server
- javafx web WebView cannot render CSS background image with SVG data
- javafx web Char value is returned as integer, not as character
- javafx web Test Case Failure in CallBackTest
- javafx web WebView can't alert from a timer
- javafx web jvm crash at javafx com.sun.webkit.WebPage.twkPrePaint (GFlag + Heap verification)
- javafx web Implement overridePreference() for DRT framework
- javafx web [WebView] Unable to tile SVG image using css background property
- javafx web WebEngine doesn't handle html5 color picker
- javafx web Assertion fails with https://html-online.com/editor/
- javafx web [Win] Timer functionality is broken after JDK-8089563
- javafx web [OS X] Compilation Issue in WebPage.cpp
- javafx web Fix compilation warnings in WebCore and JavaScriptCore
- javafx web EOFException in GZIPInputStream.readUByte while browsing
- javafx web [WebView] WebView can't display social network icons on wellsfargo.com
- javafx web General sibling selector is broken for selected input boxes in WebView
- javafx web Website weibo.com cannot be loaded
- javafx web JavaFX browser can get stuck in an infinite loop when calling path.getTotalLength()
- javafx web [Windows] JavaFX crash in WebPage.twkOpen in 8u112 when closing WebView while debugging
- javafx web Loading "https://www.windyty.com" with JavaFX WebView crashes JVM.
- other-libs corba NullPointerException in IIOPInputStream.inputClassFields
- security-libs java.security New fix for memory leak in ProtectionDomain cache
- security-libs java.security SecureRandom.nextBytes() hurts performance with small size requests
- security-libs java.security Print size of DH keysize when errors are encountered
- security-libs java.security Some methods of java.security.Security require more permissions, than necessary
- security-libs javax.crypto Ucrypto config file cannot be read when -Dfile.encoding=UTF-16 is set
- security-libs javax.crypto Improve jurisdiction policy file signing exception
- security-libs javax.crypto:pkcs11 KeyStore.load() throws an IOException with a wrong cause in case of wrong password
- security-libs javax.crypto:pkcs11 LoadKeystore.java test is failing
- security-libs javax.net.ssl Hot lock on BulkCipher.isAvailable
- security-libs javax.net.ssl Make handling of 3rd party providers more stable
- security-libs javax.security The fix for 8050402 was partially committed
- security-libs org.ietf.jgss:krb5 Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
- security-libs org.ietf.jgss:krb5 Semicolon is not recognized as comment starting character (Kerberos)
- tools Native2ascii doesn't close one of the streams it opens
- tools javac Incorrect class file created when passing lambda in inner class constructor
- tools launcher Showing incorrect result while passing specific argument in the Java launcher tools
- xml jaxp Issue in XMLScanner: EXPECTED_SQUARE_BRACKET_TO_CLOSE_INTERNAL_SUBSET when skipping large DOCTYPE section with CRLF at wrong place