明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
楼主: 不死猫

Java 自学日记

  [复制链接]
 楼主| 发表于 2012-7-17 11:49 | 显示全部楼层
20120717上午 阴
任何知识的学习都有一个痛苦的过程.
时间+精力=收获是不变的法则
大量的编码实战是学习的根本,概念的东西都可以通过大量的编码理解.
抄书百遍其义自现.

  1. public class Test {
  2.         public static void main(String[] args) {
  3.                 Computer.plugin(new Flash());
  4.                 Computer.plugin(new Print());
  5.         }
  6. }
  7. interface USB
  8. {
  9.         public void start();
  10.         public void stop();
  11. }
  12. class Computer
  13. {
  14.         public static void plugin(USB usb)
  15.         {
  16.                 usb.start();
  17.                 System.out.print("usb工作");
  18.                 usb.stop();
  19.         }
  20. }
  21. class Flash implements USB
  22. {
  23.         public void start()
  24.         {
  25.                 System.out.print("U盘工作");
  26.         }
  27.         public void stop()
  28.         {
  29.                 System.out.print("U盘停止工作");
  30.         }
  31. }
  32. class Print implements USB
  33. {
  34.         public void start()
  35.         {
  36.                 System.out.print("打印机开始");
  37.         }
  38.         public void stop()
  39.         {
  40.                 System.out.print("打印机停止");
  41.         }
  42. }
首先定义一个接口.
然后计算机类接受USB标准的设备就可以工作.
plugin就是插入操作,插入后被识别就可以工作.
下面的U盘和打印机满足接口要求的定制.
设备间就能互相通信.
 楼主| 发表于 2012-7-17 22:00 | 显示全部楼层
20120717晚 晴
  1. public class Test {
  2.         public static void main(String[] args)
  3.         {
  4.                 Fruit apple = new Apple();
  5.                 apple.eat();
  6.         }        
  7. }
  8. interface Fruit
  9. {
  10.         public void eat();
  11. }
  12. class Apple implements Fruit
  13. {
  14.         public void eat()
  15.         {
  16.                 System.out.print("eat Apple");
  17.         }
  18. }
  19. class Orange implements Fruit
  20. {
  21.         public void eat()
  22.         {
  23.                 System.out.print("eat Fruit");
  24.         }
  25. }
看到这里发现关键字比较多 需要CHM参考文档了
因此找到了这个下载地址
http://www.verycd.com/topics/254825/
看不习惯哪  看过这章,就看一遍视频吧,看书有点累啊.
 楼主| 发表于 2012-7-19 12:00 | 显示全部楼层
20120719 上午 阴
昨天偷懒没有看书
今天计划要看视频,就对照配套光盘看.
在对象之前的课程基本都是快速跳跃看的,算是简单的复习.
从类这里开始.
栈的概念简单理解是指 变量名
堆的概念简单理解是指 变量内容
 楼主| 发表于 2012-7-27 18:55 | 显示全部楼层
20120723 台风刚过
OK 一直看到了构造方法
 楼主| 发表于 2012-7-27 19:12 | 显示全部楼层
本帖最后由 不死猫 于 2012-8-5 11:06 编辑

20120727 连续下雨4天
对象数组 内部类
系统登录看过一遍后自己再模仿写一个

  1. public class Test {
  2.         public static void main(String[] args)
  3.         {
  4.                 Operate op = new Operate(args);
  5.                 System.out.print(op.刷卡());
  6.         }        
  7. }
  8. class Check{
  9.         private boolean pass;
  10.         public Check(String name,String password){
  11.                 if (name.equals("不死猫")&&password.equals("nonsmall")){
  12.                         pass= true;
  13.                 }else{
  14.                         pass=false;
  15.                 }
  16.         }
  17.         public boolean check(){
  18.                 return pass;
  19.         }
  20. }
  21. class Operate{
  22.         String info[];
  23.         String str,name,password;
  24.         public Operate(String info[]){
  25.                 this.info = info;
  26.                 isExit();
  27.         }
  28.         public String 刷卡(){
  29.                 name = info[0];
  30.                 password = info[1];
  31.                 Check it = new Check(name,password);
  32.                 if (it.check()){
  33.                         str = "登陆成功";
  34.                 }else{
  35.                         str="密码错误";
  36.                 }
  37.                 return str;
  38.         }
  39.         private void isExit(){
  40.                 if (info.length != 2){
  41.                         System.out.print("输入错误");
  42.                         System.exit(1);
  43.                 }
  44.         }
  45. }

 楼主| 发表于 2012-7-27 19:36 | 显示全部楼层
