第一课:Java简介与开发环境搭建_java开发环境一般写什么

createh53个月前 (02-08)技术教程30

1. Java简介

**1. Introduction to Java**

Java是一种广泛使用的高级编程语言,由Sun Microsystems(现为Oracle Corporation)于1995年发布。Java具有以下特点:

Java is a widely used high-level programming language, released by Sun Microsystems (now Oracle Corporation) in 1995. Java has the following characteristics:

- **跨平台性**:Java程序可以在任何支持Java虚拟机(JVM)的平台上运行。

**Platform Independence**: Java programs can run on any platform that supports the Java Virtual Machine (JVM).

- **面向对象**:Java是一种面向对象的编程语言,支持封装、继承和多态等特性。

**Object-Oriented**: Java is an object-oriented programming language that supports features such as encapsulation, inheritance, and polymorphism.

- **简单易学**:Java的语法相对简单,适合初学者学习。

**Easy to Learn**: Java's syntax is relatively simple, making it suitable for beginners.


---


#### 2. 开发环境搭建

**2. Setting Up the Development Environment**

要开始编写和运行Java程序,你需要安装以下工具:

To start writing and running Java programs, you need to install the following tools:

- **Java Development Kit (JDK)**:JDK包含了编译和运行Java程序所需的工具。

**Java Development Kit (JDK)**: The JDK contains the tools needed to compile and run Java programs.

- **集成开发环境 (IDE)**:推荐使用IntelliJ IDEA、Eclipse或NetBeans等IDE来编写和调试Java代码。

**Integrated Development Environment (IDE)**: It is recommended to use IDEs such as IntelliJ IDEA, Eclipse, or NetBeans to write and debug Java code.


##### 安装步骤:

**Installation Steps:**

1. **下载并安装JDK**:

**Download and Install JDK:**

- 访问[Oracle官网](
https://www.oracle.com/java/technologies/javase-downloads.html)下载适合你操作系统的JDK版本。

Visit the [Oracle website](https://www.oracle.com/java/technologies/javase-downloads.html) to download the JDK version suitable for your operating system.

- 按照安装向导完成安装。

Follow the installation wizard to complete the installation.


2. **设置环境变量**:

**Set Environment Variables:**

- 在Windows系统中,右键点击“此电脑” -> “属性” -> “高级系统设置” -> “环境变量”。

In Windows, right-click on "This PC" -> "Properties" -> "Advanced System Settings" -> "Environment Variables".

- 在“系统变量”中找到`Path`,点击“编辑”,然后添加JDK的`bin`目录路径(例如:`C:\Program Files\Java\jdk-版本号\bin`)。

Find `Path` in "System Variables", click "Edit", and add the JDK's `bin` directory path (e.g., `C:\Program Files\Java\jdk-version\bin`).

- 在macOS或Linux系统中,编辑`~/.bash_profile`或`~/.bashrc`文件,添加以下行:

On macOS or Linux, edit the `~/.bash_profile` or `~/.bashrc` file and add the following lines:

```bash

export JAVA_HOME=
/Library/Java/JavaVirtualMachines/jdk-版本号.jdk/Contents/Home

export PATH=$JAVA_HOME/bin:$PATH

```

- 保存文件并执行`source ~/.bash_profile`或`source ~/.bashrc`使更改生效。

Save the file and execute `source ~/.bash_profile` or `source ~/.bashrc` to apply the changes.


3. **验证安装**:

**Verify Installation:**

- 打开终端或命令提示符,输入`java -version`和`javac -version`,如果显示版本信息,则说明安装成功。

Open the terminal or command prompt, type `java -version` and `javac -version`. If the version information is displayed, the installation is successful.


4. **安装IDE**:

**Install IDE:**

- 下载并安装你选择的IDE(如IntelliJ IDEA)。

Download and install your chosen IDE (e.g., IntelliJ IDEA).

- 启动IDE并创建一个新的Java项目。

Launch the IDE and create a new Java project.


---


#### 3. 第一个Java程序

**3. Your First Java Program**

让我们编写并运行一个简单的Java程序。

Let's write and run a simple Java program.


##### 步骤:

**Steps:**

1. 打开你的IDE,创建一个新的Java项目。

Open your IDE and create a new Java project.

2. 在项目中创建一个新的Java类文件,命名为`HelloWorld.java`。

Create a new Java class file in the project and name it `HelloWorld.java`.

3. 在`HelloWorld.java`文件中输入以下代码:

Enter the following code in the `HelloWorld.java` file:

```java

public class HelloWorld {

public static void main(String[] args) {

System.out.println("Hello, World!");

}

}

```

4. 保存文件并运行程序。你应该会在控制台看到输出:

Save the file and run the program. You should see the following output in the console:

```

Hello, World!

```


---


#### 4. 代码解释

**4. Code Explanation**

- `public class HelloWorld`:定义了一个名为`HelloWorld`的公共类。类名必须与文件名相同。

`public class HelloWorld`: Defines a public class named `HelloWorld`. The class name must match the file name.

- `public static void main(String[] args)`:这是Java程序的入口点。`main`方法是程序开始执行的地方。

`public static void main(String[] args)`: This is the entry point of a Java program. The `main` method is where the program starts execution.

- `System.out.println("Hello, World!");`:这行代码用于在控制台输出文本。

`System.out.println("Hello, World!");`: This line of code is used to print text to the console.


---


### 作业

**Homework**

1. 确保你已经成功安装JDK并设置好环境变量。

Make sure you have successfully installed the JDK and set up the environment variables.

2. 在你的IDE中创建一个新的Java项目,并编写并运行`HelloWorld`程序。

Create a new Java project in your IDE, write, and run the `HelloWorld` program.

3. 尝试修改`HelloWorld`程序,使其输出不同的文本。

Try modifying the `HelloWorld` program to output different text.


如果你有任何问题或遇到困难,请随时向我提问。下一课我们将深入学习Java的基本语法和数据类型。祝你学习愉快!

If you have any questions or encounter difficulties, feel free to ask me. In the next lesson, we will dive deeper into Java's basic syntax and data types. Happy learning!

相关文章

Java基础入门篇(四)Java SE、Java EE、Java ME三者之间的区别

编者荐语:Java 是排名第一的编程语言和开发平台。它可以降低成本、缩短开发时间、推动创新并改进应用服务。随着全球数百万开发人员运行超过 510 亿台 Java 虚拟机,Java 继续成为企业和开发人...

Java程序员要不要学习Lua?_javagui有必要学吗

大家好,我是袁庭新。Java程序员要不要学习Lua?Lua虽小,但威力巨大!游戏开发、嵌入式系统、自动化脚本...哪哪都离不开它!|Lua介绍Lua官网:https://www.lua.org。Lua...

历代IE浏览器进化简史_ie浏览器2021

2015-03-19 05:01:00 作者:马荣微软的IE浏览器可能是很多人接触到的第一个浏览器,不过微软已经明确表示将在Win10中采用全新的斯巴达浏览器来取代IE,并且要逐渐淡化直至取消IE品牌...

东方标准|Web和Java的区别,如何选择这两个专业

现在网络发展迅速,很多人都开始选择计算机专业和软件工程专业,一开始都会选择Java作为他们的主修课程,但是在漫长的学习中有80%学生都放弃了Java选择web,那么对于没有学过计算机的朋友,小编在这里...

I E成长之路,但win10后无IE,你是否怀念过它?

说起微软,应该很多人都知道的吧,但不排除一些特别情况的人。比如那些没接触过电脑的老人们,“表而盖茨”响当当的人物,今天我们来看看Internet Explorer 的成长,尽管国人都已经开始嫌弃它。I...

可能是国内第一篇全面解读 Java 现状及趋势的文章

作者 | 张晓楠导读:InfoQ 发布《2019 中国 Java 发展趋势报告》,反映 Java 在中国发展的独特性,同时也希望大家对 Java 有一个正确的认识。2 个月前,InfoQ 英文站发布了...