Java language
Program : a description of the implementation process of the complete thing.
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World");
}
}
public common
} mathematics, the set {behalf. {} Where the code can be written.
inlet public static void main (String [] args) program
main door
command System.out.println ( "Hello World"); the output statement
System System print out the println
javac followed afterwards by file name java file, for example HelloWorld.java. This command is used to compile the source files to java byte code class files, such as: the javac HelloWorld.java .
After running javac command, if successful compilation no errors, file a HelloWorld.class will appear.
java followed afterwards by the class name java file, for example HelloWorld is the name of the class, such as: java HelloWorld.
Note : java command behind do not add .class.
Java is divided into three systems:
- JavaSE (J2SE) (Java2 Platform Standard Edition, java Platform, Standard Edition)
- JavaEE (J2EE) (Java 2 Platform, Enterprise Edition, java platform enterprise edition)
- JavaME (J2ME) (Java 2 Platform Micro Edition, java Platform, Micro Edition).
version version
- Object : An object is an instance of a class, have state and behavior. For example, a dog is an object that states are: color, name, breed; behavior: wagging its tail, called, eat and so on.
- Class : The class is a template that describes the behavior and state of a class object.
- Methods : The method is behavior, a class can have a number of ways. Logical operation, and all the data modification operation is done in the process.
- Examples of variables : each object has a unique instance variables, the state of the object is determined by the instance variables.
The basic syntax
When writing a Java program, you should note the following:
- Case sensitive : Java is case-sensitive, which means that the identifier Hello and hello are different.
- Class Name : For all classes, the class name first letter should be capitalized. If the class name composed of several words, the first letter of each word should be capitalized, such as MyFirstJavaClass .
- Method name : All method name should begin with a lowercase letter. If the method name contains several words, each word is capitalized later.
- Source File name : source file name must be the same as the class name. When saving files, you should use the class name as the file name to save (Remember that Java is case-sensitive), the file name extension is .java . (If the file name and class name are not the same will result in a compilation error).
- Method main entrance : all the Java programs public static void main (String [] args) method to begin.
Java identifier
All components of the Java name is required. Class names, method names and variable names are called tags.
About Java identifiers, the following points should be noted:
- All identifiers should begin with a letter (AZ or az), the dollar sign ($) or an underscore (_)
- After the first character may be a letter (AZ or az), any combination of characters dollar sign ($), underscore (_) or digital
- Keywords can not be used as an identifier keyword is given a special programming language word meaning
- Identifiers are case sensitive
- Legal identifier, for example: age, $ salary, _value, __ 1_value
- Illegal identifier example: 123abc, -salary
Java modifiers
Like other languages, Java classes can be modified in the methods and properties using the modifier. There are two types of modifiers:
- Access control modifiers: default, public, protected, private
- Non-access control modifiers: final, abstract, static, synchronized
In later chapters we will discuss in depth Java modifiers.
Java keywords
Java keywords are listed below. These reserved words can not be used to name constants, variables, and any identifiers.
category | Keyword | Explanation |
---|---|---|
Access control | private | private |
protected | under protection | |
public | public | |
Class, method and variable modifiers | abstract | Abstract statement |
class | class | |
extends | Expansion, succession | |
final | The final value can not be changed | |
implements | Implement (Interface) | |
interface | interface | |
native | 本地,原生方法(非 Java 实现) | |
new | 新,创建 | |
static | 静态 | |
strictfp | 严格,精准 | |
synchronized | 线程,同步 | |
transient | 短暂 | |
volatile | 易失 | |
程序控制语句 | break | 跳出循环 |
case | 定义一个值以供 switch 选择 | |
continue | 继续 | |
default | 默认 | |
do | 运行 | |
else | 否则 | |
for | 循环 | |
if | 如果 | |
instanceof | 实例 | |
return | 返回 | |
switch | 根据值选择执行 | |
while | 循环 | |
错误处理 | assert | 断言表达式是否为真 |
catch | 捕捉异常 | |
finally | 有没有异常都执行 | |
throw | 抛出一个异常对象 | |
throws | 声明一个异常可能被抛出 | |
try | 捕获异常 | |
包相关 | import | 引入 |
package | 包 | |
基本类型 | boolean | 布尔型 |
byte | 字节型 | |
char | 字符型 | |
double | 双精度浮点 | |
float | 单精度浮点 | |
int | 整型 | |
long | 长整型 | |
short | 短整型 | |
变量引用 | super | 父类,超类 |
this | 本类 | |
void | 无返回值 | |
保留关键字 | goto | 是关键字,但不能使用 |
const | 是关键字,但不能使用 | |
null | 空 |