Create Block Programmatically
The 'id' property in the annotation defines the unique, machine
   readable ID of your block.

The 'admin_label' annotation defines the human readable name of the
   block that will be used when displaying your block in the admin
   interface.

The 'Category' defines which section belongs to under block listing page.

The Drupal block manager scans your module's classes for a class that contains the @Block Annotation (a special comment right above your class declaration)

&lt;?php
/**
 * @file
 * Contains \Drupal\article\Plugin\Block\XaiBlock.
 */
namespace Drupal\article\Plugin\Block;
use Drupal\Core\Block\BlockBase;
/**
 * Provides a 'Article' Block
 * @Block(
 *   id = "article_block",
 *   admin_label = @Translation("Article block"),
 * )
 */
class ArticleBlock extends BlockBase {
  /**
   * {@inheritdoc}
   */
  public function build() {
    return array(
      '#type' =&gt; 'markup',
      '#markup' =&gt; 'This block list the article.',
    );
  }


custom block programatically