您必须知道的60个Java和Spring面试问题

60 Java and Spring Interview Questions You Must Know
A good Java and Spring developer is aways in demand. According to Indeed, there’s currently 29,694 job openings for Java developers and 16,085 for .Net software engineers throughout the US. Follow along and read about latest top Java and Spring Interview Questions.

Originally published on FullStack.Cafe - Never Fail Your Tech Interview Again

Q1: What is the Difference between JDK and JRE?

话题:爪哇 难度:⭐

Java运行时环境(JRE)基本上是执行Java程序的Java虚拟机(JVM)。 它还包括用于执行applet的浏览器插件。 Java开发工具包(JDK)是用于Java的功能齐全的软件开发工具包,包括JRE,编译器和工具(如JavaDoc和Java Debugger),以便用户开发,编译和执行Java应用程序。

🔗 Source: github.com/snowdream

Q2: What is the difference between an Applet and a Java Application?

话题:爪哇 难度:⭐

Applet在启用Java的浏览器中执行,但是Java应用程序是可以在浏览器之外执行的独立Java程序。 但是,它们都需要存在Java虚拟机(JVM)。 此外,Java应用程序需要具有特定签名的main方法才能开始执行。 Java applet不需要这种方法即可开始执行。 最后,Java小程序通常使用限制性安全策略,而Java应用程序通常使用更为宽松的安全策略。

🔗 Source: github.com/snowdream

Q3: What is a JSP Page?

话题:爪哇 难度:⭐

Java Server Page(JSP)是一个文本文档,其中包含两种类型的文本:静态数据和JSP元素。 静态数据可以任何基于文本的格式表示,例如HTML或XML。 JSP是一种将静态内容与动态生成的内容混合在一起的技术。

🔗 Source: github.com/snowdream

Q4: What is a Servlet?

话题:爪哇 难度:⭐

Servlet是一种Java编程语言类,用于处理客户端请求并生成动态Web内容。 Servlet通常用于处理或存储HTML表单提交的数据,提供动态内容并管理无状态HTTP协议中不存在的状态信息。

🔗 Source: github.com/snowdream

Q5: What are pass by reference and pass by value?

话题:爪哇 难度:⭐⭐

通过值传递对象时,这意味着传递对象的副本。 因此,即使对该对象进行了更改,它也不会影响原始值。 通过引用传递对象时,这意味着不传递实际对象,而是传递该对象的引用。 因此,外部方法所做的任何更改也都会反映在所有地方。

🔗 Source: github.com/snowdream

Q6: What are the basic interfaces of Java Collections Framework?

话题:爪哇 难度:⭐⭐

Ĵava Collections Framework provides a well designed set of interfaces and classes that support operations on a collections of objects. The most basic interfaces that reside in the Java Collections Framework are:

  • Collection, which represents a group of objects known as its elements.
  • Set, which is a collection that cannot contain duplicate elements.
  • List, which is an ordered collection and can contain duplicate elements.
  • Map, which is an object that maps keys to values and cannot contain duplicate keys.

🔗 Source: github.com/snowdream

Q7: What differences exist between HashMap and Hashtable?

话题:爪哇 难度:⭐⭐

Both the HashMap and Hashtable classes implement the Map interface and thus, have very similar characteristics. However, they differ in the following features:

  • A HashMap allows the existence of null keys and values, while a Hashtable doesn’t allow neither null keys, nor null values.
  • A Hashtable is synchronized, while a HashMap is not. Thus, HashMap is preferred in single-threaded environments, while a Hashtable is suitable for multi-threaded environments.
  • A HashMap provides its set of keys and a Java application can iterate over them. Thus, a HashMap is fail-fast. On the other hand, a Hashtable provides an Enumeration of its keys.
  • The Hashtable class is considered to be a legacy class.

🔗 Source: github.com/snowdream

Q8: What does System.gc() and Runtime.gc() methods do?

话题:爪哇 难度:⭐⭐

这些方法可以用作JVM的提示,以启动垃圾回收。 但是,这取决于Java虚拟机(JVM)立即或稍后启动垃圾回收。

🔗 Source: github.com/snowdream

Q9: What is the difference between Exception and Error in java?

话题:爪哇 难度:⭐⭐

