JDK: Java Development Kit
JRE: Java Runtime Environment
JVM: Java Virtual Machine
卸载JDK
- 删除Java的安装目录
- 删除JAVA_HOME
- 删除path下关于Java的目录
- java -version
安装JDK
搜索JDK8, 下载并安装,记住安装路径
配置环境变量
2.1 新建 JAVA_HOME 变量
2.2 配置path路径
HelloWorld
新建一个Java文件
编写代码
1 2 3 4 5
| public class Hello{ public static void main(String[] args){ System.out.print("Hello, World!"); } }
|
- 编译 javac Hello.java,生成一个class文件
- 运行class文件 java Hello
注释
基本类型
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| public class Demo01 { public static void main(String[] args) {
int num1 = 10; byte num2 = 20; short num3 = 30; long num4 = 30L;
float num5 = 50.1F; double num6 = 3.1415926;
char name = '国';
boolean flag = true; boolean flag_1 = false; } }
|
拓展
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| public class Demo02 { public static void main(String[] args) { int i = 10; int i2 = 010; int i3 = 0x10;
System.out.println(i); System.out.println(i2); System.out.println(i3);
float f = 0.1f; double d = 1.0/10; System.out.println(f==d);
float d1 = 2313131313131313f; float d2 = d1 + 1; System.out.println(d1 == d2);
char c1 = 'a'; char c2 = '中'; System.out.println(c1); System.out.println((int)c1); System.out.println(c2); System.out.println((int)c2); char c3 = '\u0061'; System.out.println(c3); } }
|
类型转换
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| public class Demo03 { public static void main(String[] args) { int money = 10_0000_0000; int years = 20; int total = money * years; long total2 = money * years;
long total3 = money * ((long)years); System.out.println(total3); } }
|
变量
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| public class Demo04 {
static double salary = 2500; static final double PI = 3.14;
String name; int age;
public static void main(String[] args) { int i = 10; System.out.println(i);
Demo04 demo04 = new Demo04(); System.out.println(demo04.age); System.out.println(demo04.name); System.out.println(salary); System.out.println(PI); }
public void add(){
} }
|
运算符
包机制
Javadoc
javadoc命令用于生成API帮助文档
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
public class Doc { String name;
public String test(String name) throws Exception{ return name; } }
|