Java 简明教程

Java - Environment Setup

Set Up Your Java Development Environment

如果你想为 Java 编程语言设置自己的环境,本教程将指导你完成整个过程。请按照以下步骤设置 Java 环境。

If you want to set up your own environment for Java programming language, then this tutorial guides you through the whole process. Please follow the steps given below to set up your Java environment.

Java SE 可免费下载。若要下载 click here,请下载与你的操作系统兼容的版本。

Java SE is available for download for free. To download click here, please download a version compatible with your operating system.

按照说明下载 Java,并运行 .exe 在你的计算机上安装 Java。在计算机上安装 Java 后,你需要设置环境变量来指向正确的安装目录。

Follow the instructions to download Java, and run the .exe to install Java on your machine. Once you have installed Java on your machine, you would need to set environment variables to point to correct installation directories.

Setting Up the Environment Path for Windows 2000/XP

假设你已将 Java 安装到 c:\Program Files\java\jdk 目录中。下面是设置 Windows 2000/XP 的 Java 环境路径的步骤:

Assuming you have installed Java in c:\Program Files\java\jdk directory. Below are the steps to set up the Java environment path for Windows 2000/XP:

  1. Right-click on 'My Computer' and select 'Properties'.

  2. Click on the 'Environment variables' button under the 'Advanced' tab.

  3. Now, edit the 'Path' variable and add the path to the Java executable directory at the end of it. For example, if the path is currently set to C:\Windows\System32, then edit it the following way*C:\Windows\System32;c:\Program Files\java\jdk\bin*.

Setting Up the Environment Path for Windows 95/98/ME

假设你已将 Java 安装到 c:\Program Files\java\jdk 目录中。下面是设置 Windows 95/98/ME 的 Java 环境路径的步骤:

Assuming you have installed Java in c:\Program Files\java\jdk directory. Below are the steps to set up the Java environment path for Windows 95/98/ME:

  1. Edit the 'C:\autoexec.bat' file and add the following line at the end −SET PATH=%PATH%;C:\Program Files\java\jdk\bin

Setting Up the Environment Path for Linux, UNIX, Solaris, FreeBSD

环境变量 PATH 应设置为指向已安装 Java 二进制文件的位置。如果你在这方面遇到问题,请参阅 shell 文档。

Environment variable PATH should be set to point to where the Java binaries have been installed. Refer to your shell documentation if you have trouble doing this.

例如,如果你使用 bash 作为你的 shell,那么你将在 .bashrc 的末尾添加以下行 −

For example, if you use bash as your shell, then you would add the following line at the end of your .bashrc

export PATH=/path/to/java:$PATH'

Online Java Compiler

我们在线设置了 Java 编程环境,以便你可以在线编译和执行所有可用的示例。它让你对你所读的内容充满信心,并使你能够使用不同的选项验证程序。随意修改任何示例并在线执行。

We have set up the Java Programming environment online, so that you can compile and execute all the available examples online. It gives you confidence in what you are reading and enables you to verify the programs with different options. Feel free to modify any example and execute it online.

使用以上示例代码框右上角的 Run & Edit 按钮,尝试以下示例 −

Try the following example using Run & Edit button available at the top right corner of the above sample code box −

public class MyFirstJavaProgram {
   public static void main(String []args) {
      System.out.println("Hello World");
   }
}

对于本教程中给出的大多数示例,你都会在网站代码部分的右上角找到一个 Run & Edit 选项,这会将你带到 Online Java Compiler 。因此,只需使用它并享受你的学习。

For most of the examples given in this tutorial, you will find a Run & Edit option in our website code sections at the top right corner that will take you to the Online Java Compiler. So just make use of it and enjoy your learning.

要编写 Java 程序,你需要一个文本编辑器。市场上还有功能更强大的 IDE。最受欢迎的简要介绍如下 −

To write Java programs, you need a text editor. There are even more sophisticated IDEs available in the market. The most popular ones are briefly described below −

  1. Notepad − On Windows machine, you can use any simple text editor like Notepad (recommended for this tutorial) or WordPad. Notepad++ is also a free text editor which enhanced facilities.

  2. Netbeans − It is a Java IDE that is open-source and free which can be downloaded from www.netbeans.org/index.html.

  3. Eclipse − It is also a Java IDE developed by the Eclipse open-source community and can be downloaded from www.eclipse.org.

IDE 或集成开发环境提供编程所需的所有常见工具和设施,如源代码编辑器、构建工具和调试器等。

IDE or Integrated Development Environment, provides all common tools and facilities to aid in programming, such as source code editor, build tools and debuggers etc.

What is Next?

下一章将教你如何编写和运行你的第一个 Java 程序以及开发应用程序所需的一些重要的 Java 基本语法。

Next chapter will teach you how to write and run your first Java program and some of the important basic syntaxes in Java needed for developing applications.