# 1、 本章任務html
編寫HelloWorld程序java
打印控制檯信息oracle
# 2、 本章目標ide
JDK的安裝與配置測試
會使用記事本開發簡單Java程序編碼
會使用輸出語句在控制檯輸出信息spa
熟悉MyEclipse開發環境命令行
# 3、 JDK的安裝3d
## (一) JDK的下載htm
下載地址:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
## (二) 安裝JDK
略
## (三) 配置JDK
- path
- JAVA_HOME
##(四) 驗證JDK
![Paste_Image.png](http://upload-p_w_picpaths.jianshu.io/upload_p_w_picpaths/5818381-80cb59c173e17f03.png?p_w_picpathMogr2/auto-orient/strip%7Cp_w_picpathView2/2/w/1240)
# 4、 開發第一個Java程序
## (一) 步驟
- 源代碼
- 編譯
- 運行
## (二) 編寫HelloWorld程序
### 1. 編寫源代碼
命令行:notepad
```java
public class HelloWorld{
public static void main(String[] args){
System.out.print("Hello World");
}
}
```
注意:
- 文件名必須是:HelloWorld
- 文件的後綴名:.java
### 2. 編譯
javac
![Paste_Image.png](http://upload-p_w_picpaths.jianshu.io/upload_p_w_picpaths/5818381-3a444f1f0481ffdb.png?p_w_picpathMogr2/auto-orient/strip%7Cp_w_picpathView2/2/w/1240)
注意點:javac 後面的文件名必須包括後綴名(.java)
成功的標識:
![Paste_Image.png](http://upload-p_w_picpaths.jianshu.io/upload_p_w_picpaths/5818381-259d2ab40ae2a8f4.png?p_w_picpathMogr2/auto-orient/strip%7Cp_w_picpathView2/2/w/1240)
### 3. 運行
java
![Paste_Image.png](http://upload-p_w_picpaths.jianshu.io/upload_p_w_picpaths/5818381-bfdd3f8135aebac4.png?p_w_picpathMogr2/auto-orient/strip%7Cp_w_picpathView2/2/w/1240)
**注意點:java 後面不須要文件後綴名**
## (三) 理解Java程序的結構
### 1. 結構
![Paste_Image.png](http://upload-p_w_picpaths.jianshu.io/upload_p_w_picpaths/5818381-42b7852be5ae350b.png?p_w_picpathMogr2/auto-orient/strip%7Cp_w_picpathView2/2/w/1240)
### 2. 輸出語句
- System.out.print() 不換行
```
public class HelloWorld{
public static void main(String[] args){
System.out.print("Hello World");
System.out.print("今天很熱");
}
}
```
**運行效果:**
![](http://upload-p_w_picpaths.jianshu.io/upload_p_w_picpaths/5818381-9a665541c1ac4a1f.png?p_w_picpathMogr2/auto-orient/strip%7Cp_w_picpathView2/2/w/1240)
- System.out.println() 換行
```
public class HelloWorld{
public static void main(String[] args){
System.out.println("Hello World");
System.out.println("今天很熱");
}
}
```
**運行效果:**
![](http://upload-p_w_picpaths.jianshu.io/upload_p_w_picpaths/5818381-b842753ec89057eb.png?p_w_picpathMogr2/auto-orient/strip%7Cp_w_picpathView2/2/w/1240)
## (四) 轉義字符:\t和\n
### 1. 含義
![](http://upload-p_w_picpaths.jianshu.io/upload_p_w_picpaths/5818381-c10589c00bf64a75.png?p_w_picpathMogr2/auto-orient/strip%7Cp_w_picpathView2/2/w/1240)
### 2. 示例
- \n
```
public class HelloWorld{
public static void main(String[] args){
System.out.print("Hello World\n");
System.out.println("今天很熱");
}
}
```
**運行效果**
![](http://upload-p_w_picpaths.jianshu.io/upload_p_w_picpaths/5818381-028ab536edce944d.png?p_w_picpathMogr2/auto-orient/strip%7Cp_w_picpathView2/2/w/1240)
- \t
```
public class HelloWorld{
public static void main(String[] args){
System.out.print("Hello World\t");
System.out.println("今天很熱");
}
}
```
**運行效果**
![](http://upload-p_w_picpaths.jianshu.io/upload_p_w_picpaths/5818381-984a6794e9a7b650.png?p_w_picpathMogr2/auto-orient/strip%7Cp_w_picpathView2/2/w/1240)
## (五) 打印輸出的小例子
### 1. 需求
![](http://upload-p_w_picpaths.jianshu.io/upload_p_w_picpaths/5818381-f3a0e5af8f7e7474.png?p_w_picpathMogr2/auto-orient/strip%7Cp_w_picpathView2/2/w/1240)
![](http://upload-p_w_picpaths.jianshu.io/upload_p_w_picpaths/5818381-70d9e009bb697986.png?p_w_picpathMogr2/auto-orient/strip%7Cp_w_picpathView2/2/w/1240)
### 2. 參考代碼
```
public class ShowInfo{
public static void main(String[] args){
System.out.println("姓名:張三");
System.out.println("年齡:18");
}
}
```
**程序運行效果**
![](http://upload-p_w_picpaths.jianshu.io/upload_p_w_picpaths/5818381-2758a0489711066a.png?p_w_picpathMogr2/auto-orient/strip%7Cp_w_picpathView2/2/w/1240)
```
public class ShowInfo{
public static void main(String[] args){
System.out.print("張三\t");
System.out.print("18");
}
}
```
**運行效果:**
![](http://upload-p_w_picpaths.jianshu.io/upload_p_w_picpaths/5818381-2a030bd94594d045.png?p_w_picpathMogr2/auto-orient/strip%7Cp_w_picpathView2/2/w/1240)
## (六) java的註釋
爲了方便他人閱讀程序
註釋是不會被執行的
### 1. 單行註釋
#### 語法
```
//
```
#### 示例
```
public class HelloWorld{
public static void main(String[] args){
//這是換行輸出
System.out.println("Hello World");
System.out.println("今天很熱");
}
}
```
程序運行結果
![](http://upload-p_w_picpaths.jianshu.io/upload_p_w_picpaths/5818381-5c33bbebf50926e2.png?p_w_picpathMogr2/auto-orient/strip%7Cp_w_picpathView2/2/w/1240)
**注:註釋不會被執行**
### 2. 多行註釋
#### 語法
```
/*
註釋內容
*/
```
#### 示例
```
public class HelloWorld{
/*
這是程序的入口
這是測試多行註釋
*/
public static void main(String[] args){
//這是換行輸出
System.out.println("Hello World");
System.out.println("今天很熱");
}
}
```
### 3. 文檔註釋
#### 語法
```
/**
*/
```
## (七) Java編碼規範
![](http://upload-p_w_picpaths.jianshu.io/upload_p_w_picpaths/5818381-44b406900b91e8fb.png?p_w_picpathMogr2/auto-orient/strip%7Cp_w_picpathView2/2/w/1240)
![](http://upload-p_w_picpaths.jianshu.io/upload_p_w_picpaths/5818381-1928d72a77a2e3ac.png?p_w_picpathMogr2/auto-orient/strip%7Cp_w_picpathView2/2/w/1240)
# 5、 使用MyEclipse開發Java程序
## (一) 下載
百度
## (二) 破解
參考教程
## (三) MyEclipse建立一個Java項目的步驟
![](http://upload-p_w_picpaths.jianshu.io/upload_p_w_picpaths/5818381-f7fd91d36f0229ea.png?p_w_picpathMogr2/auto-orient/strip%7Cp_w_picpathView2/2/w/1240)
### 1. 建立一個Java項目
![](http://upload-p_w_picpaths.jianshu.io/upload_p_w_picpaths/5818381-efff771442e9f842.png?p_w_picpathMogr2/auto-orient/strip%7Cp_w_picpathView2/2/w/1240)
建立成功的樣式
![](http://upload-p_w_picpaths.jianshu.io/upload_p_w_picpaths/5818381-a89d31b6d92777b7.png?p_w_picpathMogr2/auto-orient/strip%7Cp_w_picpathView2/2/w/1240)
### 2. 建立並編寫Java源程序
![](http://upload-p_w_picpaths.jianshu.io/upload_p_w_picpaths/5818381-64190bf6ff593884.png?p_w_picpathMogr2/auto-orient/strip%7Cp_w_picpathView2/2/w/1240)
![](http://upload-p_w_picpaths.jianshu.io/upload_p_w_picpaths/5818381-5341aa98181b932d.png?p_w_picpathMogr2/auto-orient/strip%7Cp_w_picpathView2/2/w/1240)
### 3. 編譯和運行
編譯自動完成
運行
![](http://upload-p_w_picpaths.jianshu.io/upload_p_w_picpaths/5818381-49bb8a4eb9d3c760.png?p_w_picpathMogr2/auto-orient/strip%7Cp_w_picpathView2/2/w/1240)
## (四) Java項目組織結構
### 1. 導航視圖
![Paste_Image.png](http://upload-p_w_picpaths.jianshu.io/upload_p_w_picpaths/5818381-d3cc24c79754e530.png?p_w_picpathMogr2/auto-orient/strip%7Cp_w_picpathView2/2/w/1240)
#### 目錄說明
![](http://upload-p_w_picpaths.jianshu.io/upload_p_w_picpaths/5818381-4e299ab27dda9555.png?p_w_picpathMogr2/auto-orient/strip%7Cp_w_picpathView2/2/w/1240)
- bin:存儲編譯後的文件
- src:存儲源程序
### 2. 包視圖
包:至關於文件夾,在不一樣的包中,能夠有相同名的代碼文件
## (五) 編寫Javat程序常見的幾種錯誤
### 1. public修飾的類名必須和文件名稱相同
![](http://upload-p_w_picpaths.jianshu.io/upload_p_w_picpaths/5818381-beb6ef044fc3e5e7.png?p_w_picpathMogr2/auto-orient/strip%7Cp_w_picpathView2/2/w/1240)
### 2. main方法做爲程序的入口,void必不可少
![](http://upload-p_w_picpaths.jianshu.io/upload_p_w_picpaths/5818381-1b6bb6ef3d03ecd3.png?p_w_picpathMogr2/auto-orient/strip%7Cp_w_picpathView2/2/w/1240)
### 3. java對大小寫敏感
![](http://upload-p_w_picpaths.jianshu.io/upload_p_w_picpaths/5818381-0a4bba84255c6b8a.png?p_w_picpathMogr2/auto-orient/strip%7Cp_w_picpathView2/2/w/1240)
### 4. 每個Java語句必須以分號結尾
![](http://upload-p_w_picpaths.jianshu.io/upload_p_w_picpaths/5818381-7ca6e8653e3a5853.png?p_w_picpathMogr2/auto-orient/strip%7Cp_w_picpathView2/2/w/1240)
### 5. 引號必不可少
![](http://upload-p_w_picpaths.jianshu.io/upload_p_w_picpaths/5818381-de7a4052ff76caee.png?p_w_picpathMogr2/auto-orient/strip%7Cp_w_picpathView2/2/w/1240)
## (六) 案例
### 1. 需求
![](http://upload-p_w_picpaths.jianshu.io/upload_p_w_picpaths/5818381-4ef35ff1eaee3bd9.png?p_w_picpathMogr2/auto-orient/strip%7Cp_w_picpathView2/2/w/1240)
### 2. 參考代碼
```
public class ShowUserInfo {
public static void main(String[] args) {
System.out.println("你好,我是青鳥的學生");
System.out.println("姓名:王五");
System.out.println("年齡:18");
System.out.println("愛好:打籃球");
}
}
```