百度360必应搜狗淘宝本站头条
当前位置:网站首页 > 技术教程 > 正文

第一课:Java简介与开发环境搭建

mhr18 2025-03-07 21:54 13 浏览 0 评论

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!

相关推荐

【预警通报】关于WebLogic存在远程代码执行高危漏洞的预警通报

近日,Oracle官方发布了2021年1月关键补丁更新公告CPU(CriticalPatchUpdate),共修复了包括CVE-2021-2109(WeblogicServer远程代码执行漏洞)...

医院信息系统突发应急演练记录(医院信息化应急演练)

信息系统突发事件应急预案演练记录演练内容信息系统突发事件应急预案演练参与人员信息科参与科室:全院各部门日期xxxx-xx-xx时间20:00至24:00地点信息科记录:xxx1、...

一文掌握怎么利用Shell+Python实现完美版的多数据源备份程序

简介:在当今数字化时代,无论是企业还是个人,数据的安全性和业务的连续性都是至关重要的。数据一旦丢失,可能会造成无法估量的损失。因此,如何有效地对分布在不同位置的数据进行备份,尤其是异地备份,成为了一个...

docker搭建系统环境(docker搭建centos)

Docker安装(CentOS7)1.卸载旧版Docker#检查已安装版本yumlistinstalled|grepdocker#卸载旧版本yumremove-ydocker.x...

基础篇:数据库 SQL 入门教程(sql数据库入门书籍推荐)

SQL介绍什么是SQLSQL指结构化查询语言,是用于访问和处理数据库的标准的计算机语言。它使我们有能力访问数据库,可与多种数据库程序协同工作,如MSAccess、DB2、Informix、M...

Java21杀手级新特性!3行代码性能翻倍

导语某券商系统用这招,交易延迟从12ms降到0.8ms!本文揭秘Oracle官方未公开的Record模式匹配+虚拟线程深度优化+向量API神操作,代码量直降70%!一、Record模式匹配(代码量↓8...

一文读懂JDK21的虚拟线程(java虚拟线程)

概述JDK21已于2023年9月19日发布,作为Oracle标准Java实现的一个LTS版本发布,发布了15想新特性,其中虚拟线程呼声较高。虚拟线程是JDK21中引入的一项重要特性,它是一种轻量级的...

效率!MacOS下超级好用的Linux虚拟工具:Lima

对于MacOS用户来说,搭建Linux虚拟环境一直是件让人头疼的事。无论是VirtualBox还是商业的VMware,都显得过于笨重且配置复杂。今天,我们要介绍一个轻巧方便的纯命令行Linux虚拟工具...

所谓SaaS(所谓三维目标一般都应包括)

2010年前后,一个科技媒体的主编写一些关于云计算的概念性问题,就可以作为头版头条了。那时候的云计算,更多的还停留在一些概念性的问题上。而基于云计算而生的SaaS更是“养在深闺人未识”,一度成为被IT...

ORA-00600 「25027」 「x」报错(报错0xc0000001)

问题现象:在用到LOB大对象的业务中,进行数据的插入,失败了,在报警文件中报错:ORA-00600:内部错误代码,参数:[25027],[10],[0],[],[],[],[],[...

安卓7源码编译(安卓源码编译环境lunch失败,uname命令找不到)

前面已经下载好源码了,接下来是下载手机对应的二进制驱动执行编译源码命令下载厂商驱动https://developers.google.com/android/drivers?hl=zh-cn搜索NGI...

编译安卓源码(编译安卓源码 电脑配置)

前面已经下载好源码了,接下来是下载手机对应的二进制驱动执行编译源码命令下载厂商驱动https://developers.google.com/android/drivers?hl=zh-cn搜索NGI...

360 Vulcan Team首战告捷 以17.5万美金强势领跑2019“天府杯“

2019年11月16日,由360集团、百度、腾讯、阿里巴巴、清华大学与中科院等多家企业和研究机构在成都联合主办了2019“天府杯”国际网络安全大赛暨2019天府国际网络安全高峰论坛。而开幕当日最激荡人...

Syslog 日志分析与异常检测技巧(syslog发送日志配置)

系统日志包含有助于分析网络设备整体运行状况的重要信息。然而,理解并从中提取有效数据往往颇具挑战。本文将详解从基础命令行工具到专业日志管理软件的全流程分析技巧,助你高效挖掘Syslog日志价值。Gr...

从Oracle演进看数据库技术的发展(从oracle演进看数据库技术的发展的过程)

数据库技术发展本质上是应用需求驱动与基础架构演进的双向奔赴,如何分析其技术发展的脉络和方向?考虑到oracle数据库仍然是这个领域的王者,以其为例,管中窥豹,对其从Oracle8i到23ai版本的核...

取消回复欢迎 发表评论: