2006年10月31日

http://www.csit.fsu.edu/~burkardt/data/data.html
可以从中找到大部分文件格式的相关信息。例如BMP,Obj等等。

http://www.csit.fsu.edu/~burkardt/data/obj/obj.html
介绍OBJ文件格式,关键是当中提供了读写和转换OBJ文件的工具建议。

posted @ 2006-10-31 00:11 cjren 阅读(254) | 评论 (0)编辑 收藏

2006年7月23日

 helloWorldEg.jpg
就一幅图,仔细看看和联想一下,也许会有点得益:-)

posted @ 2006-07-23 20:14 cjren 阅读(250) | 评论 (0)编辑 收藏
 
What do you know The Life Cycle of a Thread?
threads-states.gif
Can you say something about the life cycle of a thread, it's creating, starting, running, not runnale, and stopping? If you do want to know about more, please check it out: http://java.sun.com/docs/books/tutorial/essential/threads/lifecycle.html
posted @ 2006-07-23 20:10 cjren 阅读(300) | 评论 (0)编辑 收藏
 

(1)
The Art of Programming Language
《计算机程序设计艺术》 清华大学出版社

(2)
Introduction to Algorithms, Second Edition
Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest and Clifford Stein
MIT
《算法导论,影印版》高等教育出版社

(3)
Intruduction to The Design and Analysis of Algorithms
(US)Anany Levitin
算法设计与分析基础
潘彦 译 
清华大学出版社

其实第一本我没有看过,只是提及算法方面的书籍,这一本好像都应该为人所知道似的。第二本的课程资料可以在mit的open course ware页面下载。第三本的译本很不错,感觉很有点幽默有趣,而且书的结构挺新颖,不至于让人马上对算法这东西觉得恐怖和烦闷。推荐第三本。

posted @ 2006-07-23 19:38 cjren 阅读(725) | 评论 (0)编辑 收藏
 

移动 -- 只有GSM,GPRS是GSM的升级版,134-139 手机使用移动的SIM卡       

联通 -- GSM  130,131,132       手机使用联通SIM卡
         -- CDMA 133 (联通新时空),手机使用UIM卡


GSM比较简单。所谓的GSM 900/1800/1900是指GSM手机的工作频率,分别是中国移动支持的900MHz,1900MHz和美国常用的1900MHz。在国内用支持900MHz和1800MHz的GSM 900/1800双频手机就可以了。如果要出国到美国用的,就要用支持1900MHz的三频手机了。

CDMA比GSM的通话质量、手机辐射小和保密性方面都好,但是技术!=市场。
CDMA -- CDMA800
            -- CDMA 1X 现在联通CDMA网络所采取的技术。与真正的CDMA2000相比,CDMA 1x就像我刚才说的,只能支持到153.6kbps的数据速度,因此被称为是2.5G的技术,还不是真正3G的技术。
            -- CDMA2000 一种3G的标准。


3G 有三个标准
            -- WCDMA 有利于中国移动,设备由欧洲进口,容易升级到WCDMA。这套系统能够架设在现有的GSM网络上,对于系统提供商而言可以较轻易地过渡,而GSM系统相当普及的亚洲对这套新技术的接受度预料会相当高。因此W-CDMA具有先天的市场优势。
 
             -- CDMA2000 利于联通,设备由美国进口,容易升级到CDMA2000。目前使用CDMA的地区只有日、韩和北美,所以CDMA2000的支持者不如W-CDMA多。不过CDMA2000的研发技术却是目前各标准中进度最快的,许多3G手机已经率先面世。

             -- TD-SCDMA 中国自己有独立知识产权的产品。采用这一标准,对于国防等重要领域国民经济安全有利。据说中国电信和中国网通都在申请移动运营牌照,他们倾向于TDS-CDMA。
       至于现在中国采用哪一种现在还没有定论。毕竟需要市场和企业来最终决定,记住技术优秀的并不代表最终就能胜出。

posted @ 2006-07-23 19:28 cjren 阅读(533) | 评论 (0)编辑 收藏

2006年7月8日

"Computer science is no more about computers than astronomy is about telescopes."

                                                  E. W. Dijkstra
计算机是一个工具,一个人造的工具,人制造工具的目的是什么?协助自己完成生产劳动,或确切地说是完成自己生存和生活的需要。由于需要完成大量的运算而产生的计算机,即使是到现在也局限于信息的处理,包括简单的运算和信息(数字)的存储。

