Baidu test first interview questions sharing

1. Java commonly used exception handling mechanism

Commonly used exception handling mechanisms in Java include the following:

1) try-catch-finally statement: used to catch and handle exceptions. Place code that may throw exceptions in a try block, and then handle the exception in a catch block. Regardless of whether an exception occurs, the code in the finally block will be executed.

try {
// 可能抛出异常的代码
} catch (ExceptionType1 e) {
// 处理ExceptionType1类型的异常
} catch (ExceptionType2 e) {
// 处理ExceptionType2类型的异常
} finally {
// 无论是否发生异常,都会执行的代码
}

2) throw keyword: used to manually throw exceptions. When the program encounters a certain situation, you can use the throw keyword to throw an exception object.

if (条件) {
throw new Exception("异常信息");
}

3) throws keyword: used to declare the types of exceptions that may be thrown by a method. When a method may throw an exception but does not handle the exception, you can use the throws keyword after the method signature to declare the exception type and let the caller handle the exception.    

public void methodName() throws ExceptionType1, ExceptionType2 {
// 可能抛出异常的代码
}

3) Custom exception class: You can create a custom exception class inherited from Exception or RuntimeException to represent specific errors or exceptions in the program.

class CustomException extends Exception {
public CustomException(String message) {
super(message);
}
}

2. Two subclasses of exceptions

Java's exception classes are all subclasses of java.lang.Throwable. It derives two subclasses: Error and Exception. Error indicates an exception that the program cannot handle and generally should not be thrown or caught. Exception represents the exceptions that the program may handle, including checked exceptions and unchecked exceptions. Checked exceptions refer to exceptions that the compiler requires to be handled, such as IOException, SQLException, etc. Unchecked exceptions refer to exceptions that the compiler is not required to handle, such as NullPointerException, ArrayIndexOutOfBoundsException, etc.

3. Project logs, what levels are the logs divided into?

In the project, logs are divided into five levels: TRACE, DEBUG, INFO, WARN and ERROR. Among them, TRACE level logging records the most detailed information, DEBUG level logging records are the most detailed debugging information, INFO level logging records are general running information, WARN level logging records are warning information, and ERROR level logging records are error message.

4.The difference between equals and ==

In Java, the difference between == and equals() is as follows:

- == compares whether the values ​​of two objects are equal, while equals() compares whether the contents pointed to by the two object references are equal.

- == compares the reference addresses of two objects, while equals() compares the contents of the two objects.

- If a class does not override the equals() method, then calling the equals() method is equivalent to calling the equals() method of its parent class. If a class overrides the equals() method, then you need to determine whether you need to use the equals() method to compare two objects based on the specific situation.

5. Briefly talk about java’s IO stream

Java IO stream is a streaming data input/output model, which provides an efficient way to process input/output data. Java IO streams are divided into two types: byte streams and character streams. Byte streams are read and written with bytes as the smallest unit, while character streams are read and written with characters as the smallest unit. Java IO stream contains many classes, such as InputStream, OutputStream, Reader, Writer, etc., each class has its specific purpose. For example, FileInputStream and FileOutputStream are used for reading and writing files, while BufferedReader and BufferedWriter can buffer data to improve reading and writing efficiency.

6. Given a scenario question for processing json files

7.What collection classes are there in java?

Collection classes in Java are implementations of Java data structures. Java's collection class is an important part of the java.util package, which allows elements to be grouped in various ways and defines various methods to make these elements easier to manipulate. Java collection classes are Java's encapsulation and enhancement of some basic and frequently used basic classes and then provide them in the form of a class. Collection class is a class that can store multiple objects in it. It stores objects. Different collection classes have different functions and characteristics, which are suitable for different occasions and used to solve some practical problems.

Commonly used collection classes include List, Set, Map, etc. Among them, List is an ordered and repeatable collection, Set is an unordered and non-repeatable collection, and Map is a collection in the form of key-value pairs.

8. Which is thread-safe and which is thread-unsafe (continued from the previous question)

Collection classes in Java are divided into thread-safe and unsafe. Thread safety means that in a multi-threaded environment, the collection class behaves as expected without problems such as data loss or data errors. Unsafe collection classes may cause problems such as data loss and data errors in a multi-threaded environment.

Commonly used thread-safe collection classes include Vector, HashTable, Properties, etc., while commonly used thread-unsafe collection classes include ArrayList, LinkedList, HashSet, TreeSet, HashMap, TreeMap, etc.

9. What are the functions of the thread pool?

Thread pool is a pooling technology, similar to database connection pool, HTTP connection pool, etc. The idea of ​​pooling is mainly to reduce the consumption of each acquisition and termination of resources and improve the utilization of resources. For example, in some remote areas where it is inconvenient to fetch water, people will fetch water from time to time and store it in the pool, so that they can just get it directly when using it. The same is true for thread pools. It is precisely because each creation and destruction of threads takes up too many system resources that we build such a pool to manage threads in a unified manner. Take it out of the pool when you use it, put it back when not in use, and you don’t have to destroy it. Isn’t it a lot more convenient?  

The main functions of the thread pool are as follows:   

- Avoid memory overflow problems caused by creating too many threads.

- Reduce resource consumption.

- Reuse threads, conveniently manage threads and tasks, and decouple thread creation and task execution.

- Control the number of threads running simultaneously to avoid excessive system resource usage or even crash due to too many threads.

10.java’s garbage collection mechanism gc

11.MySQL scenario question: Check the total number of students in a student table, check the students named Zhang in the student table, and check the student with the highest score.

1) Check the total number of students in a student table:

SELECT COUNT(*) FROM 学生表;

2) Check the student list with the surname Zhang:

SELECT * FROM 学生表 WHERE 姓名 LIKE '张%';

3) Check the student with the highest score:

SELECT * FROM 学生表 WHERE 成绩 = (SELECT MAX(成绩) FROM 学生表);

12.Commonly used commands in Linux (here I mentioned vim)

Vim 是一个强大的文本编辑器,它在终端中运行,并且有着丰富的功能和快捷键。以下是一些 Vim 的常见命令:

1. **打开文件和保存文件**:
   - 打开文件:`vim 文件名`
   - 保存文件:在普通模式下,输入 `:w` 并按 Enter 键
   - 保存并退出:在普通模式下,输入 `:wq` 并按 Enter 键
   - 不保存并退出:在普通模式下,输入 `:q!` 并按 Enter 键

2. **普通模式(Normal Mode)**:
   - 进入普通模式:按下 `Esc` 键
   - 移动光标:使用方向键或以下快捷键:
     - `h`:左移
     - `j`:下移
     - `k`:上移
     - `l`:右移
   - 删除字符:
     - `x`:删除光标下的字符
   - 复制和粘贴:
     - `yy`:复制当前行
     - `p`:粘贴
   - 撤销和重做:
     - `u`:撤销
     - `Ctrl + r`:重做

3. **插入模式(Insert Mode)**:
   - 进入插入模式:
     - `i`:在光标前插入
     - `a`:在光标后插入
     - `I`:在当前行的开头插入
     - `A`:在当前行的末尾插入
   - 退出插入模式:按下 `Esc` 键

4. **可视模式(Visual Mode)**:
   - 进入可视模式:
     - `v`:按字符选中文本
     - `V`:按行选中文本
   - 复制选中文本:按 `y`
   - 剪切选中文本:按 `x` 或 `d`
   - 粘贴:在普通模式下按 `p`

5. **搜索和替换**:
   - 搜索:在普通模式下,输入 `/`,然后输入要搜索的文本,按 Enter 键。可以使用 `n` 和 `N` 来浏览搜索结果。
   - 替换:在普通模式下,输入 `:%s/要替换的文本/替换成的文本/g` 来替换全文中的匹配项。

6. **跳转和撤销**:
   - 跳转到行号:在普通模式下,输入 `:`,然后输入行号,按 Enter 键。
   - 撤销:在普通模式下,输入 `u`。

7. **保存和退出**:
   - 保存文件:在普通模式下,输入 `:w` 并按 Enter 键。
   - 保存并退出:在普通模式下,输入 `:wq` 并按 Enter 键。
   - 不保存并退出:在普通模式下,输入 `:q!` 并按 Enter 键。

13. How to use vim to replace all test in a file with dev

:%s/test/dev/g

14. How to view the ten latest modified files (use ls to view)

ls -lt | head -n 10
这个命令的作用是:

ls -lt:列出当前目录下的文件和子目录,按照修改时间从新到旧的顺序排序。

-l:以长格式显示文件信息,包括文件权限、所有者、大小、修改时间等。
-t:按照修改时间排序。
head -n 10:从排序后的文件列表中取前 10 行,即显示最新修改的十个文件。

这样,你就可以看到最新修改的十个文件的列表,它们将按照修改时间从新到旧的顺序显示在终端中。如果你想查看不同数量的文件,只需更改 head 命令中的数字即可。
例如,如果你想查看最新修改的五个文件,可以使用 head -n 5。

15. How to check how much disk space the current directory occupies?

du -sh .
这个命令的作用是:

du:表示计算磁盘使用情况。
-s:表示汇总结果,只显示目录的总大小而不显示子目录的大小。
-h:以人类可读的格式显示文件大小,以 K、M、G 等单位表示。
.:表示当前目录。

16. How to check how much memory is occupied by the current process

ps aux
如果你要查看特定进程的内存占用情况,你可以使用 grep 命令来筛选出相关信息。假设你知道要查找的进程名称,
例如 myprocess,则可以使用如下命令:
ps aux | grep myprocess

17. Do you know top? You can use top to see how much memory is occupied.

默认情况下,top 会显示所有运行的进程,按照 CPU 使用率排序。你可以按 Shift+M 来按照内存使用率排序,
以便查看占用内存最多的进程在列表的顶部。

top 会实时更新进程列表和资源使用情况。你可以在列表中看到每个进程的 PID(进程标识符)、内存使用量(RES 列)
、内存使用率(%MEM 列)等信息。

若要退出 top,可以按下 q 键。

18. Once you know a port number, how do you check the pid?

netstat -tuln | grep 端口号
sudo lsof -i :端口号

19.awk command grep command
20. You have a log file, how to see if the log file contains error information.

grep "error" 文件名

21.What is a memory leak?

A server memory leak occurs when a server application continues to allocate memory without releasing it while running, causing the server's memory usage to gradually increase, and may eventually exhaust available memory, causing server performance degradation or crash. Memory leaks are a common software problem that usually requires careful diagnosis and repair.

22.What do you know about the server?

"Server" generally refers to hardware or software in a computer network that provides services, resources, or data to other computers or devices in order to satisfy client requests. Servers play an important role in the network and are used for various purposes such as storing and managing data, providing network services, hosting websites, and supporting applications.

Here are some common concepts about servers:

  1. Hardware server: This refers to a physical server, usually a dedicated computer, used to execute server software and provide various services. Hardware servers can be in different forms such as rack servers, tower servers, blade servers, etc.

  2. Virtual Server: A virtual server is a virtual instance created on a physical server through virtualization technology. A single physical server can host multiple virtual servers, each of which can run independent operating systems and applications.

  3. Server software: Server software is an application installed on server hardware to provide various services, such as network services, database services, file sharing, etc. Common server operating systems include Linux, Windows Server, etc.

  4. Web Server: A web server is a special type of server used to host websites and serve web content to client browsers. Common web servers include Apache, Nginx, IIS, etc.

  5. Database Server: A database server is a server used to store and manage a database, allowing client applications to access and manipulate data in the database. Common database servers include MySQL, PostgreSQL, Oracle, etc.

  6. Application Server: An application server is a server used to host and execute applications, typically to support business logic and back-end processing of an application. Java application servers such as Tomcat, WebLogic and application servers such as Node.js are common examples.

  7. File Server: A file server is a server used to store and share files, allowing multiple users to access and share files and resources stored on the server.

  8. Cloud Server: Cloud servers are virtual server instances running on a cloud computing platform. They are usually hosted and managed by a cloud service provider. Users can create, configure and expand cloud servers as needed.

Servers play a key role in enterprise and Internet applications, providing reliable resources and services that enable users to access and share information. They can be physical or virtual, with appropriate server architecture and configuration chosen based on different needs and scale.

23. How to deploy the mysql service on the server
24. What is the SSH command for?

