基础语法
注释
Java语言的三种注释
//当行快捷ctrl+/
/**/多行注释 ctrl+shift+/
/*** */文档注释,用于类,方法(函数),属性功能说明
关键字
关键字中所有字母都为小写
用于定义数据类型的关键字
class interface enum byte short int long float double char boolean void
定义数据类型
true false null
用于定义流程
if else switch case default while do for break continue return
定义访问权限
private protected public
定义类,函数,变量修饰符的关键字
abstract final static synchronized
用于定义类与类之间关系的关键字
extends implements
用于定义建立实例,判断实例的关键字
new this super instanceof
用于异常的关键字
try catch finally throw throws
其他修饰符关键字
native strictfp transient volatile assert
保留字
goto 、const
标识符
规则
-
26个字母大小写 0-9,_或$组成,数字不能开头
-
不可以使用关键字和保留字,但能包含
-
Java中严格区分大小写,长度无限制
-
不可以包含空格
-
见名知意
Java中的名称命名规范
包名:多单词组成字母都小写
类名,接口名:多单词时,所有的首字母大写
变量名,方法名,第一个第一个小写,后面单词首字母大写
常量名:全部大写
练习
import java.util.Scanner; public class two1 { public static void main(String[]args){ //体验i++和++i int i1 = 10,i2 = 20; int i = i1++; System.out.print("i="+i); System.out.println("i1="+i1); i = ++i1; System.out.print("i="+i); System.out.println("i1="+i1); //体验=和== boolean b1=false; if(b1=true){ System .out .println("结果为真"); }else System.out.println("结果为假"); //体会移位符 int i=1; i*=0.1; System.out.println(i); i++; System.out.println(i); //交换数字 int a=5,b=10; a=b; b=a/2; System.out.println(a); System.out.println(b); //温度转换 System.out.println("输入一个数字"); Scanner scan=new Scanner(System.in); double a=scan.nextDouble(); double b=a*9/5+32; System.out.print(b); //字符转换 char c='A'; char s=(char)(c+32); System.out.print(s); } }