Java笔试题

  • 格式:docx
  • 大小:20.37 KB
  • 文档页数:9

1.12312.12rrr1.1.23124fff[polycom]用java输入输出流复制一个图片文件。

String file_in = “”;String file_out=””;RandomAccessFile rafIn = new RandomAccessFile(file_in,”r”);RandomAccessFile rafOut = new RandomAccessFile(file_out,”rw”);Byte[] b = new byte[13];Int count = -1;While((count=rafIn.read(b))!=-1){rafOut.write(b,0,count);}rafIn.close();rafOut.close();[intel]解释try{} catch(Exception e) {}的整个过程。

[lenovo]看程序写结果:int a = 5; int b = 10; int c = a+++b; 写出a, b, c。

[Thomson Reuters]解释什么是内部类。

[瞬联] 应聘的是高级开发,collection和collections有啥区别?A:Collections是个java.util下的类,它包含有各种有关集合操作的静态方法。

Collection是个java.util下的接口,它是各种集合结构的父接口。

[新锐国际] 垃圾回收的优点和原理。

并考虑2种回收机制。

A:Java语言中一个显著的特点就是引入了垃圾回收机制,使c++程序员最头疼的内存管理的问题迎刃而解,它使得Java程序员在编写程序的时候不再需要考虑内存管理。

由于有个垃圾回收机制,Java中的对象不再有“作用域”的概念,只有对象的引用才有“作用域”。

垃圾回收可以有效的防止内存泄露,有效的使用可以使用的内存。

垃圾回收器通常是作为一个单独的低级别的线程运行,不可预知的情况下对内存堆中已经死亡的或者长时间没有使用的对象进行清楚和回收,程序员不能实时的调用垃圾回收器对某个对象或所有对象进行垃圾回收。

回收机制有分代复制垃圾回收和标记垃圾回收,增量垃圾回收。

[极光互动]堆溢出与栈溢出危害的区别?(扩展:需要了解内存中什么是堆什么是栈) A:栈溢出是栈顶指针指向未知区域,可能造成系统崩溃,不仅仅指错数据而已。

[tsingsoft]Which of the following class definitions defines a legal abstract class? Select all right answers.A.class Animal { abstract void growl(); }B.abstract Animal {abstract void growl();}C.class abstract Animal {abstract void growl();}D.abstract class Animal {abstract void growl();} ^^^^^E.abstract class Animal {abstract void growl(){System.out.println("growl");}}[tsingsoft]What is the proper way of defining a class named Key so that it cannot besubclassed?A.class Key { }B.abstract final class Key { }C.native class Key { }D.class Key {final;}E.final class Key { }[tsingsoft]Given this class definitions:abstract class Transaction implements Runnable { }class Deposit extends Transaction {protected void process() {addAmount();}void undo(int i) {System.out.println("Undo");}private void addAmount(){}}What will happen if we attempted to compile the code? Select the one right answer:A.This code will not compile because the parameter i is not used in undo().B.This code will not compile because there is no main()method.C.This code will not compile because Deposit must be an abstract class. ^^^^^^^D.This code will not compile because Deposit is not declared public.E.Everything will compile fine.[tsingsoft]Given the following code:class Tester {public static void main(String[] args) {CellPhone cell = new CellPhone();cell.emergency();}}class Phone {final void dial911() {// code to dial 911 here . . .}}class CellPhone extends Phone {void emergency() {dial911();}}What will happen when you try to compile and run the Tester class?A.The code will not compile because Phone is not alsodeclared as final.B.The code will not compile because you cannot invoke afinal method from a subclass.C.The code will compile and run fine.D.The code will compile but will throw aNoSuchMethodException when Tester is run.E.Phone and CellPhone are fine, but Tester will not compilebecause it cannot create an instance of a class that derivesfrom a class defining a final method.[新媒传信] Vector和ArrayList是否是线程安全的?A:Vector是线程安全的,ArrayList不是。

[新媒传信] RecordStore对象在保存数据的时候跟普通的关系数据库有何区别(需要注意什么)?A:RecordStore的中的记录的RecordID是递增无重复的,即使一条记录被删除,它的RecordID 也不能被重复使用。

另外RecordStore需要显示地调用closeRecordStore方法来持久化更改过的数据。

[新媒传信] 请简述什么是“观察者模式”,它的意义是什么?可能的话举出JAVA类库中使用到这个模式的实例A:观察者模式又叫做发布-订阅(Publish/Subscribe)模式。

观察者模式定义了一种一对多地依赖模式,让多个观察者同时监听某一个主题对象。

这个主题对象在状态发生变化时,会通知所有的观察者对象,使它们能够自动更新自己。

这里的主题对象就是指通知者,又叫做发布者。

观察者又叫订阅者。

在JDK中继承java.util.Observable类可以实现观察者模式。

[新媒传信]下面这段代码从继承关系以及方法重载的角度来看,它可以通过编译么?如果可以,main()方法运行以后,屏幕输出是什么?如果不可以,请说明原因。

public class TestMain{public static void main(String[]args) {Child c = new Child();System.out.println(((Father)c).getName());}}abstract class Person{public String m_name = "God";public String getName() {return m_name;}}class Father extends Person{public String m_name = "Father";public String getName() {return super.m_name;}}class Child extends Father{public String getName() {return m_name;}}A:可以通过编译的,屏幕输出字符串"Father"[新媒传信]a)请说明synchronized关键字的作用以及使用范围。

b)请说明volatile关键字的作用以及使用范围。