而在学习当中,“sprint,struct”等这些名字听起来真的很大,而我常问自己“我需要学习它吗?”。是否不懂它们就不算懂java了呢?我从4月份开始觉得java离自己越来越远了,因为我上许多的关于java的论坛,看到的极大部分都是讨论框架,而我对此没有什么概念。“需求驱动学习”是我的信条,没有这个需求,你就没有学习那相应知识的必要,更没有动力。也许这是我懒的借口:-) 大概是自己尚且是学生,没有投身都企业生产当中因此对这些企业开发的知识没有概念吧。反正觉得现在没有学这个的必要,谁知道两年后是否有什么summer or XXname的框架出现呢?

这个暑假其实自己还是想把握时间看看书的,反正又没有找到实习工作。例如data structure & algorithm,算法分析这门课没有学过,真的遗憾,只能自己补补;还有那Developing Games in Java的part 3,当中讲的是3d的renderring,而不涉及opengl以及java3d或opengl binding等API,自己还是很有兴趣的。而昨天在国外的大学的网站上下载了一个OS课程的lecture notes,正好复习一下操作系统的概念。

posted @ 2006-07-08 10:25 cjren 阅读(618) | 评论 (1)编辑 收藏

2006年7月7日

     摘要: 2006-7-7 CP2003 -- Principles of Programming Languages 1997 This course (subject) comes frome http://www.cs.jcu.edu.au/Subjects/cp2003/1997/lecturenotes.html, and you can fin...  阅读全文
posted @ 2006-07-07 10:49 cjren 阅读(596) | 评论 (0)编辑 收藏

2006年7月6日

上午看某文章时候涉及缓冲区溢出的问题,谈到C的栈和堆,有所不懂于是baidu了一下发现论坛上的解释都较为凌乱,google一下后发现国外大学的Lecture Notes 中有不少的说明,下面简单的摘录三段,一是c中的,二是对于java的,三是从os角度看的。

Stack vs Heap Allocation
How the memory of the computer is organized for a running program? When a program is loaded into memory, it is organized into three areas of memory, called segments: the text segment, stack segment, and heap segment. The text segment (sometimes also called the code segment) is where the compiled code of the program itself resides. This is the machine language representation of the program steps to be carried out, including all functions making up the program, both user defined and system.

The remaining two areas of system memory is where storage may be allocated by the compiler for data storage. The stack is where memory is allocated for automatic variables within functions. A stack is a Last In First Out (LIFO) storage device where new storage is allocated and deallocated at only one ``end'', called the Top of the stack. This can be seen in Figure 14.13. 
 figure14.13.gif

When a program begins executing in the function main(), space is allocated on the stack for all variables declared within main(), as seen in Figure 14.13(a). If main() calls a function, func1(), additional storage is allocated for the variables in func1() at the top of the stack as shown in Figure 14.13(b). Notice that the parameters passed by main() to func1() are also stored on the stack. If func1() were to call any additional functions, storage would be allocated at the new Top of stack as seen in the figure. When func1() returns, storage for its local variables is deallocated, and the Top of the stack returns to to position shown in Figure 14.13(c). If main() were to call another function, storage would be allocated for that function at the Top shown in the figure. As can be seen, the memory allocated in the stack area is used and reused during program execution. It should be clear that memory allocated in this area will contain garbage values left over from previous usage.

The heap segment provides more stable storage of data for a program; memory allocated in the heap remains in existence for the duration of a program. Therefore, global variables (storage class external), and static variables are allocated on the heap. The memory allocated in the heap area, if initialized to zero at program start, remains zero until the program makes use of it. Thus, the heap area need not contain garbage.
小结:
Stack: automatic variables within functions
Heap: global variables (storage class external), and static variables
============================
In java 情况如下
(1)
 The stack is the program memory area, so all your primitive type variables and the memory adress of your objects are written on the stack. It is a fast access valuable memory area.
The heap is where the VM keeps the objects, and it is a huge amount of memory. When you create an object, the VM puts the object in the HEAP and puts the adress of the object created on the STACK.
(2)
 There are two kinds of memory used in Java. These are called stack memory and heap memory. Stack memory stores primitive types and the addresses of objects. The object values are stored in heap memory. An object reference on the stack is only an address that refers to the place in heap memory where that object is kept.
 It is useful to know that these two different kinds of memory exist in Java. Stack memory is the program's memory, and heap memory resides outside of the program.这好像有点跟C的不同(相反)。
