20145213《Java程序设计》第三周学习总结
2016-03-20 22:08
423 查看
20145213《Java程序设计》第三周学习总结
教材学习内容总结
正所谓距离产生美,上周我还倾心于Java表面的基础语法。其简单的流程结构,屈指可数的基本类型分类,早已烂熟于心的运算符等,让我萌生出Java不过尔尔的幻觉。然而,快乐的时间总是短暂的。随着本周学习程度的不断深入,之前一直小觑为加菲猫的Java竟也露出了它的獠牙。本周的学习任务,无论从学习难度还是学习量,与之前都不可同日而语。犹记得周三的时候,我就开始自习教材的第四章了,红红火火恍恍惚惚,看一遍下来后,脑中梳理一遍,竟无所得。于是我想绕路,跳过第四章,学习第五章,可第五章动不动就出现的类,实例,对象,封装bulabula让我瞬间懵逼。上次让我有这样感同身受的文章是小学时期鲁迅先生的朝花夕拾,亦或是百草园。对于鲁迅老先生的文章,我的小学老师教课方式是让我一直读一直读。待到读出味道了,就是学有所得之际。我把这个方式运用到学习Java。第一次阅读让我有竹篮打水一场空的挫败感,关上课本,什么都记不住了。第二次阅读也算是行至水穷处,山重水复疑无路的味道更浓墨了一些。在不熟悉类,实例,参考对象这些概念前提下,还是不算认识对象这个词。第三遍第四遍。。。说多了,其实至今我才看了四遍,虽说没有柳暗花明又一村的醍醐灌顶,但依稀摸到一条道了。在没有完全掌握第四章第五章知识的前提下要我写博客,其实我是拒绝的,但眼看娄老师的DEADLINE越来越近,愁死我了。算了,箭在弦上,不得不发!我个人理解就是设计图就是类,既然是设计图,那一定规定了设计的衣服的一些基本信息,这些基本信息就是数据成员,根据设计图设计出衣服,就像根据类,设计出一个对象一样。至于Java构建函数,是在类中进行的。
标准类就像C语言中的模块函数一样,C语言中使用要声明,Java里面可以用IMPORT偷懒一下。
至于=与==,在Java里,在基本类型里使用与在C语言中使用并无二异,在C语言中能正确区分=与==,在Java基本类型中也可以正确区分。区别在于Java中类类型中的使用,操作对象,=用在指定参考名词参考某个对象,而==是用在比较两个参考名词是否参考同一个对象。
基本类型的打包是为了像操作对象一样操作基本类型。有很多类,是可以服务于对象的。对象往往可以携带更多的信息。随着版本升级,蜜糖越来越多,也就出现了自动装箱和拆箱了。
Java里的数组要区分C语言中的数组,因为数组在Java中是对象,而在C语言中只是一些数的集合。
以上是我个人在第四章的部分总结。由于第五章看过后并没有多大收获,还是没有形成一个系统的概念,在这里就不误人子弟了。
教材学习中的问题和解决过程
首先,先分享一下我发现教材中的错误。P92输出结果应该是20与11,而不是20与10.其次,谈谈一下学习中的问题吧。感觉教材对于知识的梳理衔接并不紧凑,举例代码中很多书外的知识默认我作为一个新手是懂的,这或许就是第一章中提到的对新人并不友好吧。本周学习过程中,问题很多,但具体是什么都不懂,也就很难提问并具体阐述自己的困惑了,这或许是自学的弊端了。我认为自习过程中,重要的是能培养成一个大局观。有一个整体框架和整体概念意识。其次,就是要多读多想。其实第一次阅读很多模糊不清的知识点也反复阅读后往往能逐渐明亮清晰起来。这过程需要大量学习时间,虽然我早有准备,然而事实证明准备并不充分。解决办法就是自己再挤时间出来自习。然而学习上的空缺,我只好用实践来尽可能弥补了。下面是我的实践部分;class Clothes{ String color; char size; } public class Field{ public static void main(String[] args){ Clothes sun = new Clothes(); Clothes spring = new Clothes(); sun.color = "red"; sun.size = 'S'; spring.color = "green"; spring.size = 'L'; System.out.printf("sun (%s,%c)%n",sun.color,sun.size); System.out.printf("spring (%s,%c)%n",spring.color,spring.size); } }
执行结果如下
class Clothes2{ String color; char size; Clothes2(String color,char size){ this.color = color; this.size = size; } } public class Field2{ public static void main (String[] args){ Clothes2 sun = new Clothes2("red",'S'); Clothes2 spring = new Clothes2("green",'M'); System.out.printf("sun (%s,%c)%n",sun.color,sun.size); System.out.printf("sun (%s,%c)%n",spring.color,spring.size); } }
执行结果如下
import java.util.Scanner; public class Guess{ public static void main(String[] args){ Scanner scanner = new Scanner(System.in); int number = (int) (Math.random()*10); int guess; do{ System.out.print("猜数字(0~9):"); guess = scanner.nextInt(); }while(guess != number); System.out.println("猜中了。。。"); } }
执行结果如下
import java.math.BigDecimal; public class DecimalDemo{ public static void main(String[] args){ BigDecimal m1 = new BigDecimal ("1.0"); BigDecimal m2 = new BigDecimal ("0.8"); BigDecimal m3 = m1.subtract(m2); System.out.println(m3); } }
执行结果如下
import java.math.BigDecimal; public class DecimalDemo2{ public static void main(String[] args){ BigDecimal m1 = new BigDecimal("0.1"); BigDecimal m2 = new BigDecimal("0.1"); BigDecimal m3 = new BigDecimal("0.1"); BigDecimal m4 = new BigDecimal("0.3"); if(m1.add(m2).add(m3).equals(m4)){ System.out.println("等于 0.3"); } else{ System.out.println("不等于0.3"); } } }
执行结果如下
public class IntegerDemo{ public static void main(String[] args){ int m1 = 10; int m2 = 20; Integer w1 = new Integer(m1); Integer w2 = new Integer(m2); System.out.println(m1/3); System.out.println(w1.doubleValue()/3); System.out.println(w1.compareTo(w2)); } }
执行结果如下
public class Score{ 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]); } } }
执行结果如下
import java.util.Arrays; public class Score2{ public static void main(String[] args){ int[] scores = new int[10]; for(int score : scores){ System.out.printf("%2d",score); } System.out.println(); Arrays.fill(scores,60); for(int score : scores){ System.out.printf("%3d",score); } } }
执行结果如下
public class IrregularArray{ public static void main(String[] args){ int[][] arr = new int[2][]; arr[0] = new int[] {1,2,3,4,5}; arr[1] = new int[] {1,2,3}; for(int[] row:arr){ for(int value:row){ System.out.printf("%2d",value); } System.out.println(); } } }
执行结果如下
public class IntegerArray{ public static void main(String[] args){ Integer[] scores = new Integer[3]; for(Integer score :scores){ System.out.println(score); } scores[0] = new Integer(99); scores[1] = new Integer(87); scores[2] = new Integer(66); for(Integer score : scores){ System.out.println(score); } } }
执行结果如下
import java.util.Arrays; public class CopyArray{ public static void main(String[] args){ int[] scores1 = {88,81,74,68,78,76,77,85,95,93}; int[] scores2 = Arrays.copyOf(scores1,scores1.length); for(int score : scores2){ System.out.printf("%3d",score); } System.out.println(); scores2[0] = 99; for(int score : scores1){ System.out.printf("%3d",score); } } }
执行结果如下
class Clothes { String color; char size; Clothes(String color,char size){ this.color = color; this.size = size; } } public class ShallowCopy{ public static void main(String[] args){ Clothes[] c1 = {new Clothes("red",'L'),new Clothes("blue",'M')}; Clothes[] c2 = new Clothes[c1.length]; for(int i=0;i<c1.length;i++){ c2[i]=c1[i]; } c1[0].color = "yellow"; System.out.println(c2[0].color); } }
执行结果如下
class Clothes2{ String color; char size; Clothes2(String color,char size){ this.color = color; this.size = size; } } public class DeepCopy{ public static void main(String[] args){ Clothes2[] c1 = {new Clothes2("red",'L'),new Clothes2("green",'M')}; Clothes2[] c2 = new Clothes2[c1.length]; for(int i=0;i<c1.length;i++){ Clothes2 c = new Clothes2(c1[i].color,c1[i].size); c2[i] = c; } c1[0].color = "yellow"; System.out.println(c2[0].color); } }
执行结果如下
import java.util.Scanner; public class Sum { public static void main(String[] args){ Scanner scanner = new Scanner(System.in); long sum = 0; long number = 0; do{ System.out.printf(" 输入数字:"); number = Long.parseLong(scanner.nextLine()); sum += number; }while(number != 0); System.out.println("总和:" + sum); } }
执行结果如下
class CashCard{ String number; int balance; int bonus; CashCard(String number,int balance,int bonus){ this.number = number; this.balance = balance; this.bonus = bonus; } } public class CardApp{ 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); } } }
执行结果如下
import java.util.Scanner; public class CardApp1{ public static void main (String[] args){ CashCard[] cards = { new CashCard("A001",500,0), new CashCard("A002",300,0), new CashCard("A003",1000,1) }; Scanner scanner = new Scanner(System.in); for(CashCard card : cards){ System.out.printf("为(%s,%d,%d)储值:",card.number,card.balance,card.bonus); card.store(scanner.nextInt()); System.out.printf("明细(%s,%d,%d)%n",card.number,card.balance,card.bonus); } } }
执行结果如下
class Some{ void someMethod(int i){ System.out.println("int 版本被调用"); } void someMethod(Integer integer){ System.out.println("Integer版本被调用"); } } public class OverloadBoxing{ public static void main (String[] args){ Some s = new Some(); s.someMethod(1); } }
执行结果如下
import java.util.Scanner; import static java.lang.System.in; import static java.lang.System.out; public class ImportStatic{ public static void main(String[] args){ Scanner scanner = new Scanner(in); out.print("请输入姓名"); out.printf("%s 你好!%n",scanner.nextLine()); } }
执行结果如下
public class CallByValue{ public static void main(String[] args){ Customer c1 = new Customer("Justin"); some(c1); System.out.println(c1.name); Customer c2 = new Customer("Justin"); other(c2); System.out.println(c2.name); } static void some(Customer c){ c.name = "John"; } static void other(Customer c){ c = new Customer("Bill"); } } class Customer { String name; Customer(String name){ this.name = name; } }
执行结果如下
代码调试中的问题和解决过程
这个代码我照抄教材,然而却执行失败,很费解。我也想知道为什么这个代码没有公开类class CashCard{ String number; int balance; int bonus; CashCard(String number,int balance,int bonus){ this.number = number; this.balance = balance; this.bonus = bonus; } void store(int money){ if(money >= 0){ this.balance += money; if(money >= 1000){ this.bonus++; } } else{ System.out.println("储值是负的?"); } } void charge(int money){ if(money >= 0){ if(money <= this.balance){ this.balance -=money; } else{ System.out.println("钱不够啦"); } } else{ System.out.println("扣负数?这不是叫我储值吗?"); } } int exchange(int bonus){ if(bonus >= 0){ this.bonus -= bonus; } return this.bonus; } }
其他
本周的学习任务有点失败,因为截至写博客止,我并没有很好掌握第四章和第五章的知识。总结一下原因就是自学真的要花很多时间才琢磨教材,要一个人摄取消化,这不是偶然一次心血来潮的晚自习或者懒散地拖到周末才可以解决的。这个观念一定要纠正,我就是失败在自习时间不够上。出于弥补,我只好做一些操作题来练练手。还有一点想和老师说的就是,这周学习任务真的比上周学习任务重很多,我都没来得及过渡,希望老师能把每周任务学习量均摊一下。另附上开源中国代码托管截图如下:
学习进度条
代码行数(新增/累积) | 博客量(新增/累积) | 学习时间(新增/累积) | 重要成长 | |
---|---|---|---|---|
目标 | 5000行 | 30篇 | 400小时 | |
第一周 | 20/20 | 1/1 | 10/10 | |
第二周 | 200/220 | 1/2 | 15/25 | |
第三周 | 200/42 | 1/3 | 15/40 |
参考资料
Java学习笔记(第8版)《Java学习笔记(第8版)》学习指导
相关文章推荐
- Java多线程系列--“JUC线程池”04之 线程池原理(三)
- Java并发编程:ThreadLocal
- Java 位操作符使用---Single Number
- java中处理字符编码(网页与数据库)(转)
- Java设计模式 -- 原型模式
- java 蛙跳台阶问题解决算法
- 20145214 《Java程序设计》第3周学习总结
- Java开发流程自动化(svn+maven+nexus+jenkins) --自动编译,持续集成,测试,打包,发布/部署
- Hibernate Tools for Eclipse的使用
- Java - 多线程
- JAVA--List的应用
- 20145302张薇《Java程序设计》第三周学习总结
- Eclipse 软件设置相关
- Comparable与Comparator的区别
- Spring MVC 方法参数是list
- java构造函数详解
- Java中的流与文件:ZIP文档
- Java位操作符使用总结
- Java对象的创建过程
- java foreach 循环原理