Complete Works of Java Interview Questions(13)

Complete Works of Java Interview Questions(13)

Baiyu IT haha

121. Explain the mode and characteristics of network applications.

Answer: There are roughly three types of typical network application modes: B/S, C/S, and P2P. Among them, B represents the browser (Browser), C represents the client (Client), S represents the server (Server), P2P is a peer-to-peer model, and does not distinguish between clients and servers. The B/S application mode can be regarded as a special C/S application mode, but the special client in the C/S application mode is replaced with a browser, because almost all systems have browsers, then just open The browser can use the application without the overhead of installing, configuring, and upgrading the client. In the P2P application mode, thousands of computers connected to each other are in a peer-to-peer position, and the entire network generally does not rely on dedicated centralized servers. Each computer in the network can not only act as a requester of network services, but also respond to requests from other computers and provide resources and services. Usually these resources and services include: information sharing and exchange, computing resources (such as CPU sharing), storage sharing (such as the use of cache and disk space), etc. This application model has the greatest resistance to security, version and other issues. There are many applications that mix multiple application models. The most common network video application uses almost all three modes.

Supplement: This question should be distinguished from the "e-commerce model", because when many people are asked this question, they immediately think of B2B (such as Alibaba), B2C (such as Dangdang, Amazon, JD), C2C (such as Taobao) , Paipai), C2B (such as Witkey), O2O (such as Meituan, are you hungry). For this kind of problem, you can go to Baidu for popular science.

122. What is Web Service (Web Service)?

Answer: On the surface, Web Service is an application that exposes an API that can be called through the Web to the outside world. This means that you can call this application transparently by programming, without knowing any details, and it has nothing to do with the programming language you use. For example, you can create a Web Service that provides weather forecasts. No matter which programming language you use, you can get the weather forecast of the city by calling its API and passing in city information. It is called Web Service because it transmits data based on the HTTP protocol, which enables different applications running on different machines to exchange data or integrate with each other without the help of additional, specialized third-party software or hardware.

Supplement: A concept that must be mentioned here is SOA (Service-Oriented Architecture). SOA is an idea that connects different functional units of an application through a neutral contract, independent of the hardware platform, The operating system and programming language enable various forms of functional units to be better integrated. Obviously, Web Service is a better solution for SOA. It is more of a standard than a specific technology.

123. Concept explanation: SOAP, WSDL, UDDI.

answer:

  • SOAP: Simple Object Access Protocol (Simple Object Access Protocol) is a protocol specification for exchanging data in Web Service.
  • WSDL: Web Service Description Language, which describes the public interface of Web services. This is an XML-based service description on how to communicate with and use Web services; that is, describe the protocols and information formats that need to be bound when interacting with the Web services listed in the catalog. An abstract language is usually used to describe the operations and information supported by the service, and the actual network protocol and information format are bound to the service when used.
  • UDDI: Universal Description, Discovery and Integration (Universal Description, Discovery and Integration). It is an XML-based cross-platform description specification that enables companies worldwide to publish their services on the Internet. Simply put, UDDI is a facade for accessing various WSDLs (you can refer to the facade pattern in design patterns).

Tip: Related concepts and knowledge about Web Service can be found on W3CSchool.

124. What are the specifications related to Web Service in the Java specification?

