Answers to the most common questions in Java Web interviews

Source: Internet
Author: User
Tags informix sybase

I. Explanations of 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

Ii. 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)

Iii. 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 collections running on servers. 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 will have 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
When Session Bean is used, 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 J2EE Server
However, the advantage of stateful Session Bean is that it can maintain the user's status.

Iv. XML Parsing Method
Sax, Dom, JDOM
5. 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.

6. What are the features of object orientation?
1. Abstraction:
Abstraction is to ignore those aspects irrelevant to the current target in a topic, so that you can pay more attention to the aspects related to the current target. Abstraction is not intended to understand all the problems, but to select a part of the problem. Abstract: Process abstraction and data abstraction.
2. Inheritance:
Inheritance is a hierarchical model that connects classes and allows reuse of encouraging classes. It provides a way to clearly express commonalities. A new class of an object can be derived from an existing class. This process is called class inheritance. The new class inherits the features of the original class. The new class is called the derived class (subclass) of the original class, and the original class is called the base class (parent class) of the new class ). A derived class can inherit methods and instance variables from its base class, and the class can modify or add new methods to make it more suitable for special needs.
3. encapsulation:
Encapsulation is to enclose the process and data. Data access can only be performed through the defined interface. Object-oriented computing begins with the basic concept that the real world can be depicted as a series of completely autonomous and encapsulated objects that access other objects through a protected interface.
4. Polymorphism:
Polymorphism allows different types of objects to respond to the same message. Polymorphism includes parameterized polymorphism and inclusion polymorphism. The polymorphism language has the advantages of flexibility, abstraction, behavior sharing, and code sharing, which effectively solves the same name problem of application functions.

7. Differences between collection and collections.
Collection is the upper-level interface of the Collection class. Its inherited interfaces include set and list.
Collections is a help class for collection classes. It provides a series of static methods for searching, sorting, thread security, and other operations on various sets.

VIII. Differences between final, finally, and finalize.
Final is used to declare attributes. Methods and classes indicate that attributes are unchangeable, methods cannot be overwritten, and classes cannot be inherited.
Finally is a part of the structure of the exception handling statement, indicating that it is always executed.
Finalize is a method of the object class. This method is called when the garbage collector is executed. It can overwrite this method to collect other resources during garbage collection, for example, close a file.
9. Difference between forward and redirect
Forward is a server request resource. The server directly accesses the URL of the target address, reads the response content of that URL, and then sends the content to the browser, the browser does not know where the content sent by the server comes from, so its address bar is still the original address.
Redirect means that the server sends a status code based on logic to tell the browser to request the address again. Generally, the browser will re-request the address with all the parameters just requested, so the session and request parameters can be obtained.

10. built-in JSP objects and methods.
Request indicates the httpservletrequest object. It contains information about browser requests and provides several useful methods for obtaining cookie, header, and session data.
Response indicates the httpservletresponse object, and provides several methods (such as cookies and header information) for setting the response to the browser)
The out object is an instance of javax. jsp. jspwriter. It provides several methods for sending output results to the browser.
Pagecontext indicates a javax. servlet. jsp. pagecontext object. It is used to facilitate access to various namespaces and servlet-Related Object APIs, and encapsulates common servlet-related functions.
Session indicates the javax. servlet. http. httpsession object of a request. Session can store user status information
Applicaton indicates a javax. servle. servletcontext object. This helps you find information about the servlet engine and Servlet environment.
Config indicates a javax. servlet. servletconfig object. This object is used to access the initialization parameters of the servlet instance.
Page indicates a servlet instance generated from the page.