Ëxception and Ërror classes are both subclasses of the Throwable class. The Ëxception class is used for exceptional conditions that a user’s program should catch. The Ërror class defines exceptions that are not excepted to be caught by the user program.

🔗 Source: github.com/snowdream

Q10: What is an Java Applet?

话题:爪哇 难度:⭐⭐

Java Applet是可以包含在HTML页面中并可以在启用Java的客户端浏览器中执行的程序。 小程序用于创建动态和交互式Web应用程序。

🔗 Source: github.com/snowdream

Q11: What is JDBC?

话题:爪哇 难度:⭐⭐

JDBC is an abstraction layer that allows users to choose between databases. ĴDBC enables developers to write database applications in Java, without having to concern themselves with the underlying details of a particular database.

🔗 Source: github.com/snowdream

Q12: How are the JSP requests handled?

话题:爪哇 难度:⭐⭐

On the arrival of a JSP request, the browser first requests a page with a .jsp extension. Then, the Web server reads the request and using the JSP compiler, the Web server converts the JSP page into a servlet class. Notice that the JSP file is compiled only on the first request of the page, or if the JSP file has changed.The generated servlet class is invoked, in order to handle the browser’s request. Once the execution of the request is over, the servlet sends a response back to the client. See how to get Request parameters in a JSP.

🔗 Source: github.com/snowdream

Q13: What are Decalarations?

话题:爪哇 难度:⭐⭐

声明类似于Java中的变量声明。 声明用于声明变量,以供以后在表达式或脚本中使用。 要添加声明,必须使用序列将声明括起来。

🔗 Source: github.com/snowdream

Q14: What are benefits of using Spring?

话题:弹簧 难度:⭐⭐

以下是使用Spring Framework的一些主要好处的清单:

  • 轻巧的−就大小和透明度而言,Spring是轻量级的。spring框架的基本版本约为2MB。控制反转(IOC)−使用控制反转技术在弹簧中实现松耦合。 对象提供其依赖关系,而不是创建或查找依赖对象。面向方面(AOP)− Spring支持面向方面的编程,并通过将应用程序业务逻辑与系统服务分开来实现紧密的开发。容器− Spring包含并管理应用程序对象的生命周期和配置。MVC框架− Spring的Web框架是一个设计良好的Web MVC框架,它为Struts等Web框架或其他工程过度或不太受欢迎的Web框架提供了很好的替代方案。交易管理Spring提供了一个一致的事务管理接口,该接口可以按比例缩小到本地事务(例如,使用单个数据库),并可以扩大到全局事务(例如,使用JTA)。异常处理Spring提供了一种方便的API,可将特定于技术的异常(例如,由JDBC,Hibernate或JDO引发)转换为一致的未经检查的异常。

🔗 Source: tutorialspoint.com

Q15: What are Spring beans?

话题:弹簧 难度:⭐⭐

构成应用程序主干并由Spring IoC容器管理的对象称为豆子. A bean is an object that is instantiated, assembled, and otherwise managed by a Spring IoC container. These 豆子 are created with the configuration metadata that you supply to the container, for example, in the form of XML <bean/>定义。

🔗 Source: tutorialspoint.com

Q16: What are ORM's Spring supports?

话题:弹簧 难度:⭐⭐

Spring支持以下ORM:

  • 冬眠iBatisJPA(Java持久性API)顶联JDO(Java数据对象)J

🔗 Source: tutorialspoint.com

Q17: What is Spring Security?

话题:弹簧 难度:⭐⭐

春季安全是Spring框架的一个单独模块,致力于在Java应用程序中提供身份验证和授权方法。 它还解决了大多数常见的安全漏洞,例如CSRF攻击。

要在Web应用程序中使用Spring Security,您可以开始使用简单的注释:@EnableWebSecurity。

🔗 Source: developersbook.com

Q18: What is Circular Queue and why will you use one?

话题:数据结构 难度:⭐⭐⭐

循环队列是一个线性数据结构其中,操作是根据FIFO(先进先出)原理执行的,最后一个位置又连接回第一个位置以构成一个圆。 也叫环形缓冲区。 循环队列避免了浪费空间在使用数组的常规队列实现中。

🔗 Source: programiz.com

Q19: What does “program to interfaces, not implementations” mean?

