共 17篇 前 2 页:    每页10篇 下一页  

学步集

haohao提了一个问题,给人第一感觉是要作1000万*100万,即10万亿次的查找运算,有些吓人。因此,haohao说,要“分析时间复杂度和空间复杂度”。
我对算法是外行,只有些二分查找的概念。
数组,二分查找。
后来想,java 已经10多岁了,我能想到的这些简单的算法,java早就封装得很好了。比如,Hashtable,查找效率如何呢?
copy一个小程序测测:

ackage zdu.filter;

import java.util.*;

public class TestHashtable {

public static void main(String[] args) {
   Hashtable aHashtable=new Hashtable();
   Vector aVector=new Vector();
  
      long t1 = System.currentTimeMillis();
   System.out.println("开始::"+t1);
   for(int i=0;i<1000000;i++){
     aVector.addElement(
"论语"+i);  
     aHashtable.put(aVector.get(i),i);
   }
   long t2 = System.currentTimeMillis();
   System.out.println(
"数据准备完毕:"+t2);
     long t3 = t2-t1;
   System.out.println(
"数据准备用时:"+t3+"毫秒");
   long t4 = System.currentTimeMillis();
  
   System.out.println(
"Key:"+aHashtable.get("论语556677"));
   System.out.println(
"Key2:"+aHashtable.get("论语116677"));
   System.out.println(
"Key3:"+aHashtable.get("论语886633"));
   System.out.println(
"Key4:"+aHashtable.get("论语336655"));
   System.out.println(
"Key5:"+aHashtable.get("论语96633"));
   long t5 = System.currentTimeMillis();
       long t6 = t5-t4;
   System.out.println(
"查找用时:"+t6+"毫秒");
}

}

在eclipse里直接run一下,结果吓我一跳:
开始::1179339369314
数据准备完毕:1179339371227
数据准备用时:1913毫秒
Key:556677
Key2:116677
Key3:886633
Key4:336655
Key5:96633
查找用时:1毫秒

在100万记录中任意查5条,竟然总共用了不到1毫秒。
内存?几乎没有可以感觉到的消耗。
空间复杂度与时间复杂度,对100万条记录的查询,根本不是问题。

hofman   2007-05-17 02:47:29 阅读:2372  评论:6  引用:0
showcase是struts2自带的显示功能的包。将struts-showcase-2.0.1.war直接在jboss4.x下布署会出问题,提示Log4j方面的问题。
   解决方法是,解开该包,去掉WEB-INF/lib里面的2个logging相关的jar,大概是与jboss4.x自带的log4j发生冲突了。
    一个月前,就解决了这个问题,今天由于未记录之前的方法,再加上粗心,浪费了一个小时。
        这是2007年的第一个错误,录此为戒。
hofman   2007-01-01 02:33:57 阅读:328  评论:0  引用:0
                            国内新出了一款商业泛blog软件,xblog,据说很牛,要卖8万元一份,最高级别的要卖18万。上市不久,就拿了央视、中国经济网2个大单。据说,比oblog,phpwind牛不少。我看,基本上把hexun的个人门户那一套般过来了。说是很牛,很易用,但我注册不上,有点着急昵。我用的是FireFox,我的IE坏了,不认javascript。修好了IE6,注册成功。还是有些特点,主要是搬hexun的那一套,再把msn Spaces拖的那一套copy过来,糊弄外行没有问题了。
     在FireFox下,首页严重变形,并且可能无法注册成功,还有省份之类的下来失效。
      
hofman   2006-06-06 10:58:31 阅读:514  评论:0  引用:0
              Bog系统应该从cms系统中吸取一些技术营养,这是我早就有的看法。只不过,由于以前yulog系统过于幼稚,一直无力顾及。现在,yulog系统作为blog系统基本功能大体实现了,再向前推进,向non-blog系统学习就成为当务之急。
   对于cms系统,我以前也简单地扫描过几个网站,但印象并不深刻。今天初访动易,速度之快,功能之强大,显示之全面,流量之靠前,都是远远超出了,我以前拜访过的cms系统、siteEngine系统。
   ver 0.60有了目标了!那就是吸取以动易为代表的CMS系统的一些技术优点,补blog之短。
  
      
