In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the relevant knowledge of "what are the common Java interview questions in 2021". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
1. Explain the difference between Java 7 and 8.
To be honest, there are many differences. Here, if you can list the most important ones, that's enough. You should explain the new features of Java 8.
The most important thing you should know is:
Lambda expressions, a new language feature, are introduced in this release. Lambda expressions let you treat functionality as method parameters or code as data. Lambda expressions allow you to more compactly represent instances of a single-method interface called a functional interface.
Method references provide easy-to-read lambda expressions for methods that already have a name.
The default method allows new features to be added to the interfaces of the library and ensures binary compatibility with code written for earlier versions of these interfaces.
Duplicate annotations provide the ability to apply the same annotation type to the same declaration or type usage multiple times.
Type annotations provide the ability to apply annotations wherever types are used, not just on declarations. This feature improves the type checking of your code when used with a pluggable type system.
two。 What kind of collection do you know?
Here are the most important things you should know:
ArrayList
LinkedList
HashMap
HashSet
After that, you may encounter the following questions: when to use this particular tool, what benefits it has over another tool, how to store the data, and the data structure that works behind the scenes.
Here, the best way is to learn as much about these collection types as possible, because the problems are almost endless.
3. What are the methods of the object class?
This is a very common question to determine your mastery of the basics. These are methods that every object has:
The Object class, packaged in java.lang, sits at the top of the class hierarchy tree. Each class is a direct or indirect descendant of that class, Object. The instance method Object that each class you use or write inherits. You do not need to use any of these methods, but if you choose to use them, you may need to override them with code specific to your class. This section of Object discusses the methods you inherit from:
Protected Object clone () throws CloneNotSupportedException
Create and return a copy of this object.
Public boolean equals (Object obj)
Indicates whether some other object is "equal" to this object.
Protected void finalize () throws Throwable
When garbagecollection determines that there is no longer a reference to the object, it is called on the object by the garbage collector.
Public final Class getClass ()
Returns the runtime class of the object.
Public int hashCode ()
Returns the hash code value of the object.
Public String toString ()
Returns a string representation of the object.
The notify,notifyAll and wait methods Object are both in a program, which is discussed later in the course, and does not play a role in the activities of synchronizing independently running threads introduced here. There are five ways to do this:
Public final void notify ()
Public final void notifyAll ()
Public final void wait ()
Public final void wait (long timeout)
Public final void wait (long timeout, int nanos)
4. Why are string objects immutable in Java?
Strings are immutable only in Java, so string pooling is possible. In this way, the Java runtime can save a lot of Java heap space because different String variables can refer to the same String variables in the pool. If String is immutable, an String internship will not be possible, because if any variable changes its value, it will be reflected in other variables.
If String is immutable, it poses a serious security threat to the application. For example, the database user name and password are passed as String to obtain the database connection, and the socket programming host and port details are passed as String. Because String is immutable, its value cannot be changed. Otherwise, any hacker may change the reference value, resulting in security problems in the application.
Because String is immutable, it is safe for multithreading and a single String instance can be shared between different threads. This avoids the use of synchronization for thread safety. Strings are implicitly thread-safe.
5. What's the difference between Final,Final and Finalize?
This question is one of my favorite.
The final keyword will be used in several cases to limit entities that can be assigned only once
Java finally blocks are finally blocks used to execute important code, such as closing connections, streams, and so on. The Java block always executes whether or not the exception is handled. The Java finally block is located after the try or catch block.
This is a method that is always called before deleting / destroying an object that is suitable for garbage collection to perform cleanup activities. GarbageCollector
6. What is the diamond problem?
The diamond problem reflects why we do not allow multiple inheritance in Java. If two classes have superclasses that are shared using specific methods, they are overwritten in both subclasses. Then, if you decide to inherit subClasses from these two, the language cannot determine which one you want to call if you want to call the method.
We call this problem the diamond problem. It is obtained from the name of the warning described in the figure above.
7. How do you make a class immutable?
I think this is a very difficult question. You need to make some changes to the class to achieve immutability:
(1) the course is declared as the final course and cannot be expanded.
(2) make all fields private so that direct access is not allowed.
(3) do not provide setter methods for variables
(4) set all variable fields as final values so that their values can only be assigned once.
(5) initialize all fields by performing a deep copy of the constructor.
(6) perform a clone of the object in the getter method to return a copy instead of the actual object reference.
8. What does Singleton mean?
A singleton is a class that allows only a single instance of itself and provides access to that created instance. It contains static variables that can accommodate unique and private instances of itself. You can use it when users want to limit the instantiation of a class to only one object. This is usually useful when you need a single object to coordinate actions throughout the system.
This is the end of the content of "what are the common Java interview questions in 2021"? thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.