话题:设计模式 难度:⭐⭐⭐

针对接口编码意思是,客户端代码始终包含一个由厂。

工厂返回的任何实例的类型都是任何工厂候选类都必须实现的Interface类型。 这样,客户端程序就不必担心实现,并且接口签名确定可以完成所有操作的内容。

此方法可用于在运行时更改程序的行为。 从维护的角度来看,它还可以帮助您编写更好的程序。

🔗 Source: tutorialspoint.com

Q20: What is Observer pattern?

话题:设计模式 难度:⭐⭐⭐

观察者模式(也称为发布-订阅模式) is used when there is one-to-many relationship between objects such as if one object is modified, its dependent objects are to be notified automatically. 观察者模式 falls under 行为的模式类别。

与其他对其状态感兴趣的对象具有一对多关系的对象称为学科要么发布者。 的观察者每当状态为学科 changes and can act accordingly。 的学科可以有任意数量的依赖观察者通知,以及任意数量的观察者可以订阅学科接收此类通知。

观察者模式使用两个actor类:

  • Observer(os Subscriber)抽象类提供了一个update()主题将调用此方法以将主题的状态更改通知主题。Subject(或Publisher)类也是一个抽象类,它定义了四个主要方法:连接(),分离(),setState(),and 通知()

W3sDesign_Observer_Design_Pattern_UML.jpg

🔗 Source: sitepoint.com

Q21: Can you access non static variable in static context?

话题:爪哇 难度:⭐⭐⭐

Java中的静态变量属于其类,并且其所有实例的值均相同。 JVM加载类时,将初始化静态变量。 如果您的代码尝试在没有任何实例的情况下访问非静态变量,则编译器会抱怨,因为这些变量尚未创建并且它们与任何实例都没有关联。

🔗 Source: github.com/snowdream

Q22: Does Java support multiple inheritance?

话题:爪哇 难度:⭐⭐⭐

不,Java不支持多重继承。 每个类只能在一个类上扩展,但可以实现多个接口。

🔗 Source: github.com/snowdream

Q23: Explain different ways of creating a thread. Which one would you prefer and why?

话题:爪哇 难度:⭐⭐⭐

There are three ways that can be used in order for a Ťhread to be created:

  • A class may extend the Thread class.
  • A class may implement the Runnable interface.
  • An application can use the Executor framework, in order to create a thread pool.

The Runnable interface is preferred, as it does not require an object to inherit the Ťhread class. In case your application design requires multiple inheritance, only interfaces can help you. Also, the thread pool is very efficient and can be implemented and used very easily.

🔗 Source: github.com/snowdream

Q24: What’s a deadlock?

话题:爪哇 难度:⭐⭐⭐

A condition that occurs when two processes are waiting for each other to complete, before proceeding. The result is that both processes wait endlessly.

🔗 Source: github.com/snowdream

Q25: What is difference between fail-fast and fail-safe?

话题:爪哇 难度:⭐⭐⭐

The Iterator's fail-safe property works with the clone of the underlying collection and thus, it is not affected by any modification in the collection. All the collection classes in java.util package are fail-fast, while the collection classes in java.util.concurrent are fail-safe. Fail-fast iterators throw a ConcurrentModificationException, while fail-safe iterator never throws such an exception.

🔗 Source: github.com/snowdream

Q26: What is Java Priority Queue?

话题:爪哇 难度:⭐⭐⭐

The PriorityQueue is an unbounded queue, based on a priority heap and its elements are ordered in their natural order. At the time of its creation, we can provide a Comparator that is responsible for ordering the elements of the PriorityQueue. A PriorityQueue doesn’t allow null values, those objects that doesn’t provide natural ordering, or those objects that don’t have any comparator associated with them. Finally, the Java PriorityQueue is not thread-safe and it requires O(log(n)) time for its enqueing and dequeing operations.

🔗 Source: github.com/snowdream

Q27: When is the finalize() called? What is the purpose of finalization?

话题:爪哇 难度:⭐⭐⭐

在释放对象的内存之前,垃圾回收器将调用finalize方法。 通常建议在finalize方法中释放对象持有的资源。

🔗 Source: github.com/snowdream

Q28: What is structure of Java Heap?

话题:爪哇 难度:⭐⭐⭐

