面试3

InterviewQuestions

(30 minutes)

Notes: Pleaseanswer the questions in English

Name:                                     Date:

1.     Choices(10 * 5 pts):

1)     Afterbelow codes, what’s the value of k? (Answers: A)

Int k = 0;

int x = 20;

int y = 30;

k = (x > y)? y: x;

A.    20    B.  30    C. 0   D: 10

 

2)     Amethod is defined in a class as (Multiple Choices) : (Answers: C,D)

void processUser(int i) { }

If this method is overridden in a sub class,_

A.    thenew method should return int

B.    thenew method can return any type of values

C.   theargument list of new method should exactly match that of overridden method

D.   thereturn type of new method should exactly match that of overridden method

 

3)     Whichis wrong in using session(Multiple Choices) (Answers: A,B,C)?

A.    HttpSessionsession = new HttpSession();

B.    Stringhaha = session.getParameter(“Test”);

C.   session.removeAttribute(“haha”);

D.   session.setAttribute(“haha”);

 

4)     Whichclass below could be extended by the other object class?(Multiple Choices) (Answers: A,B)

A.    java.lang.Thread

B.    java.lang.ClassLoader

C.   java.lang.Class

D.   java.lang.Math

 

5)     Pleaserefer to below codes. HelloAction wants to forward the request to hello.jsp, sohow to implement the excute method in HelloAction. (Answer: B)

<action  path     = "/HelloWorld"

          type      = "hello.HelloAction"

          name      = "HelloForm"

          scope     = "request"

          validate  = "true"

          input     = "/hello.jsp"  >

   <forward name="SayHello"path="/hello.jsp" />

</action>

A.    return(new ActionForward());

B.    return(mapping.findForward("SayHello"));

C.   return(mapping.findForward(“hello.jsp"));

D.   return(mapping.findForward(“hello"));

6)     What’sthe results of Math.round(11.5) and Math.round(-11.5), Math.round(11.2),Math.round(-11.3),Math.round(-11.6) (Answer: A)

A.    12,-11,11,-11,-12     B.  11, -12              C.12,-12               D. 11, -11

 

7)     Given: (Answer: A)

class C {

publicstatic void main(String[] args) {

int i1=1;

switch(i1){

case1:

System.out.println("one");

case2:

System.out.println("two");

case3:

System.out.println("three");

}

}

}

What is the result of attempting to compileand run the program?

A.    printsone two three

B.    printsone

C.   compilestime error

D.   Runtimeexception

E.    Noneof the above

 

8)     Given: (Answers: D)

1.public class Foo {

2.public static void main (String args) {

3.StringBuffer a = new StringBuffer (“A”);

4.StringBuffer b = new StringBuffer (“B”);

5.operate (a,b);

6.system.out.printIn(a + “,” +b);

7.)

8.static void operate (StringBuffer x, StringBuffer y) {

9.x.append (y);

10.y = x;

11.)

12.}

Whatis the result?

A.    Thecode compiles and prints “A,B”.

B.    Thecode compiles and prints “A,A”.

C.   Thecode compiles and prints “B,B”.

D.   Thecode compiles and prints “AB,B”.

E.    Thecode compiles and prints “AB,AB”.

F.    Thecode does not compile because “+” cannot be overloaded for StringBuffer.

 

9)     Considerthe following codes please:(Answers: C,D,E)

Integer s = new Integer (9);

Integer t = new Integer (9);

Long u = new Long (9);

So which of the below will be true? (Multiplechoices)

A. (s==u)      B.(s==t)     C. (s.equals(t))     D.(s.equals(9))     E. (s.equals(new Integer(9))

10)   Given: (Answers: B)

publicclass Example{

  Stringstr=new String("good");

  char[]ch={'a','b','c'};

  publicstatic void main(String args[]){

    Exampleex=new Example();

    ex.change(ex.str,ex.ch);

    System.out.print(ex.str+"and ");

    Sytem.out.print(ex.ch);

  }

  publicvoid change(String str,char ch[]){

    str="testok";

    ch[0]='g';

  }

}

       Which result is correct?

A.    goodand abc

B.    goodand gbc

C.   testok and abc

D.   testok and gbc

 

 

2.     Questions: (50 pts)

1)     Please list the eight primitive Java types. Such asint…(8 pts)

Answer: The eight primitive types are byte, char, short, int, long,float, double, and Boolean

 

 

 

 

2)     Whatis the difference between checked and Unchecked Exceptions in Java(8 pts)

Answer: All predefined exceptions in Java are either a checked exceptionor an unchecked exception. Checked exceptions must be caught using try ..catch() block or we should throw the exception using throws clause. If you don’t,compilation of program will fail

 

 

 

 

 

3)     What'sthe difference between an interface and an abstract class? (8 pts)

Answer: An abstract class may contain code in method bodies, whichis not allowed in an interface. With abstract classes, you have to inherit yourclass from it and Java does not allow multiple inheritances. On the other hand,you can implement multiple interfaces in your class

 

 

 

 

 

 

4)     Whatis the life cycle of a servlet? (8 pts)

Answer: Each Servlet has the same life cycle: a) A server loads andinitializes the servlet by init () method. b) The servlet handles zero or moreclient’s requests through service() method. c) The server removes the servletthrough destroy() method.

5)     Pleaselist the basic steps of one query operation with JDBC (8 pts)

1.  Load the driver

2.  Define the Connection URLUsername and Password

3.  Establish the Connection

4.  Create a Statement object

5.  Execute a query

6.  Process the results

7.  Close the connection

 

6)     What is a singleton? And please give us a sample ofsingleton(10 pts)

Answer: A singletonis an object that cannot be instantiated. The restriction on the singleton isthat there can be only one instance of a singleton created by the Java VirtualMachine (JVM) - by preventing direct instantiation we can ensure that developersdon't create a second instance.

public classClassicSingleton {

   private static ClassicSingleton instance =null;

   protected ClassicSingleton() {

      // Exists only to defeat instantiation.

   }

   public static synchronized ClassicSingletongetInstance() {

      if(instance == null) {

         instance = new ClassicSingleton();

      }

      return instance;

   }

}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值