引入一点垃圾回收机制的知识
 When you need a new object, Java allocates the required memory. When you are done with an object, the memory is reclaimed for you automatically via Java's garbage collection facility.
 Garbage collection runs as a thread in the background, looking for objects that no longer have a usable reference. When it finds them, it destroys them and reclaims the memory.
 The implementation of garbage collection varies between Java Virtual Machines. They generally follow the same process, however. First, the garbage collector gets a snapshot of all running threads and all loaded classes. Then, all objects that are referred to by this thread set are marked as current. The process stops when all objects that it is possible to reach have been marked and the rest have been discarded.
 In order to help the Virtual Machine, it is a good idea to remove your references to unneeded objects. This is often done by simply setting your reference to null:
 Test t = new Test();
 t.someAction();
 // all done
 t = null;
小结:
Stack: Primitive data types(primitive types), the addresses of objects(=references).
Heap:  objects.

===============================================
从系统的角度看 stack(栈)和heap(堆)
Dynamic Data Structures: The Heap
A typical personal computer or workstation today has somewhere between 16 and 64 megabytes of RAM installed. Using a technique called virtual memory, the system can swap pieces of memory on and off the machine's hard disk to create an illusion for the CPU that it has much more memory, for example 200 to 500 megabytes. While this illusion is complete as far as the CPU is concerned, it can sometimes slow things down tremendously from the user's perspective. Despite this drawback, virtual memory is an extremely useful technique for "increasing" the amount of RAM in a machine in an inexpensive way. Let's assume for the sake of this discussion that a typical computer has a total memory space of, for example, 50 megabytes (regardless of whether that memory is implemented in real RAM or in virtual memory).
The operating system on the machine is in charge of the 50-megabyte memory space. The operating system uses the space in several different ways, as shown here:

 c-heap.gif
The operating system and several applications, along with their global variables and stack spaces, all consume portions of memory. When a program completes execution, it releases its memory for reuse by other programs. Note that part of the memory space remains unused at any given time.

This is, of course, an idealization, but the basic principles are correct. As you can see, memory holds the executable code for the different applications currently running on the machine, along with the executable code for the operating system itself. Each application has certain global variables associated with it. These variables also consume memory. Finally, each application uses an area of memory called the stack, which holds all local variables and parameters used by any function. The stack also remembers the order in which functions are called so that function returns occur correctly. Each time a function is called, its local variables and parameters are "pushed onto" the stack. When the function returns, these locals and parameters are "popped." Because of this, the size of a program's stack fluctuates constantly as the program is running, but it has some maximum size.

As a program finishes execution, the operating system unloads it, its globals and its stack space from memory. A new program can make use of that space at a later time. In this way, the memory in a computer system is constantly "recycled" and reused by programs as they execute and complete.

In general, perhaps 50 percent of the computer's total memory space might be unused at any given moment. The operating system owns and manages the unused memory, and it is collectively known as the heap. The heap is extremely important because it is available for use by applications during execution using the C functions malloc (memory allocate) and free. The heap allows programs to allocate memory exactly when they need it during the execution of a program, rather than pre-allocating it with a specifically-sized array declaration.

posted @ 2006-07-06 17:30 cjren 阅读(4404) | 评论 (3)编辑 收藏
 


在尝试建立自己的可重用package的时候,对package和import语句做了些试验,记录结果如下。

使用说明:
(1)对于src\com\cjren\util\ClassA.java这个提供给其他类使用的class.
package com.cjren.util;
public class ClassA {
  ...
}
编译时:
javac -d . ClassA.java  // -d . 表示了以当前目录为package语句生成的相对根目录。
结果是在ClassA.java所在的目录下生成了com.cjren.util包,里面含ClassA.class,这个包可以复制剪贴到其他的地方供其他类使用。
Notes:
必须使用"-d .",否则ClassA.class并不会放在com.cjren.util包里面,而是生成在和ClassA.java相同的目录下。


(2)对于要使用ClassA的ClassB.java.
import com.cjren.util.ClassA;
public class ClassB {
  ... // use ClassA here
}

To compile: javac ClassB.java
To run:     假设com包放在和ClassB.java的当前目录
            java ClassB       
            // or java -cp . ClassB // here use the "-cp ." as the current directory to find the package com.
            假设com包放在D:\Program Files\Java\mypackages下
            java -cp D:\Program Files\Java\mypackages ClassB

Notes:
错误一:
package com.cjren.util;
public class ClassA {
  ...
}
编译后直接把com.cjren.util包里面的ClassA.class文件拷贝到和ClassB.java相同的目录下直接使用,
public class ClassB {
  ... // use ClassA here
}
To compile: javac ClassB.java
错误信息是
"ClassB.java:某一行: 无法访问 ClassA
 错误的类文件: .\ClassA.class
 类文件包含错误的类: com.cjren.util.ClassA
 请删除该文件或确保该文件位于正确的类路径子目录中。"
