> For the complete documentation index, see [llms.txt](https://jupiter-1992.gitbook.io/jupiter-note/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jupiter-1992.gitbook.io/jupiter-note/hou-duan/note/09-mian-shi-zhi-nan.md).

# 09 面试指南

## 基础语法

### 0x01 Java 有哪些数据类型

1. 分为基本数据类型和引用数据类型。
2. 基本数据类型包括：数值型（byte、short、int、long、float、double），字符型（char）以及布尔型（boolean）。除了基本类型外，其他数据类型都属于引用类型，包括类、接口、数组等。

### 0x02 float number=3.4;有没有问题？为什么？

有问题，因为 3.4 是双精度数，将双精度型（double）赋值给浮点型（float）属于向下转型，可能会造成精度损失，所以必须进行强制类型转换，正确的写法是 `float number =(float)3.4;/ float number =3.4F;`。

### 0x03 字符串拼接的方式以及效率？

1. 使用 `+` 直接拼接，String 是 final 对象，不会被修改，每次使用 `+` 进行拼接都会创建新的对象，而不是改变原来的对象，效率低，是线程安全的。
2. 使用 `StringBuffer` 可变字符串，效率较高，是线程安全的（`StringBuffer` 的方法使用了 `synchronized` 关键字进行修饰）。
3. 使用 `StringBuilder` 可变字符串，效率最高，但是线程不安全。

### 0x04 简述 final，finally 和 finalize 区别

1. `final` 可以修饰类、方法和变量，被 `final` 修饰的类不可继承，被 `final` 修饰的方法不可重写，被 `final` 修饰的变量引用不可更改，引用的内容可以更改。
2. `finally` 用于 `try-catch` 代码块中，无论是否发生异常最后都将执行，作用是释放资源。
3. `finalize` 是 Object 类的方法，在对象被垃圾回收之前将调用一次，一般用于资源的释放。

### 0x05 ==和 equals 有什么区别？equals 和 hashCode 有什么联系？

1. 如果是引用类型，`==` 比较的是两个对象的引用是否完全相同，如果是基本类型，比较的是两个基本类型的数值是否相同。
2. 如果没有重写的话，`equals` 默认按照 `==` 进行比较，如果重写了 `equals()` 方法，则按照对应的比较规则比较。
3. 两个对象如果相等，那么它们的 hashCode 值必须相等，但两个对象的 hashCode 值相等时，它们不一定相同。

参考文章： [【7 万字干货】2021Java 实习必看面试两百题解析](https://blog.csdn.net/qq_41112238/article/details/105074636)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://jupiter-1992.gitbook.io/jupiter-note/hou-duan/note/09-mian-shi-zhi-nan.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
