亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Table of Contents
1. Evaluate yourself on a 10-point scale - How good are you at Java?
2. Explain the difference between Java 7 and Java 8.
Here you should know the most important point:
1. Because strings are immutable in Java , to have String pool. In this way, the Java runtime saves a lot of Java heap space because different string variables can reference the same string variable in the pool. If String is not immutable, then String interning is not possible because if any variable changes value, it will be reflected in other variables.
6. What is the difference between Final, Finally and Finalize?
7. What is the problem with diamond?
8. How can you make a class immutable?
9. What does Singleton mean?
10. What is dependency injection?
Summary
Home Java JavaInterview questions 10 Frequently Asked Java Interview Questions

10 Frequently Asked Java Interview Questions

Feb 04, 2021 am 10:20 AM
java interview

10 Frequently Asked Java Interview Questions

The following are 10 questions that are often asked in recent interviews. They are now compiled and shared for reference.

1. Evaluate yourself on a 10-point scale - How good are you at Java?

If you are not sure about yourself or your proficiency in Java, then this is a very Tough questions. If you are a Java expert, you should keep it low. After this, you may get questions depending on the level you admit to. So, for example, if you said 10 but couldn't answer a fairly difficult question, that would be a disadvantage.

2. Explain the difference between Java 7 and Java 8.

Honestly, there are a lot of differences. Here, if you can list the most important ones, it will be enough. You should explain the new features in Java 8. For a complete list, visit the original website: Java 8 JDK.

The most important thing you should know is:

Lambda expressions, a new language feature, have been introduced in this version. Lambda expressions allow you to treat functions as method parameters or code as data. Lambda expressions allow you to express instances of single-method interfaces (called functional interfaces) more compactly.

Method references provide easy-to-read lambda expressions for methods that already have names.

Default methods allow new functionality to be added to a library's interfaces and ensure binary compatibility with code written for older versions of these interfaces.

Repeating annotations

Provides the ability to apply the same annotation type multiple times to the same declaration or type usage.

Type annotations

Type annotations provide the ability to apply annotations anywhere a type is used, not just in declarations. This feature supports improved code type checking when used with a pluggable type system. 3. Do you know what collection types there are?

Here you should know the most important point:

ArrayList

LinkedList

HashMap

HashSet

After this, you may have some questions like when should you use this particular collection type, what are the benefits compared to other types, how is it stored data, and how the data structures work behind the scenes.

The best approach here is to learn as much as possible about these collection types, as the variety of questions is almost inexhaustible.

4. What methods does the Object class have?

This is a very common question used to determine your familiarity with basic knowledge. These are the methods that every object has: The

Object class, which belongs to the java.lang package, is at the top of the class hierarchy tree. Every class is a direct or indirect descendant of the object class. Every class you use or write inherits an object's instance methods. You are not required to use any of these methods, however, if you choose to do so, you may need to override them with class-specific code.

The methods inherited from the Object discussed in this section are:

    protected Object clone() throws CloneNotSupportedException
  • Create and return a copy of this object.
  • public boolean equals(Object obj)
  • Identifies whether other objects are "equal" to this object.
  • protected void finalize() throws Throwable
  • The garbage collector is called on an object when it determines that there are no references to the object.
  • public final Class getClass()
  • Returns the runtime class of the object.
  • public int hashCode()
  • Returns the hashcode of the object
  • public String toString()
  • Returns the string representation of the object.
  • Object's notify, notifyAll and wait methods all play a role in the activities of independently running threads in the synchronization program. This will be discussed later and will not be discussed here.

There are five methods:

    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)
  • 5. Why are String objects immutable in Java?

1. Because strings are immutable in Java , to have String pool. In this way, the Java runtime saves a lot of Java heap space because different string variables can reference the same string variable in the pool. If String is not immutable, then String interning is not possible because if any variable changes value, it will be reflected in other variables.

(Recommendations for more related interview questions:

java interview questions and answers

)2. If the string is not immutable, then it will cause serious problems to the application. security threats. For example, the database username and password are passed as strings to get the database connection, socket programming host and port details passed as strings. Because String is immutable, its value cannot be changed. Otherwise, any hacker may change the reference value, causing security issues in the application.

3. Since String is immutable, it is safe for multi-threading, and a single string instance can be shared between different threads. For thread safety, avoid using synchronization; strings are implicitly thread safe.

4. Strings are used in Java class loaders. Immutability provides the security that the correct class is loaded by the class loader. For example, consider an instance where you are trying to load java.sql. The connection class is connected, but the referenced value is changed to myhacking. Connection class, which can perform unnecessary operations on the database.

5. Because String is immutable, its hashcode will be cached when created and does not need to be calculated again. This makes it a good candidate for keys in a map, and it is processed faster than other HashMap key objects. This is why String is the most commonly used object for HashMap keys.

6. What is the difference between Final, Finally and Finalize?

This question is my favorite.

final keyword is used in several contexts to define an entity that can only be allocated once.

Java finally block is a block used to execute important code, such as closing connections, streams, etc. Regardless of whether the exception is handled or not, the Java finally block is always executed. Java finally block follows try or catch block.

Finalize is a method called by the GarbageCollector (garbage collector) before deleting/destroying an object that is eligible for garbage collection to perform cleanup activities.

7. What is the problem with diamond?

The diamond problem reflects why multiple inheritance is not allowed in Java. If there are two classes that have a shared super class with a specific method, then it will be overridden in both subclasses. Then, if you decide to inherit from either subclass, the language has no way of deciding which method you want to call if you want to call it

We call this problem Diamond question. Its name comes from the image above, which depicts the warning.

8. How can you make a class immutable?

I think this is a very difficult problem. You need to make some modifications to your class to achieve immutability:

1. Declare the class as final so that it cannot be extended.

