• 一些java笔试题解


    1) Which of the following techniques can a Java SE programmer use to increase the thread
    safety of a program?
    a. Use public static variables
    b. Write classes so they are immutable
    c. Use ThreadLocal variables
    d. Use Final classes
    e. Annotate a class with @Multithread
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    这题考的是java线程安全的理解。

    只有有状态的对象才会有线程安全问题

    通常解决线程安全的方法有两个

    1. 加锁顺序访问关键资源(牺牲时间)
    2. 每个线程单独一个资源副本(牺牲空间)

    其中b的意思将类写为不可变的,就是没状态的,从根本上解决问题。(例如spring的service , dao 等无状态 beans)
    c是第2种解决方案。

    a 是制造线程安全隐患
    d.只是令到类不能被继承
    e. 我没见过@Mutithread 这注解

    答案: bc



    2) Under which of the following conditions will an alert message be displayed for the Java
    script code given below
    <form name=”frm”>
    <label for=äge”> Please enter your birthday</label>
    <input type =”text” name=äge” id=äge” onblur=validate(this.value)<input type=”submit”id=Ënter”/></form>
    <script language =”javascript”>
    functionvalidate(val)
    {
    if (isNaN(val)
    {
    alert(“XXX XXX XXX”);
    document.frm.age.focus();
    }
    }
    </script>
    a. If the text box age contains a numerical value and the submit button Submit is
    clicked
    b. If textbox age loses focus and contains a non-numerical value
    c. If textbox age contains a non-numerical value and gains focus
    d. If textbox age contains a non-numerical value and the submit button Enter is clicked
    e. If textbox age loses focus and contains a numerical value
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22

    这题问的是那种情况下会有alert message 弹出
    考的是基本J2EE 知识

    考点1, onblur事件, 可以理解为失去元素focus的事件, 一般用于验证用于在元素上的输入
    考点2, isNaN() 判断是否为numeric的函数。NaN -> Not a number, 所以isNaN对数字类的参数返回值是False

    答案:b



    3) A Java EE servlet uses the line of code below:
    String targetEmailForRequest = getServletConfig().getInitParameter(“corporateEmail”);
    From which of the following locations will the application read the corporateEmail
    value?
    a. An attribute corporateEmailasteriin the request
    b. A <servlet-mapping> element in web.xml
    c. A corporateEmail entity in properties.xml
    d. An <init-param> element in web.xml
    e. A corporateEmail item in the session
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    这题厉害了, 考的是servlet的知识。。
    问题是上的面的代码是从哪里读取 corporateEmail 的值。

    既然是getInitParameter
    从答案都猜得出是d
    答案:d



    4) Which of the following statements correctly describe lightweight and heavyweight Java
    Swing components?
    a. Lightweight components are faster in response and performance
    b.  JWindow, JFrame , JDialog and JApplet  are lightweight components
    c. Heavyweight components provide a consistent look and feel on all platforms
    d. Heavyweight components depend on native code counterparts to handle their
    functionality
    e. AWT components are heavyweight, whereas Swing components are lightweight
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    一般的swing组件都是从awt组件继承的,swing是轻量组件没有本地peer跟他对应
    而awt是重量组件,每个组件都有一个本地peer.这就是为什么swing组件在大多数系统上显示都差不多而awt就反之了。

    AWT是通过调用操作系统的native方法实现的,所以在Windows系统上的AWT窗口就是Windows的风格,而在Unix系统上的则是XWindow风格。
    Swing是所谓的Lightweight组件,不是通过native方法来实现的,所以Swing的窗口风格更多样化。但是,Swing里面也有heaveyweight组件。比如JWindow,Dialog,JFrame

    a. 是正确的。
    b. 他们是heavyweight的
    c. 错误, 参考上面的黄色highlight解析
    d.正确
    e.正确

    答案:ade



    5) Which of the following can be returned in the variable result from invoking the below
    Java SE code
     java.util.Random r = new java.util.Random();
    int result = r.nextInt(7);
    a. 3
    b. -1
    c. 1234567
    d. 7
    e. 0
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    这题考的是Random类的nextInt()函数
    nextInt()里的参数是bound 边界。
    nextInt(7) 代表在0到6的数字里随机选1个。

    答案:a,e


    6) Which of the following statements regarding the usage of the Java SE this() and super()
    keywords are valid?
    a. If used, this() or super() calls must always be the first statements in a constructor
    b. this() and super() can be used in the same (non-constructor) method
    c. If neither this() nor super() is coded then the compiler will generate a call to the zero
    argument superclass constructor
    d. this() and super() calls can be used in methods other than a constructor
    e. this() and super() can be used in the same constructor
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    这题就厉害了
    考的是this() 和 super()的用法。
    注意不是this.xxx 和 super.xx
    this.xxx -> 访问本对象的其他成员
    super.xxx -> 访问夫类的成员, 极少会使用, 如果未初始化默认值为null
    参考
    https://www.runoob.com/w3cnote/the-different-this-super.html

    而this() 和 super()都用于构造函数
    this() -> 调用本类其他参数类型的构造函数
    super() -> 调用父类的构造函数
    都只能写在构造函数的第一行…

    调用super()必须写在子类构造方法的第一行,否则编译不通过。每个子类构造方法的第一条语句,都是隐含地调用 super()(調用supper() or this()),如果父类没有这种形式的构造函数,那么在编译的时候就会报错。

    this() 和 super() 不能同时出现在一个构造函数里面,因为this()必然会调用其它的构造函数,其它的构造函数必然也会有 super() 语句的存在,所以在同一个构造函数里面有相同的语句,就失去了语句的意义,编译器也不会通过。

    答案: a, c



    8) In Java EE environment, which of the following statements are valid concerning the
    choice of a JDBC driver to access a database?
    a. Type 2 drivers have been deprecated since J2SE 5.0 and so should not be chosen
    b. Type 4 drivers exist for MySQL, Oracle, SQL Server and DB2
    c. A type1 driver will perform slightly faster than type2 driver
    d. A type3 driver does not support calls to stored procedures
    e. Type 4 drivers have the fastest performance but require the installation of software
    on the client
    f. Which is vendor indepenedent – type 
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    Type -1 Bridge driver
    Type -2 Native API
    Type -3 Network Protocol
    Type -4 Native Protocol

    Type 1 需要橋接ODBC(安裝在windows ODBC那玩意), 所以又叫橋接驅動
    在这里插入图片描述

    Type 2 本地API, 需要安装本地的API(Lib) 于数据库通讯
    在这里插入图片描述

    Type 3 网络协议, 需要1个中间(Vendor) app中间层去处理通讯
    在这里插入图片描述
    Type 4 本地协议,不需要安装任何client软件, 也叫瘦 驱动, 性能最好
    我们现在用的基本上都是Type 4驱动(只需要引入java编写的驱动jar包)

    答案:b

    当然我也不知道为什么要出这么傻逼的笔试题



    9) What will be the output of the following code snippet?
    import java.util.*;
     public class LinkEx{
     public static void main(String args[])
    {
    Set <String> set = new LinkedHashSet<String>();
    set.add(3);
    set.add(1);
    set.add(3);
    set.add(2);
    set.add(3);
    set.add(1);
     for(Iterator<String> it=set.iterator(); it.hasNext(); ){
    String str=(String) it.next();
    System.out.print( str+-);
     }
     }
     }
    a. 3-1-2-
    b. An exception will be thrown at runtime
    c. 1-2-3-
    d. 3-1-3-2-3-1-
    e. The program will run to completion, but the output will vary depending on the JVM
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24

    这题考点就是LinkedHashSet, 这个集合类型是实现了SortedSet接口, 所以里面的元素是有序的.
    简单地讲,类似Linklist, 每个元素加入了指向下1个元素的尾部指针

    这不跟Set是1个无序集合矛盾, Set所谓的无序是指存放的元素在内存中的位置无序。(AarryList)是1个连续的内存, 所以是有序。

    答案: a



    10) Based on the annotated hibernate code below, which of the following statements are
    correct?
    @Entity
    public class Peanut {
    @Id
    @Column (name= “peanut_id”)
    private String id;
    @Column private BigDecimal price;
    @OneToMany(cascade={CascadeType.All})
    @JoinColumn(name=”peanut_id”)
    @IndexColumn(name=ïdx”)
    private List<Walnut> walnuts;
    }
    @Entity
    public class Walnut{
    @Id
    @Column (name= “walnut_id”)
    private String id;
    @ManyToOne
    @JoinColumn(name=”peanut_id”, insertable=false, updatable=false,
    nullable=false)
    private Peanut peanut;
    }
    a. A Walnut cannot have any Peanuts
    b. A Walnut cannot update a Penut
    c. A Walnut can have multiple Peanuts
    d. A Peanut can have multiple Walnuts
    e. A Peanut can delete a Walnut
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28

    insertable=false means Walnut类不能通过 setPeanut(new Peanut())来插入一条数据去Peanut表
    updatable=false means Walnut类不能通过 getPeanut().setXXX() 去更新Peanut表数据
    Nullable = false 会令Hibenate 自动创建表示会让这个列为Not Null

    答案: b,d,e



    11) A Java SE class, MyFileProcessor, opens and uses a FileReader object in response to calls
    by its clients. Which of the following techniques could be used so that a client can
    guarantee that the FileReader object is closed at a certain point?
    a. The client sets its MyFileProcessor object reference to null
    b. The client makes a call to System.gc()
    c. MyFileProcessor contains code to close files in its destructor
    d. MyFileProcessor contains code to close the FileReader in its finalizer
    e. MyFileProcessor includes a public closeFiles method that contains code to close the
    files. The client calls this method
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    a 是泄露内存的典型
    b 跟a差不多

    c,d 意思是关闭资源 在 这个MyFileProcessor对象被回收时, 但是不能确定什么时候这个对象被jvm释放回收
    e 是直接调用MyFileProcessor对象的close file方法。

    答案: e



    12) The role of Spring in a full fledged Spring Web application is which of the following?
    a. It provides only an application-tier and data-tier logic web application framework,
    while the presentation-tier logic is left to itself
    b. It provides only a presentation-tier Web application framework, while the
    application-tier and data-tier logic is left to itself
    c. It provides the domain logic which implements the business rules to be provided by
    the web application
    d. It provides the management and configuration of business objects, enabling data
    access, integration, and presentation with simple POJOs
    e. It does not provide support for a full-fledged Spring Web application, but provides
    the infrastructure to support third-party Web frameworks
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    答案:b,d



    13) Which of the following will be the result of an attempt to compile and execute the Java
    SE code snippet below?
    1. class ExceptionDemo {
    2. public static void main(String[] args) {
    3. for (int x=3, int y=0; x>y; x--, y++) {
    4. System.out.print(x+ “ “+y+” ”);
    5. }
    6. }
    7. }
    a. The output is “3 1 0 2b. A compilation error will occur at line number 4
    c. The output is “ 3 0 2 1d. A compilation error will occur at line number 3
    e. A runtime exception will occur
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14

    我也很想选答案c,
    可惜第3行有语法错误

    for初始化 只能简单初始1个变量。
    ![](https://img-blog.csdnimg.cn/6dfecae9baac46b9acde92b3c62a4979.png
    答案: d



    14) Which of the following can be the output of an attempt to compile and execute the Java
    SE code snippet
    public class ExceptionDemo {
    public static void main(String args[]) {
    int x=5, y=0;
    try{
    try {
    System.out.println(x);
    System.out.println(x/y);
    System.out.println(y);
    }
    catch(ArithmeticException ex)
    {System.out.println(Ïnner Catch1);
    throw ex;
    }
    } catch(RuntimeException ex)
    {System.out.println(Ïnner Catch2);
    throw ex;
    }
    Finally {
    System.out.println(Inner Finally);
    }
    catch(Exception ex)
    {
    System.out.println(Outer Catch);
    }
    }
    }
    a. 5
    Inner Catch1
    Inner Finally
    Outer Catch
    b. 5
    Inner Catch1
    Outer Catch
    c. 5
    Inner Catch2
    Outer Catch
    Inner Finally
    d. 5
    Inner Catch1
    Inner Finally
    e. 5
    Inner Catch2
    Inner Finally
    Outer Catch
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46

    考点就是基本的try Catch 流程, 篇幅有限不想详细解析
    答案:A



    15) Which of the following statements correctly describe hibernate annotations?
    a. They are the indicators for the database on how to map database table to Java
    objects
    b. They are embedded metadata in Plain Old Java Objects(POJO)
    c. They cannot be combined with the XML-based configuration
    d. They can be combined with Java Persistent API (JPA) implementations
    e. They are retrieved by the Java Virtual Machine (VM) at runtime
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    这题考的是JPA/Hibernate 对Entity Class 的注解

    a 明显是正确的
    b 正确, Entity class 也称为POJO
    c 一开始, 肯定是基于xml注解
    d 正确, 这就是JPA
    e. 错误, 编译时就会检查这些zhuju

    答案: abd



    16) In Java EE, which of the following JSP and EL statements will get the URI string of the
    client request?
    a. ${pageContext.getRequest.getRequestURL}
    b. <%=request.getClientURI() %>
    c. ${pageContext.request.requestURI}
    d. ${requestScope.requestURI}
    e. <$pageContext.request.requestURI>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    考的是如何获得 request 的url(jsp文件的具体path)。。
    https://blog.csdn.net/yinbucheng/article/details/54095937

    本人不擅长前端, 不能很好地解析
    答案: C


    17) Which of the following statements correctly describe Hibernate id generation
    strategies?
    a. The Native strategy uses Identity, Sequence, or Hilo depending on the database
    hibernate is connecting to
    b. The sequence strategy generates the next available sequence for Sybase
    database
    c. The assigned strategy allows the Java application to create the database
    identifier
    d. The Hilo strategy uses a sequence number calculated from a Hilo algorithm
    e. Ids generated with the Increment strategy are unique
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    这题考的是hibernate的主键生成策略

    GenerationType.AUTO

    它是默认的生成策略,并允许持久性提供程序选择生成策略,如果使用Hibernate作为持久性框架,它将基于数据库特定的Dialect选择生成策略,对于大多数流行的关系数据库,它会选择GenerationType.SEQUENCE生成策略。

    GenerationType.SEQUENCE

    它是使用数据库序列生成唯一值的方法,它需要其他select语句才能从数据库序列中获取下一个值,但这对大多数应用程序没有性能影响。如果应用程序必须保留大量的新实体,则可以使用某些特定于Hibernate的优化来减少语句的数量。

    GenerationType.IDENTITY

    该策略是最容易使用的,但从性能角度来看却不是最佳的。它依靠自动递增的数据库列,并允许数据库在每次插入操作时生成一个新值,从数据库的角度来看非常有效,因为对自动增量列进行了高度优化,并且不需要任何其他语句。但是则此方法有一个很大的缺点,Hibernate需要每个管理实体的主键值,因此必须立即执行insert语句,这样阻止了它使用其他优化技术(例如JDBC批处理)。

    b, Sybase 不使用sequence(Oracle 会使用)
    d, HILO (High Low 高低位策略) 很少用了…, 被Hibernate某个版本去掉

    答案: a, c, e



    18) In Java SE, which of the following from the java.io package are concrete classes that can
    be instantiated?
    a. PrintWriter
    b. OutputStream(A)
    c. DataInput(I)
    d. FilterInputStream
    e. FilterReader(A)
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    考的是java IO
    https://mp.csdn.net/mp_blog/creation/editor/38237781

    a, printWriter 可以包裹在1个outputStream 上实例化
    b. outputStream是1个抽象類, 繼承这个接口的常用类包括FileOutputStream, ObjectOutputStream等
    c. DataInput input是1个接口, 实现这个接口的常用类包括DataInputStream等
    d. FilterInputStream 是1个类, 但是它的构造方法是protected 的, 一般我们只使用它的子类, 例如BufferedInputStream等
    e. Filter Reader 是1個抽象類.

    答案:a,d
    其實d有待商榷… 一般我認爲FilterInputStream 是無法實例化的…



    19) Which of the following statements are correct about the java.util.Queue<E> interface in
    Java SE?
    a. The Queue class has 2 constructors, a zero argument constructor and a
    constructor that takes an int param(capacity)
    b. A Queue object orders its elements in a FIFO (First In First Out) manner
    c. In a PriorityQueue<Integer>, a call to element is guaranteed to return the
    element with the highest integer value
    d. In a Queue object containing one or more elements, the element and remove
    methods both return the same element – head element
    e. In a BlockingQueue<E>, a call to put is guaranteed to block unless the queue is
    full
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    队列是一种特殊的线性表,它只允许在表的前端进行删除操作,而在表的后端进行插入操作。
    LinkedList类实现了Queue接口,因此我们可以把LinkedList当成Queue来用。

    a. Queue 是接口 , 沒有構造方法, 錯誤
    b. 先入先出是隊列的特性, 正確
    c. 要使用PriorityQueue,我们就必须给每个元素定义“优先级”, 也就是實現comparable接口, 而Interger默認是從小開始排隊, 所以會返回最小的數值,而不是highest interger value, 錯誤
    d. element() 和 remove()方法都會返回頭元素對象, 正確
    在这里插入图片描述

    e. 阻塞队列 (BlockingQueue)是Java util.concurrent包下重要的数据结构,BlockingQueue提供了线程安全的队列访问方式:当阻塞队列进行插入数据时,如果队列已满,线程将会阻塞等待直到队列非满而不是抛出異常or直接返回隊列已滿信息給Client;从阻塞队列取数据时,如果队列已空,线程将会阻塞等待直到队列非空。阻塞队列常用于生产者和消费者的场景,生产者是往队列里添加元素的线程,消费者是从队列里拿元素的线程。并发包下很多高级同步类的实现都是基于BlockingQueue实现的。

    e 說的是BlockingQueue中, put動作會被阻塞除非隊列已滿, 剛好相反了 。 錯誤
    答案: b,d



    20) Which of the following correctly describe what the command javah – jni_FooBar will
    produce?
    a. A library called jni_FooBar.h based on annotated elements in the FooBar class
    b. A Java class called FooBarH which Java used when invoking native code
    c. A Java style header file called jni_FooBar.h based on the annotations in the
    FooBar native library
    d. A C-style application from data elements in the jni_FooBar.java file
    e. A C-style header file called jni_FooBar .h based on the native methods defined in
    the FooBar clas
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    javah命令主要用于在JNI开发的时,把java代码声明的JNI方法转化成C\C++头文件,以便进行JNI的C\C++端程序的开发。

    JNI是Java Native Interface的缩写,通过使用 Java本地接口书写程序,可以确保代码在不同的平台上方便移植。 [1] 从Java1.1开始,JNI标准成为java平台的一部分,它允许Java代码和其他语言写的代码进行交互。JNI一开始是为了本地已编译语言,尤其是C和C++而设计的,但是它并不妨碍你使用其他编程语言,只要调用约定受支持就可以了。使用java与本地已编译的代码交互,通常会丧失平台可移植性。但是,有些情况下这样做是可以接受的,甚至是必须的。例如,使用一些旧的库,与硬件、操作系统进行交互,或者为了提高程序的性能。JNI标准至少要保证本地代码能工作在任何Java 虚拟机环境。

    答案:e



    21) Which of the following techniques can resolve an OutOfMemoryError in a Java SE
    application?
    a. Configure the garbage collector to run more frequently
    b. Increase the page file size of the computer’s virtual memory
    c. Increase the available JVM heap size.
    d. Ensure that references to objects are released when they are no longer needed.
    e. Increase the amount of physical RAM on the computer
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    如何解決OOM。。。
    a .garbage collector GC 就是垃圾回器, 一般我們不會動這個, 增加觸發GC的次數也沒什麽狗用
    b. 增加虛擬内存的分頁大小也沒什麽意義
    c. 增加JVM heap size, 有用
    d. 保證無用對象内存釋放(釋放資源),真正有效地解決問題。有用
    e. 有用, 但增加物理内存不算是技術吧…

    答案: cd



    22) Two Java SE classes are declared as shown below:
    public class Invoice {
    public static String formatId(String oldId) {
    return oldId + “_Invoice”
    }
    }
    public class SalesInvoice extends Invoice {
    public static String formatId (String oldId) {
    return oldId + “_SalesInvoice”;
    }
    }
    Which of the following statements are true about attempts to use these classes?
    a. Invoice invoice = new SalesInvoice();
    System.out.println(invoice.formatId(1234));
    Will output 1234_SalesInvoice
    b. Invoice invoice = new Invoice();
    System.out.println((SalesInvoice)Invoice.formatId(1234));
    Will output 1234_SalesInvoice
    c. Invoice invoice = new Invoice(); .
    System.out.println(invoice.formatId(1234));
    Will output 1234_Invoice
    d. SalesInvoice invoice = new SalesInvoice();
    System.out.println(Invoice.formatId(1234));
    Will output 1234_SalesInvoice
    e. SalesInvoice invoice = new SalesInvoice();
    System.out.println(invoice.formatId(1234));
    Will output 1234_Invoice
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27

    java中静态属性和静态方法可以被继承,但是没有被重写(overwrite)而是被隐藏.

    1). 静态方法和属性是属于类的,调用的时候直接通过类名.方法名完成对,不需要继承机制及可以调用。如果子类里面定义了静态方法和属性,那么这时候父类的静态方法或属性称之为"隐藏"。如果你想要调用父类的静态方法和属性,直接通过父类名.方法或变量名完成,至于是否继承一说,子类是有继承静态方法和属性,但是跟实例方法和属性不太一样,存在"隐藏"的这种情况。
    2). 多态之所以能够实现依赖于继承、接口和重写、重载(继承和重写最为关键)。有了继承和重写就可以实现父类的引用指向不同子类的对象。重写的功能是:"重写"后子类的优先级要高于父类的优先级,但是“隐藏”是没有这个优先级之分的。
    3). 静态属性、静态方法和非静态的属性都可以被继承和隐藏而不能被重写,因此不能实现多态,不能实现父类的引用可以指向不同子类的对象。非静态方法可以被继承和重写,因此可以实现多态。

    a. 对象的类型 invoice 被定义了父类, 执行对象实际类型是子类, 但是这种情况下调用的仍然是父类的static 函数. 错误
    b. 父类的对象不能被强转为子类的对象。 除非Invoice invoice = new Invoice() 改为 Invoice invoice = new SalesInvoice() 改为
    c. 明显是正确的
    d. System.out.println(Invoice.formatId(“1234”)); 这里直接调用类名调用静态方法, 所以调用的是父类的静态方法
    e. 这里应该调用的是子类的静态方法, 因为引用类型和对象类型都是子类

    答案: c



    23) Java SE class ThirdPartyObject, that is not thread-safe, is to be used in some new Java
    code. Which of the following design decisions can be made to ensure that no race
    conditions will occur?
    a. Provide a static getter for a ThirdPartyObject instance
    b. Store instances of ThirdPartyObject in a ThreadLocal .
    c. Make any instance of ThirdPartyObject a local (method) variable and ensure
    that no references to it are published.
    d. Use @Immutable as an annotation with ThirdPartyObject instances.
    e. Ensure that an instance of ThirdPartyObject is private and can only be
    accessed using a public getter method
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    考的是线程安全:
    问的是:
    Java SE类ThirdPartyObject,它不是线程安全的,将在一些新的Java中使用
    代码。以下哪一种设计决策可以确保没有竞争情况会发生。

    a. 无论getter 是否静态, 如果这个instance被多个线程同时访问就会竞争
    b. 正确
    c. 正确, 只在local方法创建对象, 并保证不会被其他方法访问, 这样每个线程都会有自己单独的对象。
    d. 不知道什么鬼
    e, 单例模式, 如果这个对象是有状态的, 就会发生竞争(线程安全问题)

    答案: bc



    24) Java EE servlet-based application uses a context attribute that is vital to the operation of
    the application. Which of the following approaches can be used to ensure thread-safe
    access to the attribute?
    a. Access the attribute within a code block that is synchronized on the request
    object
    b. Agree a strategy where all servlets must access the attribute within a code
    block that is synchronized on the session object
    c. Specify synchronized in the method declarations of doGet and doPost in the
    servlet
    d. Agree a strategy where all servlets must access the attribute within the code
    block that is synchronized on the context object.
    e. Access the attribute within a code block that is synchronized on the session
    object
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    考的是synchronized 方法,
    既然 那个是1个 context 属性, 所以我们就必须让context 对象里访问attribute的方法是Synchronized(同步的, 要排队访问的)
    答案: d



    25) Given code below contains overloaded and overridden constructor. Which of the
    following can be the result of an attempt to compile and execute this code?
    class Superclass {
    	Superclass() {
      		this(0);
    		System.out.println(1);
    	}
    	Superclass(int x) {
    		System.out.println(2+x);
    	}
    }
    public class Subclass extends Superclass {
    	Subclass(int x) {
    		System.out.println(3+ x);
    	}
    	Subclass(int x, int y) {
    		this(x);
    		System.out.println(4+ x + y);
    	}
    	
    	public static void main(String[] args) {
    	new Subclass(2,3);
    }
    }
    a. The output is
    32
    423
    b. The output is.
    20
    1
    32
    423
    c. The output is
    22
    32
    423
    d. The output is
    5
    9
    e. A Recursive constructor invocation compilation error occurs
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40

    考的是子类如何调用父类构造函数
    参考
    https://blog.csdn.net/nvd11/article/details/126926028?csdn_share_tail=%7B%22type%22%3A%22blog%22%2C%22rType%22%3A%22article%22%2C%22rId%22%3A%22126926028%22%2C%22source%22%3A%22nvd11%22%7D

    重点在Subclass 的双参构造函数中, 因为无显示声明super(), 所以会隐含调用父类的无参构造函数

    答案: b
    评论:又是1个恶心的考题, 项目中有人这样写隐含调用的代码我马上把他操了



    26) In Java the two classes below are declared in the same file:
    class Parent {
    	protected static int count=0;
    	public Parent () { count++; }
    	static int getCount() { return count; }
    }
    
    public class Child extends Parent {
    	public Child() { count++; }
    	public static void main(String [] args) {
    		System.out.println(Count =+getCount());
    		Child obj = new Child();
    		System.out.println(Count =+ getCount());
    	}
    }
    Which of the following can be the result of trying to compile and execute this file?
    a. The file will compile and run and the output will be :
    Count = 0
    Count = 1
    b. The file will not compile
    c. The file will compile and run and the output will be :
    Count = 1
    Count = 2
    d. The file will compile and run and the output will be : .
    Count = 0
    Count = 2
    e. The file will compile but will generate a runtime error
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27

    又是考隐含调用父类无参构造函数, 参考上一题
    答案:d

    27) In the Java SE statement shown below, which of the following accurately describe the
    parameter “MyBundle?
    ResourceBundle bundle = ResourceBundle.getBundle(MyBundle, currentLocale);
    a. An Internet URL
    b. The name of a Java class
    c. The name of a command line switch
    d. The name-prefix of a series of property files.
    e. The name of a .Net dll
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    下面我们来模拟一个多语言的环境
    定义四个资源文件:res_en_US.properties、res_zh_CN.properties、res_zh.properties、res.properties
    res_en_US.properties:cancelKey=cancel
    res_zh_CN.properties:cancelKey=\u53D6\u6D88(取消)
    res_zh.properties:cancelKey=\u53D6\u6D88zh(取消zh)
    res.properties:cancelKey=\u53D6\u6D88default(取消default)

    命名规则按照:资源名+_语言_国别.properties,每个资源文件中定义了本地化的信息,那么系统如何取到对应的资源文件呢?
    ResourceBundle bundle = ResourceBundle.getBundle(“res”, new Locale(“zh”, “CN”));

    其中new Locale(“zh”, “CN”);这个对象就告诉了程序你的本地化信息,就拿这个来说吧:程序首先会去classpath下寻找res_zh_CN.properties
    若不存在,那么会去找res_zh.properties,若还是不存在,则会去寻找res.properties,要还是找不到的话,那么就该抛异常了:MissingResourceException
    我们可以来写个测试程序验证一下:

    public static void main(String args[]) {
    	ResourceBundle bundle = ResourceBundle.getBundle("res", new Locale("zh", "CN"));
    	String cancel = bundle.getString("cancelKey");
    	System.out.println(cancel);
    	
    	bundle = ResourceBundle.getBundle("res", Locale.US);
    	cancel = bundle.getString("cancelKey");
    	System.out.println(cancel);
    	
    	bundle = ResourceBundle.getBundle("res", Locale.getDefault());
    	cancel = bundle.getString("cancelKey");
    	System.out.println(cancel);
    
    	bundle = ResourceBundle.getBundle("res", Locale.GERMAN);
    	cancel = bundle.getString("cancelKey");
    	System.out.println(cancel);
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17

    }

    输出:
    取消
    cancel
    取消
    取消
    ————————————————
    版权声明:本文为CSDN博主「百里马」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/u012345283/article/details/42082253

    明显参数是配置文件的前序, 考德很偏阿
    答案:d

    28) Which of the following are implementations of the Front Controller pattern for fullfledged Spring Web application described by the deployment descriptor below?
    
    
    <display-name>Archetype Created Web Applicationdisplay-name>
    <servlet>
    <servlet-name> Spring MVC Web Applicationservlet-name>
    <servlet-class>
    [Spring Front Controller implementation]
    servlet-class>
    servlet>
    <servlet-mapping>
    <servlet-name>Spring MVC Web Applicationservlet-name>
    <url-pattern>/*url-pattern>
    servlet-mapping>
    web-app>
    a. RequestContextListener
    b. RequestContextFilter
    c. WebApplicationContext
    d. DispatcherServlet 
    e. ContextLoaderListener
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24

    参考spring MVC
    在这里插入图片描述

    答案:d

    29) To troubleshoot a problem in a live system, a class is modified slightly resulting in the
    code shown below:
    import java.util.ArrayList;
    import java.util.List;
    public List<String> queueSequence;
    	public void setup()
    	{	
    		try {
    		 	establishQueueSequence();
    		}
    		finally {
    			cleanupQueueSequence();
    			System.out.println(Queue sequence successfully cleaned up”);
    		}
    	}
    	
    	private void cleanupQueueSequence() {
    		if (queueSequence.size() > 0) {
    			System.out.println(Queue size > 0);
    		}
    	}
    	
    	private void establishQueueSequence() {
    		if (true) {
    			throw new IllegalArgumentException();
    		}
    		queueSequence = new ArrayList<String>();
    	}
    }
    Which of the following can be the result of an attempt to execute the code shown
    below?
    IKMProcessor processor = new IKMProcessor();
    processor.setUp();
    System.out.println(Processing complete”);
    
    a. The program runs to completion without exception, but nothing is output
    b. The program outputs: Queue sequence successfully cleaned up
    c. Processing ends abnormally with an IllegalArgumentException
    d. Processing ends abnormally with a NullPointerException .
    e. The program outputs: Processing complete
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40

    考的是Try Catch Exception 处理流程
    只不过这里的Exception没有被显式catch.

    因为establishQueueSequence throw 出了IllegalArgumentException 异常, 导致queueSequence 没有被初始化
    而这个IllegalArgumentException 异常被 隐藏地catch了但是没有任何处理

    Finally里调用cleanupQueueSequence, 尝试去访问.size()方法, 导致NullPointerException

    答案:d



    30) Which of the following are valid results of executing the JavaScript code snippet below?
    <body onLoad=hi()” onUnload =bye()>
    <script language=javascript>
    	var nm= “ ”;
    	function hi() {
    		nm= prompt(Hello! Your name?, “ “);
    	}
    	{
    		Function bye() { alert(Goodbye+ nm);
    	}
    </script>
    </body>
    a. There is no visible output when the document loads
    b. After the document loads, a welcome message is displayed and the user is
    prompted for a name.
    c. A syntax error is displayed when function hi() is executed
    d. When the user request another URL, a good-bye message is displayed.
    e. The document displays and error message, since all functions must be in the
    <HEAD>section of the document
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19

    考的是javascript… 这不是java笔试题吗?

    var Hello = new Function(“alert(‘Hello World’);”);
    Hello();

    上面这种函数定义跟下面是一样的。

    function Hello(){
    alert(“Hello World”);
    }
    Hello();

    另:js是大小写敏感的语言,var a,A;这样的定义两个不同的变量。
    Function是一个类的,而function是定义一个函数的关键字

    答案:b,d



    31) Which of the following Java Native Interface (JNI) types and keywords map to their
    machine-dependent Java equivalents?
    a. const : constant
    b. void : void .
    c.  jintArray : int []
    d.  jlong : long.
    e.  jarray : array
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    答案: b,d
    没写过JNI, 无法解析…



    32) Which of the following statements are valid about the JDBC code snippet below, written
    for a Java EE environment?
    imports here
    …..
    public class MyJDBCInsertServlet extends HttpServlet {
    	@Resource (name=”jdbc/TimetableDBPool)
    	private DataSource dataSource;
    	
    	@Override
    	protected void doGet (httpServletRequest request, HttpServletResponse
    			response) throws ServletException, IOException {
    		String insertSql= “INSERT INTO purchase_order (id, description)
    											VALUES (?,?);
    		try {
    			Connection connection = dataSource.getConnection();
    			PreparedStatement insertStatement =
    			connection.prepareStatement(insertSql);
    			insertStatement.setInt(1, 12345);
    			insertStatement.setString(2, “QAC Demo);
    			insertStatement.executeInsert();.
    			insertStatement.close();
    			connection.close();
    	}
    		catch (SQLException e) {
    			e.printStackTrace();
    		}
    	}
    }
    a. The code will not compile
    b. The code will throw an IndexArrayOutOfBoundsException
    c. After execution, a record will be added to the purchase_orders table with
    id=12345 and description=”QAC Demod. A SQLException will be caught, then the code will continue execution
    e. The code will throw a NullPointerException
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34

    答案: a 虽然我想选c
    我也不李姐阿



    33) Which of the following statements correctly describe Hibernate caching?
    a. Caching causes extra database activity
    b. Caching dynamic data will improve application performance
    c. Hibernate bypasses the session cache by default
    d. Cached data resides between the application and the database
    e. Hibernate does not support second level caching
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    参考:https://segmentfault.com/a/1190000015454980
    Hibernate 1级缓存默认开启, 生命周期在session中, 所以c错误

    Hibernate 二级缓存默认关闭, 但是可以通过配置开启嘛, 所以e错误

    答案:b,d



    34) Before forwarding the request to a JSP, a Java servlet executes the code below:
     java.util.ArrayList peopleNames = new java.util.ArrayList();
    peopleNames.add(John);
    peopleNames.add(Michelle);
    peopleNames.add(Michael);
    peopleNames.add(Susan);
    request.setAttribute(“favoriteNames”, peopleNames);
    In the JSP, which of the following EL statements will cause one or more of these
    names to be shown on the web page?
    a. Second name is ${peopleNames[1]}
    b. Last name is ${favoriteNames[Susan]}
    c. Names are ${favoriteNames}
    d. Initial name is ${favoriteNames[O]}
    e. Favorite names are ${peopleNames}
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14

    其实这题考的更多是JPA的数组。
    a. 只能从favoriteNames 变量去获取 , 错误
    b. Last name is ${favoriteNames[“Susan”]} , 中括号里面应该是index, 而不是元素本身
    c. 会显示所有元素
    d. 同b
    e. 同a

    答案: c



    35) A company is building a new application which stores all employee information
    1. @Entity
    2. public class Company {
    3.	 @Id
    4. 	@Column(name=”company_id”)
    5. 	private String id;
    6.
    7.	 private String employeeNumber;
    8. 	@Column(name=”employee_number”)
    9. 	public void setEmployeeNumber (String value) {
    10.	 price = value;
    11. }
    12. }
    When the above code is executed, a mapping exception is thrown, which of the
    following changes will allow the code to successfully execute?
    a. Add at Line 12:
    public void setId(String value) {
    id = value;
    }
    b. Remove Line 3
    c. Remove Line 4
    d. Move Line 8 to Line 6
    e. Update Line 8 to @Column(name=”employee_number_id”)
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23

    考的是Hibernate Entity class注解
    d 肯定是对的
    但是 的确id没有setter, 而且它是注解, 所以我们必须加上setter

    答案:a, d



    36) Which of the following statements correctly describe the use of Java Native Interface
    (JNI)?
    a. JNI imports and converts non-Java code into a Java application
    b. JNI provides an out-of-the-box solution to interface with services outside
    the Java application
    c. JNI allows native operating systems to access Java based applications by
    bypassing the Java Virtual Machine (JVM)
    d. JNI gives applications direct access to computer hardware
    e. JNI allows applications to use native code in situations where Java cannot
    be used
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    Shit, 又考JNI
    以下哪一种表述正确地描述了Java本机接口(JNI)的使用?
    a. JNI导入非Java代码并将其转换为Java应用程序
    b. JNI提供了一种开箱即用的解决方案,用于与Java应用程序外部的服务进行接口
    c. JNI允许本机操作系统绕过Java虚拟机(JVM)来访问基于Java的应用程序
    d. JNI让应用程序直接访问计算机硬件
    e. JNI允许应用程序在不能使用Java的情况下使用本机代码

    答案: e



    37) Which of the following blocks of code can replace the asterisks in the Java Swing code
    below to
    import java.util.Locale;
    import java.util.ResourceBundle;
    import javax.swing.JFrame;
    public class SwingInternationalizationDemo {
    public static void main (String[] args) {
    String language;
    String country;
    Locale locale;
    ResourceBundle rb;
    *****
    }
    }
    a. Locale = new Locale();
    rb= ResourceBundle.getBundle(MessageBundle, locale);
    JFrame frame=new JFrame();
    frame.setSize(300,300);
    frame.setTitle(rb.getString(“frameTitle”));
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
    b. language = Locale.getDefault().getLanguage();
    country=Locale.getDefault().getCountry();
    locale=new Locale(language, country);
    rb= new ResourceBundle(MessageBundle, locale);
    JFrame frame=new JFrame();
    frame.setSize(300,300);
    frame.setTitle(rb.getString(“frameTitle”));
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
    c. language = System.getLanguage();
    country = System.getCountry();
    locale=new Locale(language, country);
    rb= ResourceBundle.getBundle(MessageBundle, locale);
    JFrame frame=new JFrame();
    frame.setSize(300,300);
    frame.setTitle(rb.getString(“frameTitle”));
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
    d. language = Locale.getDefault().getLanguage();
    country=Locale.getDefault().getCountry();
    locale=new Locale(language, country);
    rb= ResourceBundle.getBundle(MessageBundle, locale);
    JFrame frame=new JFrame();
    frame.setSize(300,300);
    frame.setTitle(rb.getString(“frameTitle”));
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
    e. locale = new Locale();
    language = System.getDefaultLanguage();
    country = System.getDefaultCountry();
    locale.setLanguage(language);
    locale.setCountry(country);
    rb= ResourceBundle.getBundle(MessageBundle, locale);
    JFrame frame=new JFrame();
    frame.setSize(300,300);
    frame.setTitle(rb.getString(“frameTitle”));
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true)
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59

    考得好偏阿。
    其实locale对象应该用new Locale()实例化
    ResourceBundle 用 getBundle()获得对象

    答案:c



    38) Two Java SE classes are declared as shown below:
    package com.ikmnet;
    public class MySuper {
    protected String buildString(String current) {
    return current +1;
    }
    }
    package com.ikmnet;
    public class MySub extends MySuper {
    @override
    public String buildString (String current) {
    return super.buildString(current);
    }
    }
    A test harness is accessed using the line of code below:
    new MyTestHarness().writeString();
    Which of the following class declarations for MyTestHarness will result in a console
    output of
    a. package anotherpackage;
    import com.ikmnet.MySub;
    public class MyTestHarness {
    public void writeString() {
    MySub object = new MySub();
    System.out.println(object.buildString(O,));
    }
    }
    b. package anotherpackage;
    import com.ikmnet.MySub;
    import com.ikmnet.MySuper;
    public class MyTestHarness {
    public void writeString() {
    MySuper object = new MySub();
    System.out.println(object.buildString(O,));
    }
    }
    c. package com.ikmnet;
    public class MyTestHarness {
    public void writeString() {
    MySuper object = new MySuper();
    System.out.println(object.buildString(O,));
    }
    }
    d. package anotherpackage;
    import com.ikmnet.MySuper;
    public class MyTestHarness extend MySuper {
    public void writeString() {
    MySuper object = new MySuper();
    System.out.println(object.buildString(O,));
    }
    }
    e. package anotherpackage;
    import com.ikmnet.MySuper;
    public class MyTestHarness {
    public void writeString() {
    MySuper object = new MySuper();
    System.out.println(object.buildString(O,));
    }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58

    这题都唔知考麦7
    答案:a, c
    无参考意义
    在这里插入图片描述


    39) In a Java SE environment, garbage collection is causing performance problems and it is
    suspected …. Problems are caused by some of the applications making explicit calls to
    System.gc(). Which of the following JVM
    Arguments can be used to test this theory?
    a.  –XX:+DisableExplicitGC
    b.  –XX:+UseConcMarkSweepGC
    c.  –XX:+UseParNewGC
    d.  –XX:+UseParallelGC
    e.Xverify:none
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    问题是是问, 有个java程序, gc性能有问题,可能是因为程序从代码里显式释放导致的(你怎么不去写C++)

    哪个jvm选项可以测试这个问题。

    a. 禁止显式gc 正确
    b. GC算法使用CMS
    CMS为基于标记清除算法实现的多线程老年代垃圾回收器。CMS为响应时间优先的垃圾回收器,适合于应用服务器,如网络游戏,电商等和电信领域的应用。
    为了实现这个目的,与其他垃圾回收器不同的是,CMS是与应用程序并发执行的,即在CMS对老年代进行垃圾回收时,应用程序大部分时间里是可以继续执行的,应用程序只需进行非常短暂的停顿。由于与应用程序并发执行,同一时刻同时存在垃圾回收线程和应用线程,故对服务器的CPU消耗较大,需要保证服务器CPU资源充足。

    c.
    Parallel是并行的意思,ParNew收集器是Serial收集器的多线程版本,使用这个参数后会在新生代进行并行回收,老年代仍旧使用串行回收。新生代S区任然使用复制算法。操作系统是多核CPU上效果明显,单核CPU建议使用串行回收器。打印GC详情时ParNew标识着使用了ParNewGC回收器。默认关闭。
    d.
    代表新生代使用Parallel收集器,老年代使用串行收集器。Parallel Scavenge收集器在各个方面都很类似ParNew收集器,它的目的是达到一个可以控制的吞吐量。吞吐量为CPU用于运行用户代码的时间与CPU总消耗时间的比值,即吞吐量=运行用户代码时间/(运行用户代码时间+垃圾收集时间),虚拟机运行100分钟,垃圾收集花费1分钟,那吞吐量就99%。Server模式默认开启,其他模式默认关闭。
    e. –Xverify:none 关闭代码验证器

    JDK1.7/1.8 默认的垃圾回收器:Parallel Scavenge(新生代)+ Parallel Old
    JDK1.9 默认垃圾回收器:G1

    答案: a



    40) A Java EE servlet contains the code below:
    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws Servletexception, IOException {
    …
    printWriter out = response.getWriter();
    out.println(<html><body>Please wait…</body></html>);
    out.flush();
    out.close();
    response.sendRedirect(BookingPortal.jsp”);}
    Which of the following will occur when this code is executed?
    a. A page containing the text “BookingPortal.jsp”will display
    b. StackOverflowException will be thrown and be visible in the server log
    c. A page containing the text “Please wait…”will briefly display then
    disappear.
    d. IllegalStateException will be thrown and be visible in the server log.
    e. The HTML for page Bookingportal.jsp will display
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18

    a, 智商选项排除
    b. StackOverflowException 除非你写了个死循环, 否则不常见, 排除
    c. 是正确的
    d. 正确, 重点是out已经flush/close 再 redirect就出事了
    e. d正确, e就排除了

    答案: cd



    41) In Java SE, which of the following are true about the string s?
    String s = “abcd”;
    a. The statement
    s.equals(“abcd”) will evaluate to true.
    b. The statement
    S == “abcd” will evaluate to true
    c. s.replace(‘a’,’f’) will modify the string s
    d. Given
    String s2=new String(“abcd”);
    The statement
    s == s2 will evaluate to true
    e. The statement
    s = “abcd” will eval
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    a 正确
    b 比较多是地址
    c 会返回一个新字符串, s不会被改
    d. 用new String() 创建的字符串不是常量,不能在编译期就确定,所以new String() 创建的字符串不放入常量池中,它们有自己的地址空间。
    e.出题 不全
    答案:a



    42) Which of the following statement correctly describe the Java Hibernate framework?
    a. It is an Object Relation Mapping implementation.
    b. It is not supported with Enterprise Java Beans (EJBs)
    c. It increases the complexity of the application
    d. It converts Java objects to database specific SQL statements.
    e. It supports distributed database
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    答案:ade 虽然我很想选c



    43) Which of the following do NOT correctly declare a generic java SE class?
    a. public class Account<T> {
    private T accountType;
    public void add(T newType) {accountType= newType;}
    public T get() {return accountType;}
    }
    b. public class Account {
    private<T extends Object> accountType;
    public void add (<T extends Object> newType) {accountType=newType;}
    public<T extends Object> get() {return accountType;}
    }.
    c. public class Account<T>{
    private T accountType;
    public void add(T newType) {accountType =newType;}
    public T get() { return accountType;}
    }
    d. public class Account {
    private<T> accountType;
    public void add(<T> newType){ accountType =newType;}
    public Type get() { return accountType; }
    }.
    e. public class Account(Type){
    private Type accountType;
    public void add(Type newType){accountType=newType;}
    public Type get() { return accountType;}
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26

    考的是泛型。

    a 和 c代码一样是正确的
    b. 写法只用于函数的参数类型,可以令参数T 的对象在代码里执行??类的方法
    如:
    public String getFruitName(T t){
    return t.get().toString();
    }

    d. 语法错误
    e. 不是泛型

    由于问题是问not correctly 。。

    答案:bde



    44) Which of the following statements are valid about JPA Entities in Java EE?
    a. Mapping between java objects and the related databases must be defined using
    annotations.
    b. An entity class must implement a persist() method
    c. In an entity class, the annotation @ColumnInTable must be used if a field is to be
    associated with a column in a table
    d. An entity instance corresponds to a table row.
    e. An entity is a POJO annotated with the @Entity annotation.
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    考的是JPA
    a. JPA只能用注解(还不知道, 很久没写spring.xml了)
    b. 我就没用过这玩意
    c. @ColumnInTable 还怎么用过

    下面的倒是经常用,但也不是必须写的
    @Column(name=“name”)
    private String name;

    d. 一个Entity类的实例对应数据表的一行 正确
    e. 正确

    答案: ade



    45) Which of the following are created by the J2SE 5.0 code below?
    package pkg;
    class Foo {
    native int bar(String S);
    Static {
    System.loadLibrary(“foo_bar”);
    }}
    a. A native library called foo_bar .
    b. A mapping in the registry between the java class Foo and a native application called foo_bar
    c. A java class with a native method called bar.
    d. A native method called bar, which is used in the native application called foo_bar
    e. A static native class called foo_bar
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    又是是JNI。。

    答案: ac



    46) The JavaScript snippet show is to be used by a gaming software company to return the
    “x” & “y”coordinates of a user’s mouse click. The script must correctly address any
    current browser challenges as well as Internet Explore support for versions prior to IE6.
    Which of the following values can be substituted for ***A***, ***B*** and ***C*** in
    the JavaScript code to execute correctly?
    <script language=”javascript”type=”text/javascript”>
    function processClick(evt) {
    ***A***
    var x = 0; var y = 0;
    var result = new Array(2);
    var offsetX = 0; offsetY= 0;
    if (evt.pageX) {
    x=evt.pageX;
    y = evt.pageY;
    } else if (evt.clientX) {
    If (document.documentElement.scrollLeft) {
    offsetX = document.documentElement.scrollLeft;
    offsetY = document.documentElement.scrollTop;
    } else if (document.body) {
    offsetX = document.body.scrollLeft;
    offsetY = document.body.scrollTop;
    }
    }
    result[0] = evt.clientX + offsetX;
    result[1] = evt.clientY + offsetY;
    return result;
    }
    If (document.attachEvent)
    ***B***
    else
    ***C***
    </script>
    a. Replace ***A*** with evt=evt || windows.event;
    Replace ***B*** with document.attachEvent(“onclick”,processClick);
    Replace ***C*** with document.addEventListener(“click”,processClick, false); .
    b. Replace ***A*** with evt=evt || windows.event;
    Replace ***B*** with document.attachEvent(“onclick”,processClick, false);
    Replace ***C*** with document.addEventListener(“click”,processClick);
    c. Replace ***A*** with evt=evt || windows.event;
    Replace ***B*** with document.addEventListener(“onclick”,processClick );
    Replace ***C*** with document.attachEvent(“click”,processClick, false);
    d. Replace ***A*** with evt=evt || windows.event;
    Replace ***B*** with document.attachEvent(“onmouseclick”,processClick,
    false);
    Replace ***C*** with document.addEventListener(“mouseclick”,processClick);
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45

    如果见到这种傻逼问题, 直接看答案排除法。
    “onmouseclick”,“mouseclick”都不是事件, 排除 de

    abc 就看看平时又没用过attachEvent 和 addEventListener 了

    支持的浏览器不同。attachEvent在IE9以下的版本中受到支持。其它的都支持addEventListener。
    参数不同。addEventListener第三个参数可以指定是否捕获,而attachEvent不支持捕获。
    事件名不同。attachEvent第一个参数事件名前要加on,比如el.attachEvent(‘onclick’, handleClick)。

    答案:a



    47) A User application deals with late binding in its implementation as is shown in the Java
    SE code snippet
    class LB_1 {
    public void retValue() {
    System.out.println(“LB_1”);
    }
    }
    pubicl class LB_2 extends LB_1 {
    public void retValue() {
    System.out.println(“LB_2”);
    }
    public static void main(String args[]) {
    LB_1 lb = new LB_2();
    lb.retValue();
    }
    }
    a. A runtime error will occur
    b. A compilation error will occur
    c. LB_2
    d. LB_1 LB_2
    e. LB_1
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21

    送分题,无需解析
    答案:c



    48) Java EE application is to be built so that some of the functionality can be customized by each
    customer. The intention is that each customer will be able to write a class to implement the
    customer behavior then deploy the class with the application. Which of the following are valid
    approaches that will enable the deployer at the customer site to achieve this?
    a. The deployer uses Winzip to add and remove .class files in the EAR file
    b. The deployer uses the IDE to code the correct class and runs Junit tests to verify
    c. The deployer specifies the classname in a config file. The application code reads the file and
    uses reflection api to load the class
    d. The deployer uses Winzip to add and remove .class files in the RAR file
    e. In the container, the deployer adds the Java source code of the class to the classpath
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    Java EE应用程序将被构建,以便每个客户可以定制一些功能。目的是每个客户将能够编写一个类来实现客户行为,然后将该类与应用程序一起部署。以下哪一种有效的方法可以使客户站点的部署人员实现这一点?
    a, 人手替换class file,有可能可以, 但真的不建议这么做
    b. 运维怎么可能部署时还改代码
    c. 正确
    d. 同a
    e.同b
    答案:c



    49) In Java SE, which of the following statements are correct about thread management in the main
    method?
    a. The main method runs on daemon thread with a higher priority than the garbage collector’s
    thread
    b. The main method can start a daemon thread that will not affect whether the JVM instance
    exits
    c. When the main method returns, any daemon thread created by it are always automatically
    terminated
    d. Any thread launched by the main method will be a non-daemon thread with the same
    priority as the original thread
    e. When the main method of a program returns, the JVM instance must exit
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    Explain:When main method is called by default one main thread is created. And main thread
    is a non-dameon thread. When threads created by the main method it inherits it’s parant’s
    property. That means they are all non-daemon threads. As you know JVM waits until all
    non-daemon threads to complete. So it will executes even after the main thread completes

    a. main方法运行在守护线程上,守护线程的优先级高于垃圾收集器的线程
    b. main方法可以启动一个守护进程线程,它不会影响JVM实例是否退出
    C.当main方法返回时,由它创建的任何守护线程总是自动终止
    d.任何由main方法启动的线程都是非守护线程,具有与原线程相同的优先级
    e.当程序的main方法返回时,JVM实例必须退出

    答案:bd
    又学到东西了


    50) Which of the following combinations of Spring modules cover end-to-end functionalities of
    presentation, middle-tier,and data access in the full-fledged Spring Web application below?
    
    
    <mvc:annotation-driven/>
    <bean class=”MyController”/>
    <tx:annotation-driven />
    <bean id=”transactionManager”
    class=”org.springframework.jdbc.datasource.DataSourceTransactionManager”>
    <!--  - - >
    bean>
    <bean id = “localSessionFactoryBean”
    class = “org.springframework.orm.hibernate3.LocalSessionFactoryBean”
    init-method=”createDatabaseSchema”>
    <! --  -- >
    bean>
    <bean id = “myDataSource”
    class = “org.springframework.jcbc.datasource.DriverManagerDataSource”
    >
    <! --  -- >
    bean>
    beans>
    a. Web, Context, JDBC
    b. Portlet, AOP, Context
    c. Core, AOP,OXM
    d. ORM, Transactions, JDBC.
    e. Beans, Context, JDBC
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36

    哪个Spring模块的组合涵盖了下面成熟的Spring Web应用程序中的表示、中间层和数据访问的端到端功能?

    myDataSource 肯定是JDBC了
    LocalSessionFactoryBean, Hibernate包的东西, ORM
    transactionManager 事务
    答案:d



    51) Consider the deployment descriptor for a Java EE servlet shown below
    <web-app>
    <context-param>
    <param-name>GeneralSitenameparam-name>
    <param-value>S1234param-value>
    context-param>
    Web-app>
    <servlet>
    <servlet-name> ordersservlet-name>
    <init-param>
    <param-name>AccountingSitenameparam-name>
    <param-value>A5678param-value>
    init-param>
    servlet>
    Which of the following are valid?
    a. getServletConfig().getServletContext(“ÄccountingSitename”).getInitiParameter() returns
    A5678
    b. getServletContext().getAttributeNames() returns the value AccountingSitename.
    c. getServletContext().getInitParameter(“GeneralSitename”) returns the value S1234 .
    d. getServletConfig().getInitiParameter() returns the value GeneralSitename
    e. getServletConfig().getServletName() return the value AccountingSitename
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21

    答案c。。



    52) In the context of Java Hibernate, which of the following correctly describe the purpose of the
    cascade property?
    a. It ensures attributes in a non –mapped class are saved, updated, merged or deleted
    b. It replaces boiler-plate code when loading databases values
    c. It removes the need to have code for saving, updating, merging and deleting objects
    d. It replaces boiler-plate code for saving , updating ,merging and deleting collections.
    e. It ensures collections in a valid mapped class are saved, updated, merged or deleted
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    CascadeType.PERSIST:级联新增(又称级联保存):对order对象保存时也对items里的对象也会保存。对应EntityManager的presist方法
    例子:只有A类新增时,会级联B对象新增。若B对象在数据库存(跟新)在则抛异常(让B变为持久态)

    CascadeType.MERGE:级联合并(级联更新):若items属性修改了那么order对象保存时同时修改items里的对象。对应EntityManager的merge方法
    例子:指A类新增或者变化,会级联B对象(新增或者变化)

    CascadeType.REMOVE:级联删除:对order对象删除也对items里的对象也会删除。对应EntityManager的remove方法
    例子:REMOVE只有A类删除时,会级联删除B类;

    CascadeType.REFRESH:级联刷新:获取order对象里也同时也重新获取最新的items时的对象。对应EntityManager的refresh(object)方法有效。即会重新查询数据库里的最新数据 (用的比较少)

    CascadeType.ALL:以上四种都是

    答案:de



    53) If the java SE method below exists in a superclass:
    protected int getLocalCode(String value, boolean isValidated)
    Which of the following are valid subclass override declarations?
    a. @Override
    public int getLocalCode(String value, boolean isValidated) .
    b. @Override
    protected long getLocalCode(String value, boolean isValidated)
    c. @Override
    protected short getLocalCode(String value, boolean isValidated)
    d. @Override
    protected int getLocalCode(String value, boolean isValidated) throws invalideCodeException
    e. @Override
    protected int getLocalCode(String value, boolean isValidated) .
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    a虽然改大了访问权限, 但是可以的, 想想, 我用 P o = new C() 时, 只要保证Parent类能访问对应的方法就行了。
    反之就不可以

    b. 返回类型改了
    c.同b
    d. 父类无throws的异常, 子类不可以throws
    .若父类中被重写的方法使用了throws的方式处理了异常,那么子类中重写的方法也应该使用throws的方式处理异常,并且其异常类不能超过父类中的异常类

    实测, 子类throws的异常是父类异常的子异常也编译不通过, 简单来讲父类抛出什么异常,子类也抛出什么异常。
    e. 一般写法

    答案:ae



    54) Which of the following statements are valid regarding the Java SE code snippet provided below?
    Import java.io.*;
    public class FileClass{
    public static void main (String[] args) {
    File file = new File(“test.txt”);
    File backup = new File (“test.txt.bak”);
      backup.delete();
    file.renameTo(backup); // Location 1
    }
    }
    a. If before execution: file test.txt containing the line
    Original
    Result: test.txt no longer exits. File test.txt.bak is created containing line
    Original
    b. There will be a runtime error at Location 1 regardless of which files exist before execution.
    c. If before execution: test.txt.bak does not exist
    Result: an IOException is thrown during execution
    d. If before execution: test.txt does not exist
    Result: an empty file test.txt.bak is created
    e. If before execution: file test.txt exists containing the line
    Original
    Result: test.txt remains unchanged and file test.txt.bak is created containing line
    Origina
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23

    只创建File object是不用捕捉异常的, 毕竟File还有exists()方法判断存在与否
    排除bcd
    e迷之操作

    答案:a



    55) Which of the following are features of Servlet in Java EE?
    a. The container calls the servlet’s init(ServletConfig) to pass a ServletConfig reference to the
    servlet
    b. The container calls the servlet’s init(HttpServletRequest) to make the  request object
    available to the servlet.
    c. The servlet can extend HttpRequest or HttpResponse.
    d. The servlet must extend GenericServlet directly
    e. A destroy() method is called after each response to a client.
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    b看不懂
    c. servlet

    答案: a



    56) Which of the following are JTA @TransactionAttribute values for declarative transactions in Java
    EE?
    a. Manadatory
    b. ReadCommited
    c. TransactionMandatory
    d. RequiresNew
    e. Heuristic
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    JTA means Java transaction API
    https://docs.oracle.com/javaee/6/api/javax/ejb/TransactionAttributeType.html

    在这里插入图片描述
    答案: a

    @TransactionAttribute is for EJB3 beans.

    @Transactional is for POJOs (for example Seam, Spring/Hibernate).

    居然考EJB。。
    感觉自己是个智障



    57) Which of the following correctly describe the output from the Java SE program below?
     java.text.ParseException;
    import import java.text.SImpleDateFormat;
    import java.util.Calendar;
    import java.util.Date;
    public class CalendarTest {
    public static void main(Striing[] args) {
    Date aDate= null;
    try {
    aDate = new SimpleDateFormat(“yyyy-mm-dd”).parse(2012-01-15);
    Calendar aCalendar = Calendar.getInstance();
    aCalendar.setTime(aDate);
    System.out.print(aCalendar.get(aCalendar.DAY_OF_M ONTH)+,+aCalendar
    .get(aCalendar.MONTH);
    }
    Catch (ParseException ex) {System.out.println(ex);}
    }
    }
    a.  java.text.ParseException : unparseable date:2012-01-15”
    b. 1,0
    c. 15,1
    d. 1,1
    e. 15,0
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23

    Calendar.MONTH 从零开始
    答案:e
    不是C, 智商不行了



    59. Which of the following correctly describe the output from the java SE program below?
    import java.text.ParseException;
    import java.text.SimpleDateFormat;
    import java.util.Calendar;
    import java.util.Date;
    publicclass Test01 {
    publicstaticvoid main(String[] args) {
    Date aDate =null;
    try{
    aDate =new SimpleDateFormat("yyyy-mm-dd").parse("2012-01-
    15)");
    Calendar aCalendar =Calendar.getInstance();
    aCalendar.setTime(aDate);
    System.out.println(aCalendar.get(aCalendar.DAY_OF_MONTH )+"
    , "+aCalendar.get(aCalendar.MONTH ));
    }catch(ParseException ex){
    System.out.println(ex);
    }
    }
    }
    A. Java.text.Parseexception:Unparseable data:2012-01-15B. 1.0
    C. 15,1
    D. 1,1
    E. 15,0
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25

    同上題基本一樣
    答案e



    60. Which of the following can be result of an attempt to compile and execute
    the java SE code below?
    import java.math.BigDecimal;
    interface Account{
    	BigDecimal balance = new BigDecimal(0.0);
    }
    class SavingAccount implements Account{
    	public SavingAccount(BigDecimal intialValue){
    		balance = intialValue;
    	}
    	public String toString(){
    		return balance.toString();
    	}
    }
    public	class Test25 {
    public	static	void main(String[] args) {
    	SavingAccount instance= newSavingAccount(new BigDecimal(50.00));
    	System.out.println(instance);
    }
    }
    A. Class SavingAccount is the output
    B. 0.00 is output
    C. A compilation error occurs.
    D. A runtime exception is thrown
    E. 50.00 is the output.
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25

    考的是接口, 其實接口的成員都是public static final的
    而方法都是 public abstract的。

    所以。。
    答案: C



    61. Which of the following transition can occur during the life cycle of a
    thread in J2SE 6.0?
    A. New to Runnable.
    B. Terminated to Ready
    C. Blocked to Runnable.
    D. New to Timed_Wating
    E. Runnable to Waiting
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    这题虽然写的是J2SE, 但是考的是线程的状态
    在这里插入图片描述
    答案 :ACE



    62. In a Java EE environment, when setting up input parameters for a
    PreparedStatement, which of the following Java to SQL types mapping are
    valid?
    A. Java int to SQL SMALLINT
    B. Java Struct to SQL BLOB
    C. Java Resultset to SQL RESULTSET
    D. Java char[] to SQL STRING
    E. Java BigDecimal to SQL DECIMAL
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    考得真偏, 投降
    答案:E



    63. Which of the following statements are correct about the java.util.Queue<E> interface in
    Java SE?
    a. The Queue class has 2 constructors, a zero argument constructor and a
    constructor that takes an int param(capacity)
    b. A Queue object orders its elements in a FIFO (First In First Out) mannerc. In a PriorityQueue<Integer>, a call to element is guaranteed to return the
    element with the highest integer value
    d. In a Queue object containing one or more elements, the element and remove
    methods both return the same elemente. In a BlockingQueue<E>, a call to put is guaranteed to block unless the queue is
    full
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    这题上面考过

    答案:bd , 注意的是Queue是接口



    64. Which of the following correctly describe what the command javah – jni FooBar will
    produce?
    a. A library called jni_FooBar.h based on annotated elements in the FooBar class
    b. A Java class called FooBarH which Java used when invoking native code
    c. A Java style header file called jni_FooBar.h based on the annotations in the
    FooBar native library
    d. A C-style application from data elements in the jni_FooBar.java file
    e. A C-style header file called jni_FooBar .h based on the native methods defined in
    the FooBar class
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    上面考过
    答案e



    65.Which of the following statements correctly describe hibernate annotations?
    a. They are the indicators for the database on how to map database table to Java
    objects.
    b. They are embedded metadata in Plain Old Java Objects(POJO).
    c. They cannot be combined with the XML-based configuration
    d. They can be combined with Java Persistent API (JPA) implementations.
    e. They are retrieved by the Java Virtual Machine (VM) at runtime
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    又考过
    答案:abd



    66. Which of the following are valid results of executing the JavaScript code snippet below?
    <bodyonload="hi()"onunload="bye()">
    <scripttype="text/javascript">
    var nm = "";
    function hi(){
    nm = prompt("Hello!your name?", "");
    }
    function bye(){
    alert("GoodBye "+nm);
    }
    </script>
    <ahref="a.html">Click Me !</a>
    </body>
    A. When the user request another URL , a good-bye message is displayed.
    B. After the documents loads, a welcome message is displayed and the user is prompted for a
    name.
    C. The document displays an error message , since all functions must be in the <HEAD> section of
    the document
    D. There is no visible output when the documents loads
    E. A syntax error is displayed when function hi() is executed
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20

    考过
    答案:AB



    67
    Which of the following describe how to create a custom component that uses a UI delegate in Java
    Swing?
    A. Have a component extend from the AWT Component
    Create a subclass of ComponentUI for the custom component.
    Override at least the createUI() and paint() methods
    Override four methods of the Component subclass
    B. Have a component extend from the AWT Container
    Create a subclass of ContainerUI for the custom component.
    Override at least the createUI() and paint() methods
    Override four methods of the Container subclass
    C. Have a component extend from the AWT ComponentOrientation
    Create a subclass of ComponentUI for the custom component.
    Override at least the createUI() and paint() methods
    Override four methods of the ComponentOrientation subclass
    D. Have a component extend from JComponent
    Create a subclass of ComponentUI for the custom component.
    Override at least the createUI() and repaint() methods
    Override four methods of the ComponentOrientation subclass
    E. Have a component extend from JComponent.
    Create a subclass of ComponentUI for the custom component.
    Override at least the createUI() and repaint() methods.
    Override four methods of the JComponent subclass.
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23

    考的又是我的知识盲区, 谁用java写Desktop UI阿。。。
    答案E



    68. Which of the following statement correctly describe Hibernate Caching?
    A. Caching causes extra database activity
    B. Hibernate bypasses the session cache by default
    C. Cached data resides between the application and the database.
    D. Caching frequently queried data will improved application performances.
    E. Hibernate does not support second level caching
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    上面考过
    答案:CD



    69. Which of the accurately describe a checked exception in Java SE?
    A. A subclasses of java.lang.Throwable annotated with @checked
    B. A class that implements java.lang.CheckedException
    C. A subclass of java.lang.Runtimeexception
    D. A subclass of java.lang.CheckedException
    E. A subclass of java.lang.Exception.
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • Checked exception: 继承自 Exception 类是 checked exception。代码需要处理 API 抛出的 checked exception,要么用 catch 语句,要么直接用 throws 语句抛出去。

    - Unchecked exception: 也称 RuntimeException,它也是继承自 Exception。但所有 RuntimeException 的子类都有个特点,就是代码不需要处理它们的异常也能通过编译,所以它们称作 unchecked exception。RuntimeException(运行时异常)不需要强制try…catch…或throws 机制去处理的异常。

    我今天才知道RuntimeException 还有另1个名字 UncheckException。。

    A, Throwable 明显是接口
    B. 没有CheckedException 这玩意
    C. 相反
    D.同上
    E, 正确
    答案:E



    70. A Third Party java application is running out of space on the heap after executing for few
    hours.Which of the following command line argument can be used at application startup to improve the
    situation.?
    A. -Xmx
    -Xms<size> set initial Java heap size
    -Xmx<size> set maximum Java heap size
    -Xss<size> set java thread stack size
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    在这里插入图片描述



    71. If param1 and param2 are local variables, which of the following can be the result of an attempt to
    execute the Java SE code below with different values of param1 and parem2?
    Map<String, Integer> names = Calendar.getInstance().getDisplayNames(Calendar.DAY_OF_WEEK,
    Calendar.LONG, param1);
    try{
    	FileOutputStream fos= new FileOutputStream(“test.txt”);
    	Writer out = new OutputStreamWriter(fos, param2);
    	out.writer(names.toString());
    	out.close();
    }
    Catch (IOException ex){
    	System.out.printn(ex);
    }
    A. param1:Locale.RUSSIAN
    parm2: “UTF-16”
    then this message is output to the console
     java.io.UnsupportedEncodingException : UTF-16
    B. param1:Locale.ENGLISH
    parm2: “UTF-32”
    then test.txt contains:
    {##$% =7, %$#@=6, @#!%=4, $#@%=1, %$#@=5}
    C. parm1: Locale.JAPANESEparam2: “UTF-64”
    then this message is output to the console
     java.io.UnsupportedEncodingException : UTF-64
    D. parm1: Locale.CHINESE
    param2: “UTF-32”
    then test.txt contains:
    {Saturday=7, Thursday=5, Monday=2, Wednesday=4, Friday=6,Sunday=1}
    E. parm1: Locale.ENGLISH -
    param2: “UTF-16”
    then test.txt contains:
    {Saturday=7, Thursday=5, Monday=2, Wednesday=4, Friday=6,Sunday=1}
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32

    第一个参数是语言
    第二个参数是编码

    答案:CE

    72. Which of the following correctly describe the modules of the Spring architecture?
    A. The Context module provides a Web-based framework for integrating Spring’s IoC and DI
    containers through the J2EE Servlet API
    B. The Web module provide transaction management for data access business logic, utilizing
    AOP to inject transaction logic into domain functionality
    C. The inversion of Control(IOC) and dependency Injection (DI) contains , as well as fundamental
    parts of the Spring framework, are provided by the core and Beans modules.
    D. The transaction modules provides and AOP framework to utilize proxies to transparently
    inject any desired business logic into domain functionality.
    E. The Aspect-Oriented Programming(AOP) modules builds on the Core and Business modules to
    provide the ApplicationContext infrastructure, allowing access to object in a framework style.
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    下列哪项正确地描述了Spring体系结构的模块?
    a . Context模块提供了一个基于web的框架,用于通过J2EE Servlet API集成Spring的IoC和DI容器
    B. Web模块为数据访问业务逻辑提供事务管理,利用AOP将事务逻辑注入域功能
    C.控制反转(IOC)和依赖注入(DI)包含的以及Spring框架的基本部分都是由核心模块和bean模块提供的
    D.事务模块提供了一个AOP框架来利用代理透明地将任何所需的业务逻辑注入到域功能中
    E.面向切面编程(AOP)模块构建在核心和业务模块之上,提供ApplicationContext基础设施,允许以框架风格访问对象。

    A, spring context(IOC)容器不是基于web的框架
    E。在软件业,AOP为Aspect Oriented Programming的缩写,意为:面向切面编程,通过预编译方式和运行期间动态代理实现程序功能的统一维护的一种技术。

    控制反转(Inversion of Control,缩写为IoC),是面向对象编程中的一种设计原则,可以用来减低计算机代码之间的耦合度。其中最常见的方式叫做依赖注入(Dependency Injection,简称DI),还有一种方式叫“依赖查找”(Dependency Lookup)。通过控制反转,对象在被创建的时候,由一个调控系统内所有对象的外界实体将其所依赖的对象的引用传递给它。也可以说,依赖被注入到对象中。

    Class A中用到了Class B的对象b,一般情况下,需要在A的代码中显式的new一个B的对象。
    采用依赖注入技术之后,A的代码只需要定义一个私有的B对象,不需要直接new来获得这个对象,而是通过相关的容器控制程序来将B对象在外部new出来并注入到A类里的引用中。而具体获取的方法、对象被获取时的状态由配置文件(如XML)来指定。 [1]

    答案:BCD



    73. Which of the following blocks of code can replace the asterisks oin the Java Swing code
    below to
    import java.util.Locale;
    import java.util.ResourceBundle;
    import javax.swing.JFrame;
    public class SwingInternationalizationDemo {
    public static void main (String[] args) {
    String language;
    String country;
    Locale locale;
    ResourceBundle rb;
    *****
    }
    }
    a. Locale = new Locale();
    rb= ResourceBundle.getBundle(MessageBundle, locale);
    JFrame frame=new JFrame();
    frame.setSize(300,300);
    frame.setTitle(rb.getString(“frameTitle”));
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
    b. language = Locale.getDefault().getLanguage();
    country=Locale.getDefault().getCountry();
    locale=new Locale(language, country);
    rb= new ResourceBundle(MessageBundle, locale);
    JFrame frame=new JFrame();
    frame.setSize(300,300);
    frame.setTitle(rb.getString(“frameTitle”));
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
    .
    c. language = System.getLanguage();
    country = System.getCountry();
    locale=new Locale(language, country);
    rb= ResourceBundle.getBundle(MessageBundle, locale);
    JFrame frame=new JFrame();
    frame.setSize(300,300);
    frame.setTitle(rb.getString(“frameTitle”));
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
    d. language = Locale.getDefault().getLanguage();
    country=Locale.getDefault().getCountry();
    locale=new Locale(language, country);
    rb= ResourceBundle.getBundle(MessageBundle, locale);
    JFrame frame=new JFrame();
    frame.setSize(300,300);
    frame.setTitle(rb.getString(“frameTitle”));
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
    e. locale = new Locale();
    language = System.getDefaultLanguage();
    country = System.getDefaultCountry();
    locale.setLanguage(language);
    locale.setCountry(country);
    rb= ResourceBundle.getBundle(MessageBundle, locale);
    JFrame frame=new JFrame();
    frame.setSize(300,300);
    frame.setTitle(rb.getString(“frameTitle”));
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60

    上面考过了

    其实locale对象应该用new Locale()实例化
    ResourceBundle 用 getBundle()获得对象
    language = System.getLanguage();

    答案:c



    74. 
    public class MyCollection<T> {
    	private Set<T>set;
    	public Set<T> getCollection(){
    		return this.set;
    	}
    	public void TestCollection(MyCollection<?>	collection){
    		//Setset = collection.getCollection();
    	}
    }
    Which of the following code blocks will create a variable from the getCollection’s returned value?
    A. public void TestCollection(MyCollection<?> collection){.
    Set<?> set = collection.getCollection();
    }
    B. public void TestCollection(MyCollection<?> collection){
    <?> set = collection.getCollection();
    }
    C. public void TestCollection(MyCollection<?> collection){
    <T> set = collection.getCollection();
    }
    D. public void TestCollection(MyCollection<?> collection){
    Set<E> set = collection.getCollection();
    }
    E. public void TestCollection(MyCollection<?> collection){
    Set<T> set = collection.getCollection();
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26

    考的是泛型

    ? 表示不确定的 java 类型
    T (type) 表示具体的一个java类型
    K V (key value) 分别代表java键值中的Key Value
    E (element) 代表Element

    T 是一个 确定的 类型,通常用于泛型类和泛型方法的定义,?是一个 不确定 的类型,通常用于泛型方法的调用代码和形参,不能用于定义类和泛型方法。

    答案:AE



    75. In Java SE which of the following statement are true about
    RandomAccessFile class define in java.io package?
    A. The valid RandomAccessFile modes are r, w, and rw
    B. When a RandomAccessFile is created in write only mode it always
    write bytes starting at the file pointer
    C. A RandomAccessFile object can be instantiated in read only mode.
    D. If an existing file is flagged as read only on the file system
    then the RandomAccessFile constructor can throw an “access is
    denied” exception
    E. The RandomAccessFile has a method that returns the offset at
    which the next read or write will take place.
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    此类的实例支持对随机访问文件的读取和写入。随机访问文件的行为类似存储在文件系统中的一个大型 byte 数组。存在指向该隐含数组的光标或索引,称为文件指针;输入操作从文件指针开始读取字节,并随着对字节的读取而前移此文件指针。如果随机访问文件以读取/写入模式创建,则输出操作也可用;输出操作从文件指针开始写入字节,并随着对字节的写入而前移此文件指针。写入隐含数组的当前末尾之后的输出操作导致该数组扩展。该文件指针可以通过 getFilePointer 方法读取,并通过 seek 方法设置。

    下面是零内存追加数据到大文件。

                RandomAccessFile raf=new RandomAccessFile(path, "rw");  
                  
                //将记录指针移动到文件最后  
                raf.seek(raf.length());  
                raf.write("我是追加的 \r\n".getBytes());  
    
    • 1
    • 2
    • 3
    • 4
    • 5

    A,支持 r 和rw模式, 还没见只写模式的~
    B. 同上
    C. 正确
    D. 可以用r模式打开
    E. RandomAccessFile有一个方法,它返回下一次读或写的偏移量(开始位置)。正确

    long getFilePoint():设置文件指针偏移,从该文件的开头测量,发生下一次读取或写入。(前面是文档原文翻译通俗一点就是:返回文件记录指针的当前位置,不指定指针的位置默认是0。)

    void seek(long pos):设置文件指针偏移,从该文件的开头测量,发生下一次读取或写入。(前面是文档原文翻译通俗一点就是:将文件记录指针定位到pos位置。)

    答案:CE
    考的真偏



    76. A company is building a new application which stores all employee information
    @Entity
    public class Company {
    @Id
    @Column(name=”company_id”)
    private String id;
    private String employeeNumber;
    @Column(name=”employee_number”)
    public void setEmployeeNumber (String value) {
    price = value;
    }
    }
    When the above code is executed, a mapping exception is thrown, which of the
    following changes will allow the code to successfully execute?
    a. Add at Line 12:
    public void setId(String value) {
    id = value;
    }
    b. Remove Line 3
    c. Remove Line 4
    d. Move Line 8 to Line 6
    e. Update Line 8 to @Column(name=”employee_number_id”)
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22

    上面考过

    答案:ad



    77. package com.ikm
    class A{
    	public void m1(){
    		System.out.println(A.m1,);
    	}
    	protected void m2(){
    		System.out.println(A.m2, ");
    	}
    	private void m3(){
    		System.out.println(A.m3,);
    	}
    	void m4(){
    		System.out.println(A.m4,);
    	}
    }
    public class B{
    	public static void main(String [] args){
    		A a = new A();
    		a.m1();
    		a.m2();
    		a.m3();
    		a.m4();
    	}
    }
    A. The line a.m4(); causes compilation error.
    B. The program outputs:A.m1, Am2,Am3,Am4.
    C. The line a.m3(); causes compilation error.
    D. The line a.m1(); causes compilation error.
    E. The line a.m2(); causes compilation error.
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29

    最简单的问题了:
    在这里插入图片描述

    答案:C



    78. Which of the following statement can provide transaction services
    In Java EE?
    A. An EJB container can provide transaction services to an applications.
    B. Declarative transaction attributes can be specified to an application
    C. A servlet container cannot provide transaction service to an application.
    D. JTA can be used to roll back a transaction after it has committed.
    E. The Mandatory attribute is the implicit transaction attribute for all enterprise bean
    methods running with container-managed transaction demarcation
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    下面哪个语句可以在Java EE中提供事务服务?
    A. EJB容器可以向应用程序提供事务服务。
    B.声明性事务属性可以指定给应用程序
    C. servlet容器不能为应用程序提供事务服务。
    D. JTA可以用来在事务提交后回滚。
    E. Mandatory属性是所有使用容器管理的事务界定运行的企业bean方法的隐式事务属性

    EJB不懂
    个人觉得答案是:
    AB



    79. A pharmaceutical company has a nightly job which generates metrics for all its active
    research projects. A C++ library call Armadillo is used to generate the metrics. The company
    wants to build a Java application to display the metrics in a web browser. Which of the
    following J2SE 5.0 framework will allow the Java code to access the Armadillo results?
    A. Java Native Interface(JNI).
    B. A Java API for XML Web Service (JAX_WS).
    C. A Java Messaging Services(JMS)
    D. An Enterprise Java Bean(EJB)
    E. A Java Persistence API(JPA
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    都提到J2SE了, 肯定是JNI拉

    答案A

    80. Soon after a Java EE Internet application goes live, intermittent crashes occur. The line of
    code causing the trouble is identified below, where request is the HTTPServletRequest object:
    HttpSession mySession = request.getSession();
    For the cases where a crash is observed, mySession is set to a new Session when an existing
    Session should have been retrieve. Which of the following factors can contribute to this
    problem?
    A. For existing sessions request.setSessionId(String) must be called before getSession.
    B. The Java EE specification does not oblige Web Containers to implement
    HTTPServletRequest.getSession().
    C. The Servlet is using URL rewriting
    D. A web browser has disabled cookies.
    E. web.xml contains the entry <StatelessSession>true</SatelessSession>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    我跟本唔知道呢题问麦7

    答案:A



    
    81. When the code snippet below is executed, the user types “Hello” in the first text control
    and then click the Click Me button. Which of the following statement correctly describe the
    result of performing these steps?
    
    function Pass(){
    document.jane.elements[0].value = document.joe.elements[0].value;
    }
    script>
    head>
    <Body>
    
    
    form>
    
    
    form>
    
    
    form>
    Body>
    html>
    A. The text is moved to the second text control.
    B. The text is recopied in the first text control
    C. Nothing, function Pass() contains an error
    D. The text is deleted from the first test control
    E. The text is copied to the second test control.
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27

    jsp的送分题
    答案 E



    82. Which of the following statement are true about a thread pool in Java SE?
    A. The client of thread pool passes is new threads as they become eligible for executions.
    B. Class java.util.concurrent.ThreadPoolExecution provides an implementation of a thread pool
    C. In a thread pool, any deadlocked threads will be terminated after the time indicated on startup switchDthreadPoolTimeout
    D. A thread pool is generally ineffective in a multi-processor environment
    E. A thread pool can provide good performance in handling large numbers of short-lived tasks.
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    关于Java SE中的线程池,下列哪个说法是正确的?
    A: 线程池传递的客户端是新线程,因为它们有资格执行。
    B: ThreadPoolExecution提供了线程池的实现
    C.在线程池中,任何死锁线程将在启动开关上指示的时间后终止- 线程池超时
    D.线程池在多处理器环境中通常是无效的
    E.线程池在处理大量短期任务时可以提供良好的性能。

    答案BE



    Which of the following statements regarding the usage of the Java SE this() and super()
    keywords are valid?
    a. If used, this() or super() calls must always be the first statements in a constructor
    b. this() and super() can be used in the same (non-constructor) method
    c. If neither this() nor super() is coded then the compiler will generate a call to the zero
    argument superclass constructor
    d. this() and super() calls can be used in methods other than a constructor
    e. this() and super() can be used in the same constructor
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    上面考过
    答案 ac



    84. Which of the following about Exception in Java SE are true?
    A. If a method can throw a subclass of RuntimeException then the method declaration
    must include a throws clause
    B. Throwable is a subclass of Exception
    C. NullReferenceException is a subclass of runtimeException
    D. If a checked exception is thrown by a method then calling method must either catch the
    exception or declare throws.
    E. If an exception is caught then it can re-thrown.
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    A, RuntimeException(uncheck Exception)不用手动处理
    B. Throwable 才是大佬
    C. There is no NullReferenceException in Java. It’s a .NET class, which is the equivalent of Java’s NullPointerException.
    但是NullPointerException 的确是 runtimeException的自雷
    D。 正确
    E。 catch 后可以再throw出去

    答案:DE



    85. Assuming the Student class has a valid Java mapping file, which of the following lines need
    to be updated for Hibernate to successfully map the class below (lines numbers are for
    reference purpose only)?
    1. public class Student{
    2. int id;
    3. List<Course> courses;
    4. String name;
    5.
    6. private Student(){}
    7.
    8. public Student(int id, List<Course>courses, String name){
    9. this.id = id;
    10. this.courses = courses;
    11. this.name = name;
    12. };
    13. //Setter and Getters
    14. }
    A. Remove line 2
    B. Change line 8 to: private Student(int id, List<Courses> courses, String name){
    C. Remove line 3
    D. Change line 6 to: public Student() {}.
    E. Remove lines 9-12
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22

    Hibernate Entity类必须有无参构造 函数
    答案:D



    86. Which of the following statements about Java SE Interfaces are valid?
    A. If two interfaces have in common an identical method signature then a class that
    implements both the interfaces must define the method twice with different
    annotations.
    B. An interface can be implemented as an anonymous inner class.
    C. Methods inside the interface must be declared as public
    D. An abstract class that implements an interface can implement none, some or all
    methods of the interface.
    E. An interface can extends at most one other interface.
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    下列关于Java SE接口的陈述哪一个是有效的?
    a .如果两个接口有相同的方法签名,那么实现这两个接口的类必须用不同的注释定义该方法两次。
    B.接口可以实现为一个匿名内部类。
    C.接口内的方法必须声明为public
    D.实现接口的抽象类可以实现接口的任何方法,也可以实现接口的部分或所有方法。
    e一个接口最多可以扩展一个其他接口。

    A, 只重写1个方法就可以
    B 正确
    C 可以省略 public abstract
    D. 虽然很奇怪, 但是正确的
    E, 一个接口可以extends 多个接口

    答案 BD



    87. Which of the following correctly describe how JDBC objects are objects are obtained in Java
    EE system?
    A. A ResultSet object can be obtained by calling executeQuery() on a Connection object
    B. A ResultSet object can be obtained by calling getResultSet() on a Connection object
    C. A PerparedStatement object can be obtained by calling getPreparedStatement() on a
    ResultSet object
    D. A Connection object can be obtained by calling getConnection() on a DataSource object.
    E. A DataSource object can be obtained by calling getDataSource() on a Connection object
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    考的是JDBC

    在这里插入图片描述

    答案AD



    88. Which of the following describe a part of java SE memory invokes in garbage collection?
    A. Method areas
    B. Constant pools
    C. Null pointers
    D. The stack
    E. The heap
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    gc只会回收堆内存

    答案E

  • 相关阅读:
    从Python代码到诗
    鱼哥赠书活动第②期:《AWD特训营:技术解析、赛题实战与竞赛技巧》《ATT&CK视角下的红蓝对抗实战指南》《智能汽车网络安全权威指南》上下册
    解释器模式
    文章解读与仿真程序复现思路——电力系统自动化EI\CSCD\北大核心《基于网源协同多阶段投资规划的配电网过网费机制设计》
    专访 DePIN 新星 EMC 生态 Bulider:从去中心化信仰中长出的创业理想
    三分钟了解前端javaScript
    Elasticsearch GC优化实践
    Command
    leetcode刷题记录
    万物皆可截图:SwiftUI 中任意视图(包括List和ScrollView)截图的通用实现
  • 原文地址:https://blog.csdn.net/nvd11/article/details/126912729