基础语法
基础语法
-
new了一个新的Empty Project后,要注意Fileile-Project Structure中的ProjectSDK和Language level保持版本一致
-
注释 //、多行注释/*abcd /、文档注释/**注释/
标识符注意点
-
所有的标识符都应该以A-Z(a-z),美元符号$,下划线_开头
-
public class Tip { public static void main(String[] args) { String AHello = "HelloWorld"; String hello = "HelloWorld"; String $AHello = "HelloWorld"; String _AHello = "HelloWorld"; //String 1Hello = “HelloWorld”; //String #Hello = “HelloWorld”; // 所有的标识符都应该以A-Z(a-z),美元符号$,下划线_开头 /** * */ } }
-
-
不能使用关键字作为变量名或者方法名
-
标识符大小写敏感
-
String Man = "hello"; String man = "hello"; //不会冲突
-
数据类型
-
强类型语言
- 要求变量的使用严格符合规定,所有变量必须先定义才能使用
-
弱类型语言
-
Java的数据类型分为两大类
-
基本类型
-
-
数值类型
-
byte、short、int、long(整数类型)
-
float、double(浮点类型)
-
-
boolean类型(ture、false)
public class Demo1 { public static void main(String[] args) { //八大基本数据类型 //整数 //Integer、Byte int nem1 = 10; byte num2 = 20; short num3 = 30; long num4 = 30l; //Long类型要在数字后面加L //小数:浮点数 float num5 = 50.1F;//Float类型需要加F double num6 = 3.1415926; //字符 char name = 'A'; char name1 = '你'; //char name2 = '你好';//错误,只能单个 //字符串,String不是关键字、类 //boolean布尔值 boolean flag = ture; //boolean flag = false; //float 有限、离散、有误差 //用BigDecimal比较 数学工具类 float f = 0.1f; double d = 1.0/10; System.out.println(f==d); //false System.out.println(f); //0.1 System.out.println(d);//0.1 float d1 = 23321321321313131f; float d2 = d1 + 1; System.out.println(d1==d2);//ture
-
-
引用类型
- 类
- 接口
- 数组
char c1 = '\u0061';//a //转义字符 // \t 制表符Tab,\n 换行 System.out.println("Hello\nWorld"); System.out.println("================="); String sa = new String("helloworld"); String sb = new String("helloworld"); System.out.println(sa==sb);//false String sc = "helloworld"; String sd = "helloworld"; System.out.println(sc==sd);//ture //对象,从内存分析
-

浙公网安备 33010602011771号