11. Main Methods of the request object:
Setattribute (string name, object): Set the parameter value of the request whose name is name.
Getattribute (string name): returns the property value specified by name.
Getattributenames (): returns the name set of all attributes of the request object. The result is an enumerated instance.
Getcookies (): return all cookie objects on the client. The result is a cookie array.
Getcharacterencoding (): returns the character encoding method in the request.
Getcontentlength (): returns the length of the Request body.
Getheader (string name): Get the file header defined by HTTP
Getheaders (string name): returns all the values of the request header with the specified name. The result is an enumerated instance.
Getheadernames (): returns the name of the Request Header. The result is an enumerated instance.
Getinputstream (): returns the input stream of the request to obtain data in the request.
Getmethod (): method for obtaining data transmitted from the client to the server
Getparameter (string name): Get the parameter value specified by name sent from the client to the server.
Getparameternames (): obtains the names of all parameters sent from the client to the server. The result is an enumerated instance.
Getparametervalues (string name): obtains all values of the parameter specified by name.
Getprotocol (): gets the protocol name on which the client transmits data to the server.
Getquerystring (): Get the query string
Getrequesturi (): obtains the client address of the request string.
Getremoteaddr (): obtains the IP address of the client.
Getremotehost (): Get the client name
Getsession ([Boolean create]): returns the session associated with the request.
Getservername (): Get the server name
Getservletpath (): Get the path of the script file requested by the client
Getserverport (): Get the server port number
Removeattribute (string name): deletes an attribute in a request.

12. Common J2EE design patterns? Describe the factory model.
23 Design Patterns in Java:
Factory (factory mode), Builder (construction mode), factory method (Factory method mode ),
Prototype (original model mode), Singleton (Singleton mode), facade (facade mode ),
Adapter (adapter mode), bridge (Bridge Mode), composite (merging mode ),
Decorator, flyweight, proxy ),
Command (command mode), Interpreter (Interpreter mode), visitor (visitor mode ),
Iterator, mediator, memento ),
Observer (Observer mode), State (State mode), Strategy (Policy mode ),
Template Method (template method mode), chain of responsibleity (responsibility chain mode)
Factory mode: The factory mode is a frequently used mode. Classes implemented based on the factory mode can generate instances of a class in a group based on the provided data, generally, this group of classes has a common abstract parent class that implements the same method, but these methods perform different operations on different data. First, you need to define a base class. The subclass of this class implements the methods in the base class through different methods. Define a factory class. The factory class can generate different subclass instances according to the conditions. After obtaining the subclass instance, developers can call the methods in the base class without having to consider which subclass instance is returned.

XIII. Please explain (or briefly describe) the terms commonly used in J2EE below)
Web Container: provides an environment for the application components (JSP and Servlet) in the container, so that JSP and servlet can directly interact with the environment variable interfaces in the container, so that you do not have to pay attention to other system problems. It is mainly implemented by Web servers. For example, tomcat, WebLogic, and websphere. The interface provided by the container strictly complies with the Web application standard in J2EE specifications. We call the web server that complies with the above standards the Web Container in J2EE.
EJB container: Enterprise Java Bean container. More industry-specific characteristics. It provides various management functions for the component EJB running in it. As long as the EJB meeting the J2EE specification is put into the container, it will be managed efficiently by the container immediately. In addition, system-level services can be obtained through ready-made interfaces. For example, mail service and transaction management.
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.
JMS :( Java Message Service) Java Message Service. Communication between applications. Including point-to-point and broadcast.
JTA :( Java transaction API) Java transaction service. Provides various distributed transaction services. An application only needs to call the interfaces it provides.
JAF :( Java Action Framework) Java security authentication framework. Provides some security control frameworks. Developers can implement their own personalized security control policies through various deployment and customization.
RMI/IIOP :( Remote Method Invocation/Internet object request mediation protocol) They are mainly used to call services remotely. For example, if a program runs on a remote computer that provides the Stock Analysis Service, we can directly call it on a local computer. Of course, this requires certain specifications to communicate between heterogeneous systems. RMI is unique to Java.