JVM具有一个堆,该堆是运行时数据区域,从中分配了所有类实例和数组的内存。 它是在JVM启动时创建的。 对象的堆内存由称为垃圾回收器的自动内存管理系统回收。 堆内存由活动对象和死对象组成。 应用程序可访问活动对象,这些活动对象不会成为垃圾回收的主题。 死对象是那些应用程序将永远无法访问但尚未被垃圾收集器收集的对象。 此类对象将占据堆内存空间,直到最终由垃圾收集器将它们收集为止。

🔗 Source: github.com/snowdream

Q29: What are the restrictions imposed on Java applets?

话题:爪哇 难度:⭐⭐⭐

大多数情况下,出于安全原因,对Java applet施加了以下限制:

  • 小程序无法加载库或定义本机方法。小程序通常无法在执行主机上读取或写入文件。小程序无法读取某些系统属性。小程序无法建立网络连接,只能连接到其所在的主机。小程序无法在正在执行该程序的主机上启动任何程序。

🔗 Source: github.com/snowdream

Q30: What are Scriptlets?

话题:爪哇 难度:⭐⭐⭐

在Java Server Pages(JSP)技术中,小脚本是嵌入在JSP页面中的一段Java代码。 脚本是标记内的所有内容。 在这些标签之间,用户可以添加任何有效的摘要。

🔗 Source: github.com/snowdream

Q31: State the features of an interface.

话题:面向对象 难度:⭐⭐⭐

接口是仅包含方法签名的模板。 方法的签名由参数数量,参数类型(值,引用或输出)和参数顺序组成。 接口本身没有实现,因为它仅包含方法的定义,而没有任何方法主体。 使用以下命令定义接口接口 keyword. Moreover, you cannot instantiate an 接口. The various features of an 接口 are as follows:

  • 接口用于在代码中实现多重继承。 接口的此功能与抽象类的功能完全不同,因为一个类不能派生多个类的功能,但可以轻松实现多个接口。它定义了一组特定的方法及其参数。接口中的变量必须声明为上市,静态的,and 最后方法必须是上市和抽象。 A class implementing an interface must implement all of its methods。 An interface can derive from more than one interface。

🔗 Source: indiabix.com

Q32: What does SOLID stand for? What are its principles?

话题:软件架构 难度:⭐⭐⭐

固体是Robert C. Martin提出的前五个面向对象设计(OOD)原理的首字母缩写。

  • 小号--小号ingle-responsiblity principle。 班级应该只有一个改变理由,这意味着班级应该只有一份工作。Ø--Øpen-closed principle. Øbjects or entities should be open for extension, but closed for modification.大号--大号iskov substitution principle. 大号et q(x) be a property provable about objects of x of type T. Then q(y) should be provable for objects y of type 小号 where 小号 is a subtype of T.一世--一世nterface segregation principle。 绝不应该强迫客户端实现不使用的接口,或者不应该强迫客户端依赖于不使用的方法。d--dependency 一世nversion Principle. Entities must depend on abstractions not on concretions. 一世t states that the high level module must not depend on the low level module, but they should depend on abstractions.

🔗 Source: scotch.io

Q33: What are the DRY and DIE principles?

话题:软件架构 难度:⭐⭐⭐

在软件工程中不要重复自己(干)要么复制就是邪恶(DIE)是软件开发的原则。

🔗 Source: stackoverflow.com

Q34: Is it better to return NULL or empty values from functions/methods where the return value is not present?

话题:软件架构 难度:⭐⭐⭐

归来空值如果您打算指示没有可用数据,通常是最好的主意。

空对象表示已返回数据,而返回空值清楚地表明什么都没有退还。

此外,返回一个空值 will result in a 空值 exception if you attempt to access members in the object, which can be useful for highlighting buggy code - attempting to access a member of nothing makes no sense. Accessing members of an empty object will not fail meaning bugs can go undiscovered.

🔗 Source: stackoverflow.com

Q35: Explain Bean lifecycle in Spring framework

话题:弹簧 难度:⭐⭐⭐

