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

Home Java JavaInterview questions Java intern interview questions (with answers)

Java intern interview questions (with answers)

Nov 28, 2019 pm 01:39 PM
java

Java intern interview questions (with answers)

1. What are the Java container frameworks?

There are two interfaces named Collection and Set in the Java container framework

2. List, map, set, array, what are the differences between them? Implementation classes: LinkedList, ArrayList, Vector.LinkedList: The underlying implementation is based on a linked list. The linked list memory is scattered. Each element stores its own memory address and also stores the address of the next element.

The difference between ArrayList and Vector: ArrayList is non-thread-safe and has high efficiency; Vector is based on thread-safety and has low efficiency.

1) The Set interface mainly has two implementation classes: HashSet (the bottom layer is implemented by HashMap) and LinkedHashSet

2) The Map interface mainly has two implementation classes: HashMap, HashTable and LinkedHashMap

HashMap is not thread-safe, efficient, and supports NULL; HashTable is thread-safe, inefficient, and does not support NULL

Array: Array, which can store objects and basic data types, with a fixed length.

List: The elements are ordered and repeatable.

Set: The elements are unordered, not repeated, and have no index.

Map: Two-column collection, used to store key-value pairs. Key values ??are unique and cannot be repeated.

3. What is the difference between collection and collections

a.javutil.Collection is a collection interface. It provides common interface methods for basic operations on collection objects. The Collection interface has many specific implementations in the Java class library. The significance of the Collection interface is to provide a maximum unified operation method for various specific collections.

b.java.util.Collections is a wrapper class. It contains various static polymorphic methods related to collection operations. This class cannot be instantiated and is like a utility class that serves Java's Collection framework.

4. What is the difference between string, stringbuilder and stringbuffer?

The strings used in the program can be divided into two categories: one is that it will not be used again after it is created. A string variable that can be modified and changed; the other is a string variable that allows modification after creation.

For the former string variable, since the program often needs to perform operations such as comparison and search on it, it is usually placed in an object with a certain name. Since the program completes the For the above operations on objects, the string variables stored in Java programs are String class variables;

For the latter string variable, because it is often necessary to add, insert, modify, etc. in the program Operation, so this kind of string variables are generally stored in objects of the StringBuilder class.

String string variable,

StringBuffer string variable (thread-safe),

StringBuilder string variable (non-thread-safe)

5. What is the difference between == and equals

When comparing two characters in the program, use the relational operator "==", and when comparing two strings, you need to use the equals() method .

6. The difference between & and &&

&& is a concise operator, & is a non-concise operator. The difference between concise operators (&&, ||) and non-concise operators (&, |) is that non-concise operations must calculate the left and right expressions before taking the result value; while concise expressions may only calculate the left expression without calculating the expression on the right, that is, for the expression &&, as long as the expression on the left is false, the expression on the right is not calculated, and the entire expression is false; for ||, as long as the expression on the left is true, If the expression on the right is not evaluated, the entire expression is true.

7. The difference between programs, processes and threads

1) A program is a file containing instructions and data , is stored on a disk or other data storage device, which means that the program is static code.

2) A process is an execution process of a program and is the basic unit for the system to run programs, so the process is dynamic. Running a program on the system is the process from creation, operation to death of a program. Simply put, a process is an executing program. It executes instructions one after another in the computer. At the same time, each process also occupies certain system resources, such as CPU time, memory space, files, and input and output device locations. Rights of use, etc.

3) Thread: In fact, it is similar to a process. It is also an executing program, but a thread is a smaller execution unit than a process. A process can generate multiple threads during execution, forming multiple execution paths. However, unlike processes, multiple threads of the same type share the same memory space and a set of system resources. Therefore, when the system generates a thread or switches between threads, the burden is much smaller than that of a process. Because of this, and because of this, threads are also called lightweight processes.

8. What are the states of a thread?

The five states are new state, ready state, running state, blocking state, and death state

9. The difference between thread mutual exclusion and synchronization

Mutual exclusion means that two or more threads cannot run at the same time, while synchronization is a constraint on the order in which two or more threads can run.

10. What is the difference between thread synchronization and shared data?

Sharing refers to the sharing of memory data between threads, because threads jointly own the data in the memory space This will lead to data inconsistency due to multiple threads processing data at the same time. Therefore, synchronization is proposed to solve this problem. That is, synchronization is based on sharing and is proposed for the purpose of data inconsistency caused by sharing of multiple threads. .

Synchronization means that the thread processing data cannot process data that other threads have not yet processed, but can process other data.

11. The difference between thread synchronization and asynchronous

Thread synchronization is when multiple threads access the same resource at the same time and wait for the resource access to end, which is a waste of time and low efficiency; thread synchronization: When accessing resources, access other resources while waiting idle to implement a multi-threading mechanism.

12. What are the rounding methods in Java?