Answer: There are three related to Web Service in the Java specification:

  • JAX-WS (JSR 224): This specification is an alternative version of the early SOAP-based Web Service specification JAX-RPC. It does not provide downward compatibility, because the RPC style WSDL and related APIs have been introduced in Java EE5. Removed. WS-MetaData is a dependency specification of JAX-WS and provides related APIs for configuring Web Service and SOAP messages based on annotations.
  • JAXM (JSR 67): defines the API required to send and receive messages, which is equivalent to the server side of Web Service.
  • JAX-RS (JSR 311 & JSR 339 & JSR 370): is a set of Web Service specifications formulated by Java for the REST (Representation State Transfer) architectural style. REST is a software architecture model and a style. It does not carry a message protocol itself like SOAP. (Both styles of Web Service use HTTP as the transmission protocol, because the HTTP protocol can traverse firewalls. Java's Remote method invocation (RMI) is a heavyweight protocol that usually cannot traverse firewalls), so REST can be regarded as a software architecture based on the HTTP protocol. The two most important concepts in REST are resource location and resource operation, and the HTTP protocol just provides these two points completely. The URI in the HTTP protocol can complete resource positioning, and the GET, POST, OPTION, and DELETE methods can complete resource operations. Therefore, REST completely relies on the HTTP protocol to complete the Web Service, instead of using only the transmission characteristics of HTTP like the SOAP protocol. The positioning and operation are completed by the SOAP protocol itself. It is precisely because of the existence of the SOAP message that the SOAP-based Web Service is cumbersome and gradually eliminated.

125. Introduce the Web Service framework in the Java field you know.

Answer: There are many Web Service frameworks in the Java field, including Axis2 (an upgraded version of Axis), Jersey (RESTful Web Service framework), CXF (a continuation of XFire), Hessian, Turmeric, JBoss SOA, etc. Most of them are Open source framework.

Tip: When you are asked this type of question in the interview, you must choose the most familiar answer you have used. If you have not known it before, you should spend some time to understand two of them before the interview and compare their advantages and disadvantages. Give a beautiful answer during the interview.

126. What is ORM?

Answer: Object-Relational Mapping (ORM) is a technology that solves the problem of mismatch between the object-oriented model of the program and the relational model of the database; in simple terms, ORM is used to describe the relationship between the object and the database. Mapping metadata (XML or annotations can be used in Java), which automatically persists objects in the program to a relational database or converts rows in a relational database table into Java objects. Essentially, the data is changed from a kind of The form changes to another form.

127. What are the issues to be considered in the persistence layer design? What persistence layer frameworks have you used?

Answer: The so-called "persistence" means saving data to power-down storage devices for future use. In short, it means saving data in memory to relational databases, file systems, message queues, and other devices that provide persistence support. in. The persistence layer is a relatively independent layer in the system that focuses on achieving data persistence.
The goals of the persistence layer design include:

  • The separation of data storage logic provides an abstract data access interface.
  • The separation of the underlying implementation of data access allows you to switch the underlying implementation without modifying the code.
  • The separation of resource management and scheduling enables unified resource scheduling (such as a cache mechanism) at the data access layer.
  • Data abstraction provides more object-oriented data operations.
    The persistence layer framework is:
  • Hibernate
  • MyBatis
  • TopLink
  • Guzz
  • jOOQ
  • Spring Data
  • ActiveJDBC

128. Is SessionFactory thread safe in Hibernate? Is the session thread-safe (can two threads share the same session)?

Answer: SessionFactory corresponds to a data storage concept of Hibernate. It is thread-safe and can be accessed concurrently by multiple threads. The SessionFactory is generally only built at startup. For applications, it is best to encapsulate the SessionFactory in a singleton mode for easy access. Session is a lightweight non-thread-safe object (session cannot be shared between threads), which represents a unit of work that interacts with the database. Session is created by SessionFactory and will be closed after the task is completed. Session is the main interface provided by persistence layer services to the outside world. Session will delay the acquisition of database connections (that is, only when needed). In order to avoid creating too many sessions, you can use ThreadLocal to bind the session and the current thread together, so that the same thread can always get the same session. The getCurrentSession() method of SessionFactory in Hibernate 3 can do it.

129. What is the difference between the load and get methods of Session in Hibernate?

Answer: There are three main differences:
① If no qualified record is found, the get method returns null, and the load method throws an exception.
② The get method directly returns the entity class object, and the load method returns the agent of the entity class object.
③ Before Hibernate 3, the get method only searches for data in the first-level cache. If the corresponding data is not found, it will skip the second-level cache and directly issue SQL statements to complete the data reading; the load method can get data from the second-level cache ; Starting from Hibernate 3, the get method no longer only writes but does not read the second-level cache, it can also access the second-level cache.

Note: For the load() method, Hibernate believes that the data must exist in the database and can safely use a proxy to implement lazy loading. If there is no data, an exception will be thrown, and the data obtained through the get() method may not exist.

130. What do the save(), update(), merge(), lock(), saveOrUpdate() and persist() methods of Session do? What's the difference?

Answer: Hibernate objects have three states: transient, persistent and detached, as shown in the figure in question 135. Transient instances can become persistent by calling save(), persist() or saveOrUpdate() methods; free instances can become persistent by calling update(), saveOrUpdate(), lock() or replicate(). save() and persist() will trigger SQL INSERT statements, and update() or merge() will trigger UPDATE statements. The difference between save() and update() is that one is to change the transient state object into a persistent state, and the other is to change the free state object into a persistent state. The merge() method can complete the functions of the save() and update() methods. Its intent is to merge the new state into an existing persistent object or create a new persistent object. For the persist() method, follow the instructions in the official document: ① The persist() method persists a transient instance, but it does not guarantee that the identifier will be filled into the persistent instance immediately, and the filling of the identifier may be delayed Time to flush; ② The persist() method ensures that an INSERT statement is not triggered when it is called outside a transaction. When a long conversation process needs to be encapsulated, the persist() method is necessary; ③ save The () method does not guarantee Article ②, it must return the identifier, so it will execute the INSERT statement immediately, whether inside or outside the transaction. As for the difference between the lock() method and the update() method, the update() method turns an object in the detached state that has been changed into a persistent state; the lock() method turns an object in the detached state that has not been changed Become a persistent state.

Guess you like

Origin blog.51cto.com/15061944/2593711