标识符和数据类型

所有标识符都应该以字母(A-Z或者a-z),美元符($)或者下划线( _ )开始。

标识符大小写敏感。

可以使用中文命名,但一般不建议去使用。

不能用关键字作为变量名或方法名。

public class Demo04 {
public static void main(String[] args){
String a="hello";
int b=10;
System.out.println(a);
System.out.println(b);

}
}

强类型语言 //八大基本数据类型
int a=10;
byte b=20;
short c=30;
long d=40;//long类型数字后面加l
//小数,浮点数
float e=50.1f;//float要在数字后面加f
double f=3.1415926;
//字符
char name='国';
//字符串,String不是关键字,类
//String name="蜡笔小新";
//布尔值
boolean flag=true;
//boolean flag=false;
除了八大数据类型之外其余都是引用数据类型

//整数拓展: 进制  二进制0b   十进制   八进制0  十六进制0x
int i1=10;
int i2=010;//八进制0
int i3=0x10;//十六进制0x 0~9 A~F 16

System.out.println(i1);
System.out.println(i2);
System.out.println(i3);

public class Demo {
public static void main(String[]args){
String s1=new String("hello world!") ;
String s2=new String("hello world!") ;
System.out.println(s1==s2);//false
String s3=("hello world!") ;
String s4=("hello world!") ;
System.out.println(s3==s4);//true
}
}

类型转换

低-------------------------------------------------------高

byte,short,char,int,long,float,double


public class Demo {
    public static void main(String[] args) {
int i=12;
byte b=(byte) i;
//强制转换(类型)变量名 高到低
//自动转换 低到高
System.out.println(i);
System.out.println(b);
/*注意点1.不能对布尔值进行转换
2.不能把对象类型转换为不相干的类型
3.在把高转换到低叫强制转换
*/
 


posted @ 2021-08-23 16:50  小闫的姑娘  阅读(59)  评论(0编辑  收藏  举报