以下是Spring中bean生命周期的序列:

  • 实例化−首先,spring容器从XML文件中找到bean的定义并实例化bean。填充属性−使用依赖项注入,spring填充bean定义中指定的所有属性。设置豆名称−如果bean实现BeanNameAware接口,spring将bean的id传递给setBeanName()方法。设置豆工厂−如果Bean实现BeanFactoryAware接口,则spring将beanfactory传递给setBeanFactory()方法。预初始化−也称为bean的后处理。 如果有任何与Bean相关联的BeanPostProcessors,Spring会调用postProcesserBeforeInitialization()方法。初始化bean−如果bean实现了IntializingBean,则将调用其afterPropertySet()方法。 如果bean具有init方法声明,则调用指定的初始化方法。后期初始化−如果有任何与Bean关联的BeanPostProcessor,则将调用其postProcessAfterInitialization()方法。可以使用−现在,该bean已准备好由应用程序使用。破坏−如果bean实现DisposableBean,它将调用destroy()方法。

🔗 Source: tutorialspoint.com

Q36: What is Controller in Spring MVC framework?

话题:弹簧 难度:⭐⭐⭐

控制器 provide access to the application behavior that you typically define through a service interface. 控制器 interpret user input and transform it into a model that is represented to the user by the view. Spring implements a controller in a very abstract way, which enables you to create a wide variety of controllers.

🔗 Source: tutorialspoint.com

Q37: What is Aspect?

话题:弹簧 难度:⭐⭐⭐

一个方面是具有一组API的模块,可提供横切 requirements. For example, a logging module would be called AOP aspect for logging. 一个application can have any number of aspects depending on the requirement. In Spring AOP, aspects are implemented using regular classes (the schema-based approach) or regular classes annotated with the @方面 annotation (@方面J样式)。

🔗 Source: tutorialspoint.com

Q38: What is the typical Bean life cycle in Spring Bean Factory Container?

话题:弹簧 难度:⭐⭐⭐

Spring Bean Factory容器中的Bean生命周期如下:

  • spring容器从XML文件中找到bean定义并实例化bean。使用依赖注入,spring填充bean定义中指定的所有属性如果Bean实现BeanNameAware接口,则工厂调用setBeanName()传递bean的ID。如果Bean实现BeanFactoryAware接口,则工厂调用setBeanFactory(),传递自身的实例。如果有任何与Bean相关联的BeanPostProcessor,则它们的后置-ProcessBeforeInitialization()方法将被调用。如果为bean指定了初始化方法,它将被调用。最后,如果有任何与Bean关联的BeanPostProcessor,它们的postProcessAfterInitialization()方法将被调用。

🔗 Source: developersbook.com

Q39: How to handle exceptions in Spring MVC Framework?

话题:弹簧 难度:⭐⭐⭐

Spring MVC Framework提供了以下方法来帮助我们实现可靠的异常处理。

  1. ControllerBased–Wecandefineexceptionhandlermethodsinourcontrollerclasses.Allweneedistoannotatethesemethodswith@ExceptionHandlerannotation.GlobalExceptionHandler–ExceptionHandlingisacross-cuttingconcernandSpringprovides@ControllerAdviceannotationthatwecanusewithanyclasstodefineourglobalexceptionhandler.HandlerExceptionResolverimplementation–Forgenericexceptions,mostofthetimesweservestaticpages.SpringFrameworkprovidesHandlerExceptionResolverinterfacethatwecanimplementtocreateglobalexceptionhandler.ThereasonbehindthisadditionalwaytodefineglobalexceptionhandleristhatSpringframeworkalsoprovidesdefaultimplementationclassesthatwecandefineinourspringbeanconfigurationfiletogetspringframeworkexceptionhandlingbenefits.

🔗 Source: journaldev.com

Q40: What is Spring IoC Container?

话题:弹簧 难度:⭐⭐⭐

控制反转(IoC)是实现对象依赖关系之间的松散耦合的机制。 为了在运行时实现对象的松散耦合和动态绑定,这些对象定义了它们的依赖关系,这些依赖关系正在由其他汇编器对象注入。 Spring IoC容器是将依赖项注入到对象中并使其可供我们使用的程序。

Spring Framework IoC容器类是org.springframework.beans和org.springframework.context packages和provides us different ways to decouple the object dependencies.

