<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Raymond
    Java筆記

    2006年3月3日

    在Java高效編程里面看到變量一個ArrayList的時候,有兩種方式:
    假設a是個ArrayList

    1、 for (int i=0;i<a.size();i++) {
    2、 for (int i=0,n=a.size();i<n;i++) {

    帶著點懷疑我做了一下試驗,的確是方法2快一點的,估計是a.size()方法里面花費了一點多余的時間。后來我想到jdk 1.5開始還有一種遍歷的for/each方法,我做了一下比較,結果有點驚訝。

    源程序如下

     1import java.util.ArrayList;
     2
     3public class ProfileArrayList {
     4
     5  public static void main(String[] args) {
     6    ArrayList<String> s=new ArrayList<String>();
     7    for (int i=0;i<15000;i++{
     8      s.add(""+System.currentTimeMillis());
     9    }

    10    System.out.println("Start ");
    11    testOne(s);
    12    testTwo(s);
    13    testThree(s);
    14    System.out.println("End ");
    15  }

    16  
    17  private static void testOne(ArrayList<String> a) {
    18    int j=0;String s=null;
    19    for (int i=0;i<a.size();i++{
    20      s=a.get(i);
    21      j++;
    22    }

    23  }

    24  
    25private static void testTwo(ArrayList<String> a) {
    26    int j=0;
    27    String s=null;
    28    for (int i=0,n=a.size();i<n;i++{
    29      s=a.get(i);
    30      j++;
    31    }

    32  }

    33
    34private static void testThree(ArrayList<String> a) {
    35  int j=0;
    36  for (String s : a) {
    37    j++;
    38  }

    39}

    40
    41}

    42

    通過Profiling工具看結果:
    方法      運行時間
    testOne   0.055764
    testTwo  0.043821
    testThres 0.132451

    也就是說,jdk 1.5的for/each循環是最慢的。有點不相信。開頭覺得是因為賦值造成的,但后來在另兩個方法里面加上賦值語句,依然是for/each最慢。比較有趣的結果。

    從代碼清晰角度,用for/each消耗多一點點時間似乎也無所謂。但是,另兩種代碼也不見得“不清晰”,呵呵。看著辦了。

    posted @ 2006-03-03 12:00 Raymond的Java筆記 閱讀(497) | 評論 (0)編輯 收藏

    2006年3月1日


    JMeter是apache的jakarta上面的項目,用于軟件的壓力測試(Load Test),不但可以對HTTP,也可以對數據庫(通過JDBC)、FTP、Web Service、Java 對象等等進行壓力測試。

    項目地址:http://jakarta.apache.org/jmeter

    使用: 運行bin目錄下的jmeterw.bat,運行jmeter.bat也可以,不過就會有一個命令窗口顯示。

    要提醒一下的是jmeter根據當前系統的locale顯示菜單的語言,為了方便想設置回英文的話,可以修改jmeter.properties文件,設置language=en  (我下載的2.1.1版本把“退出”誤譯為“推出”,怎么看都不順眼

    使用:

    JMeter的測試計劃(Test Plan)呈樹狀結構,樹里面有多種元素類型,樹狀結構的元素之間有的是有繼承關系的(其原理有點類似log4j)。下面簡述一下元素類型:

    1、ThreadGroup
          顧名思義就是線程組,測試必須有一個ThreadGroup元素作為基礎(否則就沒有測試線程在跑了),這個元素可以配置跑多少個線程、每個線程循環多少次,所有線程數的總啟動時間(Ramp-up period)等等。

    2、Controller
         包括Logical Controller和Sampler,前者用來作一些邏輯上的控制,例如輪換、條件、循環等等。Sampler就是真正“干活”的“取樣器”,例如“HTTP Request”,就是拿來執行一個HTTP請求的。

    3、Listener
        Listener對請求過程進行監聽,可以簡單理解為獲取結果的東東。例如Simple Data Writer,可以把結果寫到一個文本文件里(其實所有Listener都可以寫數據到文件里),還有View Results in Table,就是把結果顯示在表格里。

    4、 Timer
        用來控制執行流程中的時間延遲等功能。

    5、 Assertion
        斷言,加到Sampler里面可以對返回的結果進行判斷,例如判斷HTTP返回結果里面是否含有某個字符串。如果斷言為真,JMeter會標記請求為成功,否則標記為失敗。

    6、 Configuration Element
       
    配置用的元素,很有用。由于測試計劃是樹狀和有繼承關系的,可以在高層次指定一個Configuration Element,低層次的相關Sampler如果沒有顯式地指定配置,就繼承高層次的配置信息。(跟log4j很像吧?)

    7、 Pre-Processor/Post-Processor Elements
       用來在Sampler運行前和運行后作一些預處理和后處理工作的。例如動態修改請求的參數(預處理),從返回信息里面提取信息(后處理)等等。

    舉例:要做一個最簡單的HTTP壓力測試: 用10個線程訪問一個URL,每個線程訪問100次。
    做法:
    1、 在Test Plan下面加一個Thread Group,配置里面,線程數填10,循環次數填100
    2、 在Thread Group下面加一個HTTP Request,這是一個Sampler,在它的配置里面填寫主機信息,端口、協議、路徑、參數等信息
    3、 在HTTP Request下面加一個View Results in Table,如果你想把記錄記到文件,則填寫文件路徑。
    4、 保存一些這個Test Plan,就可以選擇Run菜單下面的Run來運行了。直到Run菜單項從灰色變回黑色,就表示運行完了。在View Results in Table下面,你可以看到運行結果。

    關于元素的詳細描述可以參考官方文檔

    JMeter功能很豐富的,還有很強的擴展能力,而且又是免費,值得研究使用。
    posted @ 2006-03-01 10:04 Raymond的Java筆記 閱讀(1570) | 評論 (0)編輯 收藏

    2006年2月27日

    本文只作很簡要介紹,可視作備忘參考。

    TPTP是eclipse官方的profiling插件,初步使用下感覺功能強大。

    下載安裝: 在http://www.eclipse.org/tptp/下載,我選擇All-Runtime,然后像其它插件一樣解壓到eclipse的目錄,然后允許eclipse -clean來刷新一把。

    使用: 
       常用的profiling簡單來講就對程序運行進行記錄,然后從數據中分析哪些方法運行時間長,哪些對象吃內存多,哪些類的實例多等等。一個比較好的使用入門sample在這里: http://www.eclipse.org/tptp/home/documents/tutorials/profilingtool/profilingexample_32.html 我就不羅嗦了。

    值得多講的是Remote Profiling,就是遠程剖析。實現的原理是在遠程機器上運行一個代理進程,要被遠程剖析的程序或者Application Server啟動的時候加一個JVM參數來識別這個代理進程,兩者相互作用,代理就可以把收集到的信息發給在遠程的一方(就是運行著eclipse的一方)。

    因此要實現Remote Profiling,還要在目標機器上裝一個agent。 -->

    下載安裝:http://www.eclipse.org/tptp/home/downloads/drops/TPTP-4.0.1.html 選擇對應操作系統的Agent Controller下載,選擇Runtime即可。

    下載后,閱讀依照getting_started.html的說明來安裝即可,這里簡述一下:
    1、 把它的bin目錄放到PATH里面
    2、 運行一下SetConfig來設置參數,注意如果想讓除本地localhost意外所以機器都訪問的話,要注意設置Network Access Mode,默認是localhost的。
    3、 運行RAStart來啟動代理(Linux下)
    4、 服務器端程序(例如tomcat)啟動的JVM參數里面加入-XrunpiAgent:server=enabled即可(還有其它參數值參見文檔)
    5、 然后就可以在遠程用eclipse來啟動一個Profiling進程來attach到這個agent controller了。效果和在eclipse里面直接profile應用程序一樣。

    posted @ 2006-02-27 14:14 Raymond的Java筆記 閱讀(5634) | 評論 (2)編輯 收藏

    2006年2月19日

    Volatile Fields

    Sometimes, it seems excessive to pay the cost of synchronization just to read or write an instance field or two. After all, what can go wrong? Unfortunately, with modern processors and compilers, there is plenty of room for error:

    • Computers with multiple processors can temporarily hold memory values in registers or local memory caches. As a consequence, threads running in different processors may see different values for the same memory location!

    • Compilers can reorder instructions for maximum throughput. Compilers won't choose an ordering that changes the meaning of the code, but they make the assumption that memory values are only changed when there are explicit instructions in the code. However, a memory value can be changed by another thread!

    If you use locks to protect code that can be accessed by multiple threads, then you won't have these problems. Compilers are required to respect locks by flushing local caches as necessary and not inappropriately reordering instructions. The details are explained in the Java Memory Model and Thread Specification developed by JSR 133 (see http://www.jcp.org/en/jsr/detail?id=133). Much of the specification is highly complex and technical, but the document also contains a number of clearly explained examples. A more accessible overview article by Brian Goetz is available at http://www-106.ibm.com/developerworks/java/library/j-jtp02244.html.

    NOTE

    Brian Goetz coined the following "synchronization motto": "If you write a variable which may next be read by another thread, or you read a variable which may have last been written by another thread, you must use synchronization."


    The volatile keyword offers a lock-free mechanism for synchronizing access to an instance field. If you declare a field as volatile, then the compiler and the virtual machine take into account that the field may be concurrently updated by another thread.

    For example, suppose an object has a boolean flag done that is set by one thread and queried by another thread. You have two choices:

    1. Use a lock, for example:

      public synchronized boolean isDone() { return done; }
      private boolean done;
      

      (This approach has a potential drawback: the isDone method can block if another thread has locked the object.)

    2. Declare the field as volatile:

      public boolean isDone() { return done; }
      private volatile boolean done;
      

    Of course, accessing a volatile variable will be slower than accessing a regular variablethat is the price to pay for thread safety.

    NOTE

    Prior to JDK 5.0, the semantics of volatile were rather permissive. The language designers attempted to give implementors leeway in optimizing the performance of code that uses volatile fields. However, the old specification was so complex that implementors didn't always follow it, and it allowed confusing and undesirable behavior, such as immutable objects that weren't truly immutable.


    In summary, concurrent access to a field is safe in these three conditions:

    • The field is volatile.

    • The field is final, and it is accessed after the constructor has completed.

    • The field access is protected by a lock.

    posted @ 2006-02-19 15:58 Raymond的Java筆記 閱讀(380) | 評論 (0)編輯 收藏

    2006年2月17日

    The Joel Test: 12 Steps to Better Code


    By Joel Spolsky
    Wednesday, August 09, 2000
    Printer Friendly Version

    Have you ever heard of SEMA? It's a fairly esoteric system for measuring how good a software team is. No, wait! Don't follow that link! It will take you about six years just to understand that stuff. So I've come up with my own, highly irresponsible, sloppy test to rate the quality of a software team. The great part about it is that it takes about 3 minutes. With all the time you save, you can go to medical school.

    The Joel Test

    1. Do you use source control?
    2. Can you make a build in one step?
    3. Do you make daily builds?
    4. Do you have a bug database?
    5. Do you fix bugs before writing new code?
    6. Do you have an up-to-date schedule?
    7. Do you have a spec?
    8. Do programmers have quiet working conditions?
    9. Do you use the best tools money can buy?
    10. Do you have testers?
    11. Do new candidates write code during their interview?
    12. Do you do hallway usability testing?

    The neat thing about The Joel Test is that it's easy to get a quick yes or no to each question. You don't have to figure out lines-of-code-per-day or average-bugs-per-inflection-point. Give your team 1 point for each "yes" answer. The bummer about The Joel Test is that you really shouldn't use it to make sure that your nuclear power plant software is safe.

    A score of 12 is perfect, 11 is tolerable, but 10 or lower and you've got serious problems. The truth is that most software organizations are running with a score of 2 or 3, and they need serious help, because companies like Microsoft run at 12 full-time. 

    Of course, these are not the only factors that determine success or failure: in particular, if you have a great software team working on a product that nobody wants, well, people aren't going to want it. And it's possible to imagine a team of "gunslingers" that doesn't do any of this stuff that still manages to produce incredible software that changes the world. But, all else being equal, if you get these 12 things right, you'll have a disciplined team that can consistently deliver.

    1. Do you use source control?
    I've used commercial source control packages, and I've used CVS, which is free, and let me tell you, CVS is fine. But if you don't have source control, you're going to stress out trying to get programmers to work together. Programmers have no way to know what other people did. Mistakes can't be rolled back easily. The other neat thing about source control systems is that the source code itself is checked out on every programmer's hard drive -- I've never heard of a project using source control that lost a lot of code.

    2. Can you make a build in one step?
    By this I mean: how many steps does it take to make a shipping build from the latest source snapshot? On good teams, there's a single script you can run that does a full checkout from scratch, rebuilds every line of code, makes the EXEs, in all their various versions, languages, and #ifdef combinations, creates the installation package, and creates the final media -- CDROM layout, download website, whatever.

    If the process takes any more than one step, it is prone to errors. And when you get closer to shipping, you want to have a very fast cycle of fixing the "last" bug, making the final EXEs, etc. If it takes 20 steps to compile the code, run the installation builder, etc., you're going to go crazy and you're going to make silly mistakes.

    For this very reason, the last company I worked at switched from WISE to InstallShield: we required that the installation process be able to run, from a script, automatically, overnight, using the NT scheduler, and WISE couldn't run from the scheduler overnight, so we threw it out. (The kind folks at WISE assure me that their latest version does support nightly builds.)

    3. Do you make daily builds?
    When you're using source control, sometimes one programmer accidentally checks in something that breaks the build. For example, they've added a new source file, and everything compiles fine on their machine, but they forgot to add the source file to the code repository. So they lock their machine and go home, oblivious and happy. But nobody else can work, so they have to go home too, unhappy.

    Breaking the build is so bad (and so common) that it helps to make daily builds, to insure that no breakage goes unnoticed. On large teams, one good way to insure that breakages are fixed right away is to do the daily build every afternoon at, say, lunchtime. Everyone does as many checkins as possible before lunch. When they come back, the build is done. If it worked, great! Everybody checks out the latest version of the source and goes on working. If the build failed, you fix it, but everybody can keep on working with the pre-build, unbroken version of the source.

    On the Excel team we had a rule that whoever broke the build, as their "punishment", was responsible for babysitting the builds until someone else broke it. This was a good incentive not to break the build, and a good way to rotate everyone through the build process so that everyone learned how it worked. 

    Read more about daily builds in my article Daily Builds are Your Friend.

    4. Do you have a bug database?
    I don't care what you say. If you are developing code, even on a team of one, without an organized database listing all known bugs in the code, you are going to ship low quality code. Lots of programmers think they can hold the bug list in their heads. Nonsense. I can't remember more than two or three bugs at a time, and the next morning, or in the rush of shipping, they are forgotten. You absolutely have to keep track of bugs formally.

    Bug databases can be complicated or simple. A minimal useful bug database must include the following data for every bug:

    • complete steps to reproduce the bug
    • expected behavior
    • observed (buggy) behavior
    • who it's assigned to
    • whether it has been fixed or not

    If the complexity of bug tracking software is the only thing stopping you from tracking your bugs, just make a simple 5 column table with these crucial fields and start using it.

    For more on bug tracking, read Painless Bug Tracking.

    5. Do you fix bugs before writing new code?
    The very first version of Microsoft Word for Windows was considered a "death march" project. It took forever. It kept slipping. The whole team was working ridiculous hours, the project was delayed again, and again, and again, and the stress was incredible. When the dang thing finally shipped, years late, Microsoft sent the whole team off to Cancun for a vacation, then sat down for some serious soul-searching.

    What they realized was that the project managers had been so insistent on keeping to the "schedule" that programmers simply rushed through the coding process, writing extremely bad code, because the bug fixing phase was not a part of the formal schedule. There was no attempt to keep the bug-count down. Quite the opposite. The story goes that one programmer, who had to write the code to calculate the height of a line of text, simply wrote "return 12;" and waited for the bug report to come in about how his function is not always correct. The schedule was merely a checklist of features waiting to be turned into bugs. In the post-mortem, this was referred to as "infinite defects methodology".

    To correct the problem, Microsoft universally adopted something called a "zero defects methodology". Many of the programmers in the company giggled, since it sounded like management thought they could reduce the bug count by executive fiat. Actually, "zero defects" meant that at any given time, the highest priority is to eliminate bugs before writing any new code. Here's why. 

    In general, the longer you wait before fixing a bug, the costlier (in time and money) it is to fix.

    For example, when you make a typo or syntax error that the compiler catches, fixing it is basically trivial.

    When you have a bug in your code that you see the first time you try to run it, you will be able to fix it in no time at all, because all the code is still fresh in your mind.

    If you find a bug in some code that you wrote a few days ago, it will take you a while to hunt it down, but when you reread the code you wrote, you'll remember everything and you'll be able to fix the bug in a reasonable amount of time.

    But if you find a bug in code that you wrote a few months ago, you'll probably have forgotten a lot of things about that code, and it's much harder to fix. By that time you may be fixing somebody else's code, and they may be in Aruba on vacation, in which case, fixing the bug is like science: you have to be slow, methodical, and meticulous, and you can't be sure how long it will take to discover the cure.

    And if you find a bug in code that has already shipped, you're going to incur incredible expense getting it fixed.

    That's one reason to fix bugs right away: because it takes less time. There's another reason, which relates to the fact that it's easier to predict how long it will take to write new code than to fix an existing bug. For example, if I asked you to predict how long it would take to write the code to sort a list, you could give me a pretty good estimate. But if I asked you how to predict how long it would take to fix that bug where your code doesn't work if Internet Explorer 5.5 is installed, you can't even guess, because you don't know (by definition) what's causing the bug. It could take 3 days to track it down, or it could take 2 minutes.

    What this means is that if you have a schedule with a lot of bugs remaining to be fixed, the schedule is unreliable. But if you've fixed all the known bugs, and all that's left is new code, then your schedule will be stunningly more accurate.

    Another great thing about keeping the bug count at zero is that you can respond much faster to competition. Some programmers think of this as keeping the product ready to ship at all times. Then if your competitor introduces a killer new feature that is stealing your customers, you can implement just that feature and ship on the spot, without having to fix a large number of accumulated bugs.

    6. Do you have an up-to-date schedule?
    Which brings us to schedules. If your code is at all important to the business, there are lots of reasons why it's important to the business to know when the code is going to be done. Programmers are notoriously crabby about making schedules. "It will be done when it's done!" they scream at the business people.

    Unfortunately, that just doesn't cut it. There are too many planning decisions that the business needs to make well in advance of shipping the code: demos, trade shows, advertising, etc. And the only way to do this is to have a schedule, and to keep it up to date.

    The other crucial thing about having a schedule is that it forces you to decide what features you are going to do, and then it forces you to pick the least important features and cut them rather than slipping into featuritis (a.k.a. scope creep).

    Keeping schedules does not have to be hard. Read my article Painless Software Schedules, which describes a simple way to make great schedules.

    7. Do you have a spec?
    Writing specs is like flossing: everybody agrees that it's a good thing, but nobody does it. 

    I'm not sure why this is, but it's probably because most programmers hate writing documents. As a result, when teams consisting solely of programmers attack a problem, they prefer to express their solution in code, rather than in documents. They would much rather dive in and write code than produce a spec first.

    At the design stage, when you discover problems, you can fix them easily by editing a few lines of text. Once the code is written, the cost of fixing problems is dramatically higher, both emotionally (people hate to throw away code) and in terms of time, so there's resistance to actually fixing the problems. Software that wasn't built from a spec usually winds up badly designed and the schedule gets out of control.  This seems to have been the problem at Netscape, where the first four versions grew into such a mess that management stupidly decided to throw out the code and start over. And then they made this mistake all over again with Mozilla, creating a monster that spun out of control and took several years to get to alpha stage.

    My pet theory is that this problem can be fixed by teaching programmers to be less reluctant writers by sending them off to take an intensive course in writing. Another solution is to hire smart program managers who produce the written spec. In either case, you should enforce the simple rule "no code without spec".

    Learn all about writing specs by reading my 4-part series.

    8. Do programmers have quiet working conditions?
    There are extensively documented productivity gains provided by giving knowledge workers space, quiet, and privacy. The classic software management book Peopleware documents these productivity benefits extensively.

    Here's the trouble. We all know that knowledge workers work best by getting into "flow", also known as being "in the zone", where they are fully concentrated on their work and fully tuned out of their environment. They lose track of time and produce great stuff through absolute concentration. This is when they get all of their productive work done. Writers, programmers, scientists, and even basketball players will tell you about being in the zone.

    The trouble is, getting into "the zone" is not easy. When you try to measure it, it looks like it takes an average of 15 minutes to start working at maximum productivity. Sometimes, if you're tired or have already done a lot of creative work that day, you just can't get into the zone and you spend the rest of your work day fiddling around, reading the web, playing Tetris.

    The other trouble is that it's so easy to get knocked out of the zone. Noise, phone calls, going out for lunch, having to drive 5 minutes to Starbucks for coffee, and interruptions by coworkers -- especially interruptions by coworkers -- all knock you out of the zone. If a coworker asks you a question, causing a 1 minute interruption, but this knocks you out of the zone badly enough that it takes you half an hour to get productive again, your overall productivity is in serious trouble. If you're in a noisy bullpen environment like the type that caffeinated dotcoms love to create, with marketing guys screaming on the phone next to programmers, your productivity will plunge as knowledge workers get interrupted time after time and never get into the zone.

    With programmers, it's especially hard. Productivity depends on being able to juggle a lot of little details in short term memory all at once. Any kind of interruption can cause these details to come crashing down. When you resume work, you can't remember any of the details (like local variable names you were using, or where you were up to in implementing that search algorithm) and you have to keep looking these things up, which slows you down a lot until you get back up to speed.

    Here's the simple algebra. Let's say (as the evidence seems to suggest) that if we interrupt a programmer, even for a minute, we're really blowing away 15 minutes of productivity. For this example, lets put two programmers, Jeff and Mutt, in open cubicles next to each other in a standard Dilbert veal-fattening farm. Mutt can't remember the name of the Unicode version of the strcpy function. He could look it up, which takes 30 seconds, or he could ask Jeff, which takes 15 seconds. Since he's sitting right next to Jeff, he asks Jeff. Jeff gets distracted and loses 15 minutes of productivity (to save Mutt 15 seconds).

    Now let's move them into separate offices with walls and doors. Now when Mutt can't remember the name of that function, he could look it up, which still takes 30 seconds, or he could ask Jeff, which now takes 45 seconds and involves standing up (not an easy task given the average physical fitness of programmers!). So he looks it up. So now Mutt loses 30 seconds of productivity, but we save 15 minutes for Jeff. Ahhh!

    9. Do you use the best tools money can buy?
    Writing code in a compiled language is one of the last things that still can't be done instantly on a garden variety home computer. If your compilation process takes more than a few seconds, getting the latest and greatest computer is going to save you time. If compiling takes even 15 seconds, programmers will get bored while the compiler runs and switch over to reading The Onion, which will suck them in and kill hours of productivity.

    Debugging GUI code with a single monitor system is painful if not impossible. If you're writing GUI code, two monitors will make things much easier.

    Most programmers eventually have to manipulate bitmaps for icons or toolbars, and most programmers don't have a good bitmap editor available. Trying to use Microsoft Paint to manipulate bitmaps is a joke, but that's what most programmers have to do.

    At my last job, the system administrator kept sending me automated spam complaining that I was using more than ... get this ... 220 megabytes of hard drive space on the server. I pointed out that given the price of hard drives these days, the cost of this space was significantly less than the cost of the toilet paper I used. Spending even 10 minutes cleaning up my directory would be a fabulous waste of productivity.

    Top notch development teams don't torture their programmers. Even minor frustrations caused by using underpowered tools add up, making programmers grumpy and unhappy. And a grumpy programmer is an unproductive programmer.

    To add to all this... programmers are easily bribed by giving them the coolest, latest stuff. This is a far cheaper way to get them to work for you than actually paying competitive salaries!

    10. Do you have testers?
    If your team doesn't have dedicated testers, at least one for every two or three programmers, you are either shipping buggy products, or you're wasting money by having $100/hour programmers do work that can be done by $30/hour testers. Skimping on testers is such an outrageous false economy that I'm simply blown away that more people don't recognize it.

    Read Top Five (Wrong) Reasons You Don't Have Testers, an article I wrote about this subject.

    11. Do new candidates write code during their interview?
    Would you hire a magician without asking them to show you some magic tricks? Of course not.

    Would you hire a caterer for your wedding without tasting their food? I doubt it. (Unless it's Aunt Marge, and she would hate you forever if you didn't let her make her "famous" chopped liver cake).

    Yet, every day, programmers are hired on the basis of an impressive resumé or because the interviewer enjoyed chatting with them. Or they are asked trivia questions ("what's the difference between CreateDialog() and DialogBox()?") which could be answered by looking at the documentation. You don't care if they have memorized thousands of trivia about programming, you care if they are able to produce code. Or, even worse, they are asked "AHA!" questions: the kind of questions that seem easy when you know the answer, but if you don't know the answer, they are impossible.

    Please, just stop doing this. Do whatever you want during interviews, but make the candidate write some code. (For more advice, read my Guerrilla Guide to Interviewing.)

    12. Do you do hallway usability testing?
    A hallway usability test is where you grab the next person that passes by in the hallway and force them to try to use the code you just wrote. If you do this to five people, you will learn 95% of what there is to learn about usability problems in your code.

    Good user interface design is not as hard as you would think, and it's crucial if you want customers to love and buy your product. You can read my free online book on UI design, a short primer for programmers.

    But the most important thing about user interfaces is that if you show your program to a handful of people, (in fact, five or six is enough) you will quickly discover the biggest problems people are having. Read Jakob Nielsen's article explaining why. Even if your UI design skills are lacking, as long as you force yourself to do hallway usability tests, which cost nothing, your UI will be much, much better.

    Four Ways To Use The Joel Test

    1. Rate your own software organization, and tell me how it rates, so I can gossip.
    2. If you're the manager of a programming team, use this as a checklist to make sure your team is working as well as possible. When you start rating a 12, you can leave your programmers alone and focus full time on keeping the business people from bothering them.
    3. If you're trying to decide whether to take a programming job, ask your prospective employer how they rate on this test. If it's too low, make sure that you'll have the authority to fix these things. Otherwise you're going to be frustrated and unproductive.
    4. If you're an investor doing due diligence to judge the value of a programming team, or if your software company is considering merging with another, this test can provide a quick rule of thumb.
    posted @ 2006-02-17 22:02 Raymond的Java筆記 閱讀(476) | 評論 (0)編輯 收藏

    2006年2月4日

    需求: 在lucene索引中建立了很多關鍵字的索引,想獲得一個當前用戶的關鍵字列表,并且每個關鍵字還帶有使用了多少次的信息。

    解決方法:
    使用自定義的HitCollector對象,代碼如下
    import java.io.IOException;
    import java.util.ArrayList;
    import java.util.Collections;
    import java.util.HashMap;
    import java.util.Iterator;
    import java.util.Set;

    import org.apache.lucene.document.Document;
    import org.apache.lucene.search.HitCollector;
    import org.apache.lucene.search.IndexSearcher;

    public class TagCollector extends HitCollector {
        
    private IndexSearcher searcher;
        
    private HashMap<String,Integer> tagList=new HashMap<String,Integer>();
        
    public TagCollector(IndexSearcher searcher) {
            
    this.searcher=searcher;
        }

        @Override
        
    public void collect(int docID, float score) {
            
    try {
                Document doc
    =searcher.doc(docID);
                String[] tagValues
    =doc.getValues("tag");
                
    if (tagValues!=null{
                    
    for (int i=0;i<tagValues.length;i++{
                        addTagCount(tagValues[i]);
                    }

                }

            }
     catch (IOException e) {
                e.printStackTrace();
            }


        }

        
        
    private void addTagCount(String tagName) {
            
    int count=1;
            
    if (tagList.containsKey(tagName)) {
                count
    =(Integer)tagList.get(tagName)+1;
            }

            tagList.put(tagName,count);
        }

        
        
    public HashMap<String,Integer> getTagList() {
            
    return tagList;
        }

        
        @SuppressWarnings(
    "unchecked")
        
    public ArrayList<TagSummary> getSortedTagList(boolean ascending) {
            ArrayList
    <TagSummary> list=new ArrayList<TagSummary>();
            Iterator keyIterator
    =tagList.keySet().iterator();
            
    while (keyIterator.hasNext()) {
                String key
    =(String)keyIterator.next();
                
    int value=tagList.get(key);
                list.add(
    new TagSummary(key,value));
            }

            Collections.sort(list);
            
    if (!ascending) {
                Collections.reverse(list);
            }

            
    return list;
        }

        

    }

    功能說明: 每個搜索到的hits,都會調用這個方法的collect方法,因此可以在這個對象當中放一個HashMap,累計記錄每個關鍵字得到的次數。

    排序部分用另外的一個TagSummary類來獲得,這里就不詳細給出了。

    問題: 這是一個直觀的方法,但是相信頻繁調用這樣的方法會造成服務器的嚴重負擔。可以考慮一下用緩存的方法,在沒有關鍵字未曾發生改變之前,只在第一次調用這樣的方法,之后把結果緩存在數據表或者內存當中。有更新的時候,通過版本號對比以決定是否需要更新。
    posted @ 2006-02-04 14:26 Raymond的Java筆記 閱讀(1738) | 評論 (0)編輯 收藏

    2006年1月19日

    問題:
    使用Struts的ActionForm接收到的中文全部是亂碼,例如提交過去的“測試”字符串,得到的是“??????è????”。開頭以為是傳統的encoding識別的問題,但是用各種編碼重新構造得到的byte[]數組,依然無法得到正確的中文。但是如果用普通的jsp來接收form的數據,中文是完全正常的。
    我開始覺得是struts的流程當中,錯誤地使用了編碼,以至最后得到的結果完全亂了。搜索了好多文章,總算找到一個比較接近的。
    解決方法:
    定義一個filter,filter只做一件事情,就是:
          request.setCharacterEncoding("UTF-8");
    在web.xml的filter mapping里,設定和struts的action同樣的mapping。

    解釋: Filter最先攔截web請求,在這里設置了正確的CharacterEncoding,接下來各個處理的組件就不會搞錯了。在沒有Filter的情況下,我的resin服務器上獲得的是null,估計struts不同的處理組件對null的解釋和處理不太一致,導致錯誤的產生。

    要注意我所有頁面都是UTF-8編碼,所以在filter里面定義了UTF-8,如果是其它的編碼,這里應該相應改一下。
    posted @ 2006-01-19 23:28 Raymond的Java筆記 閱讀(1070) | 評論 (0)編輯 收藏

    2006年1月17日

    判斷一個字符是否中文,今天查API找到一個方法,代碼如下:   


       System.out.println(Character.UnicodeBlock.of('琴'));
       System.out.println(Character.UnicodeBlock.of('j'));
       System.out.println(Character.UnicodeBlock.of(3267));

    運行結果:
    CJK_UNIFIED_IDEOGRAPHS
    BASIC_LATIN
    KANNADA

    其實不完全夠用,因為如果得到“CJK_UNIFIED_IDEOGRAPHS”,還可能是日文或者韓文。不過對我的需求是足夠了。如果要準確判斷中文,去查一下unicode代碼就可以了。

    posted @ 2006-01-17 12:09 Raymond的Java筆記 閱讀(808) | 評論 (0)編輯 收藏

    2006年1月16日

    function Queue(size) {
     this.size=size;
     this.data=new Array();
     this.add=function(ele) {
      if (this.data.length<this.size) {
       this.data[this.data.length]=ele;
      } else {
       this.data.shift();
       this.data[this.data.length]=ele;
      }
     };
     this.getData=function() {
      return this.data;
     };
     this.toCookieValue=function(delimiter) {
      var result='';
      for (var i=0;i<this.data.length ;i++ )
      {
       if(i==0) {
        result=escape(this.data[i]);
       } else {
        result+=delimiter+escape(this.data[i]);
       }
      }
      return result;
     };
    }
    posted @ 2006-01-16 15:52 Raymond的Java筆記 閱讀(990) | 評論 (2)編輯 收藏

    2006年1月13日

    使用Resin 3.0開發,很奇怪Eclipse在啟動了remote debug,然后加斷點的時候說我的類沒有加行號。我找遍了選項,明明是加了行號的呀。甚至我在一個必定會走過的類前面加個log打出來,路照走了,居然在console不見log。百思不得其解,快崩潰之前。終于想起了臨時目錄。

    Resin默認總是在WEB-INF下面生成work和tmp目錄,是放jsp編譯而成的類的。我把這兩個目錄刪除了。一切正常,斷點也可以加了。

    原因: 應該是resin在判斷類是否需要重新編譯時有點問題,對于我jsp里面有使用到的類發生變化以后,調用它的jsp文件沒有重新編譯。導致類文件不更新,連帶就出了一堆古怪的錯誤。

    下次記住了,有問題,先刪臨時目錄!
    posted @ 2006-01-13 16:05 Raymond的Java筆記 閱讀(914) | 評論 (0)編輯 收藏
    僅列出標題  下一頁
     
    主站蜘蛛池模板: 国产AV无码专区亚洲精品| 蜜桃精品免费久久久久影院| 久久亚洲欧洲国产综合| 免费国产黄网站在线观看动图| 成人毛片免费视频| 亚洲欧美日韩中文字幕一区二区三区 | 亚洲伊人久久大香线蕉综合图片| 国产成人不卡亚洲精品91| 国产男女猛烈无遮挡免费视频网站 | 久久精品无码专区免费青青| 亚洲免费在线视频| 免费观看无遮挡www的小视频| 亚洲美女视频一区| 男女做羞羞的事视频免费观看无遮挡| 亚洲成a人片在线观看中文!!!| 免费毛片a在线观看67194| 亚洲乱妇熟女爽到高潮的片 | 国产激情久久久久影院老熟女免费| 亚洲成A人片77777国产| 青柠影视在线观看免费高清| 4444亚洲国产成人精品| 成年女人免费视频播放体验区| 亚洲成av人无码亚洲成av人| 亚洲午夜国产片在线观看| 好猛好深好爽好硬免费视频| 亚洲网址在线观看你懂的| 久久精品女人天堂AV免费观看| 国产精品亚洲а∨天堂2021| 亚洲精品无码AV人在线播放| 国产精品视频免费| 三级片免费观看久久| 亚洲AV乱码一区二区三区林ゆな| 国产99视频精品免费观看7| 深夜A级毛片视频免费| 亚洲国产精品自在线一区二区 | 国产精品99爱免费视频| 久久久无码精品亚洲日韩蜜桃 | 免费人成视频在线观看视频| 亚洲一区二区三区在线网站 | 97视频免费观看2区| 亚洲AV无码成人精品区狼人影院 |