tydk

      

深圳天源迪科信息技术股份有限公司 

 

 


技术人员(JAVA类)面试第一轮试题 

 

前言:谢谢您信任我们深圳天源迪科信息技术股份有限公司! 我们以严肃的态度、真诚的热情希望您能成为我们公司的员工。希望您能耐心、诚信地完成我们如下的试题。祝您成功。

姓名:           李海凤          

 

联系电话:          15022151250                             

 

面试时间:                          

 

一、选择题:(每题1.5分,计1.5*10=15分)

1、class Comp {

 public staticvoid main(String[] args) {

 float f1 = 2.3f;

 float[][] f2 ={{42.0f}, {1.7f, 2.3f}, {2.6f,2.7f}};

 float[] f3 = {2.7f};

 Long x = 42L;

 // 在此处插入代码(分别是F1、F2、F3、F4、F5代码段)

 System.out.println("true");

}

 }

代码段:

F1. if(f1 == f2) 编译错误

F2. if(f1 == f2[2][1]) 无

F3. if(x == f2[0][0]) ture

F4. if(f1 == f2[1,1]) 编译错误

F5. if(f3 == f2[2]) 无

分别运行程序,最终汇总结果是(D )?

A. 一次编译通过, 一次返回true.      B. 二次编译通过,一次返回true.

C. 三次编译通过, 二次返回true.      D. 三次编译通过, 一次返回true.

2、执行以下代码,程序输出的结果是( A)

  public classStrUtil {

         publicstatic void substr(String str) {

                   str.substring(5);

         }

         publicstatic void main(String[] args) {

                   Strings = "this is my test";

                   StrUtil.substr(s);

                   System.out.println(s);

         }

}

A.this is my test;      B.is mytest       C.s is my test     D. my test;

3、哪个选项编译有误(C )?

int a = 3;

A.a = a/2;       B.a = a/3;       C.a = a/2.3;      D.全部编译通过

4、启动一个线程,类MyRunnable已经实现了java.lang.Runnable接口:

MyRunnable  myRunnable= new MyRunnable();

以下哪个语句可用于启动MyRunnable任务线程:( D )

A.myRunnable.run();        B.Threadthread = new Thread(myRunnable); thread.run();

C.myRunnable.start();       D.Threadthread = new Thread(myRunnable); thread.start();

5、Which collection class(es) allows you togrow or shrink its size and provides indexed access to

its elements, but whose methods are not synchronized?( ab  )

A.java.util.HashSet        B.java.util.LinkedHashSet

C.java.util.List            D.java.util.ArrayList

6、public class TwoThreads {

static Thread laurel, hardy;

public static void main(String[] args) {

laurel = new Thread() {

public void run() {

System.out.println("A");

try {

hardy.sleep(1000);

} catch (Exception e) {

System.out.println("B");

}

System.out.println("C");

}

};

hardy = new Thread() {

public void run() {

System.out.println("D");

try {

laurel.wait();

} catch (Exception e) {

System.out.println("E");

}

System.out.println("F");

}

};

laurel.start();

hardy.start();

}

}

请问哪几个字母将被输出?(D  )ADEFC

A.A,C,D,F        B.D,E,F       C.A,C,D        D.A,C,D,E,F

7、class Emu {

static String s = "-";

public static void main(String[] args) {

try {

throw new Exception();

} catch (Exception e) {

try {

try { throw new Exception();

} catch (Exception ex) { s += "ic "; }

throw new Exception(); }

catch (Exception x) { s += "mc "; }

finally { s += "mf "; }

} finally { s += "of "; }

System.out.println(s);

} }

正确的返回结果是(c)?

A.-mc mf       B.-ic mf of      C.-ic mc mf of        D.-ic mc ofmf

8、编译并运行下面代码,结果为(   a) ?

public class MyTest {

         publicvoid finalize()throws Throwable

         {

                   System.out.println("Testfinalize");

         }

         publicstatic void main(String[] args) {

                   MyTesttest = new MyTest();

                   test.finalize();

                   test= null ;

                   Runtimer = Runtime.getRuntime();

                   r.gc();

                   r.runFinalization();

         }

}

A.代码无法编译,因为调用finalize方法有问题;

B.代码通过编译,但不显示任何东西;

C.代码通过编译,只会显示一次Test finalize;

D.代码通过编译,而且会显示二次Test finalize。

9、在同样的情况下(注:文件小于2M)分别运行以下代码,哪一个性能最高,速度最好?(  )

A、import java.io.*;

    public classintro1 {

    publicstatic void main(String args[]) {

      if(args.length != 1) {

       System.err.println("missing filename");

       System.exit(1);

      }

      try {

       FileInputStream fis =

            newFileInputStream(args[0]);

        int cnt= 0;

        int b;

        while((b = fis.read()) != -1) {

          if (b== '\n')

           cnt++;

        }

       fis.close();

       System.out.println(cnt);

      }

      catch(IOException e) {

       System.err.println(e);

      }

    }

  }

