Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
Environment to build
作者:cpx
First, what is Java
java is a programming language (programming language) has a specific syntax.
Programmers: source machine: Encoding
Two, java development
May 23, 1995 birth of the founder of java: James - Gosling
Born in 1996 Java1.0
Born in 1997 java1.1
In 1998 Java1.2 born java2.0
In 1999 java had three development direction of J2SE (Standard Edition base) J2EE (Enterprise Edition) J2ME
2004年Java5.0 JavaSE JavaEE JavaME
In 2009 the company was acquired by Oracle
The highest version Java12
Three, Java features [focus]
1. simplicity (with respect to C, C ++)
2. Cross-platform (operating systems, servers, databases)
3. pure object-oriented
Four, Java operating mechanism
Programmers: source file -------> machine code file
1. compiled language: the source files directly translated into machine code file high efficiency can not be cross-platform.
2. interpreted language: the source file line by line, line by line explanation of the low efficiency across platforms.
3. compile explain: first source file is compiled into bytecode files (platform-neutral files .class suffix), and then interpreted to run byte code file. [Focus]
V. Glossary
1. JVM: java virtual machine
Effect: the same simulated environment different operating systems, the difference has reached shielding the underlying operating system.
2. JRE: java runtime environment jvm + interpreter
3. JDK: java development environment JRE + library + Development Kit
Six, JDK installation
1. Double-click the installation
2. Configure Environment Variables
JAVA_HOME: JDK installation directory
PATH: JDK bin directory under the installation directory (the directory command)
CLASSPATH :.
3. Verify whether the installation was successful JDK
Enter cmd in the black window javac, java, java -version command a large number of information
If it is not an internal or external command appears the installation fails.
Seven common dos command
切换盘符 : 盘符: 如: d:
显示盘符下的所有的文件或者文件夹 : dir
进入到指定文件夹 : cd 文件夹
返回上一级目录 : cd ..
返回根目录 : cd/
删除文件 : del 文件名
删除文件夹 : rd 文件夹
清屏 : cls
重新启动一个窗口: start
关闭窗口 : exit
Eight, the first java file
1. The file must end with .java
2. Class name class class {}
3. Main functions: entry function program, the program execution is to perform the main function, the main function performed if finished, the program execution finished.
class First{
public static void main(String[] args){
System.out.println("hello cpx");
}
}
class Second{
public static void main(String[] args){
System.out.println("hello me");
}
}
4. java code execution [focus]
Compile command: javac .java source file name such as: javac A.java
Explain Run: java class names such as: java First
5. Note: [emphasis]
① a java source file names can contain a plurality of different classes, each class can contain a main function. After compiling will generate a .class file for each class.
② public public, open a class can be modified, such as a public class.
Request for a public class must match the class name and file name. A java source file only contains a public class
在First.java中
public class First{
public static void main(String[] args){
System.out.println("hehe");
}
}
Nine, package pack [focus]
1. role: to manage the generated .class file after compilation, similar to folders
2. positions: in a first active line of the source file.
3. syntax: package package name;
4. Compile and run the way
Compile way:. Javac -d filename .java
Automatically generated after compilation of .class files in the package structure
Run explained: java fully qualified name (fully qualified name: package name class name.)
package day1;
public class Test{
public static void main(String[] args){
System.out.println("hehe");
}
}
class Hello{
public static void main(String[] args){
System.out.println("heihei");
}
}
Note: Java source file contains a maximum of one package statement.
Ten, coding standards
1. format specification
a. Reverse indent between levels.
. B only write one line of code, and ends with;.
2. identifier naming convention [focus]
标识符: 凡是可以自己命名的内容 如:类名,包名,函数名,变量名,常量名。
a. a mandatory requirement (must be observed)
1. You must be a letter, number, underscore (_), currency symbol ($) composition, and the numbers can not begin with
2. You can not use keywords and reserved words, case sensitive.
3. There is no limit length
b. soft requirements
1. The best to do too literally, see the name EENOW
2. For specific identifier name
1. Class name: the word capitalized HelloWorld
2. Package Name: All lowercase as: helloworld test
3. variable names, function names: lowercase first letter of the first word, the other word capitalized hello_World
4. constant names: all caps FIELD HI
3. Code Comments [emphasis]
a. single line comment
Syntax: // footnotes
Features: Can not Wrap
b. Multi-line comments
Syntax: / * comment * content /
Features: Support Wrap
C. Documentation Comments special multi-line comments [understand]
Syntax: / ** annotated document contents * /
Use: javadoc -d doc .java source file name
Note: You can annotate classes and functions
.