1)Java 类型
1.简单类型
byte 1字节 char 2字节 short 2字节
int 4字节 long 8字节 boolen(没有大小true/flase)
*都在函数栈上存储*
2.引用类型 类类型
String
数组类型
2)字节 编码问题
1.使用unicode编码: 一个字符用一个字节来存储,主要是为了表示能
用一个字节表示的语言,age:中文(c中用ASCII来编码)
2.Java中只有有符号
3.强转时必须写强转类型 :
char ch='9';
int a=(int)ch;
System.out.println(a +":"+ch);
57:9
4.使用变量时必须初始化
3)类:ADT被翻译在计算机上
实体——->抽象类型数据——>属性/行为——实例化>对象
普通的成员方法,和对象相关的,调用这些方法要用对象
有些方法和对象不相关,所以实现成 static 方法
4) JAVA的内存模型
1.在函数栈上存放: a=10;
引用类型的地址(类似C中的指针)p:0x100
简单类型 a:10
*函数定义开始,函数运行结束释放*
2.堆: person p=new person();
对象
*new 开始,GC(垃圾回收器)线程释放*
3.常量池
5)equal & intern() 比较引用类型地址所保存的内容
String str1=new String=new String("hello");
String str2=new String=new String("hello");
str1!=str2 因为str1和str2保存的是对象的地址
str.equal(str2)==true 直接比较内容
str1.intern==str2.intern 把对象在常量池中的常量返回
6)遍历数组的简单方式:
for(String s:argc){
System.out.ptintln(s);
}
7)带标号的break
8)final(相当c语言的 const)
String str1="hello";
String str2=str1+"world";
String str3="helloworld";
str2!=str3
原因:str1相当于一个变量,在程序编译阶段才会链接在一起变 成helloworld,所以其实是world与helloword在比较,如果在str1前加final,相当于str1是一个常量,在编译阶段str2就变为helloworld
9)装包和拆包
1.简单类型–>包装类型 装包
int data=10;
integer value=data;=>value=integer.valueof(data);
2.包装类型—>简单类型 拆包
integer short long -128~127
byte float double 无缓存
Integer int6=120;
Integer int7=120;
if(int6==int7){
System.out. println("int6=int7");
}else{
System.out. println("int6!=int7");
}
Integer int8=220;
Integer int9=220;
if(int8==int9){
System.out. println("int8=int9");
}else{
System.out. println("int8!=int9");
输出结果
int1!=str2
int2!=int3
int4!=int5
int6=int7
int8!=int9
10).如何查看进程中类的大小
1.运行程序,设置断点让程序停住,
2.在cmd中进到filename.java的路径下使用ips查看进程号
3.jmap -histo:live 进程号 > d:\sun.txt (将正在运行的进程的信息输出到指定路径下的 .txt文件)