1. In Java, the () class provides the positioning of the local file system to perform basic operations on a file or directory and its attributes. (Single radio)
A) FileInputStream
B) FileReader
C) FileWriter
D) File
2. The collection classes in Java include ArrayList, LinkedList, HashMap, and so on, with the following information about the collection class describing the error () (radio)
A) ArrayList and LinkedList both implement the list interface
B) ArrayList access speed is faster than LinkedList
C) when adding and removing elements, the ArrayList performance is better
D) HashMap implements the map interface, which allows any type of key and value object, and allows NULL to be used as a key or value
ArrayList 保存所有元素 包括null,优点:根据索引快速访问;缺点:指定索引位置插入删除慢Linkedlist链表结构保存对象,优点:便于插入删除;缺点:随机访问,效率低
Several interview FAQs:
What is the difference between 1.q:arraylist and vectors? What's the difference between HashMap and Hashtable?
A:vector and Hashtable are thread-synchronized (synchronized). In performance, ArrayList and HashMap are better than vectors and Hashtable respectively.
2.Q: Roughly explaining the architecture of the Java collection
A:list, set, and map are the main three interfaces in this set system.
Where list and set inherit from the collection interface.
Set does not allow elements to be duplicated. HashSet and TreeSet are the two main implementation classes.
The list is ordered and allows elements to be duplicated. ArrayList, LinkedList, and vectors are the three main implementation classes.
The map also belongs to the collection system, but differs from the collection interface. A map is a collection of key pairs of value, where the key column is a collection. Key cannot be duplicated, but value can be repeated. HashMap, TreeMap, and Hashtable are the three main implementation classes.
The SortedSet and SortedMap interfaces sort the elements by the specified rules, sortedmap the key column.
3. When using the super and this keyword, the following description is correct () (radio)
A) using super () in the subclass construction method to display the constructor method that calls the parent class, super () must be written in the first row of the subclass construction method, otherwise the compilation does not pass
Remember that the correct option error has been removed
4. In Java, the JDBC API defines a set of interfaces and classes that are used to communicate with the database, which are included in the () package. (Single radio)
A) Java.lang
B) java.sql
C) Java.util
D) Java.math
5. In Java, the following () interfaces store objects in the form of key-value pairs. (Single radio)
A) java.util.Collection
B) Java.util.Map
C) java.util.List
D) Java.util.Set
6. The following description of object serialization is correct () (multiple selection)
A) use FileOutputStream to transfer objects, file
B) use PrintWriter to transfer objects
C) Use the ObjectOutputStream class to complete object storage and use the ObjectInputStream class to complete object reads
D) The owning class of the object serialization needs to implement the Serializable interface
Java object serialization ObjectOutputStream and ObjectInputStream Java ObjectInputStream and
ObjectOutputStream These two wrapper classes can be used to read the object class data in the input stream and write data of the object type to the underlying input stream
。 Objects written and read by ObjectInputStream and ObjectOutputStream classes must implement the Serializable
Interface. It is important to note that the member variables of the transient and static types in the object are not read and written.
7. In Java, the () class can be used to create an object of a linked list data structure. (Single radio)
A) LinkedList
B) ArrayList
C) Collection
D) HashMap
8. Analyze the following Java code, which runs as a result (). (Single radio)
Import java.io.*;
public class b{
public static void Main (string [] args) {
int i=12;
System.out.println (i+=i-=i*=i);}}
A) 100
B) 0
C)-120
D) The program cannot be compiled
(a) i*=i, (b) i-=i; (c) i+=i; This formula is left-to-right, such as i=5; Go first a i+=i;
+ = This algorithm is first and then equal to I=i+i; this is the wrong i+=i; the whole is 10 but I still is 5, this does not know you can understand? Go to the right again because there is multiplication in the back to do multiplication B ibid. i*=i; I have been 5 but i*=i 25 i=i*i as a whole is 25 but I or 5;
Then go to C when I-=i is actually i=a-b, is 10-25=-15;
9. The steps to use the JDBC Transaction are () (multiple selection)
A) Canceling the connection transaction Auto-Submit method
B) An exception rollback transaction occurred
C) Get Connection object
D) COMMIT TRANSACTION completed
Database open Transaction Command mode One: Manage transactions with SQL statements start
transaction;– Open the transaction, the SQL statement after this statement will be in a transaction, and these SQL statements are not immediately executed
commit– commits the transaction, and all SQL statements in the transaction are executed once the transaction is committed. rollback– rolls back the transaction, canceling all previous SQL.
Mode two: There is an auto-commit variable in the database, via show variables like '%commit% '-–autocommit
The value is on, which indicates that transaction autocommit is turned on. can set Autocommint = Off (set
autocommint=0), turn off autocommit, the SQL statement entered is not automatically submitted, requires manual roolback or commit
(1) When the JDBC program obtains a connection object to the database, by default the Connection object submits the SQL statement sent on it to the database automatically. To turn off this default submission method and have multiple SQL execute in a single transaction, use the following statement:
(2) JDBC Control TRANSACTION statement Connection.setautocommit (FALSE); Equivalent to start
Transaction Connection.rollback (); Rollback Connection.commit ();
Commit (3) sets the transaction rollback point SavePoint SP = Conn.setsavepoint ();
Conn.rollback (SP); Conn.commit (); Must be submitted after rollback
10. The following description of the JDBC transaction is incorrect () (radio)
A) JDBC transactions are part of a Java transaction
B) the JDBC transaction belongs to the container transaction type
C) JDBC transaction can guarantee the integrity and consistency of operation
D) The JDBC transaction was initiated by connection and controlled by connection
There are three types of Java transactions: JDBC Transaction, JTA (Java Transaction API) transaction, container transaction.
1. JDBC Transaction
The JDBC transaction is controlled with the Connection object. JDBC Connection Interface (java.sql.Connection
Provides two modes of transaction: auto-commit and manual commit. Java.sql.Connection provides the following methods of controlling transactions:
public void Setautocommit (Boolean) public boolean getautocommit ()
public void commit () public void rollback ()
When using JDBC transaction demarcation, you can combine multiple SQL statements into a single transaction. One drawback of JDBC transactions is that the scope of a transaction is limited to a single database connection. One
JDBC transactions cannot span multiple databases.
2. JTA (Java Transaction API) transaction
JTA is a high-level, unrelated, protocol-agnostic API that enables applications and application servers to access transactions using JTA.
JTA allows applications to perform distributed transactions-access and update data on two or more network computer resources, which can be distributed across multiple databases. The JTA support of the JDBC driver greatly enhances the data access capability.
If you plan to define transactions with JTA, then you need to have an implementation javax.sql.XADataSource,
JDBC for Javax.sql.XAConnection and Javax.sql.XAResource interfaces
Drivers. A driver that implements these interfaces will be able to participate in the JTA transaction. A Xadatasource object is a xaconnection
The factory of the object. Xaconnection S is a JDBC connection that participates in JTA transactions.
You will need to set up Xadatasource with the Application Server's administration tool. The relevant guidance can be learned from the application server and the documentation for the JDBC driver.
The Java EE application queries the data source with JNDI. Once the application finds the data source object, it calls the
Javax.sql.DataSource.getConnection () to obtain a connection to the database.
XA connections are not the same as non-XA connections. Be sure to remember that the XA connection participates in the JTA transaction. This means that the XA connection does not support JDBC
Auto-submit feature. Also, the application must not call Java.sql.Connection.commit () on the XA connection or
Java.sql.Connection.rollback (). Instead, the application should use Usertransaction.begin (),
Usertransaction.commit () and Sertransaction.rollback ().
3. Container Service
Container transactions are mainly provided by the Java EE Application Server, and the container transactions are mostly based on JTA, which is a jndi-based, fairly complex API implementation. Relative coding implements JTA transaction management,
The same functionality can be accomplished through the container transaction management mechanism (CMT) provided by the EJB container, which is provided by the Java EE Application Server. This allows us to simply specify which method to add to the
Service, once specified, the container will be responsible for transaction management tasks. This is our way of doing civil work, because in this way we can exclude the transaction code from the logic code and give all the difficulties to
The Java EE container to solve. Another benefit of using EJB CMT is that programmers do not have to care about the coding of the JTA API, but in theory we have to use EJBS.
Four or three different transaction differences
1. The limitations of JDBC transaction control are within a database connection, but they are simple to use.
2. JTA transactions are powerful, and transactions can span multiple databases or multiple DAO, and are more complex to use.
3, container transaction, mainly refers to the Java EE Application Server provides transaction management, limited to the use of EJB applications.
V. Summary
Transaction control is an indispensable part of building the Java EE application, and it is very important for the whole application to choose what kind of transaction to apply. Generally, in a single JDBC
A JDBC transaction can be selected in the case of a connection connection, and in the case of multiple connections or databases, it is necessary to choose to use the JTA transaction, and if EJB is used, you can consider using EJB container transactions.
Reference Answer:
1.D 2.C 3.A 4.B 5.B
6.CD 7.A 8.C 9.CABD 10.B
The following is a succession of Java selection questions, simple answers, Android choice questions, simple answer questions, and interview the real problem!!! Please expect
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Android Development Engineer must read the written question: Java basic choice Question (i)