hofman   2006-05-21 01:29:26 阅读:519  评论:3  引用:0
以前不明白PO,BO与VO的区别,以为多次一举,总是让PO穿越持久层,业务层,直达表现层,还自以为省事。上个月才知道,原来是自己的技术水平太低的缘故。
PO,Persistence Object,即持久层对象。
BO,Business Object,即业务层对象。
VO, View Ojbect,即表现层对象。
这三者确实不同,在简单的小系统里面,可能有时会重合。但在大一点的系统里面,三者分工明确,虽然在一开始,可能要多几行代码,显得麻烦些,可是其对系统可拓展性,可维护性的好处,远远超出了所付的代价。
比如,上个月初,为了支持一个用户多个blog,为了方便操作,给blogentry表的PO增加了sitepath,结果,从持久层,到业务层,到表现层,一路改过来。为了,增加一个字段,修改了不知道多少个程序。这就是典型的缺乏可维护性。
后来,再一想,改得不对。虽然显示blog文章的时候,新的设计需要获取sitepath,但sitepath其实与blogentry无关,而只与blog相关。正确的做法,应该是在业务层重新组合BLOG,BLOGENTRY两个PO,得到一个新的BO,这个BO既包含了PO BLOGENTRY的主要属性,也包含了PO BLOG的sitepath属性,以及其他必要的属性。
类似的,在表现层,一个VO,典型地包含多个PO里面的部分信息,比如一条BBS帖子,可能包含PO USER里面的USERNAME,PO NEWS里面的subject,body,cdate,还可能包括PO IMAGES里面的IMAGE,以及其他相关信息,而这些信息往往是通过业务层的BO传过来的,BO由于需要,可能已经对持久层的PO作了重新包装。


