应聘Java笔试时可能出现问题及其答案(二)
文章作者 100test 发表时间 2011:03:26 20:48:30
来源 100Test.Com百考试题网
9、介绍JAVA中的Collection FrameWork(包括如何写自己的数据结构)?
答:Collection FrameWork如下:
Collection
├List
│├LinkedList
│├ArrayList
│└Vector
│ └Stack
└Set
Map
├Hashtable
├HashMap
└WeakHashMap
Collection是最基本的集合接口,一个Collection代表一组Object,即Collection的元素(Elements)
Map提供key到value的映射
10、Java中异常处理机制,事件机制?
11、JAVA中的多形与继承?
12、抽象类与接口?
答:抽象类与接口都用于抽象,但是抽象类(JAVA中)可以有自己的部分实现,而接口则完全是一个标识(同时有多重继承的功能)。
13、Java 的通信编程,编程题(或问答),用JAVA SOCKET编程,读服务器几个字符,再写入本地显示?
答:Server端程序:
package test.
import java.net.*.
import java.io.*.
public class Server
{
private ServerSocket ss.
private Socket socket.
private BufferedReader in.
private PrintWriter out.
public Server()
{
try
{
ss=new ServerSocket(10000).
while(true)
{
socket = ss.accept().
String RemoteIP = socket.getInetAddress().getHostAddress().
String RemotePort = ":" socket.getLocalPort().
System.out.println("A client come in!IP:" RemoteIP RemotePort).
in = new BufferedReader(new InputStreamReader(socket.getInputStream())).
String line = in.readLine().
System.out.println("Cleint send is :" line).
out = new PrintWriter(socket.getOutputStream(),true).
out.println("Your Message Received!").
out.close().
in.close().
socket.close().
}
}
catch (IOException e)
{
out.println("wrong").
}
}
public static void main(String[] args)
{
new Server().
}
}.
Client端程序:
package test.
import java.io.*.
import java.net.*.
public class Client
{
Socket socket.
BufferedReader in.
PrintWriter out.
public Client()
{
try
{
System.out.println("Try to Connect to 127.0.0.1:10000").