Java复习题整理

目录

Chapter 1: Identifying the Features of Java

第一章:识别Java的特性

Chapter 2  Consider the following expression:

第二章  考虑以下表达式:

Chapter 3:The decision making technique

第三章:决策技术(循环及遍历)

Using the while Construct (使用while构造)

Chapter 4 : Arrays

第四章:数组

One-dimensional Array(一维数组)

Chapter 5 encapsulate reading and writing of fields

第五章:封装字段的读取和写入操作

Chapter 6:appropriate exception

第六章:异常处理

Chapter 7:

第七章:内部类&类型转换

Chapter 8:Localization

第八章:本地化

Chapter 9:set interface

第九章:Set接口

Chapter 10:Behavior parameterization

第十章:行为参数化

Chapter 11:Thread

第十一章:线程

Chapter 12

第十二章:数据流

Chapter 13:JDBC API

第十三章:通过jdbc连接java与mysql


Chapter 1: Identifying the Features of Java

第一章:识别Java的特性

Simple : Java evolved from C++, it eliminates many incomprehensible and confusing features
while inheriting most of its grammar rules from C++, so it is easy to use. For example, automatic
garbage collection: When a program creates an object, it needs to allocate memory, and destroy the object after use, Java will complete the task for the programmer.
简介:Java从C++发展而来,消除了许多晦涩难懂的特性,同时继承了大部分的C++语法规则,因此使用起来很简单。例如,自动垃圾回收:当程序创建一个对象时,需要分配内存,并在使用后销毁对象,Java会为程序员完成这个任务。
Object-oriented : Java is an object-oriented language and it incorporates the various
characteristics of an object-oriented language, such as encapsulation, inheritance and polymorphism.
面向对象:Java是一种面向对象的语言,它融合了面向对象语言的各种特性,例如封装、继承和多态。
Portable : Portability refers to the ability of a program to run on any platform without changing
the source code of the program. Just because of the platform independence of Java bytecode, Java programs can be ported to any platform that supports JVM.
可移植性:可移植性指的是程序无需更改源代码就能在任何平台上运行的能力。由于Java字节码具有平台无关性,Java程序可以移植到支持JVM的任何平台上运行。
Secure : The security model of Java is based on a customizable "sandbox", in which programs
can run safely without potential risks to the system or users.
安全性:Java的安全模型基于可自定义的"沙箱",程序可以在其中安全运行,不会给系统或用户带来潜在的风险。
Robust : Java provides various features, such as memory management and exception handling,
which
make it a robust programming language.
After defining a class, you need to save the file before it can be executed. The following naming
conventions
should be followed for naming a Java file:
A file name must be unique.
A file name cannot be a keyword.
If a class is specified as public , the file name and class name should be the same.
If a file contains multiple classes, only one class can be declared as public . The file name
should be the
same as the class name that is declared public in the file.
If a file contains multiple classes that are not declared public , any file name can be
specified for the
file.
健壮性:Java提供了各种功能,例如内存管理和异常处理,使其成为一种健壮的编程语言。
在定义一个类之后,需要保存文件才能执行。以下是命名Java文件的命名约定:

文件名必须唯一。
文件名不能是关键字。
如果一个类被指定为public,则文件名和类名应该相同。
如果文件包含多个类,只能有一个类被声明为public。文件名应与在文件中声明为public的类名相同。
如果文件包含多个未声明为public的类,文件可以指定任何文件名。

Chapter 2  Consider the following expression:

第二章  考虑以下表达式:

