1、基本类型
| 类型 | 字节数 | 范围 |
|---|---|---|
| byte | 1 | -128 ~ 127 |
| short | 2 | -32768 ~32767 |
| int | 4 | −231 ~ 231−1 |
| long | 8 | |
| float | 4 | |
| double | 8 | |
| boolean | 1 | |
| char | 2 |
注意: short、char、byte 参与运算时直接抬升到 int 型。
思考题:
- 0 是整数还是负数?
- 字节数 - 128 在内存中的存储形态是如何的?
- 字节范围为何是从 - 128 到 127 之间,而不是 - 127 到正的 128?
2、位运算
| 运算符 | 说明 | ||
|---|---|---|---|
| & | 与 | ||
| 或 | |||
| ^ | 异或 | ||
| ~ | 取反 | ||
| << | 左移 | ||
| >> | 右移 | ||
| >>> | 无符号右移动 |
3、补码
正数的取反 + 1。
4、&& 和 & 区别
&& 存在短路,& 无短路操作,& 通过位运算完成。
5、字符集
| 字符集 | 表示字节数 | |
|---|---|---|
| asc | 1 个字节的 7 位 | |
| gb2312 | 2 字节 | |
| gbk | 2 字节 | |
| big5 | 5 个字节 | |
| iso8859-1 | 1 个字节 8 位 | |
| utf-8 | 中文 3 个字节 | |
| unicode | 2 个字节,含有两个字节的头 |
任何字符集都是 asc 的超集。
6、练习
- 找出自己的名字对应的 unicode
- 定义函数,取出整数内存中的存储形态对应的 16 进制字符串
- 定义函数,取出整数内存中的存储形态对应的 2 进制字符串
- java 中 unicode 字符的全量输出
7、UML
Unified Modeling Language,同一建模语言,使用图形化元素描述事物以及之间的关系。
8、Rose
rose 是 UML 建模软件中的一种,IBM 公司开发,业界使用比较普遍。Rose 的安装步骤如下:
- 管理员运行 setup.exe 文件
- 指定安装目录,不要使用中文和空格
- 装后导入 license 文件
- 解决启动 rose 出现缺少 dll 文件问题
4.1) 进入 rose 安装目录的 Common 目录下
4.2) 复制 suite objects.dll + license.dll 文件到 C:\Windows\System32\和 C:\Windows\SysWOW64\下 - 启动 Rose
- OK
9、OOP
面向对象编程的特征:
- 封装
- 继承
- 多态
10、IO
10.1 IO 划分
输入输出流,操纵文件的读写过程。java 的流架构图如下:

IO 类型的划分为:
- 数据类型
- 字节流
InputStream / OutputStream - 字符流
Reader / Writer
- 字节流
- 方向
- 输入流
InputStream / Reader - 输出流
OutputStream / Writer
- 输入流
- 功能
- 缓冲区流
BufferedInputStream / BufferedReader / BufferedOutputStream / BufferedWriter - 转换流
InputStreamReader
- 缓冲区流
10.2 内存流
@Testpublic void writeByteArrayOutputStream() throws Exception {ByteArrayOutputStream baos = new ByteArrayOutputStream() ;baos.write("abc".getBytes("unicode"));byte[] bytes = baos.toByteArray();baos.close();System.out.println(bytes.length);}
10.3 压缩流
@Testpublic void testZip() throws Exception {FileOutputStream fos = new FileOutputStream("d:\\java\\xxx.zip") ;ZipOutputStream zos = new ZipOutputStream(fos) ;byte[] buf = new byte[1024] ;int len = -1 ;File dir = new File("d:\\java\\zip") ;File[] files = dir.listFiles();for(File f : files){if(f.isFile()){String fname = f.getName() ;FileInputStream fin = new FileInputStream(f) ;zos.putNextEntry(new ZipEntry(fname));while((len = fin.read(buf)) != -1){zos.write(buf , 0 , len);}fin.close();}}zos.close();fos.close();}@Testpublic void testUnzip() throws Exception {FileInputStream fin = new FileInputStream("d:\\java\\xxx.zip") ;ZipInputStream zis = new ZipInputStream(fin) ;byte[] buf = new byte[1024] ;int len = 0 ;ZipEntry entry ;String ouputDir = "d:\\java\\zip\\out" ;while((entry = zis.getNextEntry()) != null){String fname = entry.getName() ;File f = new File(ouputDir , fname) ;FileOutputStream fos = new FileOutputStream(f) ;while((len = zis.read(buf)) != -1){fos.write(buf , 0 , len);}fos.close();}zis.close();}
10.4 对象流
@Testpublic void testSerial() throws Exception {Person p = new Person("");p.setId(15);p.setName("tomas");p.setAge(22);FileOutputStream fos = new FileOutputStream("d:\\java\\p.dat") ;ObjectOutputStream oos = new ObjectOutputStream(fos) ;oos.writeObject(p);oos.close();fos.close();}@Testpublic void testDeserial() throws Exception {FileInputStream fis = new FileInputStream("d:\\java\\ppp.dat") ;ObjectInputStream ois = new ObjectInputStream(fis) ;Person p = (Person) ois.readObject();ois.close();fis.close();System.out.println(p.getName());System.out.println(p.isMarried());}
11、设计模式
12、作业
- 把 long 数据转换成字节数组
- 把字节数组数据转换成 long
- 有 5 亿整数 (非负),去重计算不同整数的个数,300M 内存
- 通过程序创建文本文件,内容是 abc,采用 uncode 码,文件大小是 10 字节
- 将 byte 变换成无符号的整数 (0 ~ 255 , 正数不变)
https://www.cnblogs.com/xupccc/p/9594153.html
https://www.cnblogs.com/xupccc/p/9594153.html
