J2EE interview questions collection

1. Basic Q&A

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. The difference between abstract class and interface

(1) Interfaces can be multiple implements, abstract classes can only be extended by a single extension
  (2) Interfaces have only definitions, abstract classes can have definitions and implementations
  (3) The field definition of the interface defaults to: public static final, and the default field of the abstract class is " friendly" (visible in this package)

3. The principle of Hashtable, and tell the difference between HashMap and Hashtable

The principle of HashTable: Determine the storage location of the node through the key code of the node, that is, the key code k of a given node, and obtain the function value H(k) through a certain functional relationship H (hash function), and interpret this value as this The storage address of the
node.HashMap is very similar to Hashtable, but HashMap is unsynchronized and can use null as the key.

4. The difference between forward and redirect

forward: an internal transfer in servlet
  redirect: redirect, there are 2 requests, the 2nd request will lose the first attributes/parameters, etc.

5. What is a web container?

Implement the application of the web protocol in the J2EE specification. The protocol defines the runtime environment of the web program, including: concurrency, security, life cycle management, etc.

6. Explain the following terms about J2EE

(1) JNDI: Java Naming & Directory Interface, JAVA naming directory service. The main function provided is: to provide a directory system, allowing other applications to leave their own indexes on it, so as to meet the rapid search and positioning The function of the application.
  (2) JMS: Java Message Service, JAVA message service. Mainly realize the communication between various applications. Including point-to-point and broadcast.
  (3) JTA: Java Transaction API, JAVA transaction service. Provide various distribution Type transaction service. The application only needs to call the interface it provides.
  (4) JAF: Java Action FrameWork, JAVA security certification framework. Provides some security control framework. Let developers realize themselves through various deployments and customizations Personalized security control strategy.
  (5) RMI: Remote Method Interface, remote method invocation

7. What technologies are EJB based on? And tell the difference between SessionBean and EntityBean, and the difference between StatefulBean and StatelessBean.

EJB includes Session Bean, Entity Bean, Message Driven Bean, based on JNDI, RMI, JAT and other technologies.

SessionBean is used in J2EE applications to complete some server-side business operations, such as accessing the database, calling other EJB components. EntityBean is used to represent the data used in the application system. For the client, SessionBean is a non-persistent object , It implements certain business logic running on the server; EntityBean is a persistent object, which represents an object view of an entity stored in persistent storage, or an entity implemented by an existing enterprise application.

Session Bean can also be subdivided into Stateful Session Bean and Stateless Session Bean. Both of these Session Beans can execute system logic in the method. The difference is that Stateful Session Bean can record the state of the caller, so it is usually Say, a user will have a corresponding entity of Stateful Session Bean. Although Stateless Session Bean is also a logical component, it is not responsible for recording the state of the user, which means that when the user calls Stateless Session Bean, EJB Container It will not find the entity of a specific Stateless Session Bean to execute this method. In other words, it is possible that when several users execute the methods of a Stateless Session Bean, they will be executed by the same Bean Instance. From a memory perspective Compared with Stateless Session Bean, Stateful Session Bean consumes more memory in J2EE Server. However, the advantage of Stateful Session Bean is that it can maintain the user's state.

8. XML parsing method

Sax, DOM, JDOM

9. What is Web Service?

Web Service is an interface proposed to enable the information between the original isolated sites to communicate and share with each other.
Web Service uses unified and open standards on the Internet, such as HTTP, XML, SOAP (Simple Object Access Protocol), WSDL, etc., so Web Service can be used in any environment (Windows, Linux) that supports these standards.

Note: SOAP protocol (Simple Object Access Protocol, Simple Object Access Protocol), it is an XML-based communication protocol for network information exchange in a decentralized and distributed environment. Under this protocol, software components or applications can communicate through the standard HTTP protocol. Its design goals are simplicity and scalability, which facilitates interoperability between a large number of heterogeneous programs and platforms, so that existing applications can be accessed by a wide range of users.

Advantage:

(1). Cross-platform.
  (2) The SOAP protocol is based on industry standards such as XML and HTTP, and has been supported by all important companies.
  (3). Because of the use of SOAP, the data is transmitted in ASCII text instead of binary, which is very convenient for debugging; and because of this, its data can easily pass through the firewall, and there is no need for the firewall to open a separate "hole" for the program.
  (4). In addition, the technical difficulty of WebService implementation is much smaller than CORBA and DCOM.
  (5). To achieve B2B integration, EDI is relatively complete and complex; while using WebService, it can be implemented at low cost and can also be used by small companies.
  (6). In the C/S program, WebService can deal with the server and fetch data without refreshing the web page as a whole.

Disadvantages:

(1). WebService uses XML to encapsulate data, which will cause a large amount of data to be transmitted on the network.
  (2). The WebService specification does not specify any implementation-related details, including object models and programming languages. In this regard, it is not as good as CORBA.

10. There are several implementation methods for multithreading, what are they? There are several implementation methods for synchronization, and what are they?

Answer: There are two implementation methods for multithreading, namely, inheriting the Thread class and implementing the Runnable interface
  . There are two ways to achieve synchronization, namely synchronized, wait and notify.

11. What is the difference between dynamic INCLUDE and static INCLUDE in JSP?

Dynamic INCLUDE is realized with jsp:include action

<jsp:include page="included.jsp" flush="true"/>

It will always check the changes in the included files, suitable for containing dynamic pages, and can take parameters

Static INCLUDE is implemented with include pseudo-code, which will not check the changes of the included files, and is suitable for including static pages

<%@ include file="included.htm" %>

1.Java programming, print the current moment 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. File read and write, realize 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));            //可能是编码的原因,如果直接写入int的话,将出现java编码和windows编码的混乱,因此此处写入的是String            out.close() ;        }catch(Exception e){            e.printStackTrace();        }    }

3. Indicate the running result of the following program:

class A{    static{        System.out.print("1");    }    public A(){        System.out.print("2");    }}class B extends A{    static{        System.out.print("a");    }    public B(){        System.out.print("b");    }  }public class Hello{    public static void main(String[] ars){        A ab = new B(); //执行到此处,结果: 1a2b ab = new B(); //执行到此处,结果: 1a2bab    }}

Note: The static code segment of a class can be regarded as the code executed for the first time the class is loaded (loaded by the virtual machine), and for the loading of the class, the construction of its base class must be executed first, and then its own construction must be executed.

4. Write an example of the Singleton pattern

public class Singleton{ private static Singleton single = new Singleton(); private Singleton(){} public Singleton getInstance(){  return single; }}

Three, the database

1. Delete duplicate records in the table

If the records are exactly the same, it is considered a duplicate record, then: (tested under sql server2000)

select distinct * into #tmpp from tiddelete from tid    insert into tid select * from #tmppdrop table #tmpp

If there is an id primary key (number, self-increasing by 1), then: (tested under sql server2000)

delete from tableA where id not in(select id = min(id) from tableA group by name)

2. The difference between delete from tablea & truncate table tablea

The truncate statement executes quickly, occupies less resources, and only records the log of page deletion;
 delete needs to record the log for each record deletion

end:

I cannot guarantee that everything I write is correct, but at least I can guarantee that it will not be copied or pasted, and that every sentence and every line of code has been carefully considered and carefully considered. Behind every article, I hope to see my attitude towards technology and life.

I believe what Jobs said, only those who are crazy enough to think they can change the world can really change the world. In the face of pressure, I can use the lamp to fight night and sleep endlessly; in the face of difficulties, I am willing to face the difficulties and never back down.

In fact, what I want to say is that I am just a programmer, and this is all of my pure life now.

Finally, I hope you can support the one-click triple connection + comment and present my own "Dachang Zhenti + Microservice + MySQL + Distributed + SSM framework + Java + Redis + data structure and algorithm + network + Linux + Spring family bucket + JVM+ High concurrency + major learning mind map + interview collection"