A little bit more...

Monday, September 03, 2007

Common sense: difference between application database and data warehouse

(This post is a collection of information found available on line)
Introduction

I'm a beginner in this aspect. Basically, an app database and a data warehouse have in common is that they're both databases. However they serve for different purposes.

Diff

cite from resource 1:
The primary difference betwen you application database and a data warehouse is that while the former is designed (and optimized) to record , the latter has to be designed (and optimized) to respond to analysis questions that are critical for your business.


Application databases are OLTP (On-Line Transaction Processing) systems where every transaction has to be recorded, and super-fast at that. An application database system is designed to make sure that every transaction gets recorded within the time users are served.

Data warehouses are designed as OLAP (On-Line Analytical Processing) systems, these databases contain read-only data that can be queried and analyzed far more efficiently as compared to your regular OLTP application databases.

cite from resource 3 (read this resource linked below for a thorough understanding):

A common way of introducing data warehousing is to refer to the characteristics of a data warehouse as set forth by William Inmon:


Figure 1-1 Contrasting OLTP and Data Warehousing Environments

Text description of dwhsg005.gif follows
Text description of the illustration dwhsg005.gif


More words on either one

An application database mainly serve for processing real time business data. It shows the whole picture of the business objects world. Every application should normally have an application database to gain any feature concerning persistence. However, a data warehouse is not a must for every business application. It is mainly for analysis of historical (or accumulated) data, and sometimes for real time. Because it is for analysis, it is normally configured as read only for the analysis that is based on it (that is, the end user). In data warehouses there're not only data directly reflecting the status of business objects of some time, but also (and mainly this kind) data derived from business objects data.

data in data warehouse:
Raw data: mappings of business object data
Summary data: monthly statistics
Meta data: day, month, year, etc

Further reading:     
  1. Business Intelligence: What is Data Mining?
  2. Business Intelligence - What is it?
Resources
  1. Database vs. Data Warehouse
  2. GeekInterview.com  >  Interview Questions  >  Data Warehousing
  3. Oracle9i Data Warehousing Guide Release 2 (9.2)

Sunday, August 05, 2007

Smartly load your properties

Method Parameter format Lookup failure behavior Usage example
ClassLoader.
getResourceAsStream()
"/"-separated names; no leading "/" (all names are absolute) Silent (returns null) this.getClass().getClassLoader()
.getResourceAsStream
("some/pkg/resource.properties")
Class.
getResourceAsStream()
"/"-separated names; leading "/" indicates absolute names; all other names are relative to the class's package Silent (returns null) this.getClass()
.getResourceAsStream
("resource.properties")
ResourceBundle.
getBundle()
"."-separated names; all names are absolute; .properties suffix is implied Throws unchecked
java.util.MissingResourceException
ResourceBundle.getBundle
("some.pkg.resource")

and there're more tips in the linked resource below.

Resources
  1. Smartly load your properties

Difference Between ResourceBundle and Properties Classes in Java

GMHK wrote:
> Can anyone tell me the whats the difference between the resource bundle
> and Properties classes in java.
> As both uses the .properties file to get the string constants.

No, they don't necessarily. A resource bundly does not have to be
file-based. The common implementation, however is. And that common
implementation (PropertyResourceBundle) indeed uses properties files and
thr Properties class.

However, resource bundles also come with a particular lookup-schema to
select a particular bundle according to the Locale. Something which you
don't get with Properties, but which is important when you do some
actual localization.

> At what point of time would the programmer decide to choose which of
> the either classes.

A resource bundle (properties file based or otherwise) when in need for
the lookup of locale-specific data. A naked properties file when in need
for keeping some small (FSWO) set of data persistent (e.g. application
configuration data), which is not supposed to be translated.

You didn't mention Preferences. I still preferen Properties over
Preferences because of the easy-to-work-with text file format, but they
can be used for the same purpose as Properties, without the need of
having to deal with files.

> What i understood so far is resourcebundle makes uses of String manager
> to get the string.
> where as the Properties tries to read the properties directly.

Both map keys to values. The biggest difference is how they get that
mapping. ResourceBundles follow a build-in lookup schema taking a locale
into account. Properties need to be provided with some InputStream,
which the programmer has to handle explicitely. Properties have an easy
way to be written to an OutputStream, while ResourceBundles are ment to
be read-only.

/Thomas
Resources
  1. Difference Between ResourceBundle and Properties Classes in Java

Friday, July 27, 2007

Regular expression and CharSequence in Java

Introduction
Regular expression, specified as a string, is first compiled into an instance of Pattern. The regular expression constructs supported by Pattern are almost the same (see comparison to Perl 5 in javadoc of class pattern) as that supported by Perl 5. The Pattern engine performs traditional NFA-based (Nondeterministic Finite Automate) matching with ordered alternation as occurs in Perl 5.

The regex Package
Two major class Pattern and Matcher, both of which have non-public constructor which means  the client can't new instances of them directly. A Pattern instance is the compiled intermediate representation, plus some helper methods, of the string form regular expression. Instances of Pattern are immutable which means they're thread-safe. And each instance of Matcher, produced by factory method of Pattern, corresponds to each matching between the bound regular expression of the target string ( i.e., the string to be matched). Further information about how to use this package in a program can be found in the resources section.

regex matching in CharSequence
Despite being as part of the java library, the regex package is also used by other parts of the library. These usages are listed below:
boolean String.matches( String regex );
String String.replaceAll( String regex, String replacement )
String String.replaceFirst( String regex, String replacement )
String[] split( String regex )

Note that rather than class String or some other concrete representation of CharSequence, interface CharSequence is widely depended upon both in Pattern and String. Classes implementing CharSequence mainly include String, StringBuffer and StringBuilder. And the implemented methods include such methods that we usually use with String as charAt(int), length(), and subSequence(int, int).


Resources
  1. Interface java.lang.CharSequence
  2. Package java.util.regex
  3. Lesson: Regular Expressions

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: , , , , , ,

Thursday, May 03, 2007

Exception as Non-Exception

Introduction