想一想为什么出错信息是说:“错误的类文件: .\ClassA.class, 类文件包含错误的类: com.cjren.util.ClassA”呢?因为"错误的类文件: .\ClassA.class"当中包含了"错误的类: com.cjren.util.ClassA"这个信息,而这个"com.cjren.util.ClassA"是在ClassA.java中的"package com.cjren.util;"语句所造成的。
正确的做法是把ClassA.class所在的包整个复制粘贴到ClassB.java所在的目录下,或者在ClassB.java所在的目录下人为手动的建立com\cjren\util\目录,然后直接把ClassA.class文件复制粘贴到此。这暗示了代码生成的包和手动建立的目录可能是一样。
可见,当ClassA.java的源代码中含"package com.cjren.util;"语句,则生成com.cjren.util包里面的ClassA.class文件里面应该就也包含了自己这个class文件所属的包信息,所以这个ClassA.class只能放在这个代码中已经指定的特定包的路径下使用,而不能把这个ClassA.class独立出来使用,因为这样的话将ClassA.class文件属性中的的包信息不相符。当然当这个ClassA.java没有显式地制定package语句信息时候,我怀疑(也觉得应该)是默认在ClassA.class文件当中包含了包的信息就是".",可以理解为默认的加入了"package .;"语句。

错误二:
public class ClassA {
  ...
}
编译后这个ClassA.class文件中含有的包的信息是"."当前目录就包!
把这个ClassA.class文件,移到以ClassB.java所在的目录为当前父目录的人为手动建立的com\cjren\util目录下。
import com.cjren.util.ClassA;
public class ClassB {
  ... // use ClassA here
}

To compile: javac ClassB.java
错误信息是
"ClassB.java:某一行: 无法访问 com.cjren.swing.ClassA
 错误的类文件: .\com\cjren\util\ClassA.class
 类文件包含错误的类: ClassA
 请删除该文件或确保该文件位于正确的类路径子目录中。"
想一想为什么出错信息是说:“错误的类文件: .\com\cjren\util\ClassA.class,类文件包含错误的类: ClassA”呢?因为你这个com.cjren.util包中的ClassA.class文件本来所默认的包信息是".",在ClassA.java中并没有使用"package"语句指定ClassA应该属于包com\cjren\util这个信息。

小结:
在尝试过程当中发现,
public class ClassA {
  ...
}

package com.cjren.util;
public class ClassA {
  ...
}
这两个只差了一个package语句的class文件大小有十几到几十k上的区别,这可能进一步证明了.java文件中的package语句会在.class文件中加入相应的包信息,这个包信息决定了这个class被使用时候的方式(是否需要import特定的包)。
还有一点要注意的是:
package com.cjren.util;
public class ClassA {
  ...
}
之后无论是使用 javac ClassA.java 或者 javac -d . ClassA.java编译都不会影响ClassA.class文件当中所含有的包信息,这两种编译方式所造成的区别在上面的使用说明中已经说过了。


 

posted @ 2006-07-06 09:00 cjren 阅读(799) | 评论 (3)编辑 收藏

2006年6月26日

2006-6-24

尝试以一个例子来说明搭建一个 project 时候的目录构建情况。

 

情况一

下面以一个地图编辑器的例子为例

project mapeditor

父目录是
”project mapeditor”,

.\Image 程序使用到的图片。

.\Maps 程序运行时用户保存的自定义地图。

.\com 主程序 MapEditor.java 将会是用到的 package 的源文件。

.\com\cjren\swing\MyFilter.java

MapEditor.java 主程序源文件,代码中没有 ”package” 语句。

runMapEditor.bat 完成编译和运行所需的所有工作。

 

下面主要看看 runMapEditor.bat 的内容:

@echo off

rem output the date and time

date /T

time /T

echo welcome to my map editor :-)

 

rem make the directory for class files

mkdir .\build\classes

 

rem compile the source files

javac -d .\build\classes MapEditor.java

 

rem run the application,

rem but you must avoid this: java.\build\classes\MapEditor,

rem which will be an error

java -cp .\build\classes MapEditor

 

rem clean everything in the build folder

rmdir .\build /S /Q

 

pause

 

从上面的具体代码中可以看出在编译和运行的时候,所有的 class 文件都回被放在 .\build\classes 这个文件夹中,这个文件夹是动态生成并且最后会被清楚掉的。

 

这里有三个值得注意的地方。

一,通过 ” javac -d .\build\classes MapEditor.java” ,不单只是 MapEditor.java 所定义的 class 都被放于 .\build\classes 中,甚至连 .\com MyFilter.java 所对应的 class 也都在 .\build\classes\com\cjren\swing 中,而 com 包在 .\bulid\classes 下是自动被准确生成的。也就是说所有的 .class 文件都被放在 .\bulid\classes 文件夹中了。

