Intermediate java face questions

1, Java heap and stack What is the difference?

Each thread has its own stack memory for storing local variables, method parameters and the call stack, variables stored in a thread on the other thread is not visible. The heap is shared by all threads in a public area of ​​memory. Objects are created on the heap, in order to enhance the efficiency of thread will get from a heap cache to its own stack, it could cause problems if multiple threads use the variable, then the volatile variables come into play, and it requires from the main thread reading stored values ​​of the variables.

:( heap objects)

Reference type variable, which is allocated on the heap memory or a constant pool (string constants, constant basic data types), need to be created by other means new.

The main role is to create a memory heap (new) object storage operation.

(Mainly used to store objects, slow access speed, dynamic memory allocation, survival does not need to determine ahead of time can run)

:( stack variable basic data types, object reference variables)

Reference basic data types of variables (int, short, long, byte, float, double, boolean, char, etc.) and an object variable, which is allocated on the stack memory, the variables will be automatically released out of scope.

2, Spring of Scope There are several, is achieved by @Scope notes:

(1) Singleton: only one example of a container of Bean Spring, Spring this default configuration, for example a shared full container.

(2) Prototype: each call to create a new Bean instance.

(3) Request: Web project, every http request to create a new Bean instance.

(4) Session: Web project, each http session to create a new Bean instance.

(5) GlobalSession: This is only useful in portal applications, to each create a new global http session Bean instance.

5, Spring transaction propagation behavior

The so-called spread behavior of affairs means that if before the start of the current transaction, a transaction context already exists, then there are several options you can specify execution behavior of a transactional approach. Comprising the following several represents the propagation constant in the behavior definition TransactionDefinition:

TransactionDefinition.PROPAGATION_REQUIRED: If the current transaction exists, it is added to the transaction; if no transaction, create a new business. It's the default value. 
TransactionDefinition.PROPAGATION_REQUIRES_NEW: create a new transaction, if the current transaction exists, put the current transaction pending. 
TransactionDefinition.PROPAGATION_SUPPORTS: If the current transaction exists, it is added to the transaction; if no transaction, non-transactional way places continue to run. 
TransactionDefinition.PROPAGATION_NOT_SUPPORTED: non-transaction run, if the current transaction exists, put the current transaction pending. 
TransactionDefinition.PROPAGATION_NEVER: non-transaction run, if the current transaction exists, an exception is thrown. 
TransactionDefinition.PROPAGATION_MANDATORY: If the current transaction exists, it is added to the transaction; if no transaction, an exception is thrown. 
TransactionDefinition.PROPAGATION_NESTED: If the current transaction exists, create a transaction to run as the current nested transaction transaction; if no transaction, the value is equivalent to TransactionDefinition.PROPAGATION_REQUIRED.

6, Spring's declarative transaction management efforts is what level?

Struts2 is the class level, Spring is the method level

spring transactions can be divided into programmatic and declarative transaction Affairs

7, spring MVC with struts2 difference:

Reference:   http://blog.csdn.net/chenleixing/article/details/44570681

① Struts2 class level is intercepted, a class corresponding to a request context, method level interception SPRINGMVC

② SpringMVC substantially independent of the method, exclusive request response data

③ Since Struts2 required for each package request, a variable request, session servlet like a life cycle of a package into the Map, supplying each Action use, and to ensure thread safety, so in principle, it is more memory-intensive

④ on the implementation mechanism interceptor, Struts2 interceptor has its own mechanism, SpringMVC with independent AOP way

⑤ SpringMVC entrance is servlet, and the filter is Struts2

⑥ SpringMVC integrated Ajax

⑦ SpringMVC validation support JSR303, treatment is relatively more flexible, but more complicated Struts2 validation, feeling too distraught

⑧ Spring MVC and Spring is seamless. From the management and security of this project is also higher than Struts2

⑨ Struts2 more in line with the OOP programming ideas, SpringMVC is more cautious, spread over servlet

⑩ SpringMVC development efficiency and performance than Struts2

8, the difference between ArrayList and LinkedList substantially as follows:

1.ArrayList data structure is implemented based on dynamic array, LinkedList based linked list data structure. 
2. For random access get and set, ArrayList feel better than LinkedList, because LinkedList to move the pointer. 
3. For new and delete operations add and remove, LinedList comparative advantage, because ArrayList to move data.

9, ArrayList, Vector is the main difference between the following points: 

(1): Vector is thread-safe, there are a lot of synchronized source code can be seen, rather than ArrayList. Vector and ArrayList result in efficiency can not be compared; 

(2): ArrayList and Vector are continuous linear memory space, when the storage space is insufficient, increasing the ArrayList original default 50%, Vector is increased to twice the original default;

10, HashSet and HashMap difference:

 

 

11, HashMap and Hashtable difference:

HashMap and Hashtable implement the Map interface, but the decision must first figure out which one to use before the distinction between them. The main differences are: thread safety, synchronization (synchronization), as well as speed.

  1. HashMap almost equivalent to Hashtable, except HashMap non-synchronized, and may accept the null (HashMap acceptable to null key (key) and the value (value), and is not Hashtable).
  2. HashMap non-synchronized, while Hashtable is synchronized, which means that Hashtable is thread-safe, multiple threads can share a Hashtable; and if not properly synchronized, then multiple threads can not share the HashMap. Java 5 provides ConcurrentHashMap, it is an alternative HashTable better scalability than the HashTable.
  3. Another difference is HashMap iterator (the Iterator) iterator is fail-fast, and the enumerator Hashtable iterator is not fail-fast. So when there is another thread changes the structure of HashMap (add or remove elements), it will throw ConcurrentModificationException, but the iterator's own remove () method does not remove elements throw ConcurrentModificationException exception. But this is not a certain behavior occurs, depending on JVM. This is also the difference between the Enumeration and Iterator.
  4. Because Hashtable is thread-safe is synchronized, so in a single-threaded environment, it is slower than HashMap. If you do not need to synchronize only a single thread, then use HashMap performance is better than Hashtable.
  5. HashMap does not guarantee the order of the elements with the passage of time in the Map is unchanged.

13, Spring Bean's life cycle:

  • Bean establishment, reads the BeanFactory Bean by the definition file, and generates various examples
  • Setter injection, performed Bean attributes dependency injection
  • BeanNameAware the setBeanName (), if the interface is achieved, which is executed method setBeanName
  • BeanFactoryAware the setBeanFactory (), if the interface is achieved, which is executed method setBeanFactory
  • BeanPostProcessor of processBeforeInitialization (), if the associated processor, it will be executed before this instance processBeforeInitialization Bean initialization () method
  • The InitializingBean afterPropertiesSet (), if the interface is achieved, which is executed afterPropertiesSet () for
  • Bean definition file defined in init-method
  • BeanPostProcessors of processAfterInitialization (), if the associated processor, it will be executed before this instance processAfterInitialization Bean initialization () method
  • DisposableBean's destroy (), when the container is closed, if the Bean class implements the interface, it is executed to destroy () method
  • Bean definition file defines destroy-method, when the container is closed, may be used "destory-method" defined in the definition file Method Bean

The simple answer springbean life cycle:

(1) Examples of the (necessary) Constructor objects

(2) Assembly (optional) for the property assignment

(3) correction (optional) (vessel - control classes and components - callback class)

(4) the initialization (init-method = "")

(5) Ready

(6)销毁(destroy-method=" ")

15, springmvc life cycle:

1A) client sends a http request, as long as the requests conform to the form web.xml
file configured * .action then it by the DispatcherServlet
processed.

1B) DispatcherServlet then entrusted to the http request mapper
object to the corresponding Action http requests to be processed

2) The customer mapper http request, then compare <bean name = "/ hello.action
If a match is correct, then the http request to the programmer to write Action

