This is the 15th day of my participation in Gwen Challenge

Today we continue to look at some Java interview questions, basically the interview is often asked, there is a certain probability will encounter, I hope you can interview smoothly.

1. What are the common methods of String?

Equals: string comparison method.

Length: Returns a string length method.

Trim: Removes whitespace before and after the string and returns a new string.

ToLowerCase: the current string is converted toLowerCase.

ToUpperCase: The current string is uppercase.

SubString: intercepts a string.

Split: Splits a string based on a character and returns an array.

Replace: A string replaces a specific element.

2. What are the common methods of Files class?

Exists: Checks whether the file path exists.

CreateFile: Creates a new file.

CreateDirectory: Creates a new folder.

Delete: deletes a file or directory.

Copy: copies files.

Move: Moves a file.

Read: Reads a file.

Write: Writes files.

3. What is the initial capacity of the HashMap?

The initial capacity of a HashMap is 16.

4. To what extent will the capacity of HashMap be expanded? What is the law of capacity expansion?

HashMap has a threshold of 0.75. Once 75% of the current total capacity is reached, the capacity expansion mechanism is performed. During expansion, the capacity is directly used as the new total capacity.

5. What are the ways to create a thread?

Create a Thread class by inheriting the Thread class

Create thread classes by implementing the Runnable interface

Create threads by implementing the Callable and Future interfaces

6. What is the difference between a deep copy and a shallow copy?

Shallow copy: just copy the reference address of the object. Although it is two variables, they both point to the same memory block address, so if you change one variable, the other variable will be affected.

Deep copy: Copy a specific value directly into a new object, creating a new memory address, and modifying one variable without affecting the other.

Note: the answer is only a basic answer, not what the standard answer, everyone is not the same when the interview, so the answer to the interview questions also need to have their own heart draft, just a record, I hope you can use for reference.