[Java面试]JavaSE知识回顾
JavaSE(Java Standard Edition)是Java的标准版,适用于桌面或者服务器环境。以下是一些常见的JavaSE知识点及其简单示例代码:
- 变量和数据类型:
int num = 10;
double price = 20.95;
String name = "Alice";
char letter = 'A';
boolean isMember = true;
- 控制流程:
if (isMember) {
System.out.println("Welcome back, Alice!");
} else {
System.out.println("Welcome, new member!");
}
for (int i = 0; i < 5; i++) {
System.out.println("Iteration: " + i);
}
while (num > 0) {
System.out.println(num);
num--;
}
- 方法和类:
public class Greeting {
public static void main(String[] args) {
Greeting greeting = new Greeting();
greeting.sayHello("Alice");
}
public void sayHello(String name) {
System.out.println("Hello, " + name + "!");
}
}
- 异常处理:
try {
int divisor = 0;
int result = 10 / divisor;
} catch (ArithmeticException e) {
System.out.println("Caught an arithmetic exception!");
} finally {
System.out.println("Finally block executed.");
}
- 集合:
List<String> names = new ArrayList<>();
names.add("Alice");
names.add("Bob");
for (String name : names) {
System.out.println(name);
}
- 输入/输出:
import java.io.*;
public class IOExample {
public static void main(String[] args) {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter your name:");
try {
String name = reader.readLine();
System.out.println("Hello, " + name + "!");
} catch (IOException e) {
e.printStackTrace();
}
}
}
这些代码片段涵盖了基本的JavaSE语法和常用的功能,如控制流程、方法、异常处理、集合、输入输出等。在实际的面试中,面试官可能会根据你的回答深入询问某些特定的知识点或者提出相关的编程题进行考察。
评论已关闭