我们使用的一些有用的ApplicationContext实现是:

  • AnnotationConfigApplicationContext:对于使用基于注释的配置的独立Java应用程序。ClassPathXmlApplicationContext:对于使用基于XML的配置的独立Java应用程序。FileSystemXmlApplicationContext:与ClassPathXmlApplicationContext相似,除了可以从文件系统中的任何位置加载xml配置文件。AnnotationConfigWebApplicationContext和XmlWebApplicationContext用于Web应用程序。

🔗 Source: journaldev.com

Q41: Is the DispatcherServlet instantiated via an application context?

话题:弹簧 难度:⭐⭐⭐

不,分派器由Servlet容器(例如Tomcat或Jetty)实例化。 您必须定义分派器放入web.xml文件,如下所示。

您会看到load-on-startup标签为1,这意味着分派器当您将Spring MVC应用程序部署到Tomcat或任何其他Servlet容器时,实例化。 在实例化期间,它将查找文件servlet-name-context.xml,然后初始化在此文件中定义的bean。

🔗 Source: dzone.com

Q42: What is the purpose of the session scope?

话题:弹簧 难度:⭐⭐⭐

目的会话范围是为HTTP会话创建bean的实例。 这意味着,如果同一bean在会话中作用域,则它可以处理多个请求。 您可以使用scope属性或@范围Spring MVC应用程序中的注释。

🔗 Source: dzone.com

Q43: What is the difference between a synchronized method and a synchronized block?

话题:爪哇 难度:⭐⭐⭐⭐

在Java编程中,每个对象都有一个锁。 线程可以使用synced关键字获取对象的锁。 可以在方法级别(粗粒度锁)或代码的块级别(细粒度锁)中应用synced关键字。

🔗 Source: github.com/snowdream

Q44: How do you ensure that N threads can access N resources without deadlock?

话题:爪哇 难度:⭐⭐⭐⭐

在使用N个线程时避免死锁的一种非常简单的方法是在锁上施加一个顺序,并强制每个线程都遵循该顺序。 因此,如果所有线程以相同顺序锁定和解锁互斥锁,则不会出现死锁。

🔗 Source: github.com/snowdream

Q45: What is Perm Gen space in Heap?

话题:爪哇 难度:⭐⭐⭐⭐

彼尔姆Gen代表永久一代。 它是Java Heap上的空间,用于保存描述用户类(不属于Java语言的类)的元数据。 此类元数据的示例是描述类和方法的对象,它们存储在永久代中。 具有大型代码库的应用程序可以快速填充堆的这一部分,这将导致java.lang.OutOfMemoryError:PermGen不管你多高-Xmx(内存分配池的最大大小)以及计算机上的内存量。

🔗 Source: github.com/snowdream

Q46: What is RMI?

话题:爪哇 难度:⭐⭐⭐⭐

Java远程方法调用(Java RMI)是一种Java API,它执行与远程过程调用(RPC)相等同的面向对象,并支持直接传输序列化Java类和分布式垃圾回收。 远程方法调用(RMI)也可以看作是在远程运行的对象上激活方法的过程。 RMI提供了位置透明性,因为用户感觉方法是在本地运行的对象上执行的。

🔗 Source: github.com/snowdream

Q47: Explain different types of inheritance.

话题:面向对象 难度:⭐⭐⭐⭐

OOP中的继承有四种类型:

  • 单继承-包含一个基类和一个派生类层次继承-包含一个基类和相同基类的多个派生类多级继承-包含从派生类派生的类多重继承-包含几个基类和一个派生类

所有.NET语言都支持单,继承和多级继承。 它们不支持多重继承,因为在这些语言中,派生类不能具有多个基类。 但是,您可以通过接口在.NET中实现多重继承。

🔗 Source: indiabix.com

Q48: What is GOD class and why should we avoid it?

话题:软件架构 难度:⭐⭐⭐⭐

破坏其创建的应用程序的最有效方法神类。 那是跟踪大量信息并承担多项责任的类。 一个代码更改很可能会影响该类的其他部分,因此间接影响使用该类的所有其他类。 反过来,这导致更大的维护麻烦,因为除了向其添加新功能之外,没有人敢进行任何更改。

🔗 Source: stackoverflow.com

Q49: What bean scopes does Spring support? Explain them.

话题:弹簧 难度:⭐⭐⭐⭐

