Chapter1 基础知识
//
Java API contains predefined classes and interfaces for developing Java programs.
Java API包含用于开发Java程序的预定义类和接口。
.
Java JDK consists of a set of separate programs for developing and testing Java programs, each of which is invoked from a command line.
Java JDK由一组用于开发和测试Java程序的独立程序组成,每个程序都是从命令行调用的。
.
Java language specification is a technical definition of the language that includes the syntax and semantics of the Java programming language.
Java语言规范是一种语言的技术定义,它包括Java编程语言的语法和语义。
//
Due to security reasons, Java ___________ cannot run from a Web browser in the new version of Java.
A.
applications
B.
applets
C.
servlets
D.
Micro Edition programs
小程序是不能移动的
If a program compiles fine, but it produces incorrect result, then the program suffers __________.
A.
a compilation error
B.
a runtime error
C.
a logic error
A block is enclosed inside __________. braces
A.
parentheses 圆括号
B.
braces 花括号
C.
brackets 方括号
D.
quotes 引号
Chapter2
1)A Java character is stored in ________.
A)three bytes B) two bytes
C)one byte D) four bytes
JAVA中,char占2字节,16位,可在存放汉字。
Math.pow(4, 1 / 2) returns __________.
A.2
B.2.0
C.0
D.1.0
E.1
答案为1.0的原因是:1/2 = 0, pow(4,0) = 1.0
Which of the following is incorrect?
A.int x = 9;
B.long x = 9;
C.float x = 1.0;
D.double x = 1.0;
float 类型初始化的时候不能用 float x = 1.0; 1.0是double类型, 要改成1
调用System.currentTimeMillis()
To obtain the current second, use ___System.currentTimeMillis() / 1000 % 60
To obtain the current minute,use ____System.currentTimeMillis() / 1000 / 60 % 60
To obtain the current hour in UTC,use____System.currentTimeMillis() / 1000 / 60 / 60 % 24
2)Which of the following statement prints smith\exam1\test.txt?
A)System.out.println("smith\exam1\test.txt");
B)System.out.println("smith\\exam1\\test.txt");
C)System.out.println("smith"\exam1"\test.txt");
D)System.out.println("smith"exam1"test.txt");
对\进行转义
3)An int variable can hold ________. (Choose all that apply.)
A)120.0 B) 120 C) "120" D) "x" E) 'x'
int型可以用来存放整型和字符类型
4)The ________ method parses a string s to an int value.
A)integer.parseInt(s); B)Integer.parseInteger(s); C)integer.parseInteger(s); D) Integer.parseInt(s);
5)The ________ method parses a string s to a double value.
A)Double.parsedouble(s); B) double.parse(s);
C)double.parseDouble(s); D) Double.parseDouble(s);
Chapter 3 操作符
6)________ is the code with natural language mixed with Java code.
A)A flowchart diagram B) Java program C)A Java statement D) Pseudocode
flowchart diagram 流程图
Pseudocode 伪代码
9)Analyze the following code:
boolean even = false;
if (even = true) {
System.out.println("It is even!");
}
A)The program has a runtime error.
B)The program runs fine, but displays nothing.
C)The program has a compile error.
D)The program runs fine and displays It is even!.
注意这里是赋值=号!!!
注意这里的判断, x-- x++都不进行
17)Suppose x=10 and y=10. What is x after evaluating the expression (y > 10) && (x-- > 10)?
A)9 B) 11 C) 10
18)Suppose x=10 and y=10 what is x after evaluating the expression (y > 10) && (x++ > 10)?
A)11 B) 10 C) 9
19)Suppose x=10 and y=10 what is x after evaluating the expression (y >= 10) || (x-- > 10)?
A)11 B) 9 C) 10
20)Suppose x=10 and y=10 what is x after evaluating the expression (y >= 10) || (x++ > 10)?
A)10 B) 9 C) 11
B)The switch control variable cannot be double.
31)Which of the following are valid specifiers for the printf statement? (Choose all that apply.)
A)%4c B)%10.2e C)%10b D)%6d E)%8.2d
%c 字符输出 %e 标准科学记数法形式的数 %d 十进制整数输出
To check if a string s contains the prefix "Java", you may write ______. ABCD
A.
if (s.startsWith("Java")) ...
B.
if (s.indexOf("Java") == 0) ...
C.
if (s.substring(0, 4).equals("Java")) ...
D.
if (s.charAt(0) == 'J' && s.charAt(1) == 'a' && s.charAt(2) == 'v' && s.charAt(3) == 'a'
To check if a string s contains the suffix "Java", you may write ______. ACE
A.
if (s.endsWith("Java")) ...
B.
if (s.lastIndexOf("Java") >= 0) ...
C.
if (s.substring(s.length() - 4).equals("Java")) ...
D.
if (s.substring(s.length() - 5).equals("Java")) ...
E.
if (s.charAt(s.length() - 4) == 'J' && s.charAt(s.length() - 3) == 'a' && s.charAt(s.length() - 2) == 'v' && s.charAt(s.length() - 1) == 'a') ...
Which of the following is not a correct method in the Character class? CE
A.
isLetterOrDigit(char)
B.
isLetter(char)
C.
isDigit()
D.
toLowerCase(char)
E.
toUpperCase()
Chapter4 循环
21)After the continue outer statement is executed in the following loop, which statement is executed?
outer:
for (int i = 1; i < 10; i++) {
inner:
for (int j = 1; j < 10; j++) {
if (i * j > 50)
continue outer;
System.out.println(i * j);
}
}
next:
A)The program terminates.
B)The statement labeled next.
C)The control is in the inner loop, and the next iteration of the inner loop is executed.
D)The control is in the outer loop, and the next iteration of the outer loop is executed.
外部循环是outer 跳转到outer
控件位于外部循环中,执行外部循环的下一个迭代。
24)Suppose the input for number is 9. What is the output from running the following program?
import java.util.Scanner;
public class Test {
public static void main(String[ ] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter an integer: ");
int number = input.nextInt();
int i;
boolean isPrime = true;
for (i = 2; i < number && isPrime; i++) {
if (number % i == 0) {
isPrime = false;
}
}
System.out.println("i is " + i);
if (isPrime)
System.out.println(number + " is prime");
else
System.out.println(number + " is not prime");
}
}
A)i is 4 followed by 9 is prime
B)i is 4 followed by 9 is not prime
C)i is 3 followed by 9 is prime
D)i is 3 followed by 9 is not prime
本题如果输入的不是素数,那么要找的第一个与输入的数不互质的数的后一个数;如果是素数,就返回输入的数本身。注意i++!! 跳出循环时,还要进行一次i++
Chapter5 方法
17)A variable defined inside a method is referred to as ________.
A)a method variable B) a global variable C)a block variable D) a local variable
在方法内部定义的变量称为局部变量
18)The client can use a method without knowing how it is implemented. The details of the implementation are encapsulated in the method and hidden from the client who invokes the method. This is known as ________. (Choose all that apply.)
A)encapsulation B) information hiding C)simplifying method D) method hiding
封装和信息隐藏
29)________ is to implement one method in the structure chart at a time from the top to the bottom.
A)Top-down approach
B)Bottom-up and top-down approach
C)Bottom-up approach
D)Stepwise refinement
自顶向下的方式是在结构图中从上到下依次实现一个方法。
30)________ is a simple but incomplete version of a method.
A)A stub
B)A main method
C)A method developed using top-down approach
D)A non-main method
待实现的方法可以用存根方法(stub)代替,存根方法是方法的一个简单但不完整的版本。使用存根方法可以快速地构建程序的框架。
Chapter 6 一维数组
10)How can you initialize an array of two characters to 'a' and 'b'? (Choose all that apply.) A,D;
A)char[ ] charArray = {'a', 'b'};
B)char[2] charArray = {'a', 'b'};
C)char[ ] charArray = new char[2]; charArray = {'a', 'b'};
D)char[ ] charArray = new char[ ]{'a', 'b'};
A)The program has a compile error because xMethod(new double[3]{1, 2, 3}) is incorrect.
0开头表示八进制整数直接量!! 016 = 14
16)In the following code, what is the printout for list1?
class Test {
public static void main(String[ ] args) {
int[ ] list1 = {1, 2, 3};
int[ ] list2 = {1, 2, 3};
list2 = list1;
list1[0] = 0; list1[1] = 1; list2[2] = 2;
for (int i = 0; i < list1.length; i++)
System.out.print(list1[i] + " ");
}
}
A)1 2 3 B) 0 1 2 C) 0 1 3 D) 1 1 1
将list1的引用赋给list2,list1和list2指向内存中的同一块区域
28)The JVM stores the array in an area of memory, called ________, which is used for dynamic memory allocation where blocks of memory are allocated and freed in an arbitrary order. A)dynamic memory B) memory block C)stack D) heap ##heap
Java中的数组可以看出一个特殊的对象,声明时放在栈中,分配的空间存储在堆中。
41)Assume int[ ] scores = {1, 20, 30, 40, 50}, what value does java.util.Arrays.binarySearch(scores, 3) return? 41) C
A)1 B) -1 C) -2 D) 2 E) 0
-(insertion point + 1)
binarySearch()方法的返回值为:1、如果找到关键字,则返回值为关键字在数组中的位置索引,且索引从0开始2、如果没有找到关键字,返回值为负的插入点值,所谓插入点值就是第一个比关键字大的元素在数组中的位置索引,而且这个位置索引从1开始。
Chapter7 多维数组
1)Which of the following statements are correct? 1) _______
A)char[ ][ ] charArray = {{'a', 'b'}, {'c', 'd'}};
B)char[2][2] charArray = {{'a', 'b'}, {'c', 'd'}};
C)char[2][ ] charArray = {{'a', 'b'}, {'c', 'd'}};
D)char[ ][ ] charArray = {'a', 'b'};
二维数组静态初始化[ ][ ]不允许出现数字
6)Which of the following statements are correct? (Choose all that apply.) 6) _______
A)char[ ][ ][ ] charArray = new char[2][2][ ];
B)char[ ][ ][ ] charArray = {{{'a', 'b'}, {'c', 'd'}, {'e', 'f'}}};
C)char[2][2][ ] charArray = {'a', 'b'};
D)char[ ][ ][ ] charArray = {{'a', 'b'}, {'c', 'd'}, {'e', 'f'}};
注意:初始化的时候只有最后一个可以省略, 且要小心括号的层数
Chapter8 对象与类
1)An object is an instance of a ________.
A)data B) method C) class D) program
对象是类的一个实例
2)Which of the following statements are true? (Choose all that apply.) 6) _______
A)Constructors must have the same name as the class itself.
B)Constructors do not have a return type, not even void.
C)Constructors are invoked using the new operator when an object is created.
D)A default no-arg constructor is provided automatically if no constructors are explicitly declared in the class.
E)At least one constructor must always be defined explicitly. 必须始终显式定义至少一个构造函数。
如果类中没有显式声明构造函数,则自动提供默认的无参数构造函数。
构造函数是在创建一个对象时由new 操作符调用的。构造函数可以不显式定义
3)Which of the following statements are true about an immutable object? (A、B、D、E)
The contents of an immutable object cannot be modified.
All properties of an immutable object must be private.
All properties of an immutable object must be of primitive types.
An object type property in an immutable object must also be immutable.
An immutable object contains no mutator methods
4)You can declare two variables with the same name in __________.
a method one as a formal parameter and the other as a local variable
a block
two nested blocks in a method (two nested blocks means one being inside the other)
different methods in a class
5)Analyze the following code:
class Test {
private double i;
public Test(double i) {
this.t();
this.i = i;
}
public Test() {
System.out.println("Default constructor");
this(1);
}
public void t() {
System.out.println("Invoking t");
}
}
this.t() may be replaced by t().
this.i may be replaced by i.
this(1) must be called before System.out.println("Default constructor").
this(1) must be replaced by this(1.0)