Quotes: One of the unexpected benefits of exception handling is better performance because many errors can be processed centrally instead of after each function call. - by Bruce Eckel, the author of Thinking in Java.

-First, what is exception?

In JVM SPEC, an exception is defined to be an error that JVM would signal to a program if a program violates the semantic constrains of the Java programming language. But that’s not the complete fact, more generally, causing an exception is considered to be an exceptional condition or abnormal state that a program is in. So besides violating the semantic constrains of a programming language, which may be a critical and unrecoverable condition, breaking the assumption on the logic functionality of a program can also be considered to be exceptions. From a more formal perspective, every statement, method or generally, module are expected to fullfill some implicit or explicit contract, and an exception indicates the inability to fullfill the contract. Regardeless of the context of the specific programming languge (such as Java) exception handling mechanism, exception and error are interchangeablely used.

-Second, what is exception handling?

Informally speaking, exception handling is what you do about the exceptional condition. However, though an agreement on the defintion of exception are generally achieved, exception handling mechanisms are from time to time debated on. Generally, three techinques / mechanisms / notions are concerning with exception handling. First, exceptions can be identified by returning distinguished error values and handling exceptions is immediately done based on the error values. This is the most conventional way of identifying and handling exceptions. Many large system written in C or most conventional procedure languages utilize this way. Second, exceptions identifying and handling are distinguished from other features that a porgramming language provides. This can be found in many modern OO language such as C++ and Java. An Exception class (or method ?) is and can be designated for each kind of exceptional condition, and special satements with special keywords are introduced to notify ( or throw ) the condition and then handle the condition, usually at different places in your program. Third, exceptions are covered or at least not emphasized based on the assumption that a module and the client of a module take clearly divided responsiblities. This is mainly concerning an OO design principle called design by contract, DBC for short.

Old-fashioned style by returning distinguished error values

When encountering an error, return distinguished error values that are not considered normal return values. For example, a method that is to calculate the square root of a number doesn’t consider a negative number as a normal return value, so returning -1 / -2 / -3 indicates an error. The client code can distinguish a normal return value from error return values, so the client programmer can write code to cope with each exceptional condition according to returned error values, each of which indicate a kind of exceptional condition. E.g.,

int sqrt( int num )

{

if ( .. ) return -1;

else if ( … )

{

return -2;

}

}

-pros and cons

pros: Both notifying and handling exceptions are light weight. 1) No extra mechanisms are needed to notify and handle exceptional condition, which means codes notifying and handling exceptional conditions are executed in exactly the same way other codes that solving the core problems runs. 2) This will not introduce any extra runtime overhead for exception handling.

cons: 1) This idiom tend to cause spaghetti codes. It will complexicate your method codes by having to place many error checking codes. 2) Agreements on what each error value means must be established between the author and the user of the method. And if the same meaning of an error value must be used among more than one method, the global agreement is hard to be established. For instance:

return -1, if the passed in argument <>

3) For the client code, it is not enforced to handle any exceptional conditions. In other words, it’s completely up to the client programmer whether or not to handle any exceptional conditions. 4) In addition, even exceptional conditions are to be handled, duplicate codes must be written for each call of the mehod, that is, several calls to the same method requires several times of handling several same kind of exceptional conditions which means codes for handing exceptional conditions can’t be centralized and thus be reused. 5) More worse, handling exceptions must usually be followed immediately after recieving the error values, regardless of whether or not the then’s current context can provide enough information to handle the exceptions. That is, it is hard to propagate the exception to the right level of abstraction only on which such exceptions can be properly handled.

Exception handling style

Utilize dedicated constructs, such as Exception types, to represent the exceptions and collect information about the exceptional conditions, and handle exceptions based on information wrapped in such constructs.

-pros and cons

pros: 1) Exceptions and their handling are standardized as part of the features of a programming language that are distinguished from other features of that language. Handling some kinds of exceptions are enforced by the compiler, which means the learning curve are to some degree flattened. It less depends on the experiences, but are forced to be done. 2) Agreements on what exception means are easily established by the kind of dedicated constructs. And global reuse of these agreements needs no extra effort. 3) Though, it will stil cause spaghetti codes, it is alleviated by exception handling mechanism enabling that some exceptional conditions (such as access members on a null reference) are automatically notified in the standard way which means less error checking codes are needed. 4) Exceptions notifying and handling are loosely coupled, that is, identifying exceptions and handling them can be at two point far away from each othe in the control flow. This also means it is easy to propagate exceptions to the right level of abstraction on which such exceptions can be properly handled. 5) Due to easily propagating exceptions, handling the same kind of exceptions can be centralized, for which someone argues that unexpected performance benefits will be get as opposed to old-fashioned error values way.

cons: 1) Extra runtime overhead are needed to notify and handle exceptions for which at the implementation level, extra transfer of control is needed. 2) Client codes are complicated by exceptions handler codes which are more obvious if exceptions notifying are misued and/or overused.

Design by contract

A contract is established, explicitly or implicitly, between a module and the user (client code) of the module. Any side must comform to the contract at any time, under any circumstance. The contract consists of precondition, invariant and postcondition. Whenever wherever the module is called (used) the precondition must be met, and after executing the module, the postcondition must be met. In the whole process the invariant must always be met. Obligations and benefits for both parties are specified. It is the obligation of the client to ensure the precondition is met before calling the module, and that of the module to ensure the invariant and postcondition are met. So any party is committed to its obligation regardless of the other party’s obligation.

More specificly, the client will check and ensure the precondition is met before it calling the module, so on most occassions, no exception mechanism is needed. Because if the contract is always conformed to, no exceptions are foreseen. But, usually, extra mechanism, such as assertion, is needed to help tell and/or check whether or not the contract is conformed to. However, even no such extra mechanism is provided, the idea behind DBC can also be used to prevent from overusing exceptions which may be caused by defensive programming. In general, DBC is sometimes considered to be a formal method.

p.s., the DBC community considers returning error values and exception handling two rivals :)

Defensive programming