SSH (Secure Shell) is a network protocol and encryption technology used to securely remotely access and manage computer systems. The main uses of SSH include the following aspects:

  1. Remote Login: SSH allows users to securely log in to a remote computer system from their local computer. This is achieved by encrypting communications so sensitive data such as usernames and passwords are protected during transmission. SSH remote login is commonly used for the management of remote servers, network devices, and cloud computing instances.

  2. File transfer: SSH can be used to securely transfer files, including uploading and downloading files. A common use case is using  scpthe (Secure Copy Protocol) command, which is based on SSH and is used to copy files between the local computer and a remote server.

    For example, copy files from local to remote server:

  3. scp 文件名 用户名@远程服务器IP:目标路径

    Copy files from remote server to local

  4. scp 用户名@远程服务器IP:远程文件路径 本地目标路径

  5. Remote command execution: SSH allows users to execute commands on a remote computer without directly logging into the remote system. This is useful for automation and batch processing tasks. Use  ssh commands to execute commands on the remote system, for example:

  6. ssh 用户名@远程服务器IP "远程命令"

  7. Port forwarding: SSH supports port forwarding, allowing users to transmit traffic in a secure communication tunnel. This is useful for protecting sensitive services and accessing restricted resources. SSH can perform local port forwarding and remote port forwarding.

  8. Encrypted communications: SSH uses encryption technology to protect the confidentiality and integrity of communications. This makes it difficult for hackers to eavesdrop or tamper with data transmissions. SSH typically uses a public and private key pair for authentication to ensure that only authorized users can access the system.

In short, SSH is a secure remote management protocol used for tasks such as remote login, file transfer, and remote command execution. It plays an important role in network and system management, especially in protecting sensitive data and system security.

25. Talk about how to upload projects to git and how to resolve conflicts

To upload a project to Git and resolve conflicts, the following steps are typically required. In this example, assume that you have created a Git repository on your local computer and want to push it to the remote repository, and may encounter conflicts when pushing.

Steps to upload the project to Git (push to the remote repository):

  1. Initialize the repository: If your project has not been initialized as a Git repository, please run the following command:

    git init

2. Add files: Add the files in the project to the staging area of ​​the Git warehouse:

git add .

This will add all changes to the staging area. This can be used if you only want to add specific files  git add 文件名.

3. Submit changes: Submit the changes in the staging area to the local warehouse and add a commit message:

git commit -m "提交消息"

4. Connect to the remote warehouse: Associate the local warehouse with the remote warehouse and add the address of the remote warehouse:

git remote add origin 远程仓库地址

For example:

git remote add origin https://github.com/你的用户名/你的仓库.git

5. Push to the remote warehouse: Push changes from the local warehouse to the remote warehouse:

git push -u origin 主分支名称

For example:

git push -u origin main

This will upload the project to the remote repository. -u Option to associate the local master branch with the remote master branch for future pushes and pulls.

Steps to resolve conflicts:

If you encounter conflicts when pushing your project, it's usually because changes in the remote repository conflict with your local changes. The steps to resolve conflicts are as follows:

  1. Pull latest changes: Before resolving conflicts, first pull the latest changes from the remote repository:

  2. git pull origin 主分支名称

    For example

  3. git pull origin main

    This will merge the changes from the remote repository locally.

  4. Resolve conflicts: Open a file that contains a conflict. You will usually see the conflicting parts wrapped in tags similar to the following:

    <<<<<<< HEAD
    本地更改
    =======
    远程更改
    >>>>>>> 远程/分支名称

    You'll need to manually edit the file, keeping the changes you want and removing the parts you don't. After resolving the conflict, save the file.

  5. Mark as resolved: Once the conflict is resolved, mark the file as resolved using the following command:

  6. git add 文件名

  7. Commit changes: Commit changes after conflict resolution

  8. git commit -m "解决冲突"

  9. Push changes: Push the changes after conflict resolution to the remote warehouse:

  10. git push origin 主分支名称

    For example:

  11. git push origin main

26. Dig deeper into the project

Finally: The complete software testing video tutorial below has been compiled and uploaded. Friends who need it can get it by themselves [guaranteed 100% free]

Software Testing Interview Document

We must study to find a high-paying job. The following interview questions are from the latest interview materials from first-tier Internet companies such as Alibaba, Tencent, Byte, etc., and some Byte bosses have given authoritative answers. After finishing this set I believe everyone can find a satisfactory job based on the interview information.

Guess you like

Origin blog.csdn.net/weixin_50829653/article/details/132855243