B、import java.io.*;

   public classintro2 {

   public staticvoid main(String args[]) {

    if(args.length != 1) {

     System.err.println("missing filename");

     System.exit(1);

    }

    try {

     FileInputStream fis =

          newFileInputStream(args[0]);

     BufferedInputStream bis =

          newBufferedInputStream(fis);

      int cnt =0;

      int b;

      while ((b= bis.read()) != -1) {

        if (b =='\n')

          cnt++;

        }

     bis.close();

     System.out.println(cnt);

    }

    catch(IOException e) {

     System.err.println(e);

    }

  }

 }

C、import java.io.*;

    public classintro3 {

    publicstatic void main(String args[]) {

      if(args.length != 1) {

       System.err.println("missing filename");

        System.exit(1);

      }

      try {

       FileInputStream fis =

            newFileInputStream(args[0]);

        bytebuf[] = new byte[2048];

        int cnt= 0;

        int n;

        while((n = fis.read(buf)) != -1) {

          for(int i = 0; i < n; i++) {

            if(buf[i] == '\n')

             cnt++;

          }

        }

       fis.close();

       System.out.println(cnt);

      }

      catch(IOException e) {

       System.err.println(e);

      }

    }

  }

A.A最快      B.B最快       C.C最快         D.都一样

10、实例化一个类有哪几种方法?( )

a.new Xxx();

b.clone();

c.反序列化

d.反射机质的newInstance()方法。比如Class.forName(“”).newInstance();

A.a,b,c,d        B.a,b,c        C.a,b        D.a,b,d

二、简答题

1.form中的input有哪些类型(4分)

2.javascript里该代码<html><bodyoncontextmenu="return false"></body></html>的含义是什么(4分)

3.抽象类和接口的区别?(8分)

4.多线程有几种实现方法,都是什么?同步有几种实现方法,都是什么?(5分)

5.JSP中动态INCLUDE与静态INCLUDE的写法以及它们最大的区别是什么(8分)

6.try{}里有一个return语句,那么紧跟在这个try后的finally {}里的code会不会被执行,什么时候被执行,在return前还是后? (8分)

7.客户请求访问HTML页面与访问Servlet有什么异同。(8分)


最佳答案

访问html是服务器不做处理,只是收到请求之后,将html传输给你的浏览器,浏览器进行解析,你和服务器没有进行交互的。

servlet是服务器端运行的java代码,你提交的东西到了服务器端,可以进行处理,然后返回给你的浏览器

8.描述Struts的工作原理或者工作流程。(10分)

服务器启动后,根据web.xml加载ActionServlet读取struts-config.xml文件内容到内存。
  以登陆为例:第一次进login.jsp会先实例化Form、把默认值赋给表单元素。
  输入用户名密码提交表单、提交到action属性的login.do,通过ActionServlet读struts-config.xml文件找到 action下的path属性找到.do,通过name属性找form-beans中的form-bean的name属性得到ActionForm的包名类名,先实例化form,把表单的值填充给form,调用form的validate方法验证、ActionErrors返回null表示验证通过,否则失败返回input指定的页面.验证通过会实例化Action,执行Action的excute方法。

9.使用spring框架,如何在JSP里获取BO对象,请简要写出相应的配制代码和获取代码。(10分)

<%
WebApplicationContext context = (WebApplicationContext)application.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);

context.getBean("bean id");

%>

10.XML里如何注释某行,请写出注释代码。(5分)

11.oracle中如何让纵表打成横表(8分)

例如: select name,type,charge from tt

       ----------------

       name      type     charge

       费用        PHS       1000

       费用       ADSL      3000

       费用       XDSL      5000

 打成横表:

       -----------------

       name      PHS    ADSL    XDSL

       费用       1000    3000   5000

请写出sql:

select  a.name,

           sum(case when a.type='PHS' thena.charge else 0 end) PHS,

           sum(case when a.type='ADSL' thena.charge else 0 end) ADSL,

           sum(case when a.type='XDSL' thena.charge else 0 end) XDSL          

fromtt a

groupby a.name

12.描述一下数据库事务的属性及其含义。(7分)

事务时访问数据库的一个操作序列,数据库应用系统通过事务集来完成对数据库的存取。事务的正确执行使得数据库从一种状态转换成另一种状态。事务的性质有如下几个:

1.原子性。即不可分割性,事务要么全部被执行,要么就全部不被执行。如果事务的所有子事务全部提交成功,则所有的数据库操作被提交,数据库状态发生转换;如果有子事务失败,则其他子事务的数据库操作被回滚,即数据库回到事务执行前的状态,不会发生状态转换。

2.一致性或可串性。事务的执行使得数据库从一种正确状态转换成另一种正确状态。

3.隔离性。在事务正确提交之前,不允许把该事务对数据的任何改变提供给任何其他事务,即在事务正确提交之前,它可能的结果不应显示给任何其他事务。

4.持久性。事务正确提交后,其结果将永久保存在数据库中,即使在事务提交后有了其他故障,事务的处理结果也会得到保存。

13.花果山有一百个孙悟空,真悟空说真话,假悟空说假话。

第一只悟空说:“这一百个悟空里,有一个是假的。”

第二只悟空说:“一百个悟空里,有两个是假的。”

以此类推,第一百个悟空说,有一百个是假的。

问:有几个真悟空,分别是第几个?请描述你的推理方法?(加分题 10)

、第50只是真悟空

原文地址:https://www.cnblogs.com/yangy608/p/1774079.html