stock quote

7/22/09

about writing regular expression in Java

If only want to match one string once,
use:
String myPatternStr = "a*b";
boolean b = Pattern.matches(myPatternStr, "aaaaab");

If need to match multiple times, then need to use:
Pattern p = Pattern.compile("a*b");
Matcher m = p.matcher("aaaaab");
boolean b = m.matches();
See the complimentary tutorial at sun:
http://java.sun.com/docs/books/tutorial/essential/regex/index.html

For recognizing some special characters like "\d","\s", we actually need "\\":
This is because the Java core syntax will be applied first, then the reg expression special char syntax.
So if you want to find a match for "a*" (a followed by a literal star), you should write:
String patternStr = "a\\*"; not "a*"(means zero or more a); not "a\*" (because Java syntax will try to parse "\*" as a special char and the "\" as an escape symbol)
and for matching a literal backslash, we need "\\\\" in our program

http://www.javamex.com/tutorials/regular_expressions/character_classes_named.shtml
http://www.scribd.com/doc/965568/16-Java-Regex

Greedy and none greedy string match: (add "?" after the char that is not requiring strict matching)
http://www.exampledepot.com/egs/java.util.regex/Greedy.html?l=rel

Don't forget the regular expression standard, no mater which language you're using.
http://regexlib.com/CheatSheet.aspx


10/16/08

The difference of HTTP POST and GET

Reminder me of the Web basics.

When doing a form submit from client side (web browser) to the server,
POST allows you to send more data then 1024 chars in tunnel
GET will append all your data in the URL section <= 1024 chars

So in my Ext.Ajax.request(), if sending a lot of data like a JsonData object of a whole grid, use config: method: POST

See: http://www.jguru.com/faq/view.jsp?EID=56472

Answer
GET and POST basically allow information to be sent back to the webserver from a browser (or other HTTP client for that matter).

Imagine that you have a form on a HTML page and clicking the "submit" button sends the data in the form back to the server, as "name=value" pairs.

Choosing GET as the "method" will append all of the data to the URL and it will show up in the URL bar of your browser. The amount of information you can send back using a GET is restricted as URLs can only be 1024 characters.

A POST on the other hand will (typically) send the information through a socket back to the webserver and it won't show up in the URL bar. You can send much more information to the server this way - and it's not restricted to textual data either. It is possible to send files and even binary data such as serialized Java objects!

A PUT allows you to "put" (upload) a resource (file) on to a webserver so that it be found under a specified URI. DELETE allows you to delete a resource (file). These are both additions to HTTP/1.1 and are not usually used. HEAD returns just the HTTP headers for a resource. TRACE and OPTIONS are also HTTP/1.1 additions and also rarely used.

The Servlet spec allows you to implement separate Java methods implementing each HTTP method in your subclass of HttpServlet. Override the doGet() and/or doPost() method to provide normal servlet functionality. Override doPut() or doDelete() if you want to implement these methods. There's no need to override doOptions() or doTrace(). And the superclass handles the HEAD method all on its own.


7/5/08

I want my GongFu - Mac

someone as a Mac fanatic desperately recommend the Mac. I said all the family are too expensive. He said starts from $599 I can get a Mac Mini box and plug in my old monitor and keyboard. Or deal with a "refurbish" one with full warranty on-line store.
But I don't want to just label myself as a Mac holder, I don't want Mac mini and MacBook. I want a Mac Pro as a professional tech geek. To explore its processing extreme and the true differnece.

Saw one co-workers detailed pic of his Mac pro desktop. Spur me up!
http://web.mac.com/mjbrunner2001/iWeb/Photos%202007/MacPro.html

5/15/08

Ext JS Tips And Tricks

http://orderpt.com/wiki/Wiki.jsp?page=ExtJSTipsAndTricks

sadly the Code seg is not allowed here

Disable web browser back and refresh button in Javascript

use:

lt%body%gt
onload="window.history.forward(1);">
... BODY CONTENT ...
lt%body%gt

From: http://forum.java.sun.com/thread.jspa?threadID=641697&tstart=0
"
Actually window.history.forward(1) would push the current page ahead in the "visited pages history". A negative number like -1 would restore the previous visited page from browser's cache. Zero is relative to the current (displayed) page. Positive numbers would navigate forward.
If the page number (positive) does not exist in history, your browser will create an entry "copying" the current page to it and setting it as the current entry, so that the previous and actual are the same.

Using window.history.forward(1) does not disable "Back button". The button will work BUT as this script runs on page loading, it will send you "ahead" the history, which stored URL (or page) is the same. So it works like a "Refresh" button, without actually refreshing content from server, but just restoring from cache."

Some other methods used in HTML:
http://www.htmlgoodies.com/tutorials/buttons/article.php/3478911

Disable the refresh button:
http://forum.java.sun.com/thread.jspa?threadID=434163&messageID=1947210

10/4/07

how the "watch" function in Java developer's forum used

I post a question weeks ago and I didn't expect that people keep on updating the answer times again. And the answers are really incisive.
See for example:
http://forum.java.sun.com/thread.jspa?threadID=5216558

I get noticed by email of their answer because I add this topic to my "watch" list on Sun't forum and select email update. That's really a good way to get informed coz you don't need to wait on-line for the answer.

I also use the Google compt.lang.java.GUI discussion group. These are the two I stick to.

So my conclusion on using forum for Java problem is:
If you don't want to spend time on your post format and hope to get a quick answer but may not be correct, use the Google group.
If you a not in a hurry, describe your problem in detail, give a "Short, Self Contained, Compilable and Executable, Example Program "(SSCCE) and wait for sure the answer from the Java forum.

9/28/07

the java.net open lib for Swing app

Take a look at:
https://swinglabs.dev.java.net/

Esp. the desktop dev. tools

SwingLabs SwingX package:
http://swinglabs.org/projects.jsp

see demo
http://swinglabs.org/screenshots.jsp

Two useful gadget:
1. Date picker (Calender-popup)
2. Text autoComplete Combobox
3. log-In window
  • What is databinding?
    Databinding is simply associating a property of one Object (p1) with a property on another Object (p2) so that whenever the property p1 changes, the property p2 is updated to reflect that change, and vice versa. This is useful in GUI applications by automating the task of binding a UI component such as a JTextField with a data object such as a Customer object so that the text field displays the customer's "name" property. Any updates to the text field will update the "name" property of the bean, and vice versa.

9/27/07

Strongly typed language vs. weakly typed

http://www.cincomsmalltalk.com/userblogs/buck/blogView?showComments=true&entry=3252458583

Static vs dynamic typing describes at what point type analysis (determining whether a programmer's request to perform a particular operation is permissible) happens: at compile time for a statically typed language, or at run time for a dynamically typed one. Manifest typing in this view is close in the meaning, if not necessarily an exact synonym, of static typing. Statically typed languages often require type declarations in programs, however some statically typed languages such as ML can in some cases infer types from the operations performed, making manifest type declarations unnecessary. It is important to note that dynamic typing does not imply absence of type checking, in spite of the absence of variable and function type declarations--so calling dynamically typed languages such as Smalltalk "untyped" would be grossly incorrect.

Strong vs weak typing characterizes whether type checking, static or dynamic, can be meaningfully circumvented. "Meaningfully" is important here, implying that the type overrides should be predictable in their effect and at least reasonably portable between implementations. In a weakly typed language such overrides are possible. For example, in C , one can take a pointer to an Employee, cast it to char* and pass to a function that expects an argument of that type. In contrast to that, in Smalltalk it is not possible to take an instance of Employee and use with it an operation not defined for instances of Employee.

Actually, Testing is more important to guarantee program correctness than selecting among XXX-typed languages:

See Bruce Eckel's note: (In which he advocate python)

5-2-03 Strong Typing vs. Strong Testing

http://mindview.net/WebLog/log-0025

That is to say, if a program compiles in a strong, statically typed language, it just means that it has passed some tests. It means that the syntax is guaranteed to be correct (Python checks syntax at compile time, as well. It just doesn't have as many syntax contraints). But there's no guarantee of correctness just because the compiler passes your code. If your code seems to run, that's also no guarantee of correctness.

The only guarantee of correctness, regardless of whether your language is strongly or weakly typed, is whether it passes all the tests that define the correctness of your program. And you have to write some of those tests yourself. These, of course, are unit tests. In Thinking in Java, 3rd Edition, we filled the book with unit tests, and they paid off over and over again. Once you become "test infected," you can't go back.

It's very much like going from old C to C++. Suddenly, the compiler was performing many more tests for you and your code was getting right, faster. But those syntax tests can only go so far. The compiler cannot know how you expect the program to behave, so you must "extend" the compiler by adding unit tests (regardless of the language you're using). If you do this, you can make sweeping changes (refactoring code or modifying design) in a rapid manner because you know that your suite of tests will back you up, and immediately fail if there's a problem — just like a compilation fails when there's a syntax problem.

But without a full set of unit tests (at the very least), you can't guarantee the correctness of a program. To claim that the strong, static type checking constraints in C++, Java, or C# will prevent you from writing broken programs is clearly an illusion (you know this from personal experience). In fact, what we need is

Strong testing, not strong typing.