c)请说明transient关键字的作用以及使用范围。

A:a)synchronized 关键字是同步关键字,它包括两种用法:synchronized 方法和synchronized 代码块。

b)volatile修饰的成员变量在每次被线程访问时,都强迫从共享内存中重读该成员变量的值。

而且,当成员变量发生变化时,强迫线程将变化值回写到共享内存。

这样在任何时刻,两个不同的线程总是看到某个成员变量的同一个值。

它只能用于修饰变量。

c)transient 关键字表示在该对象被序列化(持久化)的时候不保存该属性。

它只能用于修饰变量或者常量(即类属性)。

[HUAWEI]第一部分QUESTION NO: 11、public class Test {public static void changeStr(String str){str="welcome";}public static void main(String[] args) {String str="1234";changeStr(str);System.out.println(str);}}Please write the output result :QUESTION NO:21. public class Test {2. static boolean foo(char c) {3. System.out.print(c);4. return true;5. }6. public static void main( String[] argv ) {7. int i =0;8. for ( foo('A'); foo('B')&&(i<2); foo('C')){9. i++ ;10. foo('D');12. }13. }14. }What is the result?A. ABDCBDCBB. ABCDABCDC. Compilation fails.D. An exception is thrown at runtime.QUESTION NO: 31. class A {2. protected int method1(int a, int b) { return 0; }3. }Which two are valid in a class that extends class A? (Choose two)A. public int method1(int a, int b) { return 0; }B. private int method1(int a, int b) { return 0; }C. private int method1(int a, long b) { return 0; }D. public short method1(int a, int b) { return 0; }E. static protected int method1(int a, int b) { return 0; }QUESTION NO: 41. public class Outer{2. public void someOuterMethod() {3. // Line 34. }5. public class Inner{}6. public static void main( String[]argv ) {7. Outer o = new Outer();8. // Line 89. }10.}Which instantiates an instance of Inner?A. new Inner(); // At line 3B. new Inner(); // At line 8C. new o.Inner(); // At line 8D. new Outer.Inner(); // At line 8//new Outer().new Inner()QUESTION NO: 5Which method is used by a servlet to place its session ID in a URL that is written to the servlet’s response output stream?A. The encodeURL method of the HttpServletRequest interface.B. The encodeURL method of the HttpServletResponse interface.C. The rewriteURL method of the HttpServletRequest interface.D. The rewriteURL method of the HttpServletResponse interface.QUESTION NO: 6Which of the following statements regarding the lifecycle of a session bean are correct?ng.IllegalStateException is thrown if SessionContext.getEJBObject() is invokedwhen a stateful session bean instance is passivated.B.SessionContext.getRollbackOnly() does not throw an exception when a session beanwith bean-managed transaction demarcation is activated.C.An exception is not thrown when SessionContext.getUserTransaction() is called in theafterBegin method of a bean with container-managed transactions.D.JNDI access to java:comp/env is permitted in all the SessionSynchronization methods ofa stateful session bean with container-managed transaction demarcation.E.Accessing resource managers in the SessionSynchronization.afterBegin method of astateful session bean with bean-managed transaction does not throw an exception.QUESTION NO: 7 描述Struts体系结构?对应各个部分的开发工作主要包括哪些?QUESTION NO: 8 JSP有哪些内置对象和动作?它们的作用分别是什么?[阿里巴巴] 什么是Web Service?A:Web Service就是为了使原来各孤立的站点之间的信息能够相互通信、共享而提出的一种接口。