hofman   2005-10-10 11:05:16 阅读:1659  评论:0  引用:0
http://www.w3schools.com/tags/default.asp
Tag Description NN IE DTD
<!--...--> Defines a comment 3.0 3.0 STF
<!DOCTYPE> Defines the document type STF
<a> Defines an anchor 3.0 3.0 STF
<abbr> Defines an abbreviation 6.2 STF
<acronym> Defines an acronym 6.2 4.0 STF
<address> Defines an address element 4.0 4.0 STF
<applet> Deprecated. Defines an applet 2.0 3.0 TF
<area> Defines an area inside an image map 3.0 3.0 STF
<b> Defines bold text 3.0 3.0 STF
<base> Defines a base URL for all the links in a page 3.0 3.0 STF
<basefont> Deprecated. Defines a base font 3.0 3.0 TF
<bdo> Defines the direction of text display 6.2 5.0 STF
<big> Defines big text 3.0 3.0 STF
<blockquote> Defines a long quotation 3.0 3.0 STF
<body> Defines the body element 3.0 3.0 STF
<br> Inserts a single line break 3.0 3.0 STF
<button> Defines a push button 6.2 4.0 STF
<caption> Defines a table caption 3.0 3.0 STF
<center> Deprecated. Defines centered text 3.0 3.0 TF
<cite> Defines a citation 3.0 3.0 STF
<code> Defines computer code text 3.0 3.0 STF
<col> Defines attributes for table columns 3.0 STF
<colgroup> Defines groups of table columns 3.0 STF
<dd> Defines a definition description 3.0 3.0 STF
<del> Defines deleted text 6.2 4.0 STF
<dir> Deprecated. Defines a directory list 3.0 3.0 TF
<div> Defines a section in a document 3.0 3.0 STF
<dfn> Defines a definition term 3.0 STF
<dl> Defines a definition list 3.0 3.0 STF
<dt> Defines a definition term 3.0 3.0 STF
<em> Defines emphasized text 3.0 3.0 STF
<fieldset> Defines a fieldset 6.2 4.0 STF
<font> Deprecated. Defines text font, size, and color 3.0 3.0 TF
<form> Defines a form 3.0 3.0 STF
<frame> Defines a sub window (a frame) 3.0 3.0 F
<frameset> Defines a set of frames 3.0 3.0 F
<h1> to <h6> Defines header 1 to header 6 3.0 3.0 STF
<head> Defines information about the document 3.0 3.0 STF
<hr> Defines a horizontal rule 3.0 3.0 STF
<html> Defines an html document 3.0 3.0 STF
<i> Defines italic text 3.0 3.0 STF
<iframe> Defines an inline sub window (frame) 6.0 4.0 TF
<img> Defines an image 3.0 3.0 STF
<input> Defines an input field 3.0 3.0 STF
<ins> Defines inserted text 6.2 4.0 STF
<isindex> Deprecated. Defines a single-line input field 3.0 3.0 TF
<kbd> Defines keyboard text 3.0 3.0 STF
<label> Defines a label for a form control 6.2 4.0 STF
<legend> Defines a title in a fieldset 6.2 4.0 STF
<li> Defines a list item 3.0 3.0 STF
<link> Defines a resource reference 4.0 3.0 STF
<map> Defines an image map 3.0 3.0 STF
<menu> Deprecated. Defines a menu list 3.0 3.0 TF
<meta> Defines meta information 3.0 3.0 STF
<noframes> Defines a noframe section 3.0 3.0 TF
<noscript> Defines a noscript section 3.0 3.0 STF
<object> Defines an embedded object 3.0 STF
<ol> Defines an ordered list 3.0 3.0 STF
<optgroup> Defines an option group 6.0 6.0 STF
<option> Defines an option in a drop-down list 3.0 3.0 STF
<p> Defines a paragraph 3.0 3.0 STF
<param> Defines a parameter for an object 3.0 3.0 STF
<pre> Defines preformatted text 3.0 3.0 STF
<q> Defines a short quotation 6.2 STF
<s> Deprecated. Defines strikethrough text 3.0 3.0 TF
<samp> Defines sample computer code 3.0 3.0 STF
<script> Defines a script 3.0 3.0 STF
<select> Defines a selectable list 3.0 3.0 STF
<small> Defines small text 3.0 3.0 STF
<span> Defines a section in a document 4.0 3.0 STF
<strike> Deprecated. Defines strikethrough text 3.0 3.0 TF
<strong> Defines strong text 3.0 3.0 STF
<style> Defines a style definition 4.0 3.0 STF
<sub> Defines subscripted text 3.0 3.0 STF
<sup> Defines superscripted text 3.0 3.0 STF
<table> Defines a table 3.0 3.0 STF
<tbody> Defines a table body 4.0 STF
<td> Defines a table cell 3.0 3.0 STF
<textarea> Defines a text area 3.0 3.0 STF
<tfoot> Defines a table footer 4.0 STF
<th> Defines a table header 3.0 3.0 STF
<thead> Defines a table header 4.0 STF
<title> Defines the document title 3.0 3.0 STF
<tr> Defines a table row 3.0 3.0 STF
<tt> Defines teletype text 3.0 3.0 STF
<u> Deprecated. Defines underlined text 3.0 3.0 TF
<ul> Defines an unordered list 3.0 3.0 STF
<var> Defines a variable 3.0 3.0 STF
<xmp> Deprecated. Defines preformatted text 3.0 3.0
hofman   2005-09-26 16:09:19 阅读:856  评论:1  引用:0
http://www.w3schools.com/xml/xml_whatis.asp
What is XML?
XML stands for EXtensible Markup Language
XML is a markup language much like HTML
XML was designed to describe data
XML tags are not predefined. You must define your own tags
XML uses a Document Type Definition (DTD) or an XML Schema to describe the data
XML with a DTD or XML Schema is designed to be self-descriptive
XML is a W3C Recommendation

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

XML is a W3C Recommendation
The Extensible Markup Language (XML) became a W3C Recommendation 10. February 1998.

You can read more about XML standards in our W3C tutorial.


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

The main difference between XML and HTML
XML was designed to carry data.

XML is not a replacement for HTML.
XML and HTML were designed with different goals:

XML was designed to describe data and to focus on what data is.
HTML was designed to display data and to focus on how data looks.

HTML is about displaying information, while XML is about describing information.


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

XML does not DO anything
XML was not designed to DO anything.

Maybe it is a little hard to understand, but XML does not DO anything. XML was created to structure, store and to send information.

The following example is a note to Tove from Jani, stored as XML:

<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>

The note has a header and a message body. It also has sender and receiver information. But still, this XML document does not DO anything. It is just pure information wrapped in XML tags. Someone must write a piece of software to send, receive or display it.


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

XML is free and extensible
XML tags are not predefined. You must "invent" your own tags.