The philosophy of defensive programming can be summed up as: Better to check too much, or check redundantly, than to check little. This is in contrast to DBC which advocates guaranteeing more by checking less. It is conceivable that defensive programming is caused because the contract in DBC is not established at all. Actually, defensive programming goes to another extreme. It assumes that the other party never burden its obligation, such as ensuring the precondition, so the module will itself burden others’ obligations, such as checking for the precondition. This is mainly responsible for complexity and obscureness of codes. For instances, we have a module:

int sqrt( int num )

{

if precondition is met then

solve the problem; return …

else return …

}

and we have a snippet of client codes to call that module:

if preondition for sqrt( .. ) is met then

call sqrt( .. );

Pseudocodes in bold are caused by defensive programming. This way of programming are extensively common.

Exception handling in Java

When an exception is thrown, the JVM will transfer the control from the point where the exception occur to the point that can be specified by the programmer. During the process, the JVM abruptly completes, one by one, any expressions, statements, method and constructor invocations, static initializers, and field initialization expressions that have begun but not yet completed the execution in the current thread. The process continues until a handler for the thrown exception is found. If no such handler is found, then the method uncaughtException is invoked for the ThreadGroup that is the parent of the current thread.

If a finally clause is executed because of abrupt completion of a try block and the finally clause itself completes abruptly, then the reason for the abrupt completion of the try block is discarded and the new reason for abrupt completion is propagated from there.

If a method throws an exception, it must assume that exception is “caught” and dealt with. One of the advantages of Java exception handling is that it allows you to concentrate on the problem you’re trying to solve in one place, and then deal with errors from that code in another place.

Goal of exception handling

Make your program more reliable, robust and error-tolerant. Usually, it provides measures for you to be notified of the exceptional condition and recover from that condition.

Best practices in Exception handling

Below are some best practices in exception handling citing from the book “Effective Java”.

-Use exceptions only for exceptional condition

Prevent from overusing exception.

-Use checked exceptions for recoverable conditions and runtime exceptons for programming errors

Three kinds of exceptions: checked exception, unchecked exception and errors. By convention, errors must be used only by JVM. Programming errors may be considered to fail to fullfill the contract and are generally unrecoverable.

-Avoid unnecessary use of checked exceptions

Two reasons: first, exceptions handling needs extra runtime overhead; second, checked exceptions are forced to be caught which would complexicate your client code. This to some degree conforms to DBC by advocating the client code calls state-testing methods which actually is to ensure the precondition.

-Prefer standard exceptions over user-defined exceptions

For learning curve about your codes, understanability and portability of your codes.

-Throw exceptions appropriate to the abstraction

Exception translation, Exception chain.

-Document all exceptions thrown by each method

Javadoc style, or declaration using the keyword throws which is also called the exception specification.

Exceptions as a part of the specification of a method.

-Include failure-capture information in detail message

Refers to the goal of exception handling

-Strive for failure atomicity

Refers to the goal of exception handling

-Don’t ignore exceptions

No empty catch block.

Other guidelines

-User visible error message should not be the same as the failure message wrapped in the exception object (needs further investigation). The latter are only for programmer to debug the program.

-Don’t assume the way which the client codes burden their obligation and/or the degree to which they burden their obligations. However, unfortunately, defensive programming is often needed, though you should try your best to avoid.

Resources

  1. Chapter 8 Exceptions, Effective Java.
  2. 2.16 Exceptions, Java Virtual Machine Spec.
  3. Chapter 10 Error Handling with Exceptions, Thinking in Java 2nd version.
  4. Building bug-free O-O software: An introduction to Design by Contract(TM)
  5. Design By Contract
  6. Design By Contract (DBC)

Monday, April 30, 2007

Java基础复习

Introduction

基本上是按照网上流传甚广的一套Java的面试题目来的,一个一个问题回答。

谈谈final、finally、finalize的区别

其实除了名字类似,是不沾边的三个东西。

final

Final is a keyword that can be used for classes, methods and data ( field / arguments ). It means what it modifies can’t be changed anymore. For final classes, they can’t be extended or derived; for final methods, the method’s behavior can’t be changed by overridden; for final data, they can only be initialized once and not be assigned values any more. But remember there’re two reasons for preventing change: design or efficiency.

> final methods

There’re two reasons why you make a method final: 1) quite small final method can be inlined when they’re called which is more efficiently; 2) you don’t want a method to be explicitly overridden.

Private methods are considered to be implicitly final, because in whatever cases, you can’t access or override a private method.

> final data

A misconception ( maybe it’s only mine : ) is that declaring data to be final doesn’t necessarily mean that its value is known at compile-time. The value can be run-time determinable. And data can also be declared to be final without any initialization value. In this case the final datum is called blank final field which has to be initialized in constructor or static initializer, or somewhere before use.

> final classes

Defining classes as final simply prevents inheritance — nothing more. Since a class declared to be final can’t be inherited, all its methods are implicitly final and the complier can opt to bring efficiency for you as with other explicitly final methods.

finally

Finally is to do with Exception handling which can introduce a piece of code that you want to execute whether or not an exception is thrown within a try blok or catched in a catch block.

finalize

Finalize which is the name of a method of Object is to do with garbage collection, that is to do with memory release. Garbage collection in java is a two-pass process. In the first pass in which case the object is eligible for garbage-collected, garbage collector will call finalize(), and in the second pass in which case the running programm may reach the point of runing out memory, garbage collector may physically release memeory of eligible objects. So the storage of a finalized object isn’t necessarily get released.

Anonymous Inner Class (匿名内部类) 是否可以extends(继承)其它类,是否可以implements(实现)interface(接口)

The answer is yes for both cases.

Inner class constructors get passed a hidden parameter, a reference to the outer class object that created them. static nested classes don’t have this hidden parameter. This is analogous to the way instance methods have hidden this parameter, where static methods do not.

Inner classes are not permitted to have static methods or fields. That is not quite true. They are allowed static final compile time constants, which are treated as if there were literals. If inner classes need statics, they have to get the outer class to hold them, or you have to use static nested classes or you have to inherit the static fields. Oddly, inner classes are permitted to extend classes that do have static methods and fields.

