Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
CSDN 技术社区
skill_tree_java
提交
6c6261df
S
skill_tree_java
项目概览
CSDN 技术社区
/
skill_tree_java
通知
43
Star
8
Fork
4
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
4
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
skill_tree_java
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
4
Issue
4
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
6c6261df
编写于
11月 18, 2021
作者:
M
Mars Liu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
class, interface, io
上级
32959c54
变更
19
显示空白变更内容
内联
并排
Showing
19 changed file
with
438 addition
and
11 deletion
+438
-11
data/1.Java初阶/12.类和接口/1.类和面向对象/classic.json
data/1.Java初阶/12.类和接口/1.类和面向对象/classic.json
+8
-0
data/1.Java初阶/12.类和接口/1.类和面向对象/classic.md
data/1.Java初阶/12.类和接口/1.类和面向对象/classic.md
+75
-0
data/1.Java初阶/12.类和接口/1.类和面向对象/config.json
data/1.Java初阶/12.类和接口/1.类和面向对象/config.json
+3
-1
data/1.Java初阶/12.类和接口/2.抽象类/abstract.json
data/1.Java初阶/12.类和接口/2.抽象类/abstract.json
+7
-0
data/1.Java初阶/12.类和接口/2.抽象类/abstract.md
data/1.Java初阶/12.类和接口/2.抽象类/abstract.md
+26
-0
data/1.Java初阶/12.类和接口/2.抽象类/config.json
data/1.Java初阶/12.类和接口/2.抽象类/config.json
+2
-1
data/1.Java初阶/12.类和接口/3.接口/config.json
data/1.Java初阶/12.类和接口/3.接口/config.json
+4
-2
data/1.Java初阶/12.类和接口/3.接口/interface.json
data/1.Java初阶/12.类和接口/3.接口/interface.json
+8
-0
data/1.Java初阶/12.类和接口/3.接口/interface.md
data/1.Java初阶/12.类和接口/3.接口/interface.md
+73
-0
data/1.Java初阶/12.类和接口/4.匿名类/anonymous.json
data/1.Java初阶/12.类和接口/4.匿名类/anonymous.json
+8
-0
data/1.Java初阶/12.类和接口/4.匿名类/anonymous.md
data/1.Java初阶/12.类和接口/4.匿名类/anonymous.md
+42
-0
data/1.Java初阶/12.类和接口/4.匿名类/config.json
data/1.Java初阶/12.类和接口/4.匿名类/config.json
+6
-2
data/1.Java初阶/13.输入和输出/1.InputStream类型/config.json
data/1.Java初阶/13.输入和输出/1.InputStream类型/config.json
+2
-1
data/1.Java初阶/13.输入和输出/1.InputStream类型/unzip.json
data/1.Java初阶/13.输入和输出/1.InputStream类型/unzip.json
+8
-0
data/1.Java初阶/13.输入和输出/1.InputStream类型/unzip.md
data/1.Java初阶/13.输入和输出/1.InputStream类型/unzip.md
+64
-0
data/1.Java初阶/13.输入和输出/2.OutputStream类型/config.json
data/1.Java初阶/13.输入和输出/2.OutputStream类型/config.json
+2
-1
data/1.Java初阶/13.输入和输出/2.OutputStream类型/zip.json
data/1.Java初阶/13.输入和输出/2.OutputStream类型/zip.json
+8
-0
data/1.Java初阶/13.输入和输出/2.OutputStream类型/zip.md
data/1.Java初阶/13.输入和输出/2.OutputStream类型/zip.md
+77
-0
data/tree.json
data/tree.json
+15
-3
未找到文件。
data/1.Java初阶/12.类和接口/1.类和面向对象/classic.json
0 → 100644
浏览文件 @
6c6261df
{
"type"
:
"code_options"
,
"author"
:
"刘鑫"
,
"source"
:
"classic.md"
,
"notebook_enable"
:
true
,
"exercise_id"
:
"80d2fc513df3404288cdd3d487f50893"
}
\ No newline at end of file
data/1.Java初阶/12.类和接口/1.类和面向对象/classic.md
0 → 100644
浏览文件 @
6c6261df
# 类和类型
## aop
### template
```
java
public
class
Main
{
static
class
Human
{
String
label
;
public
String
getLabel
()
{
return
"Human"
;
}
}
static
class
Employee
extends
Human
{
public
String
getLabel
()
{
return
"$code"
;
}
}
public
static
void
main
(
String
[]
args
)
throws
IOException
{
Human
joe
=
new
Employee
();
System
.
out
.
println
(
joe
);
}
}
```
我们有两个类型:
```
java
class
Human
{
String
label
;
public
String
getLabel
()
{
return
"Human"
;
}
}
class
Employee
extends
Human
{
public
String
getLabel
()
{
return
"Employee"
;
}
}
```
现在我们有对象
```
java
Human
joe
=
new
Employe
(...)
```
调用
`joe.getLable()`
的时候,返回的是?
## 答案
Employee
## 选项
### A
Human
### B
HumanEmployee
### C
Main$Employee@7a81197d
### D
Main$Human@7a81197d
data/1.Java初阶/12.类和接口/1.类和面向对象/config.json
浏览文件 @
6c6261df
{
"keywords"
:
[],
"children"
:
[],
"node_id"
:
"java-461a08a44ae845018b7f0356ea928085"
"node_id"
:
"java-461a08a44ae845018b7f0356ea928085"
,
"export"
:
[
"classic.json"
]
}
\ No newline at end of file
data/1.Java初阶/12.类和接口/2.抽象类/abstract.json
0 → 100644
浏览文件 @
6c6261df
{
"type"
:
"code_options"
,
"author"
:
"刘鑫"
,
"source"
:
"abstract.md"
,
"notebook_enable"
:
false
}
\ No newline at end of file
data/1.Java初阶/12.类和接口/2.抽象类/abstract.md
0 → 100644
浏览文件 @
6c6261df
# 抽象类
关于抽象类和接口的区别,以下说法正确的是
## 答案
一个实现类型只能有一个抽象基类,但是可以有多个实现接口。
## 选项
### 抽象类才能定义构造方法
接口可以抽象构造行为
### 并发安全与接口或类无关
接口是线程安全的,抽象类不是
### 接口和类型都可以使用 instanceof 判别
可以用 instanceof 判断对象是否是某一个抽象类的实现,但是不能用来判断接口
### 接口和抽象类都支持泛型
抽象类可以是泛型类型,接口不能带有模板参数
\ No newline at end of file
data/1.Java初阶/12.类和接口/2.抽象类/config.json
浏览文件 @
6c6261df
{
"keywords"
:
[],
"keywords"
:
[
"面向对象"
,
"抽象类"
,
"接口"
],
"children"
:
[],
"node_id"
:
"java-a02b334b2e364161badae34636a0284f"
}
\ No newline at end of file
data/1.Java初阶/12.类和接口/3.接口/config.json
浏览文件 @
6c6261df
{
"keywords"
:
[],
"keywords"
:
[
"面向对象"
,
"类型"
,
"接口"
],
"children"
:
[],
"node_id"
:
"java-5d28bfbed25f4ae2b4d21fc1f2222e49"
"node_id"
:
"java-5d28bfbed25f4ae2b4d21fc1f2222e49"
,
"export"
:[
"interface.json"
]
}
\ No newline at end of file
data/1.Java初阶/12.类和接口/3.接口/interface.json
0 → 100644
浏览文件 @
6c6261df
{
"type"
:
"code_options"
,
"author"
:
"刘鑫"
,
"source"
:
"interface.md"
,
"notebook_enable"
:
false
,
"exercise_id"
:
"462fc2e521564aa2b358cbcffb964db9"
}
\ No newline at end of file
data/1.Java初阶/12.类和接口/3.接口/interface.md
0 → 100644
浏览文件 @
6c6261df
# 接口
关于接口,错误的选项是
## 答案
```
java
public
interface
Named
{
Named
(
String
value
);
String
literal
();
}
```
## 选项
### interface 可以有 default 实现
```
java
public
interface
Parsec
{
Try
<
String
>
parse
(
State
<
String
>
state
);
default
T
ask
(
State
<
String
>
state
)
{
var
result
=
parse
(
state
);
if
(
result
.
isSuccess
()){
return
result
.
get
();
}
else
{
throw
result
.
err
();
}
}
}
```
### interface 可以有类型参数
```
java
public
interface
Parsec
<
E
,
T
>{
Try
<
T
>
parse
(
State
<
E
>
state
);
default
T
ask
(
State
<
E
>
state
)
{
var
result
=
ask
(
state
);
if
(
result
.
isSuccess
()){
return
result
.
get
();
}
else
{
throw
result
.
err
();
}
}
}
```
### interface 可以实现
```
java
public
class
One
implements
Parsec
<
String
,
String
>{
default
T
parse
(
State
<
String
>
state
)
{
return
state
.
next
();
}
}
```
### SAM
```
java
public
interface
Parsec
<
E
,
T
>
{
public
Parsec
<
E
,
T
>
then
(
Parsec
<
E
,
T
>
psc
)
{
return
state
->
{
this
.
parse
(
state
);
return
psc
.
parse
(
state
)
}
}
}
```
\ No newline at end of file
data/1.Java初阶/12.类和接口/4.匿名类/anonymous.json
0 → 100644
浏览文件 @
6c6261df
{
"type"
:
"code_options"
,
"author"
:
"刘鑫"
,
"source"
:
"anonymous.md"
,
"notebook_enable"
:
false
,
"exercise_id"
:
"31ea397861004b0e9df6d767380093ef"
}
\ No newline at end of file
data/1.Java初阶/12.类和接口/4.匿名类/anonymous.md
0 → 100644
浏览文件 @
6c6261df
# 匿名类
以下代码
```
java
public
class
App
{
public
Parsec
<
Character
,
String
>
text
(
String
txt
){
return
state
->
{
if
(
String
.
equals
(
state
.
read
(
txt
.
legth
),
txt
)){
return
new
Success
(
txt
);
}
else
{
return
new
NotMatch
(
state
);
}
}
}
}
```
返回的类型是:
## 答案
实现了 Parsec 接口的匿名类型。
## 选项
### A
`App`
类型
### B
`String`
类型
### C
`Parsec`
接口类型
### D
`Function<Charactor, String>`
类型
data/1.Java初阶/12.类和接口/4.匿名类/config.json
浏览文件 @
6c6261df
{
"keywords"
:
[],
"keywords"
:
[
"面向对象"
,
"匿名类"
,
"lambda"
],
"children"
:
[],
"node_id"
:
"java-b06b5b2c7a6b44cc87744168729b31e6"
"node_id"
:
"java-b06b5b2c7a6b44cc87744168729b31e6"
,
"export"
:[
"anonymous.json"
]
}
\ No newline at end of file
data/1.Java初阶/13.输入和输出/1.InputStream类型/config.json
浏览文件 @
6c6261df
...
...
@@ -2,6 +2,6 @@
"node_id"
:
"java-fc2dfe1a80f64143b4ad339378ba61da"
,
"keywords"
:
[],
"children"
:
[],
"export"
:
[],
"export"
:
[
"unzip.json"
],
"title"
:
"InputStream类型"
}
\ No newline at end of file
data/1.Java初阶/13.输入和输出/1.InputStream类型/unzip.json
0 → 100644
浏览文件 @
6c6261df
{
"type"
:
"code_options"
,
"author"
:
"刘鑫"
,
"source"
:
"unzip.md"
,
"notebook_enable"
:
false
,
"exercise_id"
:
"cc0ec19a231d4e6e940755474c7a5b47"
}
\ No newline at end of file
data/1.Java初阶/13.输入和输出/1.InputStream类型/unzip.md
0 → 100644
浏览文件 @
6c6261df
# 解压流
已知 GZIPInputStream 是 Java 标准库中用于从 gzip 格式文件读取信息的类型,那么从一个gzip文件读取信息并解压的正确实现应该是:
## 答案
```
java
String
fileZip
=
"path_to_file.zip"
;
File
destDir
=
new
File
(
"path_to_dest"
);
byte
[]
buffer
=
new
byte
[
1024
];
try
(
ZipInputStream
zis
=
new
ZipInputStream
(
new
FileInputStream
(
fileZip
)))
{
ZipEntry
zipEntry
=
zis
.
getNextEntry
();
while
(
zipEntry
!=
null
)
{
// ...
}
zis
.
closeEntry
();
}
```
## 选项
### 没有关闭资源
```
java
String
fileZip
=
"path_to_file.zip"
;
File
destDir
=
new
File
(
"path_to_dest"
);
byte
[]
buffer
=
new
byte
[
1024
];
ZipInputStream
zis
=
new
ZipInputStream
(
new
FileInputStream
(
fileZip
))
ZipEntry
zipEntry
=
zis
.
getNextEntry
();
while
(
zipEntry
!=
null
)
{
// ...
}
```
### zip 流需要接到字节输入流上工作
```
java
String
fileZip
=
"path_to_file.zip"
;
File
destDir
=
new
File
(
"path_to_dest"
);
byte
[]
buffer
=
new
byte
[
1024
];
try
(
ZipInputStream
zis
=
new
ZipInputStream
(
fileZip
))
{
ZipEntry
zipEntry
=
zis
.
getNextEntry
();
while
(
zipEntry
!=
null
)
{
// ...
}
zis
.
closeEntry
();
}
```
### 缓冲区需要分配空间
```
java
String
fileZip
=
"path_to_file.zip"
;
File
destDir
=
new
File
(
"path_to_dest"
);
byte
[]
buffer
=
null
;
try
(
ZipInputStream
zis
=
new
ZipInputStream
(
new
FileInputStream
(
fileZip
)))
{
ZipEntry
zipEntry
=
zis
.
getNextEntry
();
while
(
zipEntry
!=
null
)
{
// ...
}
zis
.
closeEntry
();
}
```
\ No newline at end of file
data/1.Java初阶/13.输入和输出/2.OutputStream类型/config.json
浏览文件 @
6c6261df
...
...
@@ -2,6 +2,6 @@
"node_id"
:
"java-cc8c2e511db54a2ca2ee798f2cdbd03b"
,
"keywords"
:
[],
"children"
:
[],
"export"
:
[],
"export"
:
[
"zip.json"
],
"title"
:
"OutputStream类型"
}
\ No newline at end of file
data/1.Java初阶/13.输入和输出/2.OutputStream类型/zip.json
0 → 100644
浏览文件 @
6c6261df
{
"type"
:
"code_options"
,
"author"
:
"刘鑫"
,
"source"
:
"zip.md"
,
"notebook_enable"
:
false
,
"exercise_id"
:
"3f6e7226750b4af5b13ee2cfbb0034fb"
}
\ No newline at end of file
data/1.Java初阶/13.输入和输出/2.OutputStream类型/zip.md
0 → 100644
浏览文件 @
6c6261df
# 压缩流
已知 ZipOutputStream 是 Java 标准库的压缩输出流,那么下列哪个选项可以正确的将指定文件压缩为zip文件?
## 答案
```
java
String
sourceFile
=
"path_to_source"
;
File
fileToZip
=
new
File
(
sourceFile
);
try
(
FileOutputStream
fos
=
new
FileOutputStream
(
"path_to_zip"
);
FileInputStream
fis
=
new
FileInputStream
(
fileToZip
);
ZipOutputStream
zipOut
=
new
ZipOutputStream
(
fos
);)
{
ZipEntry
zipEntry
=
new
ZipEntry
(
fileToZip
.
getName
());
zipOut
.
putNextEntry
(
zipEntry
);
byte
[]
bytes
=
new
byte
[
1024
];
int
length
;
while
((
length
=
fis
.
read
(
bytes
))
>=
0
)
{
zipOut
.
write
(
bytes
,
0
,
length
);
}
}
```
## 选项
### 没有关闭资源
```
java
String
sourceFile
=
"path_to_source"
;
File
fileToZip
=
new
File
(
sourceFile
);
FileOutputStream
fos
=
new
FileOutputStream
(
"path_to_zip"
);
FileInputStream
fis
=
new
FileInputStream
(
fileToZip
);
ZipOutputStream
zipOut
=
new
ZipOutputStream
(
fos
);
ZipEntry
zipEntry
=
new
ZipEntry
(
fileToZip
.
getName
());
zipOut
.
putNextEntry
(
zipEntry
);
byte
[]
bytes
=
new
byte
[
1024
];
int
length
;
while
((
length
=
fis
.
read
(
bytes
))
>=
0
)
{
zipOut
.
write
(
bytes
,
0
,
length
);
}
```
### ZipOutputStream 不能直接读写文件,需要接入其它字节流
```
java
String
sourceFile
=
"path_to_source"
;
File
fileToZip
=
new
File
(
sourceFile
);
try
(
FileInputStream
fis
=
new
FileInputStream
(
fileToZip
);
ZipOutputStream
zipOut
=
new
ZipOutputStream
(
"path_to_zip"
);)
{
ZipEntry
zipEntry
=
new
ZipEntry
(
fileToZip
.
getName
());
zipOut
.
putNextEntry
(
zipEntry
);
byte
[]
bytes
=
new
byte
[
1024
];
int
length
;
while
((
length
=
fis
.
read
(
bytes
))
>=
0
)
{
zipOut
.
write
(
bytes
,
0
,
length
);
}
}
```
### 缓冲区需要初始化
```
java
String
sourceFile
=
"path_to_source"
;
File
fileToZip
=
new
File
(
sourceFile
);
try
(
FileOutputStream
fos
=
new
FileOutputStream
(
"path_to_zip"
);
FileInputStream
fis
=
new
FileInputStream
(
fileToZip
);
ZipOutputStream
zipOut
=
new
ZipOutputStream
(
fos
);)
{
ZipEntry
zipEntry
=
new
ZipEntry
(
fileToZip
.
getName
());
zipOut
.
putNextEntry
(
zipEntry
);
byte
[]
bytes
=
null
;
int
length
;
while
((
length
=
fis
.
read
(
bytes
))
>=
0
)
{
zipOut
.
write
(
bytes
,
0
,
length
);
}
}
```
\ No newline at end of file
data/tree.json
浏览文件 @
6c6261df
...
...
@@ -1803,21 +1803,33 @@
{
"抽象类"
:
{
"node_id"
:
"java-a02b334b2e364161badae34636a0284f"
,
"keywords"
:
[],
"keywords"
:
[
"面向对象"
,
"抽象类"
,
"接口"
],
"children"
:
[]
}
},
{
"接口"
:
{
"node_id"
:
"java-5d28bfbed25f4ae2b4d21fc1f2222e49"
,
"keywords"
:
[],
"keywords"
:
[
"面向对象"
,
"类型"
,
"接口"
],
"children"
:
[]
}
},
{
"匿名类"
:
{
"node_id"
:
"java-b06b5b2c7a6b44cc87744168729b31e6"
,
"keywords"
:
[],
"keywords"
:
[
"面向对象"
,
"匿名类"
,
"lambda"
],
"children"
:
[]
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录