《Java 面向对象程序设计》前六章内容总结

作者:杨志强
学号:202402150714

第一章 初识Java与面向对象程序设计

  • Java语言概况
    • 发展历程:起源、主要版本等
    • 特点:跨平台、安全性、可移植性等
  • 面向对象思想
    • 与面向过程对比
    • 优点:可重用、可扩展、可管理等
  • 开发环境搭建
    • JDK安装与配置
    • 常用IDE介绍
  • 第一个Java程序
public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, World!");
    }
}

第二章 Java编程基础

  • 数据类型
    • 基本数据类型:整型、浮点型、字符型、布尔型
    • 引用数据类型:类、接口、数组等
  • 变量与常量
    • 变量声明与初始化
    • 常量定义:final int MAX_VALUE = 100;
  • 运算符
    • 算术、关系、逻辑、赋值等运算符
    • 优先级与结合性
  • 流程控制
    • 顺序结构
    • 分支结构:if-elseswitch
int num = 10;
if (num > 5) {
    System.out.println("num大于5");
} else {
    System.out.println("num小于等于5");
}
- 循环结构:`for``while``do-while`
for (int i = 0; i < 5; i++) {
    System.out.println(i);
}
  • 方法
    • 定义与调用
    • 参数传递
    • 返回值
    • 方法重载
public int add(int num1, int num2) {
    return num1 + num2;
}

public double add(double num1, double num2) {
    return num1 + num2;
}

第三章 面向对象程序设计(基础)

  • 类与对象
    • 类定义:属性、行为
class Person {
    String name;
    int age;

    void speak() {
        System.out.println("我叫" + name + ",今年" + age + "岁。");
    }
}
- 对象创建与使用
Person person = new Person();
person.name = "张三";
person.age = 20;
person.speak();
  • 构造方法
    • 默认构造方法
    • 带参数构造方法
class Student {
    String name;
    int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }
}
  • 成员变量与局部变量
    • 定义与区别
    • this关键字使用
class Circle {
    private double radius;

    public Circle(double radius) {
        this.radius = radius;
    }

    public double getArea() {
        return Math.PI * radius * radius;
    }
}
  • 关键字
    • this:引用当前对象成员
    • static:类变量、类方法
class Counter {
    private static int count = 0;

    public Counter() {
        count++;
    }

    public static int getCount() {
        return count;
    }
}

第四章 面向对象程序设计(进阶)

  • 封装
    • 访问修饰符:publicprivateprotecteddefault
    • 数据隐藏与保护
class BankAccount {
    private double balance;

    public void deposit(double amount) {
        if (amount > 0) {
            balance += amount;
        }
    }

    public double getBalance() {
        return balance;
    }
}
  • 继承
    • 概念与实现:extends关键字
    • 子类对父类的扩展与修改
    • 方法重写规则
class Animal {
    public void move() {
        System.out.println("动物在移动");
    }
}

class Dog extends Animal {
    @Override
    public void move() {
        System.out.println("狗在奔跑");
    }
}
  • 多态
    • 概念与意义
    • 通过方法重写、重载实现多态
class Shape {
    public void draw() {
        System.out.println("绘制形状");
    }
}

class Circle extends Shape {
    @Override
    public void draw() {
        System.out.println("绘制圆形");
    }
}

class Rectangle extends Shape {
    @Override
    public void draw() {
        System.out.println("绘制矩形");
    }
}

public class Main {
    public static void main(String[] args) {
        Shape shape1 = new Circle();
        Shape shape2 = new Rectangle();

        shape1.draw();
        shape2.draw();
    }
}
  • 抽象类与接口
    • 抽象类:抽象方法、非抽象方法
abstract class AbstractShape {
    public abstract void draw();

    public void printInfo() {
        System.out.println("这是一个形状");
    }
}
- 接口:常量、抽象方法
interface Drawable {
    void draw();
}
- 类实现接口
class Square implements Drawable {
    @Override
    public void draw() {
        System.out.println("绘制正方形");
    }
}
    • 分类管理类和接口
    • 声明与import语句使用
package com.example.myapp;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        //...
    }
}

第五章 继承与多态

  • 继承深入
    • 派生子类
    • 域继承与隐藏
    • 方法继承与覆盖
  • 多态实现细节
    • 不同实现方式:覆盖、重载、对象引用
  • 构造函数相关
    • 重载
    • 子类调用父类构造函数:super关键字
class Parent {
    private int num;

    public Parent(int num) {
        this.num = num;
    }
}

class Child extends Parent {
    public Child(int num) {
        super(num);
    }
}
  • 包的进一步应用
    • 组织管理代码作用
    • 避免命名冲突
  • 接口应用深化
    • 声明与实现规范
    • 在多类协作中的作用

第六章 工具类与算法

  • 基础类库
    • Object
    • 数据类型类:IntegerDouble
    • Math类:Math.sqrt()Math.random()
    • System类:System.out.println()System.exit()
  • Applet类与小程序
    • 工作原理
    • 常用方法
    • HTML嵌入与参数传递
  • 数组、向量与字符串
    • 数组:定义、访问元素
int[] numbers = {1, 2, 3, 4, 5};
System.out.println(numbers[0]);
- 向量:动态数组特点
import java.util.Vector;

Vector<Integer> vector = new Vector<>();
vector.add(1);
vector.add(2);
- 字符串:`String``StringBuffer/StringBuilder`
String str1 = "Hello";
String str2 = "World";
String str3 = str1 + " " + str2;

StringBuffer stringBuffer = new StringBuffer("Hello");
stringBuffer.append(" World");
  • 常用数据结构与算法
    • 递归
public int factorial(int n) {
    if (n == 0 || n == 1) {
        return 1;
    } else {
        return n * factorial(n - 1);
    }
}
- 排序算法:冒泡、选择、插入等
public class BubbleSort {
    public static void bubbleSort(int[] arr) {
        int n = arr.length;
        for (int i = 0; i < n - 1; i++) {
            for (int j = 0; j < n - i - 1; j++) {
                if (arr[j] > arr[j + 1]) {
                    int temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                }
            }
        }
    }
}
posted @   Ada荣耀  阅读(40)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· C#/.NET/.NET Core技术前沿周刊 | 第 29 期(2025年3.1-3.9)
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
点击右上角即可分享
微信分享提示