Anonymous inner class can’t define constructors. An anonymous inner class implements an interface, say, ITest, by:

new ITest() { .. }

and extends a class, say, Test, by:

new Test( name) { .. }

where Test( String name ) is an non-default constructor of Test, and default constructor can’t be used here!

For which kind of classes an anonymous class can extend / implement, refer to nested classes : Java Glossary.

Static Nested Class 和 Inner Class的不同

Differs in creating instance of them, and linking with the outter class /instance.

&和&&的区别

& is bitwise AND ( 位与) operator, while && is logical AND (逻辑与) operator.

Shift operators

The left-shift operator( << ) produces the operand to the left of the operator shifted to the left by the number of bits specified after the operator( inserting zeroes at the lower-order bits ). The signed right-shift operator( >> ) produces the operand to the left of the operator shifted to the right by the number of bits specified after the operator( inserting zeroes / ones at the higher-order bits ). There’s an unsigned right-shift operator( >>> ) will produces results inserting zeroes at the higher-order bits regardless of the sign.

Shift operators can be combined with equl sign, such as, <<=, >>=, and >>>=.

Talk about collection framwork in Java 2

Main interfaces: Collection, List, Set, Map. There’re actually only three collections List, Set and Map, and only two or three implementations of each one. And Map is not derived from Collection. The reason putting it the collection framwork is because a Map can produce collections from its key set and value list. Refer to chaper 9 of Thinking in Java 2nd version and Sun’s Java library for full details.

All collection implementation requires type checking ( especially with generic feature in Java 5 ) or bounds checking, or both.

Vector is synchronized, which means it’s thread-safe.

ArrayList is much like an array except it is variant-sized which brings extra run-time overhead.

The List interface provides four methods for positional (indexed) access to list elements. Note that these operations may execute in time proportional to the index value for some implementations (the LinkedList class, for example). Thus, iterating over the elements in a list is typically preferable to indexing through it if the caller does not know the implementation.

For the Set interface, a speicial case of prohibition is that it is not permissible for a set to contain itself as an element.

Diff between Collection and Collections

First Collections is the name of a conceptual framework coined by the designers of Java to represent a collection of interfaces and / or classes that enables an object holding a group of objects and variaous operations on it. It is generally called the collections framework ( or container classes before Java 2 ).

Collection as a type name is the name of an interface which is the root of the collecitons framework hierarchy and is located at package java.util. While it is the root of the collection hierarchy, there’re some collection classes that aren’t rooted from it, such as Map.

While Collections is a class also located in the package java.util which consists of a variety of static methods that operate on or return collections. This is common technique used to organize a bunch of related PO paradigm interfaces* ( may be not types, but methods ) into one module supported by OOP paradigm to improve the modularity and/or accessability of such interfaces*. In some cases, this is called the facade design pattern. Similar classes examplifying this techinque are Arrays, Math, etc.

Diff between HashMap and HashTable

String, StringBuffer, and StringBuilder

String class represents character strings. All string literals ( e.g., “Kenyth” ) in Java program are implemented as instances of String class. Strings are constant, namely immutable, as opposed to mutable StringBuffers. Their values can’t be changed after they’re created, which makes they can be shared ( refer to a compiler theory book about handling of constants ). And any modification to a String will produce a new instance of String, explicitly or implicitly. Concatenation of String is implemented as operations on StringBuffer( see the class file bytecode ), and conversions from an object to String is facilitated by the toString() method defined in Object class.

StringBuffer class represents a sequence of characters. It is mutable. It allows for data being appended to and inserted into it. It is thread-safe.

StringBuilder is like StringBuffer, but is not intended to be used by multi threads, that is not synchronized, or not thread-safe. It is introduced as of Java 5.

When to use assert

( Actually I’ve never used this keyword in my programming ) For the full details refer to Sun’s official document Programming With Assertions.

Simply speaking, assert in Java provides you a debugging facility similar to macros in C/C++. You can enable/disable your assertions when starting your program by passing in JVM command-line arguments ea/da. However, by default assertions are disabled at run-time.

There’s one guideline for deciding where/when to use assert that you should never use it for what your programming code do, such as method contract enforcement. Because since it is just a helper tool for debugging / observing your program and can be disabled, you must not depend the functionalities of your program on it.

more are coming soon…

Resources

  1. Thinking in java version 2.
  2. JAVA面试题目(去了两家公司,都是这样的题目) :一个很好的问题导向的复习提纲。
  3. 初识Java内部类:关于内部类的好处,静态内部类以及非静态内部类。
  4. `final’ variables and inner classes: explains why access from anonymous inner class to non-final outter variables is not allowed.
  5. nested classes : Java Glossary: contains very detailed explanation of the terms nested / inner class and their usages.
  6. Programming With Assertions

Technorati : , ,
Del.icio.us : , ,

Friday, April 20, 2007

The Architecture of Eclipse

Introduction

If explaining every bit in detail, you must be missed in the details and can’t see the architecture from a global perspective, nor will you be benifited in your practise. So I’m trying to explain the architecture based on senarios such as what will happen when you startup elipse, what will happen when an action that you contribute is fired, etc. I hope in such a way it will do help in your practice with Eclipse.

And, it is worthy to point out this is not an overview on the architecture of Eclipse for which there are tons of articles written about.

Startup of Eclipse

What will happen when the file eclipse.exe is executed.

Startup of Eclilpse begins by running a system specific executable binary file called eclilpse.exe which is located under the root directory of the eclipse installation. This executable will then lauches the org.eclipse.core.launcher.Main, located in startup.jar. After that the entry point of Main, that is static main method of Main is invoked. Below we will illustrate the calling path of important methods to demonstrate the post startup process of Eclipse.

Main.run( args )

Main.basicRun( args )

Main.getBootPath( .. ) : locate boot plugin ( in “plugin” directory of your eclispe installation ), within which Main.getDevPath( .. ) is called, within which Main.addBaseJars( .. ) is called, within which Main.readFrameworkExtensions( .. ) is called; invokeFramework( .. ): invoke EclipseStarter

the class EclipseStarter ( indicated by STARTER field ) is loaded by a URLClassLoader defined as an inner class with Main; EclipseStarter.run( .. ) is invoked in a reflective way

EclipseStarter.startup( .. ) : starts the platform and sets it up to run a single application

OSGi.new( .. ) : an instance of OSGi service platform is created

OSGi.launch() : start the OSGi framework

Framework.launch()

SystemBundle.resume() : SystemBundle subclasses Bundle to provide a system Bundle so that the framework can be represented as bundle

StartLevelManager.launch( .. ) : StartLevelManager is the startLevel service implementation for the OSGi spec

StartLevelManager.doSetStartLevel( .. )

StartLevelManager.incFWSL( .. )

StartLevelManager.getInstalledBundles( .. ) : Build an array of all installed bundles to be launch; StartLevelManager.loadInstalledBundles( .. ) : Load all bundles; StartLevelManager.resumeBundles( .. )

Framework.systemBundle.context.start() : Framework. :SystemBundle. :BundleContextImpl.start(), start the system bundle, BundleContextImpl.start() calls bundle’s BundleActivator.start()

BundleHost.loadBundleActivator() : Load and instantiate bundle’s BundleActivator class

BundleContextImpl.startActivator( .. ) : calls the start method of a BundleActivator which you have to extend when you create a plug-in.

Eclispe can also be started from with a client ( which is not part of the current Eclipse platform ), say, written in java, by using the EclispeStarter class located in org.eclipse.core.runtime.adaptor.

Action delegate and proxy

What will happen when your contributed action is fired.

Adding an action in a programatic way is different from adding it via contribution to an action extension point. For the former case, you have to implement some special API to create an action directly, while for the latter case you will have to only implement IActionDelegate+ which enables the lazy loading of the action.

At startup the registry is read and a PluginAction( extends Action, implements *Selection*Listener, IPluginContribution ) is created for each action extension point. The instance of PluginAction is an action proxy which directly represent an action in run time but doesn’t do the job a real action does. When the action that the action proxy represents is fired, the real action( the action delegate ) is created by the action proxy. After that point the action proxy delegate everything that is requested to the real action, the action delegate. This mechanism makes it possible to load the action extension lazily which is called lazy loading.

Following depicts the flow of action proxy and delegate:

read from registry ( IExtensionRegistry ) -> a PluginAction created for each action extension point ( while the action is fired -> an action delegate created -> action is delegated )

Contribute an Extension

to be continued…

Extension Pattern

Adapter pattern is extensively used in Eclipse to contribute extensions ( different from extensions to extension point ) to type or instance. This mechanism is enabled mainly by implementing IAdaptable and IAdapterFactory. For the detailed explanation with examples, please refer to Chapter 31 of the book Contributing to Eclipse: Principles, Patterns, and Plugins (Paperback).

Resources

  1. The Architecture of Eclipse. This article refers to and linked to a lot of valuable resources.
  2. A First Look at Eclipse Plug-In Programming. Contains a very detailed comparsion between Sun’s awt and swing and Eclipse’s SWT and JFace and anatomy of the process of Eclispe startup.
  3. About the OSGi Service Platform - Technical Whitepaper Revision 4.0
  4. org.eclipse.osgi_3.2.2.R32X_v20070118.jar : org.eclipse.core.runtime.adaptor.EclipseStarter.class source code, org.eclipse.osgi.framework.internal.core.AbstractBundle.class source code, org.eclipse.osgi.framework.internal.core.BundleContextImpl.class source code, org.eclipse.osgi.framework.internal.core.BundleHost.class source code, org.eclipse.osgi.framework.internal.core.Framework.class source code, org.eclipse.osgi.framework.internal.core.OSGi.class source code, org.eclipse.osgi.framework.internal.core.StartLevelManager.class source code, org.eclipse.osgi.framework.internal.core.SystemBundle.class source code, org.osgi.framework.BundleActivator.class source code.
  5. org.eclipse.ui.workbench_3.2.2.M20070119-0800.jar source code.
  6. eclipse 3.2.2 startup.jar : org.eclilpse.core.launcher.Main.class source code.
  7. Contributing to Eclipse: Principles, Patterns, and Plugins (Paperback)
  8. Eclipse Help

to be continued…

Technorati : , , , , , ,
Del.icio.us : , , , , , ,

Thursday, April 19, 2007

Knowledge on font size

声明:全部摘抄自网络资源,准确性和完整性不能保证,请读者自己辨别。

Introduction

一种字体(font)是一组字形(glyph)的集合,每一个字形代表了特定字样(typeface)的字符集(character set)里面的一个字符。

A font is a set of glyphs (images) representing the characters from a particular character set in a particular typeface. In professional typography the term typeface is not interchangeable with the word font, which is defined as a given alphabet and its associated characters in a single size. For example, 8-point Caslon is one font, and 10-point Caslon is another. Historically, fonts came in specific sizes determining the size of characters, and in quantities of sorts or number of each letter provided. The design of characters in a font took into account all these factors.

Measurement of font size

Point (pt, 磅)

在排版印刷中1pt是最小的测量单位, 12pt是1pica,具体是多长视情况而定。传统的排版印刷中1pt可能在0.18到0.4mm之间,这依赖于对foot的定义,现代的桌面出版中 (Desktop Publishing Point)1pt是1/72inch,也就是约0.3527mm,所以6pica是1inch。

Pixel(像素)

Inch(英寸)

millimeter(毫米)

Commonly used font size

9pt = 12px = 小五号

1pt = 4/3px

MS WORD中最大能定义1638pt大小的字体!

下表是字号与磅以及毫米之间的对应关系,并附以字样,以供大家在排版或调整布局时使用。

HTML和CSS中用的font size属性

Syntax: font-size: | | |
Possible Values:

*
o xx-small | x-small | small | medium | large | x-large | xx-large
*
o larger | smaller
*
* (in relation to parent element)

Both relative and absolute length units are supported in CSS1. Relative units give a length relative to another length property, and are preferred since they will better adjust to different media. The following relative units are available:

  • em (ems, the height of the element’s font)
  • ex (x-height, the height of the letter “x”)
  • px (pixels, relative to the canvas resolution)

Absolute length units are highly dependent on the output medium, and so are less useful than relative units. The following absolute units are available:

  • in (inches; 1in=2.54cm)
  • cm (centimeters; 1cm=10mm)
  • mm (millimeters)
  • pt (points; 1pt=1/72in)
  • pc (picas; 1pc=12pt)

要注意的是,相同大小的字体在不同的具体环境下显示出来的字体的真实大小可能不一样,差别比较小的可能是用px度量的大小。

关于x-height的定义可以看Typeface中的解释,简要的说是,对每一个字体都有一个假想的水平线叫baseline(想想小时候练习写英文字母的时候每一行都有三条或者四条横线那种作业本),x-height就是从baseline到字体最高处的高度。

Resources

  1. Font Size
  2. Point (typography)
  3. Typeface
  4. CSS改变字体大小而不影响网页
  5. 【知识】字体中“号”“磅”及“毫米”的关系
  6. Length Units

Technorati : , ,
Del.icio.us : , ,
Ice Rocket : , ,
Flickr : , ,
Zooomr : , ,
Buzznet : , ,

Wednesday, March 21, 2007

newClasspathContainerEntry

Introduction

Setting Java project build path involves setting classpaths of the project which are different from the Java runtime classpath. In JDT classpaths are represented with classpath entries which roughly fall into five kinds: source folder entries, binary library entries, prerequisite project entries, classpath variables, and classpath containers.

Start you eclipse JDT, open a Java project and launch the build path configuration window, and you’ll find all the options enabling you to add/remove all kinds of classpath entries. The frequently used JAVA_HOME system variable (under Windows) can be considered as a classpath variable here. And for a classpath container, hereafter comes more.

Classpath Container

Conceptually it is a data structure which represents a set of tupes with each in the form of . An instance of this data structure can be referenced as an instance of IClasspathEntry which wrapped a unique path of type IPath called a container path. It is noteworthy that all kinds of classpath entries mentioned above are represented by instances of IClasspathEntry within which there is a field called kind identifying the kind of entries. And also, it is noteworthy that an instance of ClasspathContainer is not an instance of IClasspathEntry of kind container. Simply speaking, each instance of IClasspathEntry of kind container references as its member field a container path which uniquely identifies an instance of the data structure mentioned above which contains (or references) a set of instances of ClasspathContainer. Actually, it’s still a little complicated. But that’s it. Below is sketched the relationship.

IClasspathEntry(kind: container)-aContainerPath –> , …}>.

Ways of Creating Classpath Container Entries

The implementation details are more complicated. Class or interfaces involved in include JavaModelManager, JavaCore, IClasspathEntry, ClassContainer, IClassContainerInitializer, and other Java Model classes. The set of tupes of the form of are maintained in JavaModelManager.

Generally, there’re two ways of creating a classpath container entry. The 1st way is to hard code creating instances of ClasspathContainer, and the 2nd way is to create instances of ClasspathContainer via the lazily invoked classpath container initializer which you may define onto the extension point org.eclipse.jdt.core.classpathContainerInitializer.

The hard code way:

// create an instance of IClasspathEntry of kind CPE_CONTAINER
// but ClasspathContainer associated to this entry are not yet defined.
JavaCore.newContainerEntry(..);

// Create and set the classpath container
JavaCore.setClasspathContainer(..);

// Put container path, containers and projects into hashmaps.
// Invoked in JavaCore.setClasspathContainer(..).
JavaModelManager.containerPut(..)

The initializer way:

// Contribute an extension to the initializer extension point.

When classpath entries contained in containers get resolved, the execution process is:

// Methods resolving classpath entries will get method getClasspathContainer(..) invoked.
JavaCore.getClasspathContainer(..);

JavaModelManager.getClasspathContainer(..);

// Both ways would get this method invoked.
JavaModelManager.containerGet(..);

// The initializer way would get this method invoked,
// within which initializer extension(s) will be lazily invoked.
JavaModelManager.initializeAllContainers(..);
or JavaModelManager.initializeContainer(..);

Resources

  1. Setting the Java build path
  2. JDT 3.2 Source Codes.

Technorati : , , , ,

Eclipse CDT CPU Usage 100% Solution

Solution

总的来说是把你的Eclipse使用的JRE换成6.0(早就download在机器上居然没有发现,2006.12.12就final release了,改成open source之后发布的速度快多了,现在都build100+了)的或者IBM的5.0实现,看别人的blog说是Sun的实现6.0以下有bug和 CDT不兼容,我试了BEA的Jrockit5,也是有问题。

换成6.0后,Indexer和Content Assist都没有问题了,不会CPU100%了。

另外,不像[1]里面说的CDT3.0才有问题,最新的CDT3.1.2也还是有这个问题。

Bonus Knowledge

Use something like “-vmargs -Xmx256M” when launching eclipse to use more memory.

Resources

  1. Bugzilla Bug 108242 Full Indexer in CDT3.0 extremely slow or does not work
  2. Eclipse3.2.1中使用CDT经常CPU100%问题的解决方法
  3. Eclipse CDT开发C++速度慢的解决方法
  4. CDT Indexer导致CPU 100%的解决办法
  5. Eclipse+cdt+MinGW 建立C++工程問題


Technorati : , ,
Del.icio.us : , ,
Ice Rocket : , ,
Flickr : , ,
Zooomr : , ,
Buzznet : , ,

Friday, March 16, 2007

Workshops of AOSD'07

Refer to here for all the workshops held at AOSD'07.

Below are the ones that I'm sepecially interested in:

The workshop I'm intersted the most, but not appearing at AOSD'07 is Modeling and Analysis of Concerns in Software .

Thursday, March 15, 2007

AOSD'07 "Report" - By others

Blog Posts About AOSD'07:

  • AOSD Demo a success:Can't figure out what exactly the demo is from this post. I guess it is a eclipse plug-in facilitating jps indicating.
  • AOSD Conference Day 1:About Glassbox, overhead of load-time weaving, possible usage of AOP for run-time verification/debugging, comment on the keynote "Building Robust System", etc.
update (22/03/2007):

No more...

It seems the academic people are too busy to blog. There are few posts about the conference.

Blog APIs

Resources:

  1. Getting Started with the MetaWeblog API for Windows Live Spaces
  2. Blogger Data API Developer’s Guide
  3. More…


Technorati : , ,
Del.icio.us : , ,
Ice Rocket : , ,
Flickr : , ,
Zooomr : , ,
Buzznet : , ,

Wednesday, March 14, 2007

URI, URL and Java

This post basically is a collection of resources.

1. What're URI, URN and URL?

A URI is a uniform resources identifier reference. A URL is a uniform resource locator. URNs name resources but do not specify how to locate them. The mailto, news, and isbn URIs shown above are examples of URNs. URLs and URNs both fall into URIs. But normally URNs and URLs doesn't interset. Refer to RFC 2396: Uniform Resource Identifiers (URI): Generic Syntax for the syntax of a URI instance. And the java class description of URI gives a very good summary of URI, besides providing some useful resources.

2. Syntax

Below is a little breakdown on the syntax of URI, which is directly taken from the priviously mentioned JAVA API spec.

At the highest level a URI reference (hereinafter simply "URI") in string form has the syntax:

[scheme:] scheme-specific-part [#fragment]

where square brackets [...] delineate optional components and the characters : and # stand for themselves. With a further breakdown on scheme-specific-part we can get a URI in the string form:

[scheme:] [//authority][path][?query] [#fragment]

where the characters :, /, ?, and # stand for themselves. With a further breakdown on authority we can get a more general form:

[scheme:] [// [user-info@]host[:port] ] [path] [?query] [#fragment]

where the characters @ and : stand for themselves.

Note: a scheme of a URL is called a protocol, such as "http" and "ftp".

3. Examples

An opaque URI is an absolute URI whose scheme-specific part does not begin with a slash character ('/'). Opaque URIs are not subject to further parsing. Some examples of opaque URIs are:

mailto:java-net@java.sun.com /*URN*/
news:comp.lang.java /*URN*/
urn:isbn:096139210x /*URN*/

A hierarchical URI is either an absolute URI whose scheme-specific part begins with a slash character, or a relative URI, that is, a URI that does not specify a scheme. Some examples of hierarchical URIs are:

http://java.sun.com/j2se/1.3/ /*URL*/
docs/guide/collections/designfaq.html#28
../../../demo/jfc/SwingSet2/src/SwingSet2.java
file:///~/calendar

Also URIs are categorized as absolute URIs and relative URIs. An absolute URI specifies a scheme, and a URI that is not absolute is called a relative URI.

Among above examples comments in the form of "/*...*/" tell which are URLs and which are URNs.

4. Character categories

As specified in resources accessible, we quote some that matters:

RFC 2396 specifies precisely which characters are permitted in the various components of a URI reference. The following categories, most of which are taken from that specification, are used below to describe these constraints:
alphaThe US-ASCII alphabetic characters, 'A' through 'Z' and 'a' through 'z'
digitThe US-ASCII decimal digit characters, '0' through '9'
alphanumAll alpha and digit characters
unreservedAll alphanum characters together with those in the string "_-!.~'()*"
punctThe characters in the string ",;:$&+="
reservedAll punct characters together with those in the string "?/[]@"
escapedEscaped octets, that is, triplets consisting of the percent character ('%') followed by two hexadecimal digits ('0'-'9', 'A'-'F', and 'a'-'f')
otherThe Unicode characters that are not in the US-ASCII character set, are not control characters (according to the Character.isISOControl method), and are not space characters (according to the Character.isSpaceChar method) (Deviation from RFC 2396, which is limited to US-ASCII)

The set of all legal URI characters consists of the unreserved, reserved, escaped, and other characters.

Escaped octets, quotation, encoding, and decoding


RFC 2396 allows escaped octets to appear in the user-info, path, query, and fragment components. Escaping serves two purposes in URIs:
  • To encode non-US-ASCII characters when a URI is required to conform strictly to RFC 2396 by not containing any other characters.

  • To quote characters that are otherwise illegal in a component. The user-info, path, query, and fragment components differ slightly in terms of which characters are considered legal and illegal.
These purposes are served in this class by three related operations:
  • A character is encoded by replacing it with the sequence of escaped octets that represent that character in the UTF-8 character set. The Euro currency symbol ('\u20AC'), for example, is encoded as "%E2%82%AC". (Deviation from RFC 2396, which does not specify any particular character set.)

  • An illegal character is quoted simply by encoding it. The space character, for example, is quoted by replacing it with "%20". UTF-8 contains US-ASCII, hence for US-ASCII characters this transformation has exactly the effect required by RFC 2396.

  • A sequence of escaped octets is decoded by replacing it with the sequence of characters that it represents in the UTF-8 character set. UTF-8 contains US-ASCII, hence decoding has the effect of de-quoting any quoted US-ASCII characters as well as that of decoding any encoded non-US-ASCII characters. If a decoding error occurs when decoding the escaped octets then the erroneous octets are replaced by '\uFFFD', the Unicode replacement character.
5. Java Impl.

URI, URL, URLClassLoader, URLConnection, URLDecoder, URLEncoder and URLStreamHandler, which are all located in package java.net.

Resources:
  1. Uniform Resource Identifiers (URI): Generic Syntax

  2. Format for Literal IPv6 Addresses in URL's

  3. JavaTM 2 Platform Standard Edition 5.0 API Specification
Technorati : , , ,
Del.icio.us : , , ,

Sunday, March 04, 2007

服务器租借与托管资料收集

(本文仅仅为资料收集,不存在原创内容)

1. 名词解释

1U-4U:

U(英文中的Unit?不知道)代表架式服务器的高度,1U=1.75英寸=4.45厘米。同样的2U=4*1.75英寸=4*4.45厘米,以此类推。

机柜:

一般多个机架服务器安装在一个机柜内,一个普通机柜的高度是42U。

ICP:

ICP(Internet Content Provider)证的全称:《中华人民共和国电信与信息服务业务经营许可证》即ICP证,通过互联网向上网用户提供有偿信息、网上广告、代制作网页、电 子商务及其它网上应用服务的公司必须办理的网络经营许可证。国家对经营性网站实行ICP证制度,注册资金应在100万或者100万以上的公司才能办理 ICP证,一经办理一般能在该省的通信管理局的网站查询到。同时对从事非经营性活动的网站要进行ICP备案,简称为ICP备。

2. 服务器的种类

首先,我们必需了解何谓PC服务器?所谓PC服务器(下文讨论的多为PC服务器),即是Intel架构服务器,与一些大型服务器如 Mainframe, Unix架构服务器等不同,前者大多运行Windows或Linux等操作系统,使用较为普遍,后者多为专业用途,如银行,大型制造业,物流业,证券…等 行业使用,一般人较少有机会接触到.

可以按照各种标准进行分类,按应用层次分为:入门级服务器、工作组级服务器、部门级服务器和企业级服务器;按处理器架构分为:CISC (Complex Instruction Set Computer)架构服务器、RISC(Reduced Instruction Set Computing)架构服务器和VLIW(Very Long Instruction Word超长指令集架构)架构服务器;按用途分为:通用型服务器和专用型服务器,或者WEB服务器、E-mail服务器、数据服务器、DNS服务器等等; 按机箱结构分为:台式(塔式)服务器、机架服务器、机柜服务器和刀片式(bladed)服务器。

2.1 塔式服务器

优点:服务器的主板扩展性较强、插槽也多,可以进行硬盘和电源的冗余扩展,对环境要求较低,原则上不用和机柜搭配使用,价格也相对较低,集多种常见的服务和应用于一身。

缺点:塔式服务器长得跟我们平时用的台式机一样,占用空间比较大,适合小型企业自己维护,不适合放在服务器托管商那里托管,独立性太强,协同工作在空间占用和系统管理上都不方便,在一些应用要求较高的企业中,这种单机服务器无法满足要求。

2.2 机架服务器

机架式(RACK)服务器长得像卧着的台式机,可以一台一台地放到固定机架上,因此而得名。机架服务器一般采用标准19英寸的宽度设计,其高度按照一定的单位高度的设计,其单位为U,约为4.54cm。

优点:机架是服务器的机箱宽度都是相同的,可以在标准的机柜中存放服务器,减少服务器产品对空间的要求,易于服务器的集中管理。所以机架服务器便于放在服务器托管商那里托管。

缺点: 购买价格相对较高,比同等配置的塔式服务器价格要高20%-30%,1U以上服务器服务器托管费用较高。由于在空间上非常紧凑,所以在扩展性和散热方面上具有一定限制,一般无法实现太完整的设备扩展,所以单机性能相对比较有限。

2.3 刀片式服务器

3. 服务器的购买和租借

一般服务器或者自行购买然后放到IDC(Internet Data Center)服务提供商的机房托管,或者租借IDC服务商的。租借的服务器一般IDC服务提供商都会负责托管,租借又分为送产权和不送产权两种,送产权 的即租用一定时间(如1年或者2年)后服务器的产权归用户。需要指出的是租用的服务器大多数不是新的服务器,而是旧的组装服务器,当然也有宣称租用品牌服 务器的IDC服务商。

下面主要说说PC服务器的基本硬件配置常识。主要的服务器国际生产商有:IBM,HP,Dell,Sun(最近也推出X86服务器产品),超微等; 国内生产商主要有:曙光、联想、浪潮、方正、清华同方、华硕等;服务器芯片生产商主要是:Intel和AMD;服务器芯片主要有:Pentium 4(单路)、Itanium(安腾,64位,Dual-Core)Xeon(至强,双路)、XeonMP(Multi Processing Platform,四路)、AthlonMP(速龙MP)、Opteron(皓龙,64位,100系列是单路,200系列是双路,800系列是四路和八 路)。

4. 托管服务器的流程

4.1 选择托管服务器的类型

购买全新服务器,或向服务器托管商租借。

4.2 选择服务器托管商

考察服务商、机房,最好能去现场考察,以检查其设施是否齐全。

4.3 签订托管合同

如果是自己购买的服务器,则需要运送服务器到托管商指定的机房,最后签订详细的托管合同。

5. 经验

5.1 最好不要异地托管

如果是自己购买的服务器最好不要找异地托管,因为时候要对服务器进行本地维护。

5.2 带宽保证

不管是独享带宽还是共享带宽,实际使用的带宽一般不会超过10M,甚至5M甚至更低,各地的IDC都会有限制。

5.3 ICP证

一定要检查托管商是否有ICP证。

6. 业界案例

豆瓣网,土豆网,劲舞团等等。

7. 上海的服务商简介

中国E动网www.edong.com

8. 其他

www.linkwan.com/vr ,用来测试机房速度和当前连接的路由节点。

参考资料:

  1. 首次托管服务器经验
  2. 服务器结构中的1U 2U 3U是什么意思?
  3. 机架式服务器和塔式服务器的区别
  4. 服务器有哪些种类?
  5. 典型用户案例
  6. 什么是机架式服务器?
  7. BananaSkin(持续关注IDC方面的博客)
  8. 服务器有关的Post(123)(豆瓣blog
  9. 如何挑选服务器?哪个牌子的最好?(1万元以下的)
  10. 关于”个人网站申请备案”经验
  11. 业内人士教您如何选择IDC
  12. 服务器托管—你会选1U还是2U服务器?
  13. ICP专栏:介绍ICP相关知识,ICP申请、ICP备案流程及所须资料等
  14. 【转载】教你如何租服务器和选择机房
  15. 差价缩小:现在你考虑1U还是2U?
  16. 中国IDC产业发展调查暨年度大典官方网站
  17. 找小说网正式拥有属于自己的服务器

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.