图:X+Y
In the preceding expression, X and Y are operands, and + is an operator. The following figure
shows the operator and operands used in the preceding expression.
The following types of operators are supported in Java:
在上述表达式中,X和Y是操作数,+是运算符。下图展示了上述表达式中使用的运算符和操作数。 Java支持以下类型的运算符:
Arithmetic operators(算术运算符
Assignment operators(赋值运算符
Comparison operators(比较运算符
Logical operators(逻辑运算符
Ternary operator(三元运算符
Arithmetic operators are used to perform arithmetic operations on operands.
The following table describes the arithmetic operators.
算术运算符用于对操作数进行算术运算。 下表描述了算术运算符。
图:算术运算符
翻译如下:
这里举例:x=4  y=2
+x+y=6
-x-y=2
*x*y=8
/x/y=2
%取余x%y=0
++值加一x++=5  y++=3
--值减一x--=3  y--=1

补充:你可能在代码中遇到以下运算符,虽然此内容未出现在考试复习提纲中,仍建议掌握。

同样的,这里举例这里举例:x=4  y=2。

另外注意:进行运算后,将对运算符左边的变量赋值,如实例中x在左边,则最后输出只改变x的值,y的值不变。

+=x+=y     输出   x=6
-=x-=y     输出   x=2
*=x*=y     输出   x=8

/=

x/=y     输出   x=2
%=取余x%=y     输出   x=0

Comparison operators are used to compare two values and perform an action on the basis of the

result of that comparison. Whenever you use a comparison operator, the expression results in the boolean value, true or false.
The following table describes the commonly-used comparison operators.
比较运算符用于比较两个值,并根据比较结果执行操作。当使用比较运算符时,表达式的结果为布尔值,即true或false。
下表描述了常用的比较运算符。

图:比较运算符(左下、右)
Logical operators are used to evaluate operands and return a boolean value.
The following table describes the logical operators.
See the table in the Book.

逻辑运算符用于对操作数进行逻辑运算,并返回一个布尔值。 下表描述了逻辑运算符。

图:逻辑运算符(从上至下:与 - 或 - 非)

Chapter 3:The decision making technique

第三章:决策技术(循环及遍历)

The decision making technique can be implemented in the Java programs by using the following
conditional constructs:
决策技术可以通过使用以下条件构造在Java程序中实现:
The if construct( if条件构造)
The if…else construct(if…else条件构造)
The switch construct(switch条件构造)
The if construct executes statements based on the specified condition. For example, in the
Classic Jumble Word game, you needs to display the message, You are correct !!!! . To implement the preceding functionality, you can use the if construct.
if条件构造根据指定的条件执行语句。例如,在经典的Jumble单词游戏中,您需要显示消息"You are correct !!!!"。为了实现前面的功能,您可以使用if条件构造。
The syntax for the if construct is  【if条件构造的语法如下】:
if (表达式) {
   //语句
}
In the if construct, statement(s) followed by the if statement will be executed, when
expression evaluates to true. However, if expression evaluates to false, statement(s) will be
skipped.
在if条件构造中,当表达式评估为true时,紧随if语句后面的语句将被执行。然而,如果表达式评估为false,那么语句将被跳过。
The equals() method is a method of the String class that compares the values of
two string objects.
equals()方法是String类的一个方法,用于比较两个字符串对象的值。
In the preceding example of the Classic Jumble Word game, you want to modify the existing
code to display the message, You are incorrect !!!! , if a user enters the incorrect word for the
corresponding jumbled word. For this, you can modify the existing code by using the if…else construct.
在前面的Classic Jumble单词游戏示例中,如果用户为相应的乱序单词输入了错误的单词,您希望修改现有代码以显示消息"You are incorrect !!!!"。为此,您可以使用if…else条件构造来修改现有代码。
The if…else construct executes statements based on the specified condition. The syntax for
the if…else
if…else条件构造根据指定的条件执行语句。if…else条件构造的语法如下:
if (表达式) {
   // if条件下的语句
} else {
   // else条件下的语句
}
A looping statement enables you to execute the same statements for a certain number of times.
For this, you do not need to write the statements repeatedly. You can enclose the statements within the loop construct and the loop construct executes the statements till the specified condition is met. Java supports the following loop constructs:
循环语句允许您多次执行相同的语句,而无需重复编写这些语句。您可以将语句放在循环构造内,并且循环构造将执行这些语句,直到满足指定的条件。Java支持以下循环构造:
The for loop(for循环)
The while loop(while循环)
The do…while loop(do…while循环)

Using the while Construct 使用while构造)

In the preceding example, you can implement the similar functionality with the help of the
while loop construct.
The while loop construct provides the similar functionality of the for loop construct.
However, the syntax for the while loop construct is different from the for loop construct.
在前面的示例中,您可以使用while循环构造来实现类似的功能。
while循环构造提供了与for循环构造类似的功能。
然而,while循环构造的语法与for循环构造不同。
while循环构造的语法如下:
 
while (表达式) {
   //语句
}
In the while loop construct, statement(s) followed by the while statement will be
executed, when the expression evaluates to true. The loop continues executing statement(s) until the expression evaluates to false.
在while循环构造中,当表达式评估为true时,紧随while语句后面的语句将被执行。循环会继续执行语句,直到表达式评估为false。

在前面的示例中,您可以使用以下while循环的代码片段:
int count=0;
while(count<5)
{
//statement(s)
count++;
}

In the preceding code snippet, the count variable is initialized with 0. The loop will continue executing statement(s) till the value of the count variable is less than 5.
在上面的代码片段中,count变量被初始化为0。循环将继续执行语句,直到count变量的值小于5。

Chapter 4 : Arrays

第四章:数组

You can create the following types of arrays:
您可以创建以下类型的数组:
One-dimensional array(一维数组)
Multidimensional array(多维数组)

One-dimensional Array(一维数组)

A one-dimensional array is a collection of elements with a single index value. A one dimensional array can have multiple columns but only one row.The creation of a one-dimensional array involves two steps:
一维数组是具有单个索引值的元素集合。一维数组可以有多列,但只有一行。 创建一维数组需要两个步骤:
1. Declare an array.(声明数组)
2. Assign values to the array.(为数组赋值)
Accessing Arrays(访问数组)
To perform various manipulations on the array, you need to access the following types of arrays:
要对数组执行各种操作,您需要访问以下类型的数组:
One-dimensional array(一维数组)
Two-dimensional array(二维数组)
One-dimensional Array(一维数组)
To access a one-dimensional array, the following syntax is used:
要访问一维数组,使用以下语法:
arrayname[index];
In the preceding syntax, arrayname specifies the name of the array and index specifies the
location of the array element.Consider the following code snippet:
在上述语法中,arrayname指定数组的名称,index指定数组元素的位置。 考虑以下代码片段:
String jumbledWords[] = {“alpep”,”argneo”,”rgaeps”};
System.out.println(jumbledWords[0]);
In the preceding code snippet, the jumbledWords array stores the various jumbled words.
The statement, System.out.println(jumbledWords[0]);, accesses the element stored in the first
index and displays it.
在上述代码片段中,jumbledWords数组存储了各种乱序的单词。语句System.out.println(jumbledWords[0]);访问存储在第一个索引中的元素并将其显示出来。
Manipulating Strings(操作字符串)
Using String Class. To store string literals, you can use the String class in the java.lang package. The following code snippet is used to create a string object:
使用String类。要存储字符串字面值,可以使用java.lang包中的String类。以下代码片段用于创建一个字符串对象:
String s1 = new String(“Hello”);
The preceding code snippet creates a new string object in the heap memory, with a value,
Hello , and assigns it to reference variable, s1 . In addition, it creates another string object with the value, Hello , in the string constant pool.
上述代码片段在堆内存中创建了一个新的字符串对象,其值为Hello,并将其赋给引用变量s1。此外,它还在字符串常量池中创建了另一个值为Hello的字符串对象。
You can also create a string object by using the following code snippet:
您还可以使用以下代码片段创建一个字符串对象:
String s1 = “Hello”;

The preceding code snippet creates a new string object with a value, Hello, in the string constant pool and assigns it to the reference variable, s1.上述代码片段在字符串常量池中创建了一个新的值为Hello的字符串对象,并将其赋给引用变量s1。

In Java, String class is an immutable class. This means that once a string object is created,
you cannot change its value. However, the reference variables of the String class are mutable.
在Java中,String类是一个不可变类。这意味着一旦创建了一个字符串对象,您就无法更改其值。但是,String类的引用变量是可变的。
The following table lists the some of the most commonly used methods of the String class.
以下表列出了String类的一些常用方法。
See page Number: 4.15
备注:以下是string类常用方法,目测应对考试无需完全掌握,但依然给出。

 图:常用String类方法(白皮4.15-4.19上半)

Chapter 5 encapsulate reading and writing of fields

第五章:封装字段的读取和写入操作

Through agreed get/set accessors, you can encapsulate reading and writing of fields to achieve
the purpose of controlling data permissions.
通过使用约定的get/set访问器,您可以封装字段的读取和写入操作,以实现控制数据权限的目的。
A class can inherit the features of a related class and add new features, as per the
requirement.(一个类可以继承相关类的特性并根据需求添加新特性。)
In inheritance, the class that inherits the data members and methods from another class is
known as the subclass or derived class.(在继承中,从另一个类继承数据成员和方法的类称为子类或派生类。)
The class from which the subclass inherits the features is known as the superclass or base
class.(子类继承特性的类被称为超类或基类。)
In single level inheritance, a single subclass derives the functionality of an existing
superclass.(在单级继承中,单个子类派生现有超类的功能。)
In multilevel inheritance, a subclass inherits the properties of another subclass.(在多级继承中,子类继承另一个子类的属性。)
In hierarchical inheritance, one or more subclasses are derived from a single superclass.(在层次继承中,一个或多个子类派生自单个超类。)
An abstract class is a class that contains one or more abstract methods.(抽象类是一个包含一个或多个抽象方法的类。)
An abstract class cannot be instantiated but can be inherited by other classes by using the
extends keyword.(抽象类不能被实例化,但可以通过使用extends关键字被其他类继承。)
Interfaces contain a set of abstract methods and static and final data members.(接口包含一组抽象方法和静态和最终数据成员。)
A class that implements an interface must provide the implementation of all the methods
declared in that interface.(实现接口的类必须提供对该接口中声明的所有方法的实现。)
In Java, polymorphism has the following two types
    在Java中,多态性具有以下两种类型 :
Static polymorphism(静态多态性)
Dynamic polymorphism(动态多态性)
In case of static polymorphism, an entity, such as a method, can exist in multiple forms.
在静态多态性的情况下,一个实体(例如方法)可以以多种形式存在。)
Dynamic polymorphism is implemented in Java by method overriding.
动态多态性通过方法重写在Java中实现。)
To override a method present in the superclass, the subclass method should have the same
name, same parameters, and same return type as the method in the superclass.
要重写超类中存在的方法,子类方法应与超类中的方法具有相同的名称、相同的参数和相同的返回类型。)

Chapter 6:appropriate exception

第六章:异常处理

When a run-time error occurs, an exception is thrown by the JVM which can be handled by an
appropriate exception handler.
当发生运行时错误时,JVM会抛出异常,可以通过适当的异常处理程序来处理。
To deal with these exceptions, Java provides various built-in exception classes.
    为了处理这些异常,Java提供了各种内置的异常类。
The Throwable class is the base class of exceptions in Java.
    Throwable类是Java中异常的基类。
The Exception class represents the conditions that a program should handle.
    Exception类表示程序应该处理的条件。
The Error class defines the exceptions related to the Java run-time environment.
    Error类定义了与Java运行时环境相关的异常。
Java exceptions are categorized into the following types:
    Java异常分为以下几种类型:
Checked exceptions(受检异常)
Unchecked exceptions(未检查异常)
You can implement exception handling in a program by using the following keywords and
blocks:
您可以使用以下关键字和块在程序中实现异常处理:
try
catch
throw
throws
finally
A try block encloses the statements that might raise an exception and defines one or more
exception handlers associated with it.
(try块包含可能引发异常的语句,并定义与之关联的一个或多个异常处理程序。)
In Java, the catch block is used as an exception handler.
(在Java中,catch块用作异常处理程序。)
A try block must have at least one catch block that follows the try block,
immediately.
(try块必须有至少一个紧随其后的catch块。)
You can throw an exception explicitly, by using the throw keyword.
(您可以使用throw关键字显式地抛出异常)
The throws keyword is used by a method to specify the types of exceptions that the
method can throw.
(throws关键字用于方法中指定方法可能抛出的异常类型。)
The statements specified in the finally block are executed after the control has left the
try-catch block.
(finally块中指定的语句在控制流离开try-catch块后执行。)
In addition to the built-in exceptions, you can create customized exceptions, as per the
application requirements.
(除了内置异常之外,您可以根据应用程序的需求创建自定义异常。)
Assertions are statements in Java that enable you to test any assumptions that you make
regarding a program during its execution.
(断言是Java中的语句,它使您能够在程序执行过程中测试对程序的任何假设。)
You can implement assertions by using the assert keyword provided in Java.
(您可以使用Java提供的assert关键字实现断言。)

Chapter 7:

第七章:内部类&类型转换

A class defined within another class is called an inner class.
在另一个类中定义的类被称为内部类。
Java provides the following four types of inner classes:
Java提供了以下四种类型的内部类:
Regular inner class(常规内部类)
Static inner class(静态内部类)
Method-local inner class(方法局部内部类
Anonymous inner class(匿名内部类)
A regular inner class is a class whose definition appears inside the definition of another
class. The regular inner class is similar to a member of an outer class.
◼ 常规内部类是在另一个类的定义内部出现的类。常规内部类类似于外部类的成员。
Static inner classes are inner classes marked with the static modifier.
◼ 静态内部类是使用static修饰符标记的内部类。
A method-local inner class is defined inside the method of the enclosing class. Because the
class is defined inside a method, it needs to be instantiated within the same method.
◼ 方法局部内部类定义在封闭类的方法内部。因为该类在方法内部定义,所以需要在同一个方法内实例化。
Java supports the following types of type casting:
    Java支持以下类型的类型转换:
Type casting primitive data types(基本数据类型的类型转换
Type casting objects(对象的类型转换
A primitive data type supports the following types of type casting:
   基本数据类型支持以下类型的类型转换:
Implicit casting(隐式转换)
Explicit casting(显式转换)
Implicit conversion refers to an automatic conversion of one data type into another. It occurs
if both the data types are compatible with each other.
    隐式转换是指将一个数据类型自动转换为另一个数据类型。如果两个数据类型彼此兼容,就会发生隐式转换。
Explicit conversion occurs when one data type cannot be implicitly converted into another
data type.
    显式转换发生在一个数据类型无法隐式转换为另一个数据类型时。        
In case of explicit conversion, you must convert the data type into the compatible type.
    在显式转换的情况下,您必须将数据类型转换为兼容的类型。
The casting of object references depends on the relationship of the classes involved in the
same.
    对象引用的转换取决于涉及相同继承关系的类的关系。

Chapter 8:Localization

第八章:本地化

Localization is a process of customizing the application to a specific locale and culture.
本地化是将应用程序定制为特定的区域设置和文化的过程。
Localization can be implemented on different types of data, such as date, currency, and text.
    本地化可以在不同类型的数据上实施,例如日期、货币和文本。
To localize different types of data, it is necessary to determine the language and country.
    要本地化不同类型的数据,需要确定语言和国家。
To determine the language, Java provides a predefined set of language codes, such as zh
for Chinese and en for English.
    为了确定语言,Java提供了一组预定义的语言代码,例如中文的"zh"和英文的"en"。
To work with localization, the Locale class of the java.util package is used.
    为了处理本地化,使用java.util包中的Locale类。
To localize the date, you need to use the various date formats. To determine the date format
according to the locale, you can use the java.time.format.DateTimeFormatter class.
    要本地化日期,需要使用各种日期格式。为了根据区域设置确定日期格式,可以使用java.time.format.DateTimeFormatter类。

Chapter 9:set interface

第九章:Set接口

The Set interface is used to create a collection of unique objects.
Set接口用于创建一个包含唯一对象的集合。
The package, java.util , provides the Iterator interface to traverse through the set
collection.
    java.util包提供了Iterator接口来遍历Set集合。
The HashSet class provides the implementation of the Set interface that enables you to
create a set in which insertion is faster because it does not sort the elements.
    HashSet类提供了Set接口的实现,可以创建一个插入速度较快的集合,因为它不对元素进行排序。
The TreeSet class provides the implementation of the Set interface that enables you to
create a sorted set of objects.
    TreeSet类提供了Set接口的实现,可以创建一个有序的对象集合。
The List interface is used to create an ordered collection of objects, which can contain
duplicate objects.
    List接口用于创建一个有序的对象集合,可以包含重复的对象。
The package, java.util , provides the ListIterator interface to traverse through the
list collection.
    java.util包提供了ListIterator接口来遍历List集合。
The ArrayList class provides the implementation of the List interface. The ArrayList class enables you to create a resizable array.
    ArrayList类提供了List接口的实现,它可以创建一个可调整大小的数组。
The Vector class is similar to the ArrayList class.
    Vector类与ArrayList类类似。
The methods of the Vector class are synchronized, which means that only one thread at a
given time can access it in a multithreaded environment.
    Vector类的方法是同步的,这意味着在多线程环境中只有一个线程可以访问它。
The methods of the ArrayList class are not synchronized.
    ArrayList类的方法不是同步的。
The Map interface enables you to create a collection with key-value pair objects.
    Map接口允许你创建一个带有键-值对对象的集合。

Chapter 10:Behavior parameterization

第十章:行为参数化

Behavior parameterization is the abstraction of behavior into a variable so that it can be passed.
行为参数化是将行为抽象为一个变量,以便可以传递它。
The type of a behavior parameter is defined by a functional interface.
    行为参数的类型由函数式接口定义。
A functional interface is an interface that contains only one method.
    函数式接口是只包含一个方法的接口。
A Lambda expression is an anonymous function that can be used to replace an
implementation class of a functional interface.
    Lambda表达式是匿名函数,可以用来替代函数式接口的实现类。

Chapter 11:Thread

第十一章:线程

A thread is defined as the path of execution of a program. It is a sequence of instructions that is
executed to define a unique flow of control.
线程被定义为程序的执行路径。它是一系列指令的执行,用于定义独特的控制流程。
A program that creates two or more threads is called a multi-threaded program.
Thread priorities are the integers in the range of 1 to 10 that specify the priority of one thread
with respect to the priority of another thread.
◼ 创建两个或多个线程的程序称为多线程程序。
    线程优先级是在1到10范围内的整数,用于指定一个线程相对于另一个线程的优先级。
You can set the thread priority after it is created by using the setPriority() method
declared in the Thread class.
    在创建线程之后,可以使用Thread类中声明的setPriority()方法设置线程的优先级。
The synchronization of threads ensures that if two or more threads need to access a shared
resource, then that resource is used by only one thread at a time.
    线程的同步确保如果两个或多个线程需要访问共享资源,那么该资源只会被一个线程使用。

Chapter 12

第十二章:数据流

Java handles all the input and output operations in the form of streams that act as a sequence of
bytes or characters traveling from a source to a destination.
Java以流的形式处理所有的输入和输出操作,流是一系列从源到目标的字节或字符序列。
When a stream of data is being sent, it is said to be written; and when a stream of data is
being received, it is said to be read.
    当数据流正在发送时,称为写入;当数据流正在接收时,称为读取。
To read data in the form of characters, Java provides the Reader classes inside the
java.io package.
    为了以字符形式读取数据,Java在java.io包中提供了Reader类。
The FileInputStream class is used to read data and the steams of bytes from the file.
     FileInputStream类用于从文件中读取数据和字节流。
The BufferedInputStream class is used to perform the read operations by using a
temporary storage, buffer, in the memory.
    BufferedInputStream类用于使用内存中的临时存储区(缓冲区)执行读操作。
The FileReader class is used for reading characters from a file, but it does not define
any method of its own.
    FileReader类用于从文件中读取字符,但它不定义任何自己的方法。
The BufferedReader class is used to read the text from a character-input stream, such
as a file, console, and array, while buffering characters.
    BufferedReader类用于从字符输入流(如文件、控制台和数组)中读取文本,并缓冲字符。
To write the data in the form of bytes, Java provides the OutputStream classes.
    为了以字节形式写入数据,Java提供了OutputStream类。
To write the data in the form of characters, Java provides the Writer classes inside the
java.io package.
    为了以字符形式写入数据,Java在java.io包中提供了Writer类。
FileOutputStream is used for writing data, byte by byte, to a file.
    FileOutputStream用于将数据逐字节写入文件。

Chapter 13:JDBC API

第十三章:通过jdbc连接java与mysql

The classes and interfaces of the JDBC API are defined in the java.sql and javax.sql
packages.
JDBC API的类和接口定义在java.sql和javax.sql包中。
You can load a driver and register it with the driver manager by using the forName()
method or the registerDriver() method.
    你可以使用forName()方法或registerDriver()方法加载并向驱动程序管理器注册驱动程序。
A Connection object establishes a connection between a Java application and a
database.
    Connection对象建立Java应用程序与数据库之间的连接。
A Statement object sends a request and retrieves results to/ from a database.
    Statement对象向数据库发送请求并检索结果。
You can insert, update, and delete data from a table using the DML statements in Java
applications.
    你可以使用Java应用程序中的DML语句向表中插入、更新和删除数据。
You can create, alter, and drop tables from a database using the DDL statements in Java
applications.
    你可以使用Java应用程序中的DDL语句创建、修改和删除数据库中的表。        
Once the SQL statements are executed, a ResultSet object stores the result retrieved
from a database.
    执行SQL语句后,ResultSet对象存储从数据库检索到的结果。

Chapter A:题目整理

仅凭前文晦涩难懂的知识(面向初学者)依然难以应对考试,本文继续整理一些日常练习题,希望对你有所帮助。

1、With x = 0, which of the following are legal lines of Java code for changing the value of x to 1?

当 x = 0 时,以下哪一行是将 x 的值更改为 1 的合法 Java 代码行?
   1. x++;
   2. x = x + 1;
   3. x += 1;

答案:1&2&3

2、What is the output of this program?  这个程序的输出是什么?

class increment 
    {
        public static void main(String args[]) 
        {        
             int g = 3;
             System.out.print(++g * 8);
        } 
    }

答案:32

3、What is the output of this program?  这个程序的输出是什么?

class operators 
    {
        public static void main(String args[])
        {
            int var1 = 5; 
            int var2 = 6;
            int var3;
            var3 = ++ var2 * var1 / var2 + var2;
            System.out.print(var3);
        } 
    }

答案:12

4、What is the output of relational operators?关系运算符的输出是什么?

IntegerBooleanCharacters

Double

答案:Boolean

5、What is the output of this program?这个程序的输出是什么?

class Relational_operator 
    {
        public static void main(String args[])
        {
            int var1 = 5; 
            int var2 = 6;
            System.out.print(var1 > var2);
        } 
    }

答案:FALSE

6、Which of the following loops will execute the body of loop even when condition controlling the loop is initially false?以下哪个循环将执行循环主体,即使条件控制循环最初为 false?

do-whilewhilefornone of the mentioned

答案:A

7.What is the output of this program?这个程序的输出是什么?

class selection_statements 
 {
        public static void main(String args[])
        {
            int var1 = 5; 
            int var2 = 6;
            if ((var2 = 1) == var1)
                System.out.print(var2);
            else 
                System.out.print(++var2);
        } 
    }

答案:2

8.What is true about a break?  关于“break”,正确的说法是?

 [A]Break stops the execution of entire program 中断停止整个程序的执行  

[B]Break halts the execution and forces the control out of the loop Break停止执行并强制控制退出循环

[C]Break forces the control out of the loop and starts the execution of next iteration Break强制控制退出循环并开始执行下一次迭代

[D]Break halts the execution of the loop for certain time frame Break在特定时间段内停止循环的执行

答案:B

9. What is true about do statement?以下陈述正确的是?

[A] do statement executes the code of a loop at least once do语句至少执行一次循环的代码

[B] do statement does not get execute if condition is not matched in the first iteration 如果条件在第一次迭代中不匹配,do语句将不会执行

[C] do statement checks the condition at the beginning of the loop do语句检查循环开始时的条件

[D] do statement executes the code more than once always do语句总是多次执行代码

答案:A

10、Which of these values can a boolean variable contain?布尔变量可以包含哪些值?

答案:True & False

11、Which one not is a valid keyword?哪一个不是有效的关键字?

[a] for    [b] loop   [c] int  [d] while

答案:b

12.which of the following is not a operator?以下哪项不是运算符?

%*;.

答案:   ;

13、What is the output of this program?这个程序的输出是什么?

    class Relational_operator 
    {
          
        public static void main(String args[])
        {
            int a = 20; 
            int b = 6;
            System.out.print(++a  + ++a);
        } 
    }

答案:43

14、which of the following is a unary opeartors in java?以下哪项是Java中的一元运算符?

*/%++

答案:++

15、John wants to create a class in which he wants to hide its member variables from all the other classes inluding the Child Classes . Which one of the following access specifies should be use? John 想要创建一个类,他想在其中对包含子类的所有其他类隐藏其成员变量。应使用以下哪一个访问权限指定?

private protected  public  default 

答案:private

16、Predict the output of the following program.预测以下程序的输出。

public class Test  
{  
 public static void main(String args[]) 
        {
            boolean var1 = true;
            boolean var2 = false;
            if (var1)
            System.out.println(var1);
            else
            System.out.println(var2);
       } 
 } 

答案:true

17、Jim wants to define a variable to store numbers, which of the following is not a variable name?Jim 想定义一个变量来存储数字,以下哪项不是变量名?

count3count$_countCOUNT

答案:3count

18、Which of the following component is not a part of the Java architecture?以下哪个组件不是 Java 体系结构的一部分?

Source File(.java)class file (.class)Java virtual machine (JVM)CPU

答案:CPU

19、Which of the following class name is not correct?以下哪个类名不正确?

classguessGuessNumber_guess

答案:class

20、Tom wants to develop a student management program, but the program cannot run. Please determine which line of code is wrong? 汤姆想开发一个学生管理程序,但该程序无法运行。请确定哪一行代码是错误的?

class $_Manager{ 
 1 int age; 
 2 } class 2Manager{ 
 3 private String name; 
 4 }

答案:2

21、Which of the following represents the correct output of 20-3*4+10/2?以下哪项代表 20-3*4+10/2 的正确输出?

答案:13

22、Identify the output of the following code?辨认以下代码的输出?

boolean result = (4 > 5) && (3 < 6) || (9>7); 
System.out.println(result);

答案:true

23、Which of the following operators is used to find the remainder after dividing two numbers?以下哪个运算符用于查找除以两个数字后的余数?

+-/

%

答案:%

24、Predict the output of the following code: 预测以下代码的输出:

int m = 5, n = 5; 
    if(m > n){ 
        System.out.println("True"); 
    }else if(m < n}{
        System.out.println("False"); 
    }else{
        System.out.println("Equals"); 
    }

答案:report an error(将会报错)

25、Which of the correct syntax of creating class?创建类的正确语法是什么?

                     A                        B                            C                                          D

Class Abc{
//statements
}
class 3Abc{
//statements
}
class Abc{
//statements
}
class Abc(){
//statements
}

答案:C(左数第三个)

  • 4
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
大学java的期末复习资源,试题及答案 1、编译Java Application源程序文件将产生相应的字节码文件,这些字节码文件的扩展名为( )。 A.java B..class C.html D..exe 2、下面哪一项字符序列可以作为合法的标识符( )。 A.true B.null C.2018_year D.$2018year 3、下列选项中,( )不属于Java语言的简单数据类型。 A.整数型 B.数组 C.字符型 D.浮点型 4、对于int a[ ]=new int[3],下列叙述错误的是( )。 A. a.length的值是3 B. a[1]的值是1 C. a[0]的值是0 D. a[a.length-1]的值等于a[2]的值 5、用下列哪个代码替换程序标注的【代码】会导致编译错误? A.m-->0 B.m++>0 C.m = 0 D.m>100&&true; public class E { public static void main (String args[ ]) { int m=10,n=0; while(【代码】) { n++; } } } 6、以下关于继承的叙述正确的是( )。 A. 在Java中类不能多继承 B. 在Java中一个类只能实现一个接口 C. 在Java中一个类不能同时继承一个类和实现一个接口 D. 在Java中接口只能单一继承 7、对于下列Cat类,哪个叙述是错误的?( ) A.Cat类只有 2 个构造方法,而且没有无参数的构造方法 B.Cat类有 4 个构造方法 C.Cat (int m)和 Cat (double m)是互为重载的构造方法 D.int Cat (int m)和 void Cat (double m) 是互为重载的非构造方法 class Cat { Cat (int m){ } Cat (double m){ } int Cat (int m){ return 23; } void Cat (double m){ }} 8、下列叙述哪些是正确的( )。 A final 类可以有子类 B abstract类中只能有abstract方法 C abstract类中可以有非abstract方法,但该方法不可以用final修饰 D 不可以同时用final和abstract修饰一个方法 9、假设D类有如下定义,设d是D类的一个实例对象,下列语句调用错误的是 ( )。 class D{ int i; static String s; void method1(){} static void method2(){}} A.d.method1(); B.D.method2(); C.D.method1(); D.System.out.println(d.i); 10、将下列( )哪个代码替换下列程序中的【代码】不会导致编译错误。 A.public int f(){return 100+M;} B.int f(){return 100;} C.public double f(){return 2.6;}。 D.public abstract int f();

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值