JS:
how to implement "inherited" in JS?
what is the "closure" in JS, and what is the intention for this ?
CSS:
Just mentioned it, don't have question on this.
Project:
where is the servlet been initiated?
Servlet的生命周期是由servlet的容器来控制的。分为3个阶段:初始化阶段、运行阶段、销毁阶段。
初始化阶段:
初始化阶段步骤:
Ø
Ø
Ø
Ø
通过初始化步骤,创建了servlet对象和servletConfig对象,并且servlet对象与servletConfig对象关联,而servletConfig对象又与当前对象的servletContext对象关联。当servlet容器完成servlet后,servlet对象只要通过getServletContext()方法就能得到web应用的servletContext对象。
注:servlet初始化的情况:
(1)当web应用处于运行阶段时,特定的servlet被客户端首次请求访问。
(2)在web.xml文件中为servlet设置了<load-on-startup>元素
<servlet>
<servlet-name>servlet1</servlet-name>
<servlet-class>servlet.servlet1</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
说明:
在servlet的配置当中,<load-on-startup>5</load-on-startup>的含义是:
标记容器是否在启动的时候就加载这个servlet。
当值为0或者大于0时,表示容器在应用启动时就加载这个servlet;
当是一个负数时或者没有指定时,则指示容器在该servlet被选择时才加载。
正数的值越小,启动该servlet的优先级越高。
(3)
运行阶段
在这个阶段sevlet可以随时响应客户端的请求。当servlet容器接到访问特定的servlet请求时,servlet容器会创建针对与这个请求的servletRequest和servletResponse对象,然后调用service()方法,并把这两个对象当做参数传递给service()方法。Service()方法通过servletRequest对象获得请求信息,并处理该请求,再通过servletResponse对象生成响应结果。
【不管是post还是get方法提交,都会在service中处理,然后,由service来交由相应的doPost或doGet方法处理,如果你重写了service方法,就不会再处理doPost或doGet了,如果重写sevice()方法,可以自己转向doPost()或doGet()方法】
注:当servlet容器把servlet生成的响应结果发送给客户后,servlet容器会销毁servletRequest和sevletResponse对象。
销毁阶段
当Web应用被终止时,servlet容器会先调用web应用中所有的servlet对象的destroy()方法,然后在销毁servlet对象。此外容器还会销毁与servlet对象关联的servletConfig对象。
在destroy()方法的实现中,可以释放servlet所占用的资源。如关闭文件输入输出流,关闭与数据库的连接。
注:sevlet的生命周期中,servlet的初始化和销毁只会发生一次,因此init()和destroy()方法只能被servlet容器调用一次,儿service()方法取决与servlet被客户端访问的次数。
write the SingleTon which is used in your project. how to keep thread safe in this singleTon?
if there is a variable which is defined by "Private" , and there is a public funtion use this variable, how to keep it thread safe in your singleTon?
Java Knowledge:
What is the difference between ArrayList and LinkList? how to implement Arraylist /LinkList inside? 【计算复杂度】when insert 1 element into ArrayList
What is the HashMap ? what is inside of HashMap? Is that ordered or disordered ?
What is the HashSet? What is inside of HashSet? Is that ordered or disordered?
please give your solution on how to sort List<person> ? class person{this.age=age; this.name = name}
【write the Bubble sort and explain the principle 】
1.How to sort objects in List?
please see my code as below:
public static void main(String[] args) {
// TODO Auto-generated method stub
List list = new ArrayList();
Person person1 = new Person();
person1.setAge(10);
person1.setName("Lucy");
Person person2 = new Person();
person2.setAge(20);
person2.setName("Lily");
Person person3 = new Person();
person3.setAge(8);
person3.setName("Lilei");
list.add(person1);
list.add(person2);
list.add(person3);
for (int i=0;i<list.size();i++){
Person p_temp=(Person)list.get(i);
System.out.println(p_temp.getAge()+","+p_temp.getName());
}
ComparatorPerson cp = new ComparatorPerson();
Collections.sort(list,cp);
for (int i=0;i<list.size();i++){
Person p_temp=(Person)list.get(i);
System.out.println(p_temp.getAge()+","+p_temp.getName());
}
}
public class ComparatorPerson implements Comparator{
@Override
public int compare(Object o1, Object o2) {
// TODO Auto-generated method stub
Person p1=(Person)o1;
Person p2=(Person)o2;
int flag=p1.getAge().compareTo(p2.getAge());
if(flag==0){
return p1.getName().compareTo(p2.getName());
}else{
return flag;
}
}
}
public class Person {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
private Integer age;
public Person(String name,Integer age) {
this.name=name;
this.age=age;
// TODO Auto-generated constructor stub
}
public Person(){}
}
DataBase:
if there are there query conditions , e.g. select * from xxx where a=A and b=B and c=C , how to create index for these three columns to optimize the performance?