title: 基础
date: 2019-02-20 23:00:58
tags:
- JavaSE
categories:
- JavaSE
toc: true
Noun Definition
The JVM ( the Java Virtual Machine, the Java Virtual Machine )
Because of JVM, so the same Java program can be executed in three different operating systems. This realization of cross-platform Java programs. Also known as Java has good portability.
The JRE ( the Java Runtime Environment, the Java Runtime Environment )
Including the required Java Virtual Machine and Java core libraries and other programs, to develop good if you want to run a Java program, the computer only needs to install the JRE.
The JDK ( the Java Developme Kit, the Java Development Kit )
JDK is available to developers, which contains the Java development tools, including the JRE. So install the JDK, you do not have to install the JRE alone. Which development tools: compiler tools Javac.exe, packaging tools Jar.exe and so on.
In simple terms: JDK developed using Java programs, go to the JRE run by the JVM to ensure cross-platform.
Naming Rules
Named to try to make us "see to know the name meaning" in development, this is a good habit.
package
全部小写。
单级包:ahojcn
多级包:cn.ahoj
Class or interface
一个单词:单词的首字母必须大写(Student、Dog)
多个单词:每个单词的首字母必须大写(HelloWorld、StudentName)
Method or variable
一个单词:单词的首字母小写(main、age)
多个单词:从第二个单词开始,每个单词的首字母大写(studentAge、showAllClass())
constant
一个单词:全部大写
多个单词:每个字母都大写,用_隔开
Representation of the data
2,8,10,16-ary
Binary: 0b
the beginning
Octal: 0
the beginning
Decimal: The default is decimal integer
Hex: 0x
beginning
System.out.println(0b1001); // 2
System.out.println(0100); // 8
System.out.println(1001); // 10
System.out.println(0xffff); // 16
type of data
Java is a strongly typed language, for each data has a clearly defined data type specific, allocated memory space of different sizes in memory.
Basic data types:
-
Numeric:
-
Integer type:
byte(1),short(2),int(4),long(8,超过了int范围需要加L或l,建议使用L)
-
Floating-point type:
float(4,单精度浮点数用f或F标记,建议使用F,不加默认是double类型),double(8)
-
Character:
char(2)
-
Boolean:
boolean(1)
-
-
Reference data types:
-
class:
class
-
interface:
interface
-
Array:
[]
-
*** Variable Caution: scope, initialization value, only one line is recommended to define a variable. ***
Cast
Note: boolean type can not be converted to other data types
-
Default conversion
-
byte,short,char => int => long => float => double
-
byte, short, char does not convert each other, they are involved in computing is first converted to an int
-
-
Cast
- Variable name = target type (target type) (converted data)
E.g:
byte c = (byte)(a+b);
Some special
-
Out of multiple loops
class test { public static void main(String[] args) { OUT: // 相当于给循环起了个名字 for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { for (int k = 0; k < 10; k++) { System.out.println("test"); break OUT; } } } } }
-
…