2017-02-13 Head First Java 第一章 上

2017-02-13 Head First Java

1:写一次就可以在所有地方执行 write-once/run-anywhere。

2:编译器会产生字节码。编译后的字节码与平台无关。

3:Java虚拟机可以读取与执行字节码。

4:Sharpen your pencil/sharpen |ˈʃɑːpən| vt 磨快、变尖

5:源文件:.java文件。

6:类:类的内容必须包在花括号里面。

7:每个Java程序最少都会有一个类以及一个main(),每个应用程序只有一个main()函数。

8:main()就是程序的起点。

9:不过你的程序有多大,一定都会有一个mian()来作为程序的起点。

10:编译器:compiler。

11:Java有3种循环结构:while循环、do-while循环、for循环。

12:循环的关键在于条件测试(conditional test)。在Java中,条件测试的结果是boolean值--不是true就是false。

13:我们可以用比较运算符(comparison operator)来执行简单的boolean值测试。


14:其他程序语言可以直接用整数类型测试,我也可以向下面这么做吗:

    int x = 1;

    while (x){ }

不行,Java 中的integer 与 boolean两种类型并不相容。我们只能用这样的 boolean变量来测试: 

    boolean isHot = true;

    while(isHot) { }


15:System.out.print与System.out.printIn有何区别?

    printIn会在最后面插入换行。


16:在大括号结束时注释大括号的内容:

public class BeerSong {

    public static void main (String[] args) {

        int beerNum = 99;

        String word = “bottles”;

        while (beerNum > 0) {

            if (beerNum == 1) {

                word = “bottle”; 

            }

            System.out.println(beerNum + “ ” + word + “ of beer on the wall”);

            System.out.println(beerNum + “ ” + word + “ of beer.”);

            System.out.println(“Take one down.”);

            System.out.println(“Pass it around.”);

            beerNum = beerNum - 1;

            if (beerNum > 0) {

                System.out.println(beerNum + “ ” + word + “ of beer on the wall”);

            } else {

                System.out.println(“No more bottles of beer on the wall”);

            }//else结束

        } //while循环结束

    } //main方法结束

} //class结束


17:Java的String类型数组:String[] pets = {“Fido”, “Zeus”, “Bin”};

18:数组元素提取:String s = pets[0]; // “Fido”

19:Java的随机数:int rand1 = (int) (Math.random() * oneLength); random()返回的是介于0与1之间([0,1))的值。


20:Java的String操作:

String phrase = wordListOne[rand1] + “ “ + wordListTwo[rand2] + “ “ + wordListThree[rand3];

s = s + “ “ + “is a dog”; // “Fido is a dog”


猜你喜欢

转载自blog.csdn.net/u014222687/article/details/55058887