1.单行注释
? // 单行注释
2.多行注释
? /* 多行注释 */
3.JavaDoc:文档注释
? /** 文档注释 */
关键字
标识符
所有的标识符都应该以字母(A-Z或者a-z),美元符($)\或者下划线(_)开始。
整数
int num1 = 10(最常用)
byte num2 = 20
short num3 = 30
long num4 = 40L
浮点数(小数)
float
double(最常用)
字符(String不是关键词,而是一个类)
char
布尔值
true
false
所有的字符本质还是数字
\t 制表符
\n 换行
if (flag==true)[] 与 if(flag)[] 相同
byte, short,char <<< int <<< long <<< float <<< double (由低到高)
强制转换 高到低
(类型)变量名
自动转换 低到高
类变量 stacic int allclick = 0;
实例变量 string str = "helloworld";
局部变量 public void method(){
? int i = 0;
}
public class demo02 {
//类变量 static
static double salary = 2500;
//属性:变量
//实例变量:从属于对象:如果不自行初始化,这个类型的默认值 0 0.0
//布尔值: 默认是flase
//除了基本类型,其余的默认值都是null:
String name;
int age;
//main方法
public static void main(String[] args) {
//局部变量:必须声明初始化值
int i = 10;
System.out.println(i);
//变量类型 变量名字 = new demo02();
demo02 demo02 = new demo02();
System.out.println(demo02.age);
System.out.println(demo02.name);
//类变量 static
System.out.println(salary);
}
//其他方法
public void add(){
}
}
public class demo03 {
//修饰符,不存在先后
static final double PI = 3.14;
public static void main(String[] args) {
System.out.println(PI);
}
}
原文:https://www.cnblogs.com/coreybrian/p/14425824.html