Java基础知识流程与示例
一、Java知识流程
- Java语言特点和发展历史
- 数据类型、变量和常量
- 运算符和表达式
- 控制语句(if、switch、for、while等)
- 数组和字符串
- 面向对象编程(类和对象、继承、封装、多态)
- 异常处理
- 泛型
- 集合框架
- 输入输出流
- 网络编程
- 反射机制
- 注解
- 多线程编程
- Lambda表达式
- 新特性(Java 8、Java 9、Java 10等)
二、部分基础示例
包括了Java基本语法、面向对象编程、异常处理、集合框架等知识点
import java.util.*;
public class Example {
public static void main(String[] args) {
// Java基本语法示例
System.out.println("Hello, world!");
int a = 10;
int b = 20;
int c = a + b;
System.out.println("a + b = " + c);
// 面向对象编程示例
Person p1 = new Person("Tom", 20);
Person p2 = new Person("Jerry", 25);
System.out.println(p1.getName() + " is " + p1.getAge() + " years old.");
System.out.println(p2.getName() + " is " + p2.getAge() + " years old.");
// 异常处理示例
try {
int x = 1 / 0;
} catch (ArithmeticException e) {
System.out.println("Exception: " + e.getMessage());
} finally {
System.out.println("Finally block is executed.");
}
// 集合框架示例
List<String> list = new ArrayList<>();
list.add("apple");
list.add("banana");
list.add("orange");
System.out.println("The list contains " + list.size() + " elements.");
System.out.println("The second element is " + list.get(1));
Map<String, Integer> map = new HashMap<>();
map.put("apple", 1);
map.put("banana", 2);
map.put("orange", 3);
System.out.println("The map contains " + map.size() + " entries.");
System.out.println("The value for key 'banana' is " + map.get("banana"));
}
}
class Person {
private String name;
private int age;
public Person(String name, int age) {
this.name = name;
this.age = age;
}
public String getName() {
return this.name;
}
public int getAge() {
return this.age;
}
}
后续更新......
本文来自博客园,作者:手可敲星辰脚驾七彩云,转载请注明原文链接:https://www.cnblogs.com/arek/p/17254942.html,谢谢!