2. Make all fields private so that direct access is not allowed.

3. Do not provide setter methods for variables

4. Make all variable fields final so that their values ??can only be assigned once.

5. Initialize all fields through the constructor that performs deep copying.

6. Perform object cloning in the getter method to return a copy instead of returning the actual object reference.

9. What does Singleton mean?

Singleton is a class that only allows one instance of itself to be created and provides access to the created instance. It contains static variables that can hold unique and private instances of itself. It can be used when the user wishes to limit the instantiation of a class to one object. This is often helpful when a single object is needed to coordinate operations across systems.

10. What is dependency injection?

This is the first question you must know when working in Java EE or Spring. Inversion of Control (IoC) is a design principle in object-oriented programming that can be used to reduce the coupling between computer codes. The most common method is called Dependency Injection (DI), and the other method is called Dependency Lookup. Through inversion of control, when an object is created, an external entity that controls all objects in the system passes the reference of the object it depends on to it. It can also be said that dependencies are injected into the object.

The component does not perform positioning queries and only provides ordinary Java methods for the container to determine dependencies. The container is solely responsible for the assembly of components. It will pass objects that meet dependencies to the required objects through JavaBean properties or constructors. The practice of injecting dependencies through JavaBean properties is called Setter Injection; the practice of passing dependencies as constructor parameters is called Constructor Injection

Summary

In this article, we discuss the top 10 Java interview questions, which I believe, based on my experience, are the most important questions today. If you know this, I believe you will have a huge advantage in the recruiting process.

If you have had similar experiences with this topic, or if you have some success stories, please share them in the comments below.

Related recommendations: java video tutorial

The above is the detailed content of 10 Frequently Asked Java Interview Questions. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1488
72
VSCode settings.json location VSCode settings.json location Aug 01, 2025 am 06:12 AM

The settings.json file is located in the user-level or workspace-level path and is used to customize VSCode settings. 1. User-level path: Windows is C:\Users\\AppData\Roaming\Code\User\settings.json, macOS is /Users//Library/ApplicationSupport/Code/User/settings.json, Linux is /home//.config/Code/User/settings.json; 2. Workspace-level path: .vscode/settings in the project root directory

Mastering Dependency Injection in Java with Spring and Guice Mastering Dependency Injection in Java with Spring and Guice Aug 01, 2025 am 05:53 AM

DependencyInjection(DI)isadesignpatternwhereobjectsreceivedependenciesexternally,promotingloosecouplingandeasiertestingthroughconstructor,setter,orfieldinjection.2.SpringFrameworkusesannotationslike@Component,@Service,and@AutowiredwithJava-basedconfi

How to handle transactions in Java with JDBC? How to handle transactions in Java with JDBC? Aug 02, 2025 pm 12:29 PM

To correctly handle JDBC transactions, you must first turn off the automatic commit mode, then perform multiple operations, and finally commit or rollback according to the results; 1. Call conn.setAutoCommit(false) to start the transaction; 2. Execute multiple SQL operations, such as INSERT and UPDATE; 3. Call conn.commit() if all operations are successful, and call conn.rollback() if an exception occurs to ensure data consistency; at the same time, try-with-resources should be used to manage resources, properly handle exceptions and close connections to avoid connection leakage; in addition, it is recommended to use connection pools and set save points to achieve partial rollback, and keep transactions as short as possible to improve performance.

How to work with Calendar in Java? How to work with Calendar in Java? Aug 02, 2025 am 02:38 AM

Use classes in the java.time package to replace the old Date and Calendar classes; 2. Get the current date and time through LocalDate, LocalDateTime and LocalTime; 3. Create a specific date and time using the of() method; 4. Use the plus/minus method to immutably increase and decrease the time; 5. Use ZonedDateTime and ZoneId to process the time zone; 6. Format and parse date strings through DateTimeFormatter; 7. Use Instant to be compatible with the old date types when necessary; date processing in modern Java should give priority to using java.timeAPI, which provides clear, immutable and linear

Understanding the Java Virtual Machine (JVM) Internals Understanding the Java Virtual Machine (JVM) Internals Aug 01, 2025 am 06:31 AM

TheJVMenablesJava’s"writeonce,runanywhere"capabilitybyexecutingbytecodethroughfourmaincomponents:1.TheClassLoaderSubsystemloads,links,andinitializes.classfilesusingbootstrap,extension,andapplicationclassloaders,ensuringsecureandlazyclassloa

Google Chrome cannot open local files Google Chrome cannot open local files Aug 01, 2025 am 05:24 AM

ChromecanopenlocalfileslikeHTMLandPDFsbyusing"Openfile"ordraggingthemintothebrowser;ensuretheaddressstartswithfile:///;2.SecurityrestrictionsblockAJAX,localStorage,andcross-folderaccessonfile://;usealocalserverlikepython-mhttp.server8000tor

Comparing Java Frameworks: Spring Boot vs Quarkus vs Micronaut Comparing Java Frameworks: Spring Boot vs Quarkus vs Micronaut Aug 04, 2025 pm 12:48 PM

Pre-formanceTartuptimeMoryusage, Quarkusandmicronautleadduetocompile-Timeprocessingandgraalvsupport, Withquarkusoftenperforminglightbetterine ServerLess scenarios.2.Thyvelopecosyste,

Understanding Network Ports and Firewalls Understanding Network Ports and Firewalls Aug 01, 2025 am 06:40 AM

Networkportsandfirewallsworktogethertoenablecommunicationwhileensuringsecurity.1.Networkportsarevirtualendpointsnumbered0–65535,withwell-knownportslike80(HTTP),443(HTTPS),22(SSH),and25(SMTP)identifyingspecificservices.2.PortsoperateoverTCP(reliable,c

See all articles