A little bit more...

Wednesday, July 25, 2007

Tips of Using Escape Characters

First, what is the differences between '\n' and '\r\n'?

Cite here: )

It goes back to mechanical teletypes; if you issued a line feed followed by carriage return you got a few characters printed backwards in a diagonal stripe because there was insufficient time for the carriage to move back to the left before it started printing. To overcome this, the carriage return is issued first to give the carriage enough time to return, whilst line feeding, before printing started. It has stuck as a standard ever since.
 
and here:

Different Operating Systems handle newlines in a different way. Here is a short list of the most common ones:
  • DOS and Windows

    They expect a newline to be the combination of two characters, namely '\r\n' (or 13 followed by 10).

  • Unix (and hence Linux as well)

    Unix uses a single '\n' to indicate a new line.

  • Mac

    Macs use a single '\r'.
When string are read from user input, escape character can't be explicitly input. For example, in case which string are read from the command line argument, when the user give argument "hello\nworld", the string read in and stored will be "hello\\nworld". This is because escape characters usually are parsed as format presentation rather than literal  occurrence (actually, this is the "unescapted" meaning). For the same reason, in the programming codes escape characters, the literal form of format presentation, are used instead of draw a format presentation that the compiler could understand, which is obviously of non-sense.

Note that using escape characters to specify the format presentation is not the definition of escape character, though in many cases they're used in this way.

Tuesday, July 24, 2007

Tips on XML Spec

