英文北京东方国信JAVA面试.doc_第1页
英文北京东方国信JAVA面试.doc_第2页
英文北京东方国信JAVA面试.doc_第3页
英文北京东方国信JAVA面试.doc_第4页
英文北京东方国信JAVA面试.doc_第5页
已阅读5页,还剩15页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

Part (每题1分)1) Which of the following lines will compile without warning or error? Select all valid answers. a ea) float f=0; b) char c=0; c) byte b=157; d) boolean f=null; e) int i=10; 2) What are the valid types for the given variable i ? cpublic class Baseprivate void test() / i = 1;switch (i) static public void main(String a) new Base().test(); Select most appropriate answer.a) char, int b) boolean, byte, char, short, intc) byte, char, short, intd) byte, char, short, int, long e) Only int3) What is the correct way of declarating main() so that the progarm can be compiled and executed using this entry point. abcfa) static public void main(String args)b) static public void main(String a)c) public static void main(String a)d) static void public main(String a)e) public void main(String a)f) static public void main(char arg)4) What will be output if the program is executed as belowjava -DOne -DTwo -DThree Sample public class Sample public static void main(String argv) System.out.println(argv2) Select most appropriate answer. ba) One b) Two c) Three d) Exception raised: java.lang.ArrayIndexOutOfBoundsException: 2 e) NonePart (每题1分)5) Abstract method cannot be static. True or False ? truea) Trueb) False6) What will be the output when you compile and execute the following program. d/class Basevoid test() System.out.println(Base.test();/public class Child extends Base void test() System.out.println(Child.test();static public void main(String a) Child anObj = new Child();Base baseObj = (Base)anObj;/Base b=new Child();/b.test();baseObj.test(); Select most appropriate answer.a) Child.test()Base.test() b) Base.test() Child.test()c) Base.test() d) Child.test()7) What will be the output when you compile and execute the following program. C /class Basestatic void test() System.out.println(Base.test();/public class Child extends Base void test() System.out.println(Child.test();Base.test(); /Call the parent methodstatic public void main(String a) new Child().test(); Select most appropriate answer.a) Child.test()Base.test() b) Child.test() Child.test()c) Compilation error. Cannot override a static method by an instance methodd) Runtime error. Cannot override a static method by an instance method8) What will be the output when you compile and execute the following program. Exception is the base class for all the Exception classes./import java.io.*;class Basevoid test() throws IOException System.out.println(Base.test();String a = null;/Complex logic goes hereif(a = null)throw new IOException();/public class Child extends Base protected void test() throws Exception System.out.println(Child.test();throw new Exception();static public void main(String a) try new Child().test();catch(Exception e) Select most appropriate answer. ba) Child.test()Base.test() b) Compilation Error: The method void test() declared in class Child cannot override the method of the same signature declared in class Base. Their throws clauses are incompatible.c) Compilation Error: The method void test() declared in class Child cannot override the method of the same signature declared in class Base. The access modifier is made more restrictive.d) Runtime error. Cannot make the access modifier more restrictive for test() Part (每题1分)9) What will be the output when you compile and execute the following program. bpublic class Baseprivate void test() System.out.println(6 + 6 + (Result); static public void main(String a) new Base().test(); Select most appropriate answer.a) 66(Result)b) 12(Result)c) Runtime Error.Incompatible type for +. Cant convert an int to a string.d) Compilation Error.Incompatible type for +. Cant add a string to an int.10) What will be the output when you compile and execute the following program. The symbol means space. e 1:public class Base2:3: private void test() 4: 5: String aStr = One;6: String bStr = aStr;7: aStr.toUpperCase();8: aStr.trim();9: System.out.println( + aStr + , + bStr + );7: 8: 9: static public void main(String a) 10: new Base().test();11: 12: Select most appropriate answer.a) ONE,One b) One,One c) ONE,One d) ONE,ONE e) One,One 11) What will be the output when you compile and execute the following program. dpublic class Base void test() String aStr = OneString;System.out.println(aStr.substring(3,7); static public void main(String a) new Base().test(); Select most appropriate answer.a) Strinb) Stringc) trind) Stri12) What can contain objects that have a unique key field of String type, if it is required to retrieve the objects using that key field as an index? aa) Map b) Set c) List d) Collection e) EnumerationPart (每题1分)13) At what point are the objects i2, i3 and i4 available for garbage collection.01:public class Base 02:Base i;03:public static void main(String args) 04:Base i2 = new Base();05:Base i3 = new Base();06:Base i4 = new Base();07:08:i2.i = i3; / i2 refers to i309:i3.i = i4; / i3 refers to i410:i4.i = i2; / i4 refers to i211:12:i2 = null;13:i3 = null;14:i4 = null;15:/ do complicated, memory intensive stuff16:17:Select most appropriate answer da) After line 6b) After line 9c) After line 10d) After line 14e) After line 16System.gc()Runtime.getRuntime().gc()Java的垃圾回收机制是Java虚拟机提供的能力,用于在空闲时间以不定时的方式动态回收无任何引用的对象占据的内存空间。 14) A try statement must always associate with a fa) catch b) None of thesec) throwsd) throw e) finally f) catch, finally or both15) Which of the following are correct way of throwing an exception inside a method?Select all valid answers ba) new throw Exception()b) throw new Exception()c) throws IOException()d) throws IOExceptione) catch(Exception e) 16) The method test() throws MalformedURLException and EOFException. IOException is the parent class of MalformedURLException and EOFException. What changes will make the following code to compile without any errors. import java.io.*;import .*;public class Baseprivate void test() String a = null; String b = b; / Complex processing if(a=null)throw new MalformedURLException(test);if(b =null)throw new EOFException(test);/ Complex processing Select all valid answers a da) private void test() throws IOExceptionb) private void test() throws EOFException, throws MalformedURLExceptionc) private void test() throws EOFException throws MalformedURLExceptiond) private void test() throws EOFException, MalformedURLExceptione) private void test() throws EOFException MalformedURLExceptionPart (每题1分)17) Which class or interface defines the wait(), notify(), and notifyAll() methods? a a) Objectb) Threadc) Runnabled) Class18) Given the following,1. class MyThread extends Thread 2.3. public static void main(String args) 4. MyThread t = new MyThread();5. t.run();6. 7.8. public void run() 9. for(int i=1;i3;+i) 10. System.out.print(i + .);11. 12. 13. what is the result? ca) This code will not compile due to line 4.b) This code will not compile due to line 5.c) 1.2.d) 1.2.3.e) An exception is thrown at runtime.19) Given the following,class MyThread extends Thread MyThread() System.out.print( MyThread);public void run() System.out.print( bar);public void run(String s) System.out.println( baz);public class TestThreads public static void main (String args) Thread t = new MyThread() public void run() System.out.println( foo);t.start();what is the result? ba) foob) MyThread fooc) MyThread bard) foo bare) foo bar bazf) bar foog) Compilation fails.20) Given the following,1. public class Test 2. public static void main (String args) 3. final Foo f = new Foo();4. Thread t = new Thread(new Runnable() 5. public void run() 6. f.doStuff();7. 8. );9. Thread g = new Thread() 10. public void run() 11. f.doStuff();12. 13. ;14. t.start();15. g.start();16. 17. 1. class Foo 2. int x = 5;3. public void doStuff() 4. if (x = 10) 12. notify();13. 14. 15. 16. what is the result? ba) The code will not compile because of an error on line 12 of class Foo.b) The code will not compile because of an error on line 7 of class Foo.c) The code will not compile because of an error on line 4 of class Test.d) The code will not compile because of some other error in class Test.e) An exception occurs at runtime.f) x is 5x is 6问答题Java基础(总分10分)1) 请简要描述HashMap和Hashtable的区别。(3分)1. 线程安全 2. nullHashMap 是Hashtable 的轻量级实现(非线程安全的实现),他们都完成了Map 接口,主要区别在于HashMap 允许空(null)键值(key),由于非线程安全,效率上可能高于Hashtable。HashMap 允许将null 作为一个entry 的key 或者value,而Hashtable 不允许。HashMap 把Hashtable 的contains 方法去掉了,改成containsvalue 和containsKey。因为contains方法容易让人引起误解。Hashtable 继承自Dictionary 类,而HashMap 是Java1.2 引进的Map interface 的一个实现。最大的不同是,Hashtable 的方法是Synchronize 的,而HashMap 不是,在多个线程访问Hashtable 时,不需要自己为它的方法实现同步,而HashMap 就必须为之提供外同步。Hashtable 和HashMap 采用的hash/rehash 算法都大概一样,所以性能不会有很大的差异2) 请简要描述Overload和Override的区别,并说明Overloaded的方法是否可以改变返回值的类型?(4分) 方法的重写Overriding和重载Overloading是Java多态性的不同表现。重写Overriding是父类与子类之间多态性的一种表现,重载Overloading是一个类中多态性的一种表现。如果在子类中定义某方法与其父类有相同的名称和参数,我们说该方法被重写 (Overriding)。子类的对象使用这个方法时,将调用子类中的定义,对它而言,父类中的定义如同被“屏蔽”了。如果在一个类中定义了多个同名的方法,它们或有不同的参数个数或有不同的参数类型,则称为方法的重载(Overloading)。Overloaded的方法是可以改变返回值的类型。3) 谈谈final, finally, finalize的用法。(3分)final修饰符(关键字)如果一个类被声明为final,意味着它不能再派生出新的子类,不能作为父类被继承。因此一个类不能既被声明为 abstract的,又被声明为final的。将变量或方法声明为final,可以保证它们在使用中不被改变。被声明为final的变量必须在声明时给定初值,而在以后的引用中只能读取,不可修改。被声明为final的方法也同样只能使用,不能重载。finally再异常处理时提供 finally 块来执行任何清除操作。如果抛出一个异常,那么相匹配的 catch 子句就会执行,然后控制就会进入 finally 块(如果有的话)。 finalize方法名。Java 技术允许使用 finalize() 方法在垃圾收集器将对象从内存中清除出去之前做必要的清理工作。这个方法是由垃圾收集器在确定这个对象没有被引用时对这个对象调用的。它是在 Object 类中定义的,因此所有的类都继承了它。子类覆盖 finalize() 方法以整理系统资源或者执行其他清理工作。finalize() 方法是在垃圾收集器删除对象之前对这个对象调用的。J2EE(总分20分)4) 请说明JSP中动态INCLUDE与静态INCLUDE的区别。(2分)动态INCLUDE用jsp:include动作实现它总是会检查所含文件中的变化,适合用于包含动态页面,并且可以带参数 静态INCLUDE用include实现,不会检查所含文件的变化,适用于包含静态页面 5) 请说明JSP中forward和redirect的区别。(2分)Forward: 1.可传参2. 地址栏不变 3. 不可到外部站点Redirect: 1. 不可传参 2. 地址栏变 3. 可到外部站点 6) 请对以下JSP内置对象作简单描述。(3分)l HttpServletRequest类的request对象 l HttpServletResponse类的respone对象 l JspWriter类的out对象 l HttpSession类的session对象 l ServletContex类的application对象 l ServletConfig类的config对象 7) 请描述一下Servlet的生命周期和Servlet的运行机制。(4分)实例化: 构造方法初始化: init()服务: service()-doGet()/doPost()销毁: destroy()8) 请描述hibernate的作用是什么?po、vo的含义?(3分)Hibernate: ORM映射框架 object-relationship mappingVO(value object) 值对象 通常用于业务层之间的数据传递,和PO一样也是仅仅包含数据而已。但应是抽象出的业务对象,可以和表对应,也可以不,这根据业务的需要. PO(persistant object) 持久对象 在o/r映射的时候出现的概念,如果没有o/r映射,没有这个概念存在了。通常对应数据模型(数据库),本身还有部分业务逻辑的处理。可以看成是与数据库中的表相映射的java对象。最简单的PO就是对应数据库中某个表中的一条记录,多个记录可以用PO的集合。PO中应该不包含任何对数据库的操作。9) 请简述你对设计模式的理解,并实现一个简单的singleton或observer(可以使用伪码)。(6分)设计模式:一套被反复使用、多数人知晓的、经过分类编目的、代码设计经验的总结Singleton模式:第一种实现: public class Singleton private Singleton()private static Singleton instance = new Singleton();public static Singleton getInstance() return instance; 第二种实现: 懒 public class Singleton private static Singleton instance = null;public static synchronized Singleton getInstance() if (instance=null)instancenew Singleton();return instance; Observer模式:import java.util.Iterator;import java.util.Vector;interface Observed public void addObserver(Observer o);public void removeObserver(Observer o);public void update();interface Observer public void takeAction();class Invoker private Observer o;Handler handler;public Invoker(Observer o) new Handler();this.o = o;private class Handler extends Thread public Handler() handler = this;public void run() o.takeAction();public boolean TestSameObserver(Observer o) return o = this.o;public void invoke() handler.start();class ObservedObject implements Observed private Vector observerList = new Vector();public void addObserver(Observer o) observerList.add(new Invoker(o);public void removeObserver(Observer o) Iterator it = observerList.iterator();while (it.hasNext() Invoker i = it.next();if (i.TestSameObserver(o) observerList.remove(i);break;public void update() for (Invoker i : observerList) i.invoke();class ObserverA implements Observer public void takeAction() System.out.println(I am Observer A ,state changed ,so i have to do something);class ObserverB implements Observer public void takeAction() System.out.println(I am Observer B ,i was told to do something);class ObserverC implements Observer public void takeAction() System.out.println(I am Observer C ,I just look ,and do nothing);public class Test2 public static void main(String args) ObserverA a = new ObserverA();ObserverB b = new ObserverB();ObserverC c = new ObserverC();ObservedObject oo = new ObservedObject();oo.addObserver(a);oo.addObserver(b);oo.addObserver(c);for (int i = 0; i 5; +i) oo.addObserver(new Observer() public void takeAction() System.out.println(我是观察者););/ sometime oo changed ,so it calls update and informs all observeroo.update();数据库(总分10分)10) delete和truncate有什么区别?什么是左连接、右连接、全连接?(4分)1。delete from后面可以写条件,truncate不可以2。delete from记录是一条条删的,所删除的每行记录都会进日志,而truncate一次性删掉整个页,因此日至里面只记录页释放,简言之,delete from更新日志,truncate基本不,所用的事务日志空间较少3。delete from删空表后,会保留一个空的页,truncate在表中不会留有任何页4。当使用行锁执行 DELETE 语句时,将锁定表中各行以便删除。truncate始终锁定表和页,而不是锁定各行。5。如果有identity产生的自增id列,delete from后仍然从上次的数开始增加,即种子不变,而truncate后,种子会恢复初始6。truncate不会触发delete的触发器,因为truncate操作不记录各个行删除11) 请根据以下四张表(其中course_t表的teacher_id字段是teacher_t表的id字段的外键引用),拼写出相应的sql语句(oracle语法)。(6分)学生表:students_tidnamesex001赵学生Male002钱学生Male003孙学生Male004李学生Female005周学生Female教师表:teacher_tidnamesex001吴老师Male002郑老师Male003王老师Male004刘老师Female005张老师Female课程表:course_tidnamecreditteacher_id001语文3001002数学3002003英语4003004物理3004005化学2005006政治1001007生物1005008计算机2005选课表:student_course_tidstudent_idcourse_id0010010010020010020030010030040020010050020071) 统计每个学生选修的学分,并按学分降序排序2) 统计每个学生选修的所有课程和对应的任课老师;并按学生Id和课程Id排序3) 统计所有学生、所有课程和所有任课老师的对应关系;并按学生Id和课程Id排序高级Java(仅适用高级工程师)(总分20分)1) 系统如何对待处于停滞状态的线程?请列举出常用的线程进入停滞状态的几种方式,以及相应的走出停滞状态的方式或条件?(6分)一个线程创建之后,总是处于其生命周期的4个状态之一中。线程的状态表明此线 程当前正在进行的活动,而线程的状态是可以通过程序来进行控制的,就是说,可以对线程 进行操作来改变状态。这些操作包括启动(start)、终止(stop)、睡眠(sleep)、挂起 (suspend)、恢复(resume)、等待(wait)和通知(notify)。每一个操作都对应了一个方法,这些 方法是由软件包java.lang提供的。 创建(new)状态 如果创建了一个线程而没有启动它,那么,此线程就处于创建状态。比如,下述语句执行 以后,使系统有了一个处于创建状态的线程myThread: Thread myThread= new MyThreadClass(); 其中,MyThreadClass()是Thread的子类,而Thread是由Java系统的java.lang软件包提 供的。 处于创建状态的线程还没有获得应有的资源,所以,这是一个空的线程。线程只有通过 启动后,系统才会为它分配资源。对处于创建状态的线程可以进行两种操作:一是启动 (start)操作,使其进入可运行状态,二是终止(stop)操作,使其进入消亡状态。如果进入到消 亡状态,那么,此后这个线程就不能进入其他状态,也就是说,它不再存在了。 start方法是对应启动操作的方法,其具体功能是为线程分配必要的系统资源;将线程 设置为可运行状态,从而可以使系统调度这个线程。 可运行(runnable)状态 如果对一个处于创建状态的线程进行启动操作,则此线程便进入可运行状态。仍以前面 创建的myThread线程为例,用下列语句: myThread.start(); 则线程myThread进入可运行状态。上述语句实质上是调用了线程体即run()方法。注意, run()方法包含在myThread线程中,也就是先由java.lang包的Thread类将run()方法 传递给子类MyThreadClass(),再通过创建线程由于类MyThreadClass()传递给线程 myThread。 线程处于可运行状态只说明它具备了运行条件,但可运行状态并不一定是运行状态。因 为在单处理器系统中运行多线程程序,实际上在一个时间点只有一个线程在运行,而系统中 往往有多个线程同时处于可运行状态。系统通过快速切换和调度使所有可运行线程共享处 理器,造成宏观上的多线程并发运行。 可见,一个线程是否处于运行状态,除了必须处于可运行状态外,还取决于系统的调度。 在可运行状态可以进行多种操作,最通常的是从run()方法正常退出而使线程结束,进 入消亡状态。此外,还可以有如下操作: 挂起操作,通过调用suspend方法来实现; 睡眠操作,通过调用sleep方法来实现; 等待操作,通过调用wait方法来实现; 退让操作,通过调用yield方法来实现; 终止操作,通过调用stop方法来实现。 前面三种操作都会使一个处于可运行状态的线程进入不可运行状态。比如,仍以 myThread线程

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论