微薄C语言招聘笔试题
7.ArrayList和Vector的区别,HashMap和Hashtable的区别?
答:就ArrayList与Vector主要从二方面来说.
一.同步性:Vector是线程安全的,也就是说是同步的,而ArrayList是线程序不安全的,不是同步的
二.数据增长:当需要增长时,Vector默认增长为原来一培,而ArrayList却是原来的一半
就HashMap与HashTable主要从三方面来说。
一.历史原因:Hashtable是基于陈旧的Dictionary类的,HashMap是Java 1.2引进的Map接口的一个实现
二.同步性:Hashtable是线程安全的,也就是说是同步的,而HashMap是线程序不安全的,不是同步的
三.值:只有HashMap可以让你将空值作为一个表的条目的key或value
8.简述一下MVC模式的工作原理。
三、程序题:
1.写一个Servlet 输出HelloWorld,并写出在web.xml中的配置。
参考答案:
public class HelloServlet extends HttpServlet{
public void doGet(HttpServletRequest request, HttpServletResponse response){
PrintWriter pw = response.getWriter();
pw.println("HelloWorld");
pw.close();
}
public void doPost(HttpServletRequest request, HttpServletResponse response){
doGet(request,response);
}
}
2.写出MVC2的中央控制器核心代码。
参考答案:
String path = request.getRequestURI();
int start = path.lastIndexOf(“/”) + 1;
int end = path.lastIndexOf(“.”);
String pathName = path.subString(start,end);
ActionConfig config = (ActionConfig)MVCConfig.getConfig().getMap().get(pathName);
Action action = (Action)Class.forName(config.getPath()).newInstance();
String forward = action.execute(request,response);
if(config.getRedirect().qualsIgnoreCase(“true”)){
response.sendRedirect(forward);
}else{
RequestDispatcher rd = request.getRequestDispatcher(forward);
rd.forward(request,response);
}
二分法:
int search(DataType t) {
02
int l,u,m;
03
l = 0;
04
u = n -1 ;
05
while (l <= u) {
06
m = (l + u) /2 ;
07
if (x[m] < t) {
08
l = m + 1;
09
} else if(x[m] == t) {
10
return m;
11
} else {
12
u = m - 1;
13
}
14
}
15
return -1 ;
16
}