Which set of characters and their combinations can be used as literals of attribute value?
[10]    AttValue   ::=   '"' ([^<&"] | Reference)* '"'



|  "'" ([^<&'] | Reference)* "'"
If double quotes (single quotes) are used to quote the string then the same quotation mark (single-quote character or double-quote character), in addition to the other two characters specified in the above production, can't appear in the enclosed string. But what if one wants to  use the same quotation mark as the enclosing ones inside the enclosed string? In this case, "&quot;" and "&apos;" can be used instead.

e.g., <xxx yyy="..."..."> incurs errors because of the extra double-quote character, instead, <xxx yyy="...&quot;..."> can be used.

Resources:

  1. xml spec 1.0


Thursday, July 05, 2007

TDS: Tabular Data Stream Protocol

Below cites here:

TDS is a protocol, a set of rules describing how to transmit data between two computers. Like any protocol, it defines the types of messages that can be sent, and the order in which they may be sent. Protocols describe the "bits on the wire", how data flow.

In reading this manual, it may be helpful to keep in mind that a protocol is not an API, although the two are related. The server recognizes and speaks a protocol; anything that can send it the correct combination of bytes in the right order can communicate with it. But programmers aren't generally in the business of sending bytes; that's the job of a library. Over the years, there have been a few libraries — each with its own API — that do the work of moving SQL through a TDS pipe. ODBC, db-lib, ct-lib, and JDBC have very different APIs, but they're all one to the server, because on the wire they speak TDS .

The TDS protocol was designed and developed by Sybase Inc. for their Sybase SQL Server relational database engine in 1984. The problem Sybase faced then still exists: There was no commonly accepted application-level protocol to transfer data between a database server and its client. To encourage the use of their product, Sybase came up with a flexible pair of products called netlib and db-lib.

netlib's job was to ferry data between the two computers. To do that, it had to deal with the underlying network protocol. Remember, in those days TCP/IP was not the ubiquitous thing it is today. Besides TCP/IP, netlib ran on DECnet, IPX/SPX, NetBEUI and the like.

db-lib provided an API to the client program, and communicated with the server via netlib. What db-lib sent to the server took the form of a stream of bytes, a structured stream of bytes meant for tables of data, a Tabular Data Stream.

In 1990 Sybase entered into a technology sharing agreement with Microsoft which resulted in Microsoft marketing its own SQL Server. Microsoft kept the db-lib API and added ODBC. (Microsoft has since added other APIs, too.) At about the same time, Sybase introduced a more powerful "successor" to db-lib, called ct-lib, and called the pair OpenClient.

ct-lib, db-lib, and ODBC are APIs that — however different their programming style may be — all use netlib to communicate to the server. The language they use is TDS.

The TDS protocol comes in several flavors, most of which have never been openly documented. If anything, it's probably considered to be something like a trade secret, or at least proprietary technology. The exception is TDS 5.0, used exclusively by Sybase, for which documentation is available from Sybase.

Resources:
  1. FreeTDS User Guide.

Test publishing from email

Test publishing from email
Test publishing from email
Test publishing from email
Test publishing from email
Test publishing from email
Test publishing from email
Test publishing from email

Monday, May 07, 2007

Difference among Swing, AWT, SWT and JFace

Introduction

I know questions like telling the differences among Swing, awt, SWT and JFace or some of them are frequently asked in an interview for Java programmers. I don't use them very often and extensively, nor do I know too much about those four things, especially from the implementation perspective or the guru's best practice perspective. But I do read some materials and figure out some conceptual difference between those four things that I think would suffice answering such questions in an interview.

AWT and Swing

-AWT

AWT stands for abastract window toolkit which comes with an early release of the Java Programming Language ( about 1.1 ). AWT components are referred to as heavyweight components. It is implemented as having "peer" native code for every widget you create. Most of the significant logics (including the core event handling logic) of the toolkit are written in C/C++, for which via JNI (Java Native Interface) your GUI program may directly calls those "peer" native code. It means all of the drawings of your GUI are done directly by the graphic API of the underlying operating system. This implementation underlies several limitations:

  • Not all the operating system support the same set of native widgets, so a "least common denominator" philosophy is used when shipping the AWT library, that is only a basic set of components are provided as library via which you write your GUI. So no complex components such as slider, tree and table can be found in AWT components, which you have to build yourself either through directly writing native code as AWT is implemented, or through writing Java codes which wraps AWT ( this is the way Swing is implemented).
  • Because the core logic are hided from you in the native code, debugging your GUI program can be annoying.

This kind of implementation also results in your GUI implemented with AWT always having the same look and feel as the underlying OS.

-Swing

In contrast, Swing components are known as lightweight components, because Swing doesn't implement the underlying drawing and event handling logic which are delegated to the toolkit in this case AWT, on which it is built on. As mentioned above, Swing is implemented by pure Java codes. So it is conceivable that Swing has the portability that AWT doesn't have, and that Swing has almost all the nontrivial complex components. Swing can also have the same look and feel on all OS, and can also be switched to another style of look and feel at runtime regardless of the underlying OS. It is said that Swing has a better performance than AWT, however, from the implementation logic so far I've known, I can't tell why. Swing seems well known for its good design and architecture.

-Never intermix AWT and Swing

I know a lot has been said and written about this subject. The first item in the resources section is a good example of that.

SWT and JFace

-SWT

SWT, short for standard widget tookit, is originally introduced by IBM, as a substitute of AWT. SWT now is as part of the eclipse platform based on which the eclipse GUIs are implemented. SWT is very similar to AWT conceptually, however, the underlying implementation is a little different. Different from implementing all the core logic in "peer" logic in native code, SWT bears a thin JNI layer which is used for directly call the GUI API of each underlying platform. All the significant logics are written in pure Java codes in which the thin JNI layer is used. So almost all the limitations AWT has are elimintated in SWT. Other than this, better performance are gained, for which I don't know the specific reason. As of AWT, SWT has a consisten look and feel as the underlying OS.

Disadvantages of using SWT:

  • Reuire a native library (This also holds true for AWT).
  • Low level of abstraction (This also holds true for AWT).

-JFace

JFace is conceputally similar to Swing. The relationship between JFace and SWT is very similar to the relationship between Swing and AWT. It works above the level of raw widgets, in this case, SWT. JFace has a rich set of complex widgets.

Resources

  1. Why You Shouldn't Mix AWT and Swing
  2. What is the difference between AWT and SWT
  3. what is difference between swing and awt
Technorati tags: , , , , , ,

About Me

My photo
I'm finishing my master degree in Software Engineering, Computer Science. I believe and have been following what Forrest Gump's Mam said: you have to do the best with what god gave you.