美文网首页
【IKM在线测试 JAVA】

【IKM在线测试 JAVA】

作者: liuliuzo | 来源:发表于2022-11-29 11:58 被阅读0次

Q1

Which of the following techniques can a Java SE programmer use to increase the thread
safety of a program?
b. Write classes so they are immutable
c. Use ThreadLocal variables

Q3

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?
d. An <init-param> element in web.xml

Q4

Which of the following statements correctly describe lightweight and heavyweight Java
Swing components?
a. Lightweight components are faster in response and performance
d. Heavyweight components depend on native code counterparts to handle their
functionality

e. AWT components are heavyweight, whereas Swing components are lightweight

Q6

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
c. If neither this() nor super() is coded then the compiler will generate a call to the zero
argument superclass constructor

Q7

Which of the following statements are true about variable access between a Java SE
inner class and its containing class?
c. The inner class can access private variables in the containing class
d. The containing class cannot access public variables in the inner class

Q8

In Java EE environment, which of the following statements are valid concerning the
choice of a JDBC driver to access a database?
b. Type 4 drivers exist for MySQL, Oracle, SQL Server and DB2

Q9

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-

Q11

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?
e. MyFileProcessor includes a public closeFiles method that contains code to close the
files. The client calls this method

Q12

The role of Spring in a full fledged Spring Web application is which of the following?
b. It provides only a presentation-tier Web application framework, while the
application-tier and data-tier logic is left to itself

d. It provides the management and configuration of business objects, enabling data
access, integration, and presentation with simple POJOs

Q13

class ExceptionDemo {
    public static void main(String[] args) {
        for (int x=3, int y=0; x>y; x--, y++) {
            System.out.print(x+ ""+y+"");
        }
    }
}

d. A compilation error will occur at line number 3

Q14

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("Inner Catch1");
                throw ex;
            }
        } catch (RuntimeException ex) {
            System.out.println("Inner Catch2");
            throw ex;
        } catch (Exception ex) {
            System.out.println("Outer Catch");
        } finally {
            System.out.println("Inner Finally");
        }
    }
}

5
Inner Catch1
Inner Catch2
Inner Finally
Exception in thread "main" java.lang.ArithmeticException: / by zero

Q18

In Java SE, which of the following from the java.io package are concrete classes that can
be instantiated?
PrintWriter
FilterInputStream

Q19

Which of the following statements are correct about the java.util.Queue<E> interface in
Java SE?
b. A Queue object orders its elements in a FIFO (First In First Out) manner
d. In a Queue object containing one or more elements, the element and remove
methods both return the same element – head element

Q21

Which of the following techniques can resolve an OutOfMemoryError in a Java SE
application?
c. Increase the available JVM heap size.
d. Ensure that references to objects are released when they are no longer needed.

Q22

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";
    }
    public static void main(String[] args) {
        Invoice invoice = new SalesInvoice();
        System.out.println(invoice.formatId("1234"));
        
        SalesInvoice invoice = new SalesInvoice();
        System.out.println(invoice.formatId("1234"));
    }
}

Q23

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?
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.

Q24

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?
d. Agree a strategy where all servlets must access the attribute within the code
block that is synchronized on the context object.

Q25

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);
    }
}

20
1
32
423

总结:
1、类加载到内存时static加载
2、调用类的构造方法时先调用父类的构造方法,再调用子类的构造方法
3、类初始化时,先初始化类的属性成员,在执行构造方法

Q26

public 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());
    }
}

Count = 0
Count = 2

Q27

In the Java SE statement shown below, which of the following accurately describe the
parameter “MyBundle”

ResourceBundle bundle = ResourceBundle.getBundle(“MyBundle”, currentLocale);

d. The name-prefix of a series of property files.

Q28

Which of the following are implementations of the Front Controller pattern for full fledged Spring Web application described by the deployment descriptor below?
d. DispatcherServlet .

Q29

To troubleshoot a problem in a live system, a class is modified slightly resulting in the
code shown below:
d. Processing ends abnormally with a NullPointerException .

Q30

Which of the following Java Native Interface (JNI) types and keywords map to their
machine-dependent Java equivalents?
void : void
jlong : long

Q33

Which of the following statements correctly describe Hibernate caching?
b. Caching dynamic data will improve application performance
d. Cached data resides between the application and the database

Q39

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

Q41

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
Ans: a

Q44

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.
d. An entity instance corresponds to a table row.
e. An entity is a POJO annotated with the @Entity annotation.

Q59

public class CalendarTest {
    public static void main(String[] args) {
        try {
            Date aDate = new SimpleDateFormat("yyyy-mm-dd").parse("2023-01-03");
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(aDate);
            System.out.println(calendar.get(calendar.DAY_OF_MONTH) + "," + calendar.get(calendar.MONTH));
            int year = calendar.get(Calendar.YEAR);
            int month = calendar.get(Calendar.MONTH)+1; //获取到的月份范围是0-11,所以要+1
            int day = calendar.get(Calendar.DAY_OF_MONTH);
            String tempDate = year + "年" + month + "月" + day + "日";
            System.out.println(tempDate);           
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Q60

  1. Which of the following can be result of an attempt to compile and execute the java SE code below?

Q70

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 ?

-Xms<size> set initial Java heap size
-Xmx<size> set maximum Java heap size
-Xss<size> set java thread stack size

Q72

Which of the following correctly describe the modules of the Spring architecture?
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.

Q73

//错误,传入T的参数给ArrayList,返回的结果也应该是T类型的
List<?> list = new ArrayList<T>();
//因为ArrayList必须是一种类型,得到的也是同一种类型
List<?> list2 = new ArrayList<?>();
//正确
List<T> list3 = new ArrayList<T>();

List<Student> list1 = new ArrayList<>();
list1.add(new Student("张三",18));
//这里如果add(new Teacher(...))就会报错,因为我们已经给List指定了数据类型为Student

//这里我们并没有给List指定具体的数据类型,?泛指可以存放多种类型
List<?> list2 = new ArrayList<>();
list2.add(new Student("李四",20));
list2.add(new Teacher("王五",40));

相关文章

网友评论

      本文标题:【IKM在线测试 JAVA】

      本文链接:https://www.haomeiwen.com/subject/whrdfdtx.html