3) Action of performing business method, the final return ModelAndView named
object that encapsulates data and views to the logical name of the transmission views

4) ModelAndView objects as in the response to the DispatcherServlet

5) Then DispatcherServlet received ModelAndView object,
it does not know the name of the logical view is what is intended, we have commissioned a named
object view parser to parse ModelAndView specific target
content

6) The contents parser view, again referred DispatcherServlet
core controller, when the core controller then forwards the request to a specific
view page, retrieve data, and then displayed to the user

16, ajax how to solve cross-domain?

Reference: http://blog.csdn.net/u014727260/article/details/72793459

① proxy (through background operation)

② JSONP (addition response header, to allow cross-domain)

addHeader ( 'Access-Control-Allow-Origin: *'); // allow access to all sources 

addHeader ( 'Access-Control-Allow-Method: POST, GET'); // allow access manner

③ In the embodiment ajax dataType changed to "jsonp"

17, Eureka and zookeeper difference?

① do service in the distributed use eureka discovery or better, which is distributed coordination tool AP characteristics (zookeeper because of network failure on available hosts could not return)

② zookeeper technology is more mature, more information

③ Eureka. Is a component under spring cloud service dedicated to micro-service registration and discovery, Eureka is designed for service discovery

④ Zookeeper. It is used to ensure the consistency of a distributed software. Not registered for service discovery and design, but its properties can be developed into a secondary service discovery registry Bale

18, SpringCloud What are the components?

Spring Cloud provides configuration management for the development of micro-service architecture involved, service management, fusing mechanism, intelligent routing, micro broker, a control bus, a one-time token, global consistency lock, leader election, distributed session, cluster status management operations a simple way to development.

Component column:

  • Spring Cloud Config: configuration management tools to support storage configurations using Git content, support for external storage applications configured to support client configuration information refresh, configure encryption and decryption content
  • Spring Cloud Bus: event message bus for the cluster (e.g., configuration change event) and the propagation state change, may be combined to achieve thermal Spring Cloud Config deployment.
  • Spring Cloud Netflix: Netflix components for a variety of development tools provided by the package, including Eureka, Hystrix, Zuul, Archaius and so on.
  • Netflix Eureka: a component-based service management services rest, including the realization of a service registry, service registration and service discovery mechanism to achieve a cloud failover and load balancing of middle-tier server.
  • Netflix Hystrix: fault-tolerant management tools to achieve breaker mode, the node control services, in order to provide greater fault tolerance for delay and failure.
  • Netflix Ribbon: service call client load balancing component.
  • Netflix Feign: declarative services and Hystrix Ribbon calling component based.
  • Netflix Zuul: micro-services gateway, providing dynamic routing, filtering access and other services.
  • Netflix Archaius: Configuration Management API, contains a series of configuration management API, providing a dynamic type of property, thread-safe configuration operations, polling frame, a callback mechanism and other functions.
  • Spring Cloud for Cloud Foundry: binding agreement to service by Oauth2 CloudFoundry, CloudFoundry is VMware launched an open source PaaS cloud platform.
  • Spring Cloud Sleuth: log collection kit, a package Dapper, Zipkin and HTrace operation.
  • Spring Cloud Data Flow: large data operation tool, the operation data stream through the command line.
  • Spring Cloud Security: Security Toolkit to add security controls for your application, mainly refers to OAuth2.
  • Spring Cloud Consul: Consul encapsulates operation, Consul is a service discovery and configuration tools, it can be seamlessly integrated with Docker containers.
  • Spring Cloud Zookeeper: Zookeeper operations toolkit for using the service registration and discovery zookeeper way.
  • Spring Cloud Stream: dataflow operations development kit, a package of message transmission and Redis, Rabbit, Kafka like.
  • Spring Cloud CLI: Based on Spring Boot CLI, allows you to quickly create command line cloud components

Guess you like

Origin www.cnblogs.com/xzjf/p/11443398.html