Spring框架支持以下五个范围,其中三个仅在使用Web感知的ApplicationContext时可用。

  • 单身人士−这将bean定义的范围限定为每个Spring IoC容器一个实例。原型−这将单个bean定义的范围限定为具有任意数量的对象实例。请求 − This scopes a bean definition to an HTTP 请求. Only valid in the context of a web-aware Spring ApplicationContext.会议 − This scopes a bean definition to an HTTP 会议. Only valid in the context of a web-aware Spring ApplicationContext.global-会议 − This scopes a bean definition to a global HTTP 会议. Only valid in the context of a web-aware Spring ApplicationContext.

🔗 Source: tutorialspoint.com

Q50: What is Weaving?

话题:弹簧 难度:⭐⭐⭐⭐

编织是链接的过程方面与其他应用程序类型或对象一起创建建议对象。

🔗 Source: tutorialspoint.com

Q51: What is the difference between concern and cross-cutting concern in Spring AOP?

话题:弹簧 难度:⭐⭐⭐⭐
  • 关心 − 关心 is behavior which we want to have in a module of an application. 关心 may be defined as a functionality we want to implement. Issues in which we are interested define our concerns.跨领域关注−这是适用于整个应用程序的一个问题,它会影响整个应用程序。 例如 日志记录,安全性和数据传输是应用程序几乎每个模块都需要考虑的问题,因此是跨领域的问题。

🔗 Source: tutorialspoint.com

Q52: What are some benefits of using Spring Transactions?

话题:弹簧 难度:⭐⭐⭐⭐
  • 提供跨不同事务API(例如JTA,JDBC,Hibernate,JPA和JDO)的一致编程模型支持声明式事务管理提供比某些复杂事务API(例如JTA)更简单的API进行程序化事务管理与Spring的各种数据访问抽象很好地集成

🔗 Source: baeldung.com

Q53: What is Aspect-Oriented Programming?

话题:弹簧 难度:⭐⭐⭐⭐

方面通过向现有代码添加额外的行为而无需修改受影响的类,从而实现跨领域关注的模块化,例如跨多种类型和对象的事务管理。

🔗 Source: baeldung.com

Q54: What is Spring WebFlux?

话题:弹簧 难度:⭐⭐⭐⭐

Spring WebFlux是Spring的反应式堆栈Web框架,它是Spring MVC的替代方案。 为了实现此反应性模型并具有高度可伸缩性,整个堆栈都是无阻塞的。

🔗 Source: baeldung.com

Q55: Compare @Component (v2.5) versus @Bean (v 3.0)

话题:弹簧 难度:⭐⭐⭐⭐

是否有可能重新使用@Component注释而不是引入@Bean注释?


@零件和@豆 do two quite different things,和shouldn't be confused.

  • @零件(和@服务和@资料库) are used to auto-detect和auto-configure beans using classpath scanning. There's an implicit one-to-one mapping between the annotated class和the bean (i.e. one bean per class). Control of wiring is quite limited with this approach, since it's purely declarative.@豆习惯于明确地声明一个bean,而不是让Spring做

回答你的问题: 当然可以; 但他们选择不这样做,因为两者是完全不同的。 春天已经很混乱了,又没有使水更浑浊了。

🔗 Source: stackoverflow.com

Q56: What's the difference between the Dependency Injection and Service Locator patterns?

话题:设计模式 难度:⭐⭐⭐⭐⭐
  • 随着服务定位器,该类仍负责创建其依赖项。 它只是使用服务定位器来做到这一点。服务定位器隐藏依赖关系-您无法通过查看对象(例如)何时从定位器获得连接来判断对象是否命中数据库。用DI,则为该类提供了相关性。 它既不知道,也不在乎它们的来源。

一个重要的结果是DI示例更容易进行单元测试-因为您可以将其依赖对象的模拟实现传递给它。 您可以将两者结合起来,并根据需要注入服务定位器(或工厂)。

🔗 Source: stackoverflow.com

Q57: What are the layers of RMI Architecture?

话题:爪哇 难度:⭐⭐⭐⭐⭐

