20145315 《Java程序设计》第三周学习总结

20145315 《Java程序设计》第三周学习总结

教材学习内容总结

第四章

4.1类与对象

4.1.1定义类:

new clothes();新建一个对象。


class clothes {
    String color;
    char size;
    clothes(String color,char size){
        this.color=color;
        this.size=size;
    }
}
public class field {
    public static void main(String[] args) {
        clothes sun = new clothes("red",'S');
        clothes spring = new clothes("green",'M');

        System.out.printf("sum(%s,%c)%n",sun.color,sun.size);
        System.out.printf("spring(%s,%c)%n",spring.color,spring.size);

    }
}

一个原始码中可以有多个类定义,但只能有一个是公开类,而且主文档名称必须与公开类名称相同。

4.1.2使用标准类

java.util.Scanner输入

java.math.BigDecimal精确表示小数:如果要求精确度,要小心使用浮点数。

4.1.3对象指定与相等性

在操作对象时,=用在指定参考名称参考某个对象,

而==是用在比较两个参考名称是否参考同一参考对象。

4.2基本类型打包

4.2.1打包基本类型

使用类建立实例,因为对象本身可以携带更多信息。Wrapper把基本类型打包在对象之中,这样就可以操作这个对象,就像是基本类型当作对象操作。

4.2.2自动装箱

Integer data1=10;

Integer data2=20;

number类:
Number number=3.14f;

4.3数组对象

在Java中,数组就是对象

4.3.1数组基础
public class Scores {
    public static void main(String[] args) {
        int[] scores={88,81,74,68,78,76,77,85,95,93};
        for(int i = 0;i<scores.length;i++){
            System.out.printf("学生分数:%d %n",scores[i]);
        }
    }
}

length属性可以取得数组的个数,
也可以建立不规则数组。

4.3.2类类型
public class IntegerArray {
    public static void main(String[] args) {
        Integer[] scores=new Integer[3];
        for(Integer score : scores){
            System.out.println(score);
        }
    }
}
4.3.3数组复制

建立新数组

System.arrays.copyof()

Arrays.copyOf()

4.4字符串对象

由字符组成的文字符号称为字符串,
用“”来建立字符串。

4.4.1

String name="justin";

可以将字符串剖析为基本类型

4.4.2字符串特性

只要“”里面的内容相同,无论出现几次,JVM都只会建立一个String实例,并在String Pool中维护。

第五章

5.1何谓封装

用Java的构造函数语法,实现对象初始化流程封装。

    String number;
    int balance;
    int bonus;
    CashCard(String number,int balance,int bonus){
        this.number=number;
        this.balance=balance    ;
        this.bonus=bonus;
    }
}
public class CashApp {
    public static void main(String[] args) {
        CashCard[] cards={
                new CashCard("A001",500,0),
                new CashCard("A002",300,0),
                new CashCard("A003",1000,1),
                new CashCard("A004",2000,2),
                new CashCard("A005",3000,3),
        };
        for(CashCard card:cards){
            System.out.printf("(%s,%d,%d)%n",card.number,card.balance,card.bonus);
        }
    }
}

结果:
(A001,500,0)
(A002,300,0)
(A003,1000,1)
(A004,2000,2)
(A005,3000,3)

5.1.2

感觉封装到方法中类似于使用函数,封装类私有数据,让用户无法直接存取。

5.1.3

在Java中可以用private关键字定义类所私有。

5.2类语法细节

5.2.1

声明为public,表示它是一个公开类,可以在其他包中使用,也可以在构造函数上声明,以便调用。

5.2.4

this在对象建立后,为“这个对象”
的参考名称。

Git

教材学习中的问题和解决过程

通过看视频解决了关于构造函数的疑问。

学习进度条

代码行数(新增/累积) 博客量(新增/累积) 学习时间(新增/累积) 重要成长
目标 5000行 30篇 400小时
第一周 20/20 1/1 20/20
第二周 30/ 50 1/1 18/38
第三周 50/100 1/1 22/30
posted @ 2016-03-20 19:34  君知らない  阅读(134)  评论(4编辑  收藏  举报