如果你想查看JDK自带的源代码,可以选择JAVA_HOME目录下的src.zip文件进行查看。
没有找到src.zip文件,说明你安装的JDK没有共享源代码,可以到oracle官网下载安装新的JDK。如果你使用的是Eclipse,而且JDK自带源码没有注释,就会出现如下提示:
Note: The attached Javadoc could not be retrieved as the specified
Javadoc location is either wrong or currently not accessible.
可以通过如下步骤给JDK自带源码添加注释:
Window->Preferences->Java->Installed JREs
->选择jre,点击Edit...
->选择rt.jar->点击Source Attachment...->选择Extern location
->点击External File...
->选择JAVA_HOME目录下的src.zip文件
->确认完成验证方法:
移动鼠标光标到代码“System.out.println();”的println上面。
出现如下Javadoc, 说明设置成功。
void java.io.PrintStream.println()
Terminates the current line by writing the line separator string.
The line separator string is defined by the system property line.
separator, and is not necessarily a single newline character ('\n').
另外, Eclipse下还可以通过如下方式查看源码:
按住Ctrl键,鼠标左键点击java API。