I. Basic Q &
1. Which of the following classes can be inherited?
Java. Lang. Thread (t)
Java. Lang. Number (t)
Java. Lang. Double (f)
Java. Lang. Math (f)
Java. Lang. Void (f)
Java. Lang. Class (f)
Java. Lang. classloader (t)
2. Differences between abstract classes and interfaces
(1) The interface can be multiple implements, and the abstract class can only be a single extends
(2) Only interfaces are defined. abstract classes can be defined and implemented.
(3) The default field definition of the interface is public static final. The default field of the abstract class is "friendly" (this package is visible)
3. hashtable principle and differences between hashmap and hashtable
Hashtable principle: the storage location of a node is determined by the key code of the node, that is, the key code K of a given node, through a certain function relationship H (hash function ), obtain the function value H (k), which is interpreted as the storage address of the node.
Hashmap is similar to hashtable, but hashmap is non-synchronous (unsynchronizded) and can take null as the key code.
4. Difference between forward and redirect
Forward: an internal transfer in Servlet
Redirect: redirection. There are two requests. The first attributs/parameters will be lost in 2nd requests.
5. What is a Web container?
Implement the Web Protocol application in the J2EE specification. This Protocol defines the Web Program Runtime Environment, including concurrency, security, and lifecycle management.
6. Explain the following J2EE terms
(1) JNDI: Java Naming & Directory Interface, Java Naming directory service. the main function is to provide a directory system that allows applications from other places to leave their own indexes on it to quickly find and locate distributed applications.
(2) JMS: Java Message Service, Java Message Service. It mainly implements communication between applications, including point-to-point and broadcast.
(3) JTA: Java transaction API, Java Transaction Service. It provides various distributed transaction services. The application only needs to call the interfaces it provides.
(4) JAF: Java action framework, Java Security Authentication Framework. It provides some security control frameworks for developers to implement their own personalized security control policies through various deployment and customization.
(5) RMI: Remote Method interface, remote method call
7. What technologies are EJB implemented based on? The differences between sessionbean and entitybean are also described. The differences between statefulbean and statelessbean are described.
EJB includes Session Bean, Entity Bean, and message driven bean. It is implemented based on technology such as JNDI, RMI, and JAT.
Sessionbean is used in J2EE applications to perform some server-side business operations, such as accessing the database and calling other EJB components. entitybean is used to represent the data used in the application system. for clients, sessionbean is a non-persistent object that implements some business logic running on the server. entitybean is a persistent object, it represents an object view of an object stored in persistent storage, or an object implemented by an existing enterprise application.
Session Bean can be further subdivided into stateful Session Bean and stateless Session Bean. both session beans can execute the system logic in method. The difference is that stateful session bean can record the caller's status. Therefore, generally, A user has a corresponding stateful Session Bean entity. although stateless Session Bean is also a logical component, it is not responsible for recording the user status, that is, when the user calls stateless Session Bean, the EJB container does not find the entity of the specific stateless Session Bean to execute this method. in other words, when several users execute a stateless Session Bean's methods, they will execute the same bean instance. in terms of memory, compared with stateful Session Bean and stateless Session Bean, stateful Session Bean consumes a large amount of memory on the J2EE server, however, the advantage of stateful Session Bean is that it can maintain the user's status.
8. XML Parsing Method
Sax, Dom, JDOM
9. What is Web service?
Web Service is an interface proposed to enable communication and sharing between isolated sites.
Web services use unified and open standards on the Internet, such as HTTP, XML, SOAP (Simple Object Access Protocol), and WSDL, therefore, Web services can be used in any environment that supports these standards (Windows and Linux.
Note: The SOAP protocol (Simple Object Access Protocal) is an XML-based communication protocol used for network information exchange in distributed and distributed environments. Under this protocol, software components or applications can communicate through the standard HTTP protocol. Its design goal is simplicity and scalability, which facilitates the interoperability between a large number of heterogeneous programs and platforms, so that existing applications can be accessed by a wide range of users.
Advantages:
(1). cross-platform.
(2) the SOAP protocol is based on industry standards such as XML and HTTP and is supported by all important companies.
(3 ). because soap is used, data is transmitted in ASCII text instead of binary, which facilitates debugging. In this way, its data is easily transmitted through the firewall, the firewall does not need to create a "Vulnerability" for the program ".
(4). In addition, the technical difficulty of WebService implementation is much lower than that of CORBA and DCOM.
(5). To achieve B2B integration, EDI is relatively complete and complex, while WebService can be implemented at a low cost, and can be used by small companies.
(6) In the C/S program, WebService can deal with the server and retrieve the number of webpages without overall refreshing.
Disadvantages:
(1). WebService uses XML to encapsulate data, resulting in a large amount of data to be transmitted over the network.
(2) the WebService specification does not specify any implementation-related details, including the object model, Programming Language .
10. What are several implementation methods for multithreading? What are the implementation methods of synchronization?
A: multithreading can be implemented in two ways: Inheriting the Thread class and implementing the runnable interface.
There are two types of synchronization implementation: synchronized, wait, and Y.
11. What is the difference between dynamic include and static include in JSP?
Implement Dynamic include with JSP: include action
<JSP: Include page = "embedded ded. jsp" Flush = "true"/>
It always checks changes in the contained files and is suitable for containing dynamic pages and can contain parameters
Static include is implemented by using the include pseudo code and will not check the changes in the contained files. It is applicable to include static pages.
<% @ Include file = "included.htm" %>
1. Java programming: print the current time of yesterday
Public class yesterdaycurrent {
Public void main (string [] ARGs ){
Calendar Cal = calendar. getinstance ();
Cal. Add (calendar. Date,-1 );
System. Out. println (Cal. gettime ());
}
}
2. Read and Write files to implement a counter
Public int getnum (){
Int I =-1;
Try {
String stri = "";
Bufferedreader in = new bufferedreader (New filereader (f ));
While (stri = in. Readline ())! = NULL ){
I = integer. parseint (stri. Trim ());
}
In. Close ();
} Catch (exception e ){
E. printstacktrace ();
}
Return I;
}
Public void setnum (){
Int I = getnum ();
I ++;
Try {
Printwriter out = new printwriter (New bufferedwriter (New filewriter (F, false )));
Out. write (string. valueof (I); // it may be the cause of encoding. If Int Is written directly, Java encoding and Windows encoding will be chaotic. Therefore, string is written here.
Out. Close ();
} Catch (exception e ){
E. printstacktrace ();
}
}
3. Point out the running result of the following program:
Class {
Static {
System. Out. Print ("1 ");
}
Public (){
System. Out. Print ("2 ");
}
}
Class B extends {
Static {
System. Out. Print ("");
}
Public B (){
System. Out. Print ("B ");
}
}
Public class Hello {
Public static void main (string [] ARS ){
A AB = new B (); // run the command here. The result is 1a2b.
AB = new B (); // run the command here. Result: 1a2bab
}
}
Note: static Code It can be seen as the code that is executed when the class is loaded for the first time (loaded by the Virtual Machine). to load the class, you must first execute the construction of its base class and then execute its own structure.
4. Example of writing a singleton Mode
Public class Singleton {
Private Static Singleton single = new Singleton ();
Private Singleton (){}
Public Singleton getinstance (){
Return single;
}
}
Iii. Database
1. Delete duplicate table records
If the record is identical, the record is repeated. (The test passes in SQL Server)
Select distinct * into # tmpp from TID
Delete from TID
Insert into TID select * from # tmpp
Drop table # tmpp
If there is an id Primary Key (number, auto-increment of 1), the test passes in SQL Server2000)
Delete from tablea where id not in
(Select id = min (ID) from tablea group by name)
2. Differences between Delete from tablea & truncate table tablea
Truncate statements are executed quickly, occupy less resources, and only logs deleted from pages are recorded;
Delete: logs are required to delete each record.
This article is transferred from www.35java.com