J2EE interview questions (with answers)

Source: Internet
Author: User

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 runtime environment of web programs, 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, JDO

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 and programming language. This is not as good as that of CORBA.

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" %>

Ii. Java programming and program running results
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: The static code segment of a class can be seen as the Code executed when the class is first loaded (loaded by a virtual machine). to load a class, you must first execute the construction of its base class, 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), then (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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.