重庆大学 2012-2013学年第1学期Java试卷(B卷) 下载本文

内容发布更新时间 : 2024/12/27 0:26:13星期一 下面是文章的全部内容请认真阅读。

Note: Write all your answers on the Answer Sheets.

SECTION 1: Choose ONE Correct Answer to Each Question (30

6. Which is correct about Applet? ( B ) points, 2 points each)

1. Which method is used to draw a string starting at point(x,y)? ( B )

A. drawImage B. drawString C. drawRect

D. drawLine

2. Which of the following are methods of the Runnable interface? ( A )

A. run B. start C. yield

D. stop

3. Which class can be used to create a socket in server side to wait for connection

request from client? (B ) A. Socket

B. ServerSocket C. DatagramSocket

D. URL

4. To handle mouse dragged event, which interface should be implemented?

( B )

A. MouseListner

B. MouseMotionListner C. MouseWheelListener

D. MouseAdapter

5. Which kind of file is used to distribute a collection of JavaServer Pages, Java

Servlets, Java classes, HTML files and other resources that together constitute a Web application? ( B )

A. war file B. jar file

C. zip file

D.

rar file

A. Applet is same as Servlet

B. Applet can be executed with browser C. Some Applets can be used in mobile phone D. Applet is a Java program which runs in web server 7. Which of the following statement is true? ( A )

A. A byte can represent between -128 to 127 B. A byte can represent between -127 to 128 C. A byte can represent between -256 to 256

D. A char can represent between -2*216 to 2*216-1(char确实是两个字节,但是没有符号位0~65535)

8. An Applet has its Layout Manager set to the default of FlowLayout. Which code would be correct to change to another Layout Manager? (B ) A. setLayoutManager(new GridLayout()); B. setLayout(new GridLayout(2,2)); C. setGridLayout(2,2); D. setBorderLayout();

9. Which of the following statements is NOT true? ( B )

A. If a class has any abstract methods it must be declared abstract itself. B. All methods in an abstract class must be declared as abstract

C. When applied to a class, the final modifier means it cannot be sub-classed D. transient and volatile are Java modifiers 10. Which of the following statement is true? ( B )

A. Constructors cannot have a visibility modifier

B. Constructors can be marked public and protected, but not private C. Constructors can only have a primitive return type D. Constructors cannot be inherited

11. Which of the following statements is NOT true?C

A. All of the variables in an interface are implicitly static B. All of the variables in an interface are implicitly final C. All of the methods in an interface are implicitly abstract D. A method in an interface can access class level variables 12. Which of the following statements is NOT true? ( C )

A. static methods do not have access to the implicit variable called this B. A static method may be called without creating an instance of its class C. A static method may not be overridden to be non-static D. A static method may not be overloaded

13. What will happen when you attempt to compile and run this code? ( D )

public class MyMain{

public static void main(String argv){ System.out.println(\

} }

A. The compiler will complain that main is a reserved word and cannot be used for a class

B. The code will compile and when run will print out \C. The code will compile but will complain at run time that no constructor is defined

D. The code will compile but will complain at run time that main is not correctly defined

14. You want to find out the value of the last element of an array. You write the

following code. What will happen when you compile and run it.?B

public class MyAr{

public static void main(String argv[]){ int[] i = new int[5]; System.out.println(i[5]);

} }

A. An error at compile time B. An error at run time C. The value 0 will be output D. The string \

15. In JDBC, the type of VARCHAR in DBMS can be mapping to_____A____ type in Java. A. String

B. Integer

C. boolean

D. Character

SECTION 2: Fill in the Blanks (20 points, 2 points each)

1. ____start()_____method is used to start a thread.

2.___ servlet _____ is programmed with Java and can be running in Java Application Server.

3. __InputStream_______ can be used to create input stream after getting connected socket.

4.___ JSP______ is a technology that creates dynamically generated web pages based on HTML and JAVA.

5. The ____synchronized_____ keyword provides the protection for the crucial sections that are required only to be executed by a single thread once at a

time.

6. The modifiers of member visibility in a class include public, private, protected

and __default_______.

7. __Tomcat_______ is an open source web server and servlet container

developed by the Apache Software Foundation.

8. substring(beginIndex, endIndex) of String class returns a new string that

void printMe() { System.out.println(\ } void printAll() { this.printMe(); } }

begins at the specified beginIndex and extends to the character at index ___endIndex-1______.

9. Class __Object_______ is the root of the Java class hierarchy. 10. __JDK_______ must be installed before running a Java program.

SECTION 3: Answer the Following Questions (20 points, 5 points each)

1. Describe the relationships and differences between Servlet and JSP.

JSP主要关注于HTML(或者XML)与Java代码的结合,以及加入其中的JSP标记。如果一个支持JSP的服务器遇到一个JSP页面,它首先查看该页面是否被编译成为一个servlet。由此可见,JSP被编译成servlet,即被转变为纯Java,然后被装载入服务器执行。当然,这一过程,根据不同的JSP引擎而略有不同

2. Briefly illustrate the lifecycle of android application. 3. Describe how to upload files using Servlet 3.0.

4. Describe the fundamental components in android application framework.

SECTION 4: Give the Output of the Following Programs (30

points, 5 points each)

1.

class Collection{

class Set extends Collection { void printMe() { System.out.println(\ } void printAll() { super.printMe(); this.printMe(); printMe(); } }

public class Test_this { public static void main(String args[]) { Collection collection = new Set(); collection.printAll(); } }

2.

package test;

import java.io.File;

import java.io.PrintWriter; import java.util.ArrayList; import java.util.Scanner; import java.util.TreeSet; public class Test { public static void main(String[] args) throws Exception {