14. Relationship and difference between Bs and CS.
C/s is the abbreviation of Client/Server. Servers generally use high-performance PCs, workstations, or minicomputers, and large database systems such as Oracle, Sybase, Informix, or SQL Server. The client must install dedicated client software.
B/S is the abbreviation of Brower/server. to install a browser on a client, such as Netscape Navigator or Internet Explorer, the server installs Oracle, Sybase, Informix, SQL Server, and other databases. In this structure, the user interface is fully implemented through the WWW browser. Some transaction logic is implemented at the front end, but the main transaction logic is implemented at the server end. The browser interacts with the database through the Web server.
Differences between C/S and B/S:
1. Different hardware environments:
C/s is generally built on a dedicated network. In a small network environment, the LAN provides connection and data exchange services through dedicated servers.
B/S is built on a wide area network. It does not need to be a dedicated network hardware environment, such as accessing the Internet over the phone and renting equipment. information management. it has a stronger adaptability than C/S. Generally, only the operating system and browser are available.
2. Different security requirements
C/s is generally oriented to relatively fixed user groups and has strong information security control capabilities. generally, the C/S structure is suitable for highly confidential information systems. some public information can be published through B/S.
B/S is built on a wide area network, which has relatively weak security control capabilities and may be intended for unknown users.
3. Different program Architectures
The C/S program can focus more on processes, perform multi-level permission verification, and minimize the system running speed.
B/S's multiple considerations for security and access speed are based on the need for more optimization. higher requirements for B/S architecture than c/s is a development trend, from Ms. net series of BizTalk 2000 Exchange 2000 and so on, fully support the system built by network components. the JavaBean Component Technology pushed by Sun and IBM makes B/S more mature.
4. Different Software Reuse
The reusability of components is not as good as that of components under B/S requirements.
The multiple structures of B/S pairs require relatively independent components and can be reused relatively well. You can purchase a dining table instead of a stone table on the wall.
5. Different system maintenance
Due to the integrity of the C/S program, it is necessary to make an overall investigation to solve the problems and system upgrades. Upgrading is difficult. It may be necessary to create a new system.
B/S components, which can be replaced individually to achieve seamless system upgrade. The system maintenance overhead is minimized. Users can download and install the components online to achieve the upgrade.
6. Different handling problems
The c/s program can fix the user surface and meet high security requirements in the same region. It is related to the operating system and should be the same system.
B/S is built on the Wide Area Network. It targets different user groups and is scattered across regions. This is what C/S cannot do. It has the least relationship with the operating system platform.
7. Different user interfaces
C/s is mostly built on Windows platforms, with limited performance methods and high requirements on programmers.
B/S is built on a browser, with richer and more vivid expressions to communicate with users, and most of the difficulties are reduced to reduce development costs.
8. Different information flows
C/S programs are generally typical centralized mechanical processing, with relatively low interaction.
B/S information flow to changeable, B-B B-C B-G and other information, flow changes, more like the transaction center.

15. Give me the most common runtime exception.
Arithmeticexception, arraystoreexception, bufferoverflowexception, bufferunderflowexception, cannotredoexception, cannotundoexception, classcastexception, cmexception, concurrentmodificationexception, domexception, emptystackexception, fatal,
Illegalmonitorstateexception, illegalpathstateexception, illegalstateexception, imagingopexception, exception, missingresourceexception, exception, nosuchelementexception, nullpointerexception, profiledataexception, providerexception,
Rasterformatexception, securityexception, systemexception, undeclaredthrowableexception, unmodifiablesetexception, unsupportedoperationexception

16. Scope: public, private, and protected. Differences between them when they are not written

A: The differences are as follows:
Scope: current class, same package, Child class, other package
Public √
Protected √ ×
Friendly √ ××
Private √ ×××
The default value is friendly when no data is written.

17. Differences between arraylist and vector, and between hashmap and hashtable

A: arraylist and vector are mainly used in two aspects.
1. Synchronization: the vector is thread-safe, that is, synchronous, while the arraylist is not secure or synchronous
2. Data growth: When we need to increase, the vector grows to the original training by default, while the arraylist is half of the original growth.
Hashmap and hashtable are mainly used in three aspects.
I. Historical Reasons: hashtable is based on the obsolete dictionary class, And hashmap is an implementation of the map interface introduced by Java 1.2.
2. Synchronization: hashtable is thread-safe, that is, synchronous, while hashmap is not secure or synchronous.
3. Value: Only hashmap allows you to use a null value as the key or value of a table entry.

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.