一线互联网大厂Java核心面试题库
正逢面试跳槽季,给大家整理了大厂问到的一些面试真题,由于文章长度限制,只给大家展示了部分题目,更多Java基础、异常、集合、并发编程、JVM、Spring全家桶、MyBatis、Redis、数据库、中间件MQ、Dubbo、Linux、Tomcat、ZooKeeper、Netty等等已整理上传,感兴趣的朋友可以看看支持一波!
创建面向对象的设计是一项艰巨的任务。这是因为我们有几个
important elements to think about with regard to the scenario that we’ll work in and the
关于我们将要工作的场景和
problem we’ll solve. This includes defining the appropriate objects that we need to create in
我们要解决的问题。这包括定义需要在其中创建的适当对象
order to reach the solution; defining the granularity of objects and looking at what
以达到解决方案;定义对象的粒度并查看
interfaces we need to create. These tasks need to be addressed during the creation process
我们需要创建的接口。这些任务需要在创建过程中解决
in design. Objects can be created to represent a real-world object or to represent a process
在设计上。可以创建对象来表示真实世界的对象或表示过程
with its algorithms and responsibilities. Furthermore, we even need to consider the number
以及它的算法和职责。此外,我们甚至需要考虑这个数字
of objects, their size, and the interface we need to access.
对象的大小,以及我们需要访问的接口。
Design patterns are great tools for helping us to identify classes and objects that don’t
设计模式是一个很好的工具,它可以帮助我们识别出不存在的类和对象
represent real-world objects and objects that are less-obvious abstractions. Moreover,
表示真实世界的对象和不太明显的抽象对象。而且,
design patterns help us to apply the finest granularity to objects and they also allow us to
设计模式帮助我们将最细的粒度应用于对象,它们也允许我们
analyze a problem and solution as a model. Design patterns make the design flexible,
分析问题和解决方案作为模型。设计模式使设计更加灵活,
providing a decoupling between classes and objects. They also provide the ability to
提供类和对象之间的解耦。它们还提供了
organize solutions, allowing delegate responsibilities to classes with the best way.
组织解决方案,允许以最佳方式将职责委派给类。
Building software is an expensive process for companies because it requires capable
对于公司来说,构建软件是一个昂贵的过程,因为它需要有能力的
professionals and infrastructure to build and maintain the software. Design patterns, with
构建和维护软件的专业人员和基础设施。设计模式,使用
their flexibility and decoupled design, make maintenance easy and therefore decrease its
他们的灵活性和解耦设计,使维护容易,因此减少了它
cost.
成本。
Understanding the basic design patterns of
了解 基础的设计模式
the Java world
Java世界
All GoF patterns have a good purpose and solve major problems of object-oriented design,
所有GoF模式都有很好的用途,解决了面向对象设计的主要问题,
but some patterns are most commonly used in the Java and Java EE ecosystem. In this book,
但是有些模式在Java和javaee生态系统中最常用。在这本书里,
these patterns are treated as basic design patterns because they are most commonly used to
这些模式被视为基本设计模式,因为它们最常用于
implement solutions on Java’s APIs, frameworks, and algorithms. Consequently,
在Java的api、框架和算法上实现解决方案。因此,
understanding these patterns will help us to understand these APIs, frameworks, and
理解这些模式将有助于我们理解这些api、框架和
algorithms, and we’ll, in turn, be able to create a better solution using Java. These patterns
算法,然后我们将能够使用Java创建一个更好的解决方案。这些模式
are Singleton, Abstract Factory, Facade, Iterator, and Proxy
是Singleton、抽象工厂、Facade、Iterator和Proxy
Explaining Singleton
解释单例
In a software project, in some solutions, we may want to ensure that a class has only one
在软件项目中,在某些解决方案中,我们可能希望确保一个类只有一个
instance of an object throughout the project and that this object is accessible at any point in
对象的实例,并且此对象在
the project. Creating a global instance or static instance will not ensure that this class will
项目。创建全局实例或静态实例不能确保该类
not be used at another point in another instance. The best way to solve this is by using the
不能在另一个实例的另一个点上使用。解决这个问题的最好方法是使用
Singleton pattern, which ensures that there is only one instance of a class in the entire
单例模式,它确保整个类中只有一个实例
project. In the following diagram, we are showing the structure of Singleton and how it is
项目。在下面的图表中,我们展示了Singleton的结构以及它是怎样的
designed:
设计:
Here, we have one class called Singleton which has a private constructor, as well as a
这里,我们有一个名为Singleton的类,它有一个私有构造函数,以及一个
reference variable of Singleton and a method for returning its unique instance. A good
惊喜
最后还准备了一套上面资料对应的面试题(有答案哦)和面试时的高频面试算法题(如果面试准备时间不够,那么集中把这些算法题做完即可,命中率高达85%+)
]