The tags used to mark up HTML documents and the structure of HTML documents are predefined. The author of HTML documents can only use tags that are defined in the HTML standard (like <p>, <h1>, etc.).

XML allows the author to define his own tags and his own document structure.

The tags in the example above (like <to> and <from>) are not defined in any XML standard. These tags are "invented" by the author of the XML document.


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

XML is a complement to HTML
XML is not a replacement for HTML.

It is important to understand that XML is not a replacement for HTML. In future Web development it is most likely that XML will be used to describe the data, while HTML will be used to format and display the same data.

My best description of XML is this: XML is a cross-platform, software and hardware independent tool for transmitting information.


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

XML in future Web development
XML is going to be everywhere.

We have been participating in XML development since its creation. It has been amazing to see how quickly the XML standard has been developed and how quickly a large number of software vendors have adopted the standard.

We strongly believe that XML will be as important to the future of the Web as HTML has been to the foundation of the Web and that XML will be the most common tool for all data manipulation and data transmission.

hofman   2005-09-26 16:00:41 阅读:1431  评论:1  引用:0
今天是正式开始学习Tapestry的第一天。作为java web开发重要的MVC开发框架,tapestry在2005年日益受专业的Java 程序员青睐。
月初休假的时候,我在宝鸡的网吧里面,顶着酷暑(老板小气,一天只开几个小时空调),查了一个星期的资料。终于选定Tapestryz作为YuLog系统的Web层开发框架。
webwork,jsf,struts, springframework mvc等等Java Web层开发框架似乎很多,我想之所以这么多,还是因为没有一个真正让人满意的,各吹各的优点,其实各有各的缺点。
中国程序员的话不要轻信。“你还用struts?太落后了!赶紧扔了!”“最好的java mvc,就数webwork了”,诸如此类,一些非常对立的看法,让新手无所适从。
幸好,还认识几个英文单词,只好看老外怎么说,读那些真正的高手的东西,才知道,原来各有特点,如何选择,就看你的需求以及起点,或者个性,没有谁好谁坏。
选择Tapestry,是因为2004年以来,它进步得非常块(同期,Struts也进步得很块!)。它有2个吸引我的特点:
1.它真正将oo思想落实到Web层开发,这决定了它的逻辑,让人比较舒服,并且Web真正组件化,对将来的复用肯定是有帮助的。
2.它的调试能力,让人非常诧异。

还有,一般认为Tapestry学习曲线比较陡,但后来的效率补偿,也比较明显。YuLog开发任务很重,唯有靠它提升Web层的开发效率,虽然已经预计学习时,要吃些苦头。
hofman   2005-07-31 23:51:50 阅读:2762  评论:4  引用:0
这次代码重整中,碰到一个新问题。
ps = conn.preParedStatement(sql)
rs = conn.executeQuery()
正常。
为了提高效率,改为
ps = conn.prePareStatement(sql, ResutSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCURRENT_READ_ONLY);
ps.setString(1, key);
能够取出结果,文本正常(clob字段),但是其它的文本字段不正常,比如标题、日期,都是乱码。

被这个问题浪费了一个多小时,才想到可能是oracle的jdbc 驱动问题。因为现在使用的是比较老的oracle 8i。
才知道了问题的所在。

恢复过去,果然又能够正常显示了。
但是,与ps的属性是否相关,还应该进一步测试。
毕竟ps.setString()是正途,效率高些。


hofman   2005-04-11 23:58:31 阅读:1608  评论:0  引用:0
这个假期比较长,但我只带了一本书:《java编程思想》。2003年就买了,2005年的现在才开始看。
看书,应该在适当的时候看适当的书。 在这个时候读,我想正是时候。因为明白了不少以前知其然,不知所以然的东西。比如,static, final,inner class,
这是有思想的书,难怪名声那么大。
作者先有《C++编程思想》,所以不但java比照非oop的优点,讲得非常透彻,java比照其他oop语言尤其是C++的长处与短处,分析得让人非常明白。
java的垃圾回收机制的前因后果,其技术根基,巨大的方便性以及其必然的代价...,精彩之处颇多,确实值得反复阅读。
我希望,能够学点可重用的方法,提高开发效率,这是主要目的。
hofman   2005-02-04 14:16:54 阅读:3328  评论:3  引用:0
2003-2007@copyright