The Math class provides three methods related to rounding: ceil, floor, round, these methods The meanings of the English names that act on them correspond to each other. For example: The English meaning of

ceil is the ceiling. This method means rounding up. The result of Math.ceil (11.3) is 12, and the result of Math.ceil (- The result of 11.6) is -11;

floor means floor in English, and this method means rounding down. The result of Math.floor(11.6) is 11, and the result of Math.floor(-11.4) is - 12;

The most difficult thing to master is the round method. It means "rounding". The algorithm is Math.floor(x 0.5), which means adding 0.5 to the original number and then rounding it down. Therefore, Math. The result of round(11.5) is 12, and the result of Math.round(-11.5) is -11.

Math.round() conforms to this rule: add all the positive numbers after the decimal point that are greater than 5, which is equal to 5 plus positive numbers. If it is less than 5, don’t add anything.

13.What does MVC refer to?

M - model model layer, usually the classes we write are placed in the model layer

V - View is the view layer, generally speaking of jsp page

C - control control layer, including action, service, dao, processing related business logic

14. What is the difference between classes and objects?

A class is a description of a certain type of thing, which is an abstract and conceptual definition; while an object is an actual concrete individual of that type of thing, so it is also called an instance.

15.Usage of Final?

a. Declaring a class as a final class, that is, a non-inherited class, means that it cannot be inherited by other classes.

b. Final modifier. Specifies that the value of this variable cannot be changed.

c. Final modifier. Specifies that this method cannot be overloaded.

Usage of Abstract

a. Declaring a class as an abstract class has no implementation method and requires a subclass to provide the implementation of the method, so instances of this class cannot be created. .

b. Abstract modifier. Specify that the method only declares the method header without the method body. The abstract method needs to be implemented in the subclass.

Usage of Static

a. Static modifier. Specifies that the variable is shared by all objects, that is, all instances can use the variable.

b. Final modifier. Specifies methods that can be called without instantiating an object.

16. The difference between member variables and local variables

The variables defined in the class are member variables, while the variables defined in the method are local variables.

Difference:

a. From a grammatical perspective, member variables belong to the class, while local variables are variables defined in the method or parameters of the method. ; Member variables can be modified by public, private, static and other modifiers, while local variables cannot be modified by access control modifiers and static; both member variables and local variables can be modified by final.

b. Judging from the way variables are stored in memory, member variables are part of the object, and the object exists in the heap memory, while local variables exist in the stack memory.

c. From the perspective of the survival time of variables in memory, member variables are part of the object. They exist with the creation of the object, while local variables are generated with the call of the method. The result will disappear automatically.

d. If a member variable is not assigned an initial value, it will automatically be assigned the default value of the type (with one exception, member variables modified by final but not modified by static must be assigned explicitly); Local variables are not automatically assigned a value and must be explicitly assigned before they can be used.

The above is the detailed content of Java intern interview questions (with answers). 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

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.

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

python itertools combinations example python itertools combinations example Jul 31, 2025 am 09:53 AM

itertools.combinations is used to generate all non-repetitive combinations (order irrelevant) that selects a specified number of elements from the iterable object. Its usage includes: 1. Select 2 element combinations from the list, such as ('A','B'), ('A','C'), etc., to avoid repeated order; 2. Take 3 character combinations of strings, such as "abc" and "abd", which are suitable for subsequence generation; 3. Find the combinations where the sum of two numbers is equal to the target value, such as 1 5=6, simplify the double loop logic; the difference between combinations and arrangement lies in whether the order is important, combinations regard AB and BA as the same, while permutations are regarded as different;

Troubleshooting Common Java `OutOfMemoryError` Scenarios Troubleshooting Common Java `OutOfMemoryError` Scenarios Jul 31, 2025 am 09:07 AM

java.lang.OutOfMemoryError: Javaheapspace indicates insufficient heap memory, and needs to check the processing of large objects, memory leaks and heap settings, and locate and optimize the code through the heap dump analysis tool; 2. Metaspace errors are common in dynamic class generation or hot deployment due to excessive class metadata, and MaxMetaspaceSize should be restricted and class loading should be optimized; 3. Unabletocreatenewnativethread due to exhausting system thread resources, it is necessary to check the number of threads, use thread pools, and adjust the stack size; 4. GCoverheadlimitexceeded means that GC is frequent but has less recycling, and GC logs should be analyzed and optimized.

python pytest fixture example python pytest fixture example Jul 31, 2025 am 09:35 AM

fixture is a function used to provide preset environment or data for tests. 1. Use the @pytest.fixture decorator to define fixture; 2. Inject fixture in parameter form in the test function; 3. Execute setup before yield, and then teardown; 4. Control scope through scope parameters, such as function, module, etc.; 5. Place the shared fixture in conftest.py to achieve cross-file sharing, thereby improving the maintainability and reusability of tests.

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

See all articles