本帖最后由 不死猫 于 2012-8-5 11:07 编辑

看过链表的默写
  1. public class Test {
  2.         public static void main(String[] args){
  3.                 Node root = new Node("a");
  4.                 Node a1 = new Node ("a1");
  5.                 Node a2 = new Node ("a2");
  6.                 Node a3 = new Node ("a3");
  7.                 root.SetNode(a1);
  8.                 a1.SetNode(a2);
  9.                 a2.SetNode(a3);
  10.                 TestNode(root);
  11.         }
  12.         public static void TestNode(Node a){
  13.                 System.out.print(a.Getdata());
  14.                 if(a.GetNode() != null){
  15.                         TestNode(a.GetNode());
  16.                 }
  17.         }
  18. }

  19. class Node {
  20.         private String data;
  21.         private Node node;
  22.         public Node(String data){
  23.                 this.data = data;
  24.         }
  25.         public String Getdata(){
  26.                 return data;
  27.         }
  28.         public void SetNode (Node node){
  29.                 this.node = node;
  30.         }
  31.         public Node GetNode (){
  32.                 return this.node;
  33.         }
  34. }
发表于 2012-7-27 20:52 | 显示全部楼层
聪明出于勤奋,天才在于积累
 楼主| 发表于 2012-7-29 12:15 | 显示全部楼层
20120728 阴
看过链表,实际上是创建带有数据和指向方法的类,指向方法可以复用。
我觉得双向链表做拆装好像比较方便,应用还不知道。
看视频果然还是理解更快一些的。
 楼主| 发表于 2012-7-29 12:26 | 显示全部楼层
本帖最后由 不死猫 于 2012-8-5 11:07 编辑

20120729 终于出太阳了
基础的继承
  1. public class Test {
  2.         public static void main(String[] args){
  3.                 Student st = new Student();
  4.                 st.SetAge(1);
  5.                 st.SetName("1");
  6.                 st.setSchool("1");
  7.                 System.out.print(st.GetAge());
  8.         }
  9. }

  10. class Person{
  11.         private String Name;
  12.         private int Age;
  13.         public String GetName(){
  14.                 return Name;
  15.         }
  16.         public void SetName(String name){
  17.                 Name = name;
  18.         }
  19.         public int GetAge(){
  20.                 return Age;
  21.         }
  22.         public void SetAge(int age){
  23.                 Age = age;
  24.         }
  25. }

  26. class Student extends Person{
  27.         private String School;
  28.         public String getSchool(){
  29.                 return School;
  30.         }
  31.         public void setSchool(String school){
  32.                 School = school;
  33.         }
  34. }
  35. 扩展继承,访问父类

  36. public class Test {
  37.         public static void main(String[] args){
  38.                 Son son = new Son();
  39.                 son.Super().print();
  40.         }
  41. }
  42. class Father{
  43.         public void print(){
  44.                 System.out.print("father");
  45.         }
  46. }
  47. class Son extends Father{
  48.         public void print(){
  49.                 System.out.print("Son");
  50.         }
  51.         public Father Super(){
  52.                 return new Father();
  53.         }
  54. }
 楼主| 发表于 2012-7-29 13:07 | 显示全部楼层
745235222222222








'`.../j






























































oooooo
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-4-27 01:35 , Processed in 0.273254 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表