都是自己做的,可能有错
PART 1: The essential of java
1. Given the following code, what test would you need to put in place of the comment line?
//place test here
to result in an output of the string Equal
public class EqTest{
public static void main(String argv[]){
EqTest e=new EqTest();
}
EqTest(){
String s="Java";
String s2="java";
//place test here {
System.out.println("Equal");
}else
{
System.out.println("Not equal");
}
}
}
A) if(s==s2)
B) if(s.equals(s2)
C) if(s.equalsIgnoreCase(s2))
D) if(s.noCaseMatch(s2))
题目意思是让s1和s2相等,添加判断条件,所以只能是忽略大小写了
选C
2. Given the following code how could you invoke the Base constructor that will print out the string "base constructor";
class Base{
Base(int i){
System.out.println("base constructor");
}
Base(){
}
}
public class Sup extends Base{
public static void main(String argv[]){
Sup s= new Sup();
//One
}
Sup()
{
//Two
}
public void derived()
{
//Three
}
}
A. On the line After //One put Base(10);
B. On the line After //One put super(10);
C. On the line After //Two put super(10);
D. On the line After //Three put super(10);
调用父类构造方法,选C
3. What is the value of seasons.length for the following array?
String[] seasons = {"winter", "spring", "summer", "fall", };
A. undefined
B. 3
C. 4
D. 5
字符串数组长度,最后一个逗号只是为了格式需要,有时可以动态生成数组,可有可无
所以只有4个元素
选C
4. When you use the new keyword to create an object, where is it created?
A. Heap
B. Garbage collector
C. Queue
D. Stack
使用new创建对象时会创建在哪儿
这里又分两种情况如果是普通的Book book = new Book();对象放在堆里,而对象名,即其引用,是放在栈中,同时,八个基本类型不属于对象,所以放在栈中,局部变量也放在栈中。
根据题意应该选A
5.What will happen if you attempt to compile and run the following code?
class Base {}
class Sub extends Base {}
class Sub2 extends Base {}
public class CEx{
public static void main(String argv[]){
Base b=new Base();
Sub s=(Sub) b;
}
}
A. Compile and run without error
B. Compile time Exception
C. Runtime Exception
会产生java.lang.ClassCastException应该选C吧
6. An overridden method can be in the same class.
A. True
B. False
注意分清overload和override
前者是重载后者是覆写
重载是方法名相同即可,即为重载,返回值和参数都可以不同
重要的是,重载可以出现在一个类中
而覆写,顾名思义,就是重新写,这种情况大多数放生在子类继承父类,然后覆盖了父类的一个方法
重写的方法必须具备:同名,返回值相同,参数数目相同,参数类型也必须相同,唯一的区别在于重新定义了方法。
重载 |
重写 |
同在父类(或子类)中或一个在父类和一个在子类 |
一个父类,一个子类 |
1.参数类型不同 |
1.返回值相同,参数数目相同,参数类型也必须相同 |
所以选B
7.Given the following code
import java.io.*;
public class Th{
public static void main(String
argv[]){
Th t = new Th();
t.amethod();
}
public void amethod(){
try{
ioCall();
}catch(IOException ioe){}
}
}
What code would be most likely for the body of the ioCall method
A. public void ioCall (){
DataInputStream din = new DataInputStream(System.in);
din.readChar();
}
B. public void ioCall ()throw IOException{
DataInputStream din = new DataInputStream(System.in);
din.readChar();
}
C. public void ioCall ()throws IOException{
DataInputStream din = new DataInputStream(System.in);
din.readChar();
}
D. public void ioCall throws IOException(){
DataInputStream din = new DataInputStream(System.in);
din.readChar();
}
AD语法就有问题可以排除
接下来就是throw和throws的问题了
既然外边都catch exception了你总得抛出异常不是。
throw关键字通常用在方法体中,并且抛出一个异常对象。程序在执行到throw语句时立即停止,它后面的语句都不执行。通过throw抛出异常后,如果想在上一级代码中来捕获并处理异常,则需要在抛出异常的方法中使用throws关键字在方法声明中指明要跑出的异常;如果要捕捉throw抛出的异常,则必须使用try—catch语句。
throws关键字通常被应用在声明方法时,用来指定可能抛出的异常。多个异常可以使用逗号隔开。当在主函数中调用该方法时,如果发生异常,就会将异常抛给指定异常对象。
很明显选C了
8. How do you force the garbage collector to run?
A. Call System.gc()
B. Call Runtime.gc()
C. Either A or B
D. There is nothing you can do
C
为了方便Runtime.gc()封装在System.gc()里了,所以都可以
9. When multiple methods exist within the same class with different method signatures, this is known as what?
A. Method overloading
B. Overriding methods
C. Message passing
D. A headache
题目的意思主要是method signatures即方法签名
函数签名就是把函数名字去掉以后剩下的东西(返回值、参数、调用方式等)。
函数在重载时,利用函数签名的不同(即参数个数与类型的不同)来区别调用者到底调用的是那个方法。
所以选A
10. What's printed when the following program is executed: class PrintMe {
public void do(int character) {
System.out.println(character+character);
}
public static void main (String args[]) {
new PrintMe().do('A');
}
}
A. AA
B. 130 (The ASCII value of A is 65)
C. Does not compile
B.向上转型
11. What will be printed out if you attempt to compile and run the following code?
int i=9;
switch (i) {
default:
System.out.println("default");
case 0:
System.out.println("zero");
break;
case 1:
System.out.println("one");
case 2:
System.out.println("two");
}
A. default
B. default, zero
C. error default clause not defined
D. no output displayed
B,没有break的话会一直执行下去,直到碰到break
12.What will be the result of attempting to compile and run the following code?
abstract class MineBase {
abstract void amethod();
static int i;
}
public class Mine extends MineBase {
public static void main(String argv[]){
int[] ar=new int[5];
for(i=0;i < ar.length;i++)
System.out.println(ar[i]);
}
}
A. a sequence of 5 0's will be printed
B. Error: ar is used before it is initialized
C. Error: Mine must be declared abstract
D. IndexOutOfBoundes Error
C,抽象方法没实现那么你也是抽象类哦
Part 2 . The essential of jdbc
1. If you need to use a stored procedure with output parameters, which of the following statement type should be used to call the procedure?
A. Statement
B. PreparedStatement
C. CallableStatement
如果存储过程需要输出参数,根据概念只有callableStatement可以输出参数
选C
2. Which of the following will not cause a JDBC driver to be loaded and registered with the DriverManager?
A. Class.forName(driverString);
B. new DriverClass();
C. Include driver name in jdbc.drivers system property
D. None of the above
D,找到一篇blogs,很详细http://www.cnblogs.com/elleniou/archive/2013/04/16/3024994.html
3. From which object do you ask for DatabaseMetaData?
A. Connection
B. ResultSet
C. DriverManager
D. Driver
A、 DatabaseMetaData metadata = conn.getMetaData();
4. If one intends to work with a ResultSet, which of these PreparedStatement methods will not work?
A. execute()
B. executeQuery()
C. executeUpdate()
C.不会。。。请指教
5. Can a ResultSet be reliably returned from a method that creates a Statement and executes a query?
A. Yes
B. No
不会。。。请指教
6. How can I use JDBC to create a database?
A. Include create=true at end of JDBC URL
B. Execute "CREATE DATABASE jGuru" SQL statement
C. Execute "STRSQL" and "CREATE COLLECTION jGuru" SQL statements
D. Database creation is DBMS specific
D 不会
7. Which character is used to represent an input parameter in a CallableStatement?
A. %
B. *
C. ?
D. #
C.查的
8. Which one of the following will not get the data from the first column of ResultSet rs, returned from executing the following SQL statement: SELECT name, rank, serialNo FROM employee.
A. rs.getString(0);
B. rs.getString("name");
C. rs.getString(1);
A,rs.getString()之间的参数可以是int值也可以是列名字符串,如果是int值,则值代表第几列,第一列是name所以C应该可以
9. Which of the following can you do with a JDBC 2.0 database driver that you cannot with a JDBC 1.x driver?
A. Batch multiple statements, to be sent to the database together
B. Scroll through result sets bi-directionally
C. Work with SQL3 data types directly
D. All of the above
D.百度下新特性吧
10. Which class contains the transaction control methods setAutoCommit, commit, and rollback?
A. Connection
B. Statement
C. ResultSet
C,这些是结果集的功能
Part 3 . The essential of xml
1. There is a way of describing XML data, how?
A. XML uses XSL to describe data
B. XML uses a description node to describe data
C. XML uses a DTD to describe the data.
D. XML uses a SCHEMA to describe the data.
C
2. What is the correct syntax of the declaration which defines the XML version?
A. <?xml version="1.0" />
B. <?xml version="1.0"?>
C. <xml version="1.0" />
B
3.Which one is this a correct XML document?
A.
<?xml version="1.0"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
B.
<?xml version="1.0"?>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
C.
<?xml version="1.0"?>
<note>
<to>Tove</to>
<to>kiko</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
A.其实我是觉得AC都可以的,但是如果只能选一个的话,只能舍弃C了
4. Which statement is true?
A. All XML elements must be lower case
B. All XML documents must have a DTD
C. All XML elements must have a closing tag
D. All the statements are true
C
- 1. XML大小写敏感,可用大写
- 2. Scheme模式也可以阿
5. Which statement is true?
A. XML documents must have a root tag
B. XML elements must be properly nested
C. XML tags are case sensitive
D. All the statements are true
选D,全对
6. Which is not a correct name for an XML element?
A. All 3 names are incorrect
B. <age>
C. <first name>
D. <NAME>
E. <xmlDoc>
XML 元素必须遵循以下命名规则:
- 名称可以含字母、数字以及其他的字符
- 名称不能以数字或者标点符号开始
- 名称不能以字符 “xml”(或者 XML、Xml)开始
- 名称不能包含空格
选C
PART FOUR:The essential of JSP
1. Choose the statement that best describes the relationship between JSP and servlets:
A. Servlets are built on JSP semantics and all servlets are compiled to JSP pages for runtime usage.
B. JSP and servlets are unrelated technologies.
C. Servlets and JSP are competing technologies for handling web requests. Servlets are being superseded by JSP, which is preferred. The two technologies are not useful in combination.
D. JSPs are built on servlet semantics and all JSPs are compiled to servlets for runtime usage.
选D.JSP运行时都会转成Servlet,实际上每一个JSP都是一个Servlet,所以A错,JSP和Servlet当然有关系,B错,C选项前面都说的很对,最后一句错了。
2. Why use RequestDispatcher to forward a request to another resource, instead of using a sendRedirect?
A. Redirects are no longer supported in the current servlet API.
B. Redirects are not a cross-platform portable mechanism.
C. The RequestDispatcher does not use the reflection API.
D. The RequestDispatcher does not require a round trip to the client, and thus is more efficient and allows the server to maintain request state.
D
3. What type of scriptlet code is better-suited to being factored forward into a servlet?
A. Code that deals with logic that is common across requests.
B. Code that deals with logic that is vendor specific.
C. Code that deals with logic that relates to database access.
D. Code that deals with logic that relates to client scope.
C
4. Choose the statement that best describes how to connect JSP pages and Enterprise JavaBeans (EJBs):
A. Lookup the EJBs from within a JSP, but use the EJBs from within a basic JavaBean.
B. Lookup and use the EJBs from a separate business delegate. The JavaBeans that work with JSP pages are clients to these business delegates and know nothing about EJB specifics.
C. Lookup and use the EJBs from within a JSP page, but only as remote references.
D. Lookup the EJBs from within a servlet, delegating usage to specific JSP pages.
不会EJB,B
5. Are custom tags available in JSP 1.0? If not, how else might you implement iteration from within a JSP?
A. Yes, but the only tags available relate to database access.
B. No. To iterate over a collection of values, one must use scriptlet code.
C. No, but there is a standard <iterate> tag that may be used.
D. Yes, but custom tags will not help developers create tags for use in iterating over a collection.
The answer is:D
6. What is the difference between doing an include or a forward with a RequestDispatcher?
A. The forward method transfers control to the designated resource, while the include method invokes the designated resource, substitutes its output dynamically in the display, and returns control to the calling page.
B. The two methods provide the same functionality, but with different levels of persistence.
C. The forward method is deprecated as of JSP 1.1 and the include method should be used in order to substitute portions of a dynamic display at runtime.
D. The include method transfers control to a dynamic resource, while the forward method allows for dynamic substitution of another JPS pages output, returning control to the calling resource.
The answer is:D
7. What line of code below might be combined in the same JSP page with a validation guard (for example, <% bean.validationGuard(); %> ), in order to create an alternate flow of control for scenarios in which exceptions arise. The validationGaurd method might throw an exception, which should cause the flow of control to continue in another user-defined page (assume JSP 1.0).
A. <jsp:error page="errorPage.jsp" guard="true" />
B. <%@ page language="java" buffer="8k" %>
C. <jsp:useBean id="bean" class="examples.Bean" scope="request" />
D. <%@ page language="java" errorPage="errorPage.jsp" buffer="8k" %>
PART FIVE: The essential of SQL92
1) Given the table:
STAFF
ID LASTNAME
1 Jones
2 Smith
3 <null>
Which of the following statements removes all rows from the table where there is a NULL value for LASTNAME?
A. DELETE FROM staff WHERE lastname IS NULL
B. DELETE FROM staff WHERE lastname = 'NULL'
C. DELETE ALL FROM staff WHERE lastname IS NULL
D. DELETE ALL FROM staff WHERE lastname = 'NULL'
A
2) Given the tables:
COUNTRY
ID NAME PERSON CITIES
1 Argentina 1 10
2 Canada 2 20
3 Cuba 2 10
4 Germany 1 0
5 France 7 5
STAFF
ID LASTNAME
1 Jones
2 Smith
How many rows would be returned using the following statement?
SELECT * FROM staff, country
A. 0
B. 2
C. 5
D. 7
E. 10
E.
3) Which of the following statements eliminates all but one of each set of repeated
rows in the final result table?
A. SELECT UNIQUE * FROM t1
B. SELECT DISTINCT * FROM t1
C. SELECT * FROM DISTINCT T1
D. SELECT UNIQUE (*) FROM t1
E. SELECT DISTINCT (*) FROM t1
4) Given the two table definitions:
ORG
deptnumb INTEGER
deptname CHAR(30)
manager INTEGER
division CHAR(30)
location CHAR(30)
STAFF
id INTEGER
name CHAR(30)
dept INTEGER
job CHAR(20)
years INTEGER
salary DECIMAL(10,2)
comm DECIMAL(10,2)
Which of the following statements will display all departments, alphabetically by
department name, and the name of the manager of each department?
A. SELECT a.deptname, b.name FROM org a, staff b WHERE b.manager=a.id
B. SELECT a.deptname, b.name FROM org a, staff b WHERE b.manager=a.id GROUP BY a.deptname, b.name
C. SELECT a.deptname, b.name FROM org a, staff b WHERE a.manager=b.id ORDER BY a.deptname, b.name
D. SELECT a.deptname, b.name FROM org a, staff b WHERE a.manager=b.id GROUP BY b.name ORDER BY a.deptname
5) Given the following table definitions:
DEPARTMENT
deptno CHAR(3)
deptname CHAR(30)
mgrno INTEGER
admrdept CHAR(3)
EMPLOYEE
empno INTEGER
firstname CHAR(30)
midinit CHAR
lastname CHAR(30)
workdept CHAR(3)
Which of the following statements will produce a result set satisfying these criteria?
The empno and lastname of every employee
For each employee, include the empno and lastname of their manager
Includes employees both with and without a manager
A. SELECT e.empno, e.lastname FROM employee e LEFT OUTER JOIN
(department INNER JOIN employee m ON mgrno = m.empno)
ON e.workdept = deptno
B. SELECT e.empno, e.lastname, m.empno, m.lastname FROM employee e LEFT INNER JOIN
(department INNER JOIN employee m ON mgrno = m.empno)
ON e.workdept = deptno
C. SELECT e.empno, e.lastname, m.empno, m.lastname FROM employee e LEFT OUTER JOIN
(department INNER JOIN employee m ON mgrno = m.empno)
ON e.workdept = deptno
D. SELECT e.empno, e.lastname, m.empno, m.lastname FROM employee e RIGHT OUTER JOIN
(department INNER JOIN employee m ON mgrno = m.empno)
ON e.workdept = deptno