您的位置:首页 > 编程语言 > Java开发

我的JAVA之旅(二)初识JAVA

2009-05-20 22:07 363 查看
三年后《Thinking》里的文字依旧晦涩难懂。看完前几章节,只觉得对这种以绕口令的方式书写理解起来还是颇为费力。费力归费力,但也总算有了一点收获。了解了JAVA和C/C++的区别,了解了JAVA的一些名词,比如对象(Object),封装(encapsulation),继承(Inheritance)。。等。

相比起来,《Thinking》里的文字还是过于理论,幸好手边还有一本《JAVA参考大全》,也许边看程式边看《Thinking》效果会更好一些呢!

在翻看了JAVA的一些基础的类库和数据类型之后,参考了一些范例。开始书写我的第一个程式,熟悉JAVA的工作原理,熟悉 eclpise的使用。

The first program.

code:

public class Example{

public static void main(String gac2[])

{

int x,y;

y=20;

for(x=0;x<10;x++){

System.out.println("The value of X is "+x);

System.out.println("The value of Y is "+y);

y=y-2;

}

}

}

---------------------------------

The value of X is 0

The value of Y is 20

The value of X is 1

The value of Y is 18

The value of X is 2

The value of Y is 16

The value of X is 3

The value of Y is 14

The value of X is 4

The value of Y is 12

The value of X is 5

The value of Y is 10

The value of X is 6

The value of Y is 8

The value of X is 7

The value of Y is 6

The value of X is 8

The value of Y is 4

The value of X is 9

The value of Y is 2

eclpise里按ctrl+s保存会自动编译。就如同dos下运行javac一样。

就像 helloworld一样,这段代码定义了一个公共类Example,主函数main里申明了一个空数组,定义两个整形变量x,y,病对y赋值,循环里调用了基类System里的换行方法println,输出括号里的内容到屏幕上
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: