博文

Design Pattern - Singleton

The Singleton Design Pattern 1.1. Definition The singleton Pattern ensures a class has only one instance, and provides a global point of access to it. 1.2. Usage Singletons are useful to define classes which should only be available once, e.g. a model which is use in several view of an application, a logger or a device driver. An example is an application which reads the data from a file into another class A. This content should be available in the whole application. Therefore the class A is defined as a singleton. Another example would be the following View A and View B would like to display the same data of class with hold the data (model class). Using a singleton for the model class ensures that same data is used. 1.3. Code Example The possible implementation of Java depends on the version of Java you are using. As of Java 6 you can singletons with a single-element enum type. package mypackage...

JavaScript Object-Oriented Concept Essential Part2

1. Argument (kinda like polymophism in oop) Every function in Javascript has a private varibale called arugments , which can be used to access all the arguments passed to the function without specifying them as parameters when defiend the function. Ex. function testArg() { for(i =0; i } testArg("argmentnaisni1","ajgajdskgl2"); 2. Prototype 2.1 (kinda like static field of class) prototype is a field of all object, ex, you can use: function Square(){;} // Square.prototype.size = 5;// //then all Square object has a field of size which has value 5. // but one can override prototype filed value, ex function Square(){ this.size = 1; } Square.prototype.size = 5; //because prototytpe loads before the object constructor, so it's // //overrided to 1. 2.2 (use like Inheritance) because prototype is shared by all objects constructed by the function, it can achieve inheritance. Ex. function Car() { this. doors = 4; this. speed = 0; this. brake = function(){this.spe...

JavaScript Object-Oriented Concept Essential Part1

1. Everything excpet primitive types in JavaScript is object. 2. Primitive types include Undefined, Null, Boolean, Number and String. 3. JavaScript has three kinds of objects. 3.1 Build-in objects: Array, Image, Date... 3.2 Host objects: window, document, forms.. 3.3 User-defined. 4. Primitive types has associated object. Ex, var stringObj = new String("create String object"); 5. new is used to create objects. 6. this is used to refer the current object. 7. class in Javascript is defiend as function. class field and function is defined by this . Ex, function Cicle(radius){ this . radius = radius; // defined class field, assigned by parameter of constructor this . getArea = getArea; // defined class function, getArea is a function function getArea(){return this. radius;}// still use this to refer current object //the function getArea can also be defiend outside the class, with this. radius always //refer the object who use the funtio...

Introduction to REST

Building Web Services the REST Way Roger L. Costello I will first provide a brief introduction to REST and then describe how to build Web services in the REST style. What is REST? REST is a term coined by Roy Fielding in his Ph.D. dissertation [1] to describe an architecture style of networked systems. REST is an acronym standing for Representational State Transfer. Why is it called Representational State Transfer? The Web is comprised of resources. A resource is any item of interest. For example, the Boeing Aircraft Corp may define a 747 resource. Clients may access that resource with this URL: http://www.boeing.com/aircraft/747 A representation of the resource is returned (e.g., Boeing747.html). The representation places the client application in a state . The result of the client traversing a hyperlink in Boeing747.html is another resource is accessed....

Install tomcat in ubuntu

1) Find a correct tomcat package to install sudo apt-cache search tomcat 2) Install all Tomcat package with following command sudo apt-get install tomcat5.5-webapps sudo apt-get install tomcat5.5-admin sudo apt-get install tomcat5.5 3) Done apt-get help Ubuntu to configure almost everything and create a script put inside init .d folder for Tomcat auto startup script. we can start/stop/restart Tomcat with following command /etc/init.d/tomcat5.5 start /etc/init.d/tomcat5.5 stop /etc/init.d/tomcat5.5 restart apt-get help to create a share folder in /usr/share also, please access cd /usr/share/tomcat5.5 and issue a ls -lh in /usr/share/tomcat5.5 to find out the rest of the Tomcat location. drwxr-xr-x bin drwxr-xr-x common lrwxrwxrwx conf -> /etc/tomcat5.5 lrwxrwxrwx doc -> ../doc/tomcat5.5 lrwxrwxrwx logs -> /var/lib/tomcat5.5/logs drwxr-xr-x server lrwxrwxrwx shared -> /var/lib/tomcat5.5/shared lrwxrwxrwx temp -> /var/lib/tomcat5.5/temp lrwxrwxr...

Centralized Priority-Widget Engine linux

Keywords: widget Develop HTML widgets with Dojo: http://www.ibm.com/developerworks/edu/wa-dw-wa-dojowidgets.html http://dojocampus.org/explorer/#Dojo_Data Which engine is the best to develop a widget for? http://www.widgipedia.com/forum/read.php?16,276,342 Develop Widgets: http://blog.auinteractive.com/learn-to-develop-widgets Keywords: widget engine All in one: http://en.wikipedia.org/wiki/Widget_engine Keywords: widget engine linux http://linux4world.blogspot.com/2007/10/top-8-widget-engines-for-linux-platform.html http://alp.access-company.com/files/ACCESS_WP_Force_2009-02-11.pdf http://www.kryogenix.org/days/2006/01/22/jackfield-apples-dashboard-for-the-linux-gnome-desktop adobe AIR : http://www.adobe.com/products/air/ Keywords: multi-monitor http://en.wikipedia.org/wiki/Multi-monitor products and adaptor: http://www.multi-monitors.com/SUPER_PC_Multi_Monitor_Adapters_USB_VGA_Matrox_Head2Go_s/22.htm xWindow system: http://en...

Class.forName用途及与new辨析

Class.forName(xxx.xx.xx) 返回的是一个类 首先你要明白在java里面任何class都要装载在虚拟机上才能运行。这句话就是装载类用的(和new 不一样,要分清楚)。 至于什么时候用,你可以考虑一下这个问题,给你一个字符串变量,它代表一个类的包名和类名,你怎么实例化它?只有你提到的这个方法了,不过要再加一点。 A a = (A)Class.forName("pacage.A").newInstance(); 这和你 A a = new A(); 是一样的效果。 关于补充的问题 答案是肯定的,jvm会执行静态代码段,你要记住一个概念,静态代码是和class绑定的,class装载成功就表示执行了你的静态代码了。而且以后不会再走这段静态代码了。 Class.forName(xxx.xx.xx) 返回的是一个类 Class.forName(xxx.xx.xx);的作用是要求JVM查找并加载指定的类,也就是说JVM会执行该类的静态代码段 动态加载和创建Class 对象,比如想根据用户输入的字符串来创建对象 String str = 用户输入的字符串 Class t = Class.forName(str); t.newInstance(); 在初始化一个类,生成一个实例的时候,newInstance()方法和new关键字除了一个是方法,一个是关键字外,最主要有什么区别?它们的 区别在于创建对象的方式不一样,前者是使用类加载机制,后者是创建一个新类。那么为什么会有两种创建对象方式?这主要考虑到软件的可伸缩、可扩展和可重用 等软件设计思想。 Java中工厂模式经常使用newInstance()方法来创建对象,因此从为什么要使用工厂模式上可以找到具体答案。 例如: class c = Class.forName(“Example”); factory = (ExampleInterface)c.newInstance(); 其中ExampleInterface是Example的接口,可以写成如下形式: String className = "Example"; class c = Class.forName(className); factory = (ExampleInterface)c.newInstance(...