Java intern interview questions (with answers)

(*-*)浩
Release: 2019-11-28 13:39:06
Original
4230 people have browsed it

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!

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template