How can I create wordpress widget

WordPress widget create is very simple and easy. Just copy the following code and create a file. Then upload the file into plugin directory and active the plugin and get results.

<?php
/*
Plugin Name: Widget sample from rmweblab
Plugin URI: http://www.rmweblab.com
Description: widget sample for new user
Version: 1.0
Author: RM Web Lab
Author URI: http://www.rmweblab.com
*/

class RMWidget extends WP_Widget {
/** constructor */
function RMWidget() {
parent::WP_Widget(false, $name = 'RMWidget');
}

/** @see WP_Widget::widget */
function widget($args, $instance) {
extract( $args );
$title = apply_filters('widget_title', $instance['title']);
?>
<?php echo $before_widget; ?>
<?php if ( $title )
echo $before_title . $title . $after_title; ?>

<?php echo "RM Web Lab"; ?>

<?php echo $after_widget; ?>
<?php
}

/** @see WP_Widget::update */
function update($new_instance, $old_instance) {
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
return $instance;
}

/** @see WP_Widget::form */
function form($instance) {
$title = esc_attr($instance['title']);
?>
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /></label></p>
<?php
}

} // class FooWidget
// register FooWidget widget
add_action('widgets_init', create_function('', 'return register_widget("RMWidget");'));

?>