java
强类型语言(java,c++)
变量的使用严格符合规定,所有变量先定义再使用.
弱类型语言(js,vb)
数据类型
基本数据类型
byte(1个字节):-128~127
short(2个字节):-32768~32767
int(4个字节):-2147483648 ~ 2147483647
long(8个字节):-9223372036854774808 ~ 9223372036854774807
float(4个字节)
double(8个字节)
char(2个字节)
boolean(1个位)
引用数据类型(类,接口,数组)
浮点数拓展
public class hello {
public static void main(String[] args) {
float f1 = 0.1f;
float f2 = 1.0f/10;
System.out.println(f1 == f2);
System.out.println(f1);
System.out.println(f2);
float f3 = 1000000000f;
float f4 = f3 + 1;
System.out.println(f3 == f4);
System.out.println(f3);
System.out.println(f4);
//应该尽量避免使用浮点数数据类型进行比较。
}
}
浮点数有限,会进行舍入
字符串拓展(内存池)
public class hello {
public static void main(String[] args) {
String s1 = new String("hello world");
String s2 = new String("hello world");
System.out.println(s1 == s2);
System.out.println("--------------------------------");
String s3 = "hello world";
String s4 = "hello world";
System.out.println(s3 == s4);
}
}
上面的结果是flase
下面的是true