RMI体系结构包括以下几层:

  • 存根和骨架层:此层位于开发人员视图的下方。 该层负责拦截客户端对接口的方法调用,并将这些调用重定向到远程RMI服务。远程引用层:RMI体系结构的第二层处理从客户端到服务器的远程对象的引用的解释。 该层解释和管理从客户端到远程服务对象的引用。 该连接是一对一(单播)链接。传输层:该层负责连接参与服务的两个JVM。 该层基于网络中机器之间的TCP / IP连接。 它提供了基本的连接性,以及一些防火墙的渗透策略。

🔗 Source: github.com/snowdream

Q58: What is the difference between association, aggregation and composition?

话题:面向对象 难度:⭐⭐⭐⭐⭐
  • 协会是一种关系,其中所有对象都有其自己的生命周期,并且没有所有者。

让我们以老师和学生为例。 多个学生可以与一个老师联系,一个学生可以与多个老师联系,但是对象之间没有所有权,并且都有自己的生命周期。 两者都可以独立创建和删除。

  • 聚合是协会的一种特殊形式,其中所有对象都有其自己的生命周期,但是存在所有权,子对象不能属于另一个父对象。

让我们以部门和老师为例。 一个老师不能属于多个部门,但是如果我们删除该部门,则该老师对象将不被摧毁。 我们可以将其视为“具有”关系。

  • 组成又是聚合的一种特殊形式,我们可以称其为“死亡”关系。 这是一种很强的聚合。 子对象没有生命周期,如果删除了父对象,则所有子对象也将被删除。

让我们再次以房屋与房间之间的关系为例。 房子可以包含多个房间-没有独立的房间生活,任何房间都不能属于两个不同的房子。 如果我们删除房屋-房间将被自动删除。

让我们再来看一个问题和选项之间的关系示例。 单个问题可以有多个选项,而选项不能属于多个问题。 如果我们删除问题,选项将自动删除。

🔗 Source: stackoverflow.com

Q59: What are some of the best practices for Spring Framework?

话题:弹簧 难度:⭐⭐⭐⭐⭐
  1. 避免在架构参考中使用版本号,以确保我们拥有最新的配置。根据它们的关注点来划分spring bean配置,例如spring-jdbc.xml,spring-security.xml。对于在Spring MVC中的多个上下文中使用的Spring Bean,请在根上下文中创建它们,并使用侦听器进行初始化。尽可能配置Bean依赖项,并尝试避免自动装配。对于应用程序级属性,最好的方法是创建一个属性文件,并在spring bean配置文件中读取它。对于较小的应用程序,注释很有用,但对于较大的应用程序,注释可能会很麻烦。 如果我们将所有配置都保存在XML文件中,则维护起来会更加容易。为组件使用正确的注释,以轻松理解其目的。 对于服务,请使用@Service;对于DAO bean,请使用@Repository。Spring框架有很多模块,可以使用所需的模块。 删除所有通过Spring Tool Suite模板创建项目时通常添加的额外依赖项。如果使用的是Aspect,请确保将连接的品脱保持尽可能的窄,以免出现不需要的方法的建议。 考虑更易于使用并避免任何问题的自定义注释。如果有实际好处,请使用依赖项注入,只是为了松散耦合,不要使用它,因为它很难维护。

🔗 Source: journaldev.com

Q60: How does autowiring work in Spring?

话题:弹簧 难度:⭐⭐⭐⭐⭐

首先,也是最重要的一点-所有Spring Bean都受到管理-它们“实时”存在于称为“应用程序上下文”的容器中。

其次,每个应用程序都有一个指向该上下文的入口。 Web应用程序具有Servlet,JSF使用el-resolver等。此外,在某个地方可以引导应用程序上下文,并且所有bean都可以自动连接。 在Web应用程序中,它可以是启动侦听器。

通过将一个bean的实例放置到另一个bean的实例的所需字段中来进行自动装配。 这两个类均应为bean,即应将其定义为存在于应用程序上下文中。

应用程序上下文中的“生存”是什么? 这意味着语境实例化对象,而不是实例化。 即 -你永远不会新的UserServiceImpl()-容器找到每个注入点并在那里设置实例。

🔗 Source: stackoverflow.com

Thanks 🙌 for reading and good luck on your interview!
Please share this article with your fellow devs if you like it!
Check more FullStack Interview Questions & Answers on 👉 www.fullstack.cafe

from: https://dev.to//aershov24/60-java-and-spring-interview-questions-you-must-know-802

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值