JAVA复习题

写在前面:未标明正确答案是存在争议部分,欢迎各位小伙伴指正

Socket连接指定服务,构造方法通常需要( C )参数
A 域名,IP地址
B 协议,IP地址
C IP地址,端口号
D 协议,端口号
正确答案:C

可以Socket的连接探测目标主机端口的开放状态,通常的写法( D )
A Socket s = new Socket(host,port);

B Socket s = new Socket();
SocketAddress sa = new SocketAddress(host, port);
s.connect(sa, 5000)

C Runtime.getRuntime().exec(“telnet host port”)

D Socket s = new Socket(host, port)
if(s.isReachable())
正确答案:D

以下( AB )是Socket类的方法
A getInputStream
B getOutputStream
C shutdownInput
D shutdownOutput
参考资料:https://www.runoob.com/java/java-networking.html
正确答案:AB

SocketServer类的作用( ABCD )
A 与客户端的Socket对象进行通信
B 监听指定端口,等待客户端Socket对象的连接请求
C 获得服务器端通信输入流
D 获得服务器端通信输出流
正确答案:ABCD

有如下代码
Socket s = new Socket(host, port)
InputStream is = s.getInputStream()
is.read()
如果is.read()返回为-1表示(D)
A 没有收到对端数据
B 连接异常
C 没有可用字节
D 对端发送了一段长度为0的数据

关于ServerSocketChannel正确的是(BCD)
A 它是ServerSocket的子类
B 它通过ServerScoketChannel.open()创建实例对象
C 可以通过configureBlocking(true)设置为非阻塞模式
D 可以通过register(SelectorKey.OP_ACCEPT)方法监听握手事件

SelectionKey中定义的事件有( ABCD )
A SelectionKey.OP_ACCEPT
B SelectionKey.OP_CONNECT
C SelectionKey.OP_READ
D SelectionKey.OP_WRITE
参考资料:https://www.cnblogs.com/liuxiuhao/p/5785027.html
正确答案:ABCD

java.nio包提供了支持非阻塞通信的类包括( AB )
A ServerSocketChannel
B SocketChannel
C Selector
D SelectionKey
正确答案:AB

serverSocketChannel监听某端口port的语句为(B)
A serverSocketChannel.socket().bind(new InetSocketAddress(port));
B serverSocketChannel.socket().bind(port);
C serverSocketChannel.socket(port);
D serverSocketChannel(port);
参考资料:https://www.jianshu.com/p/e41bd8b2f6f2
正确答案:B

关于Vector类正确的是(ABCD)
A 属于java.util包
B 实现一个动态数组
C 支持同步访问
D new Vector()默认的大小是10
参考资料:https://www.runoob.com/java/java-vector-class.html
正确答案:ABCD

原文地址:https://www.cnblogs.com/ryyy/p/14228097.html