A collection of questions on Java EE face (with answers)

Source: Internet
Author: User
Tags abstract implement sql object model string thread thread class access
J2ee

First, the basic question and answer

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 classes and interfaces

(1) The interface can be multiple implements, the abstract class can only be a single extends

(2) The interface is defined and the abstract class can be defined and implemented

(3) The field definition for the interface defaults to: public static final, the abstract class field by default is "friendly" (this package is visible)

3.Hashtable principle, and say the difference between HashMap and Hashtable

Hashtable principle: Through the node key code to determine the node storage location, that is, given the node's key code K, through a certain function of the relationship H (hash function), the function value h (k), this value is interpreted as the node's storage address.
HashMap is similar to Hashtable, but HashMap is unsynchronized (unsynchronizded) and can be null-critical.
The difference between 4.forward and redirect

Forward:an internal transfer in servlet
Redirect: Redirect, 2 times request, 2nd request will lose the first attributs/parameters and so on
5. What is a Web container?

Realize the application of Web protocol in Java EE specification. This protocol defines the runtime environment for Web applications, including concurrency, security, lifecycle management, and so on.
6. Explain the following nouns about Java EE

(1) Jndi:java Naming & Directory Interface, Java Naming directory service. The main features are providing a directory system that allows other local applications to leave their own indexes on them, thus satisfying the ability to quickly find and locate distributed applications.

(2) Jms:java Message Service,java Messaging service. Primarily implement communication between applications. Includes point-to-point and broadcast.

(3) Jta:java Transaction Api,java Services. Provides a variety of distributed transaction services. The application simply invokes the interface it provides.

(4) Jaf:java Action Framework,java Security Certification framework. Provides a framework for security controls. Let developers implement their own personalized security control strategies through various deployments and customizations.

(5) Rmi:remote methods Interface, remote method call

What technology is the 7.EJB based on? And tell the difference between Sessionbean and Entitybean, Statefulbean and Statelessbean.

    EJBs include session beans, Entity beans, message driven beans, and are implemented based on the techniques of Jndi, RMI, Jat, and so on.
    Sessionbean is used in Java EE applications to perform some server-side business operations, such as accessing databases, Invoke 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 of the business logic running on the server; Entitybean is a persistent object that represents an object view of an entity that is stored in persistent storage, or an entity that is implemented by an existing enterprise application. The
    session Bean can also be subdivided into Stateful session beans and stateless session beans. Both of the session beans can place the system logic in the Me Thod, the difference is that the Stateful session Bean can record the status of the caller, so typically a user has an entity that corresponds to the Stateful sessions bean. The stateless session bean, while also a logical component, is not responsible for recording the user state, meaning that when the user calls the stateless session bean, the EJB Container does not look for a specific stateless Ses Sion the Bean's entity to execute this method. In other words, it is likely that several consumers will execute the Instance of the same bean when executing the methods of a stateless session bean. From the memory side, Stateful The session bean is compared to the stateless sessions bean, which consumes more Java-Stateful Server memory, but the Stateful of the session bean is that he can dimension The status of the user in the holder.
    8.XML Resolution method

Sax,dom,jdom
9. What is a Web Service?

The Web service is a kind of interface to make the information between the isolated sites communicate and share with each other.

Web service uses unified, open standards on the Internet, such as HTTP, XML, SOAP (Simple Object Access Protocol), WSDL, and so on, so Web service can be used in any environment that supports these standards (WINDOWS,LINUX).

Note: The SOAP protocol (Simple Object access protocal) is an xml-based communication protocol for Network information exchange in decentralized and distributed environments. Under this protocol, a software component or application can communicate through a standard HTTP protocol. Its design goal is simplicity and extensibility, which facilitates interoperability between 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, which is based on the industry's standards of XML and HTTP, is supported by all the key companies.

(3). Because of the use of SOAP, data is used in ASCII text rather than binary transmission, debugging is convenient, and because of this, its data easily through the firewall, do not need a firewall for the program to open a separate "vulnerability."

(4). In addition, WebService implementations are much less technically difficult than CORBA and DCOM.

(5). To achieve business-to-business integration, EDI is more complete and more complex, and with WebService can be low-cost implementation, small companies can also be used.

(6). In the C/S program, WebService can achieve the Web page without the overall refresh with the server to deal with and take number.

Disadvantages:

(1). WebService uses XML to encapsulate data, causing a lot of data to be transmitted over the network.

(2). The WebService specification does not prescribe any implementation-related details, including the object model, programming language, which is inferior to CORBA.

10. There are several ways to implement multithreading, what is it? There are several ways to achieve synchronization.

A: Multithreading has two implementation methods, is the inheritance of the thread class and implementation of the Runnable interface
There are two kinds of implementations of synchronization, namely Synchronized,wait and notify
What is the difference between dynamic include and static include in 11.JSP?

Dynamic include using Jsp:include action to implement
<jsp:include page= "included.jsp" flush= "true"/>
It always checks for changes in the contained files, suitable for inclusion of dynamic pages, and can be used with parameter
Static include with the include pseudo code implementation, will not check the file contains changes, applicable to include static pages
<%@ include file= "included.htm"%>
Second, Java programming and program running results

1.Java programming, printing 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, 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)); May be the reason for the encoding, if you write int directly, there will be Java encoding and Windows encoding confusion, so write here is a string
Out.close ();
}catch (Exception e) {
E.printstacktrace ();
}
}
3. Indicate the results of the following procedure:

    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 ();//execute here, Result: 1a2b
    ab = new B (); Execute here, Result: 1a2bab
   }
   }
    Note: The static code snippet for the class, which can be considered the first load of a class ( Code executed by the virtual machine, and for the load of the class, first execute the construction of its base class, and then execute its own construction
    4. Write an example of a singleton pattern

public class singleton{
private static Singleton single = new Singleton ();
Private Singleton () {}
Public Singleton getinstance () {
return single;
}
}
Third, the database

1. Delete duplicate records of a table

If the record is exactly the same as the duplicate record, then: (The test passes under SQL server2000)

SELECT DISTINCT * into #tmpp tid
Delete from Tid
INSERT INTO TID select * from #tmpp
drop table #tmpp
If you have the ID primary key (the number, the one that increases by 1), then: (SQL server2000 test pass)

Delete from TableA where ID isn't in
(SELECT id = min (id) from TableA Group by name)

2.delete from TableA & truncate TABLE TableA difference

The TRUNCATE statement executes faster, takes up less resources, and records only the log of page deletions;
Delete for each record requires logging



Related Article

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.