Simple program example:
1 public class Demo1 { 2 public static void main(String[] args){ 3 int num1=4; 4 int num2=5; 5 if(num1>num2){ 6 System.out.println("num1>num2!"); 7 } 8 9 } 10 }
Java keywords: Keywords are some of Java was given a special meaning, as a special-purpose string, keywords are lowercase
Identifier: Java are used to variables, arrays, methods, classes, etc. from the name is a sequence of characters used, which is what we in the program itself to a variety of ingredients from the name
Naming rules: 1, letters, numbers, underscores, $ Composition
2, case sensitive
3, can not start with a number
4, can not be keywords
5, the length is not limited, but the known sense should see the name
Java data types:
整数类型 byte short int long
数值型 非数值型 float double
8种基本数据类型
非数值型 字符型 char
布尔型 boolean //与C++不同,注意
Java数据类型
类class
引用数据类型 接口 interface
数组
Java靠内存中占用的空间大小和数据的范围区分不同的数据类型
数据类型 | 所占字节 | 表示范围 |
long | 8 | -9223372036854775808~ 9223372036854775807 |
int | 4 | -2147483648~2147483647 |
short | 2 | -32768~32767 |
byte | 1 | -128~127 |
float | 4 | -3.4E38~3.4E38 |
double | 8 | -1.7E308~1.7E308 |
Java中没有无符号数,而且各种类型在内存中占用的字节数不会随着编译平台的不同而变化