美文网首页
Thinking in Java(1)

Thinking in Java(1)

作者: Mrz晴天 | 来源:发表于2015-11-08 20:08 被阅读52次

Think in Java

1:面向对象语言的特征<br />
Alan Kay 曾经总结过面向对象的编程语言的特点:

a:万物都是对象 <br />
b:程序是对象的集合,通过发送消息来告知彼此需要做的事情。

c:每个对象都有自己的有其他对象构成的存储。<b1r/>
d:每个对象都有其类型

e:某一个特定类型的对象可以接收所有的消息

2:JAVA语言小注意<br />
Ok,Java中如果变量没有初始化,会有默认值,下列程序都有体现

解决了我的一个疑惑,main方法调用void方法要么初始化,要么static
1:static方法
>public class BasicType {

/**
 * Java5支持基本类型转换成包装类型,同样也支持反转类型
 */
Character c = 'x';
char ch = c;
int i;

public static void main(String[] args) {
    print();
}

/**
 * 如果BasicType的c等于ch,那就say yes
 */
public static void print() {
    BasicType b = new BasicType();

    b.c = 'x';
    if (b.c == b.ch) {
        System.out.println("say yes" + b.i + b.returnMethod());
    } else {

        System.out.println("say no" + b.i + b.returnMethod());
    }
}

/**
 * return 有两种作用:1:表明此方法已经结束,2:返回数据
 */
public String returnMethod() {
    BasicType b = new BasicType();
    b.c = 'x';
    if (b.c == b.ch) {
        return "say yes" + b.i;
    } else {

        return "say yes" + b.i;
    }

}}

2:main方法对象初始化:

/**
 * 基本类型测试类 <br />
 * Ok,JavaDoc只能为public,以及protected对象和方法创建
 * 
 * @author James
 * @version 1.0
 * 
 */
public class BasicType {

/**
 * Java5支持基本类型转换成包装类型,同样也支持反转类型
 */
Character c = 'x';
char ch = c;
int i;

public static void main(String[] args) {
    BasicType b = new BasicType();
    b.returnMethod();
    b.print();
}

/**
 * 如果BasicType的c等于ch,那就say yes
 */
public void print() {
    BasicType b = new BasicType();

    b.c = 'x';
    if (b.c == b.ch) {
        System.out.println("say yes" + b.i + b.returnMethod());
    } else {

        System.out.println("say no" + b.i + b.returnMethod());
    }
}

/**
 * return 有两种作用:1:表明此方法已经结束,2:返回数据
 */
public String returnMethod() {
    BasicType b = new BasicType();
    b.c = 'x';
    if (b.c == b.ch) {
        return "say yes" + b.i;
    } else {

        return "say yes" + b.i;
    }

}}

关于JavaDoc:

/**
 * 基本类型测试类 <br />
 * Ok,JavaDoc只能为public,以及protected对象和方法创建
 * 
 * <pre>
 * System.out.println(new Date());
 * </pre>
 * 
 * @author James
 * @version 1.0
 * @since jdk1.7
 * 
 */
public class BasicType {

/**
 * Java5支持基本类型转换成包装类型,同样也支持反转类型
 */
Character c = 'x';
char ch = c;
int i;

public static void main(String[] args) {
    BasicType b = new BasicType();
    b.returnMethod();
    b.print();
}

/**
 * 如果BasicType的c等于ch,那就say yes
 */
public void print() {
    BasicType b = new BasicType();

    b.c = 'x';
    if (b.c == b.ch) {
        System.out.println("say yes" + b.i + b.returnMethod());
    } else {

        System.out.println("say no" + b.i + b.returnMethod());
    }
}

/**
 * return 有两种作用:1:表明此方法已经结束,2:返回数据
 */
public String returnMethod() {
    BasicType b = new BasicType();
    b.c = 'x';
    if (b.c == b.ch) {
        return "say yes" + b.i;
    } else {

        return "say yes" + b.i;
    }

}}

相关文章

网友评论

      本文标题:Thinking in Java(1)

      本文链接:https://www.haomeiwen.com/subject/jdochttx.html