二,当使用 ”java -cp .\build\classes MapEditor” 来运行程序的时候,并没有因为 Image 文件夹不在 .\build\classes 而出错。这说明了 .java 文件中的代码已经决定了它所使用到的 Image 文件夹的位置,这个位置是相对于 .java 文件所在的位置来说的,而不是 .class

三,我尝试了在 d 盘下新建了一个 a 目录,然后把

javac -d .\build\classes MapEditor.java

java -cp .\build\classes MapEditor

换成

javac -d d:\a MapEditor.java

java -cp d:\a MapEditor

之后,其他 ”project mapeditor” 下的所有东西都没有改变,程序依然成功执行。这就进一步证明了 .java 文件中的代码决定了所有其他目录或文件元素的相对位置,这个位置以 .java 文件所在的目录为标准。而与 .class 文件的路径无关。但是:别混淆了 A.class 它所使用到的包的 .class 的路径是以 A.class 文件的路径为标准的!!!这就与上面 MapEditor.class 也和(必须和) com 包同处于 bulid\classes 目录下没有矛盾。

 

情况二

目的是把上面情况一中所有的文件和文件夹都包含在 src 这个文件夹中,而 src 本身就是父目录 project mapeditor2 下的一个文件夹。而且我希望编译时候生成的 build 文件夹和 src 文件夹的关系是:

\project mapeditor2\src

\project mapeditor2\build



src
文件夹的内容如下:

pj2-src
注意批处理文件
runMapEditor.bat src 文件夹下,而且在此情况下, runMapEditor.bat 的内容将有所变化:

@echo off

rem output the date and time

date /T

time /T

echo welcome to my map editor :-)

 

rem make the directory for class files

mkdir ..\build\classes

 

rem compile the source files

javac -d ..\build\classes MapEditor.java

 

rem run the application,

rem but you must avoid this: java.\build\classes\MapEditor,

rem which will be an error

java -cp ..\build\classes MapEditor

 

rem clean everything in the build folder

rmdir ..\build /S /Q

 

pause

 

情况一和情况二的差别不大,只是源代码文件多一层的文件夹的包裹。而且最大的共同点是 runMapEditor.bat 和源代码文件在同一个文件夹下。

 

情况三

尝试在情况二的基础上把 runMapEditor.bat 提到和 src 以及 build 相同的父目录下。假设父目录是 project mapeditor3 ,则:

pj3
现在
runMapEditor.bat 的内容是:

@echo off

rem output the date and time

date /T

time /T

echo welcome to my map editor :-)

 

rem make the directory for class files

mkdir .\build\classes

 

rem go into the src directory

cd src

 

rem compile the source files

javac -d ..\build\classes MapEditor.java

 

rem run the application,

rem but you must avoid this: java.\build\classes\MapEditor,

rem which will be an error

java -cp ..\build\classes MapEditor

 

rem clean everything in the build folder

rmdir ..\build /S /Q

 

pause

 

在尝试工程当中,发现以下的做法将找不到 Image 文件夹:

cd src

javac -d ..\build\classes MapEditor.java

cd ..

java -cp .\build\classes MapEditor

这种修改所造成的区别是运行 ”java” 命令的位置不同了。可以猜想是需要在 src 文件夹内运行 java 命令,而 src 文件夹中含有所有程序所需的代码和 image 素材。

 

下面提供一个稍微不同的批处理文件, runMapEditor2.bat ,它也同样处于 project mapeditor3 这个父目录下:

pj3-

runMapEditor2.bat
的内容如下:

@echo off

mkdir d:\a

cd src

javac -d d:\a MapEditor.java

java -cp d:\a MapEditor

rmdir d:\a /S /Q

pause

这个修改过的例子把 class 文件都移到较远的地方 (d:\a) ,但是还可以成功运行。小结一下它能成功运行的特点:

一, src 文件夹中已经包含了所有的元素,包括所需的外部 package 代码,包括 image 文件夹。这些元素都必须使得主程序 .java 能成功的编译。

二,运行 ”java” 命令都在 src 这个目录下。也就是说都在和代码处在相同的文件路径下,而不是其他任何路径。

 

情况一都三的小结

基本满足了在 windows 系统下开发小项目的需求,我在这三个尝试的例子中主程序 MapEditor.java 都没有含有 ”package main” 这类的打包语句。

posted @ 2006-06-26 01:35 cjren 阅读(374) | 评论 (0)编辑 收藏
仅列出标题  下一页