Before we discuss about Data Cube or how to implement it using Java let us examine few preliminaries. Remember Square and Cubes in geometry. Cube is actually a three-dimensional extension of a square. Much the same way we store data in a tabular format, which can be visualized as a square and can be implemented using 2D array. For example:

ID Science Computer Science Maths
1 90 99 98
2 57 77 43
3 89 86 80
4 56 67 59
5 90 92 93

Now this can be implemented in java using a 2D array:

int  student[][]=new int[5][4];

 

We can even initialize this array to populate the data above:

int student[][]={

{1,90,99,98},

{2,57,77,43},

{3,89,86,80},

{4,56,67,59},

{5,90,92,93}

};

Implementation of data cube is discussed in the later section of this article.

Data Cubes – Introduction

What if same data is to be stored for every month? We can still store it in tabular format but we can also store it Data Cubes.  Data Cubes can be implemented using more than 2 dimensions. In the above example if we are to implement same type of data for each month we can do so using Data Cube.

Data cubes can be visualized as multidimensional extensions of 2-D table (One created above). Moment you hear about cube it brings to your mind a 3-Dimensional object. This is because we know that cube is a 3-D object. Hence it seems Data Cube is nothing but a set of similarly structured 2-D tables stacked on top of one another. Though such a structure would also be a data cube, but data cubes are not just restricted to 3-Dimensions.

As per the concepts of OLAP or Online Analytical processing – a powerful technology behind applications involving Business Intelligence (BI), data cubes can take as many dimensions – 1D, 2D, 3D..ND. Microsoft SQL Server 2000 Analysis Services for example support up to 64 dimensions and that might just blow your mind visualizing that kind of data structure. OLAP is a powerful technology evolved and emerged to answer new challenges being imposed by ever growing data and changing needs around this massive data. OLAP can be utilized for:

  • Data discovery that also includes capabilities for viewing reports in so many different ways.
  • Complex analytical calculations and be performed so easily, and
  • Predictive “what if” scenario (budget, forecast) planning, etc

Up to 3-Dimensions you can visualize in geometric terms, beyond that might not be that easy. For example 4-Dimension data cubes can be visualized as series of 3-D data cubes.

Let’s not get into that many dimensions. That is not our objective today. Today we will try to implement Data Cube having 3 Dimensions using Java as a language. Data Cube implemented using 3D array in java, might look like:

static void ThreeD_Array()
{
     System.out.println("\nInside ThreeD_Array ...");
     int edukers[][][] = new int[][][]
     { 
         { // September
            {1,90,99,98}, 	//student 1
            {2,57,77,43},	//student 2
            {3,89,86,80},	//student 3
            {4,56,67,59},	//student 4
            {5,90,92,93}	//student 5
         },
         { // October
            {1,89,92,97}, 	//student 1
            {2,62,76,57},	//student 2
            {3,84,89,78},	//student 3
            {4,64,68,56},	//student 4
            {5,88,82,97}	//student 5
         },
         { // November
            {1,91,90,88}, 	//student 1
            {2,55,67,53},	//student 2
            {3,67,84,69},	//student 3
            {4,43,57,89},	//student 4
            {5,64,82,90}	//student 5
         },
         { // December
            {1,66,77,78}, 	//student 1
            {2,77,32,73},	//student 2
            {3,39,49,80},	//student 3
            {4,36,87,69},	//student 4
            {5,89,82,73}	//student 5
    }
};

This can be visualized as shown in the image at the top, in the form of multidimensional extension of 2D tabular data. It can also be visualized as a geometric view of a cube.

Data Cube Geometric view

 

The complete program is shown below:

class DataCube 
{
  static void threeD_Arrays() 
    	{
    System.out.println("\nInside threeD_Arrays ...");
    
    int edukers[][][] = new int[][][]
    { 
      { // September
        {1,90,99,98}, 	//student 1
        {2,57,77,43},	//student 2
        {3,89,86,80},	//student 3
        {4,56,67,59},	//student 4
        {5,90,92,93}	//student 5
      },
      { // October
        {1,89,92,97}, 	//student 1
        {2,62,76,57},	//student 2
        {3,84,89,78},	//student 3
        {4,64,68,56},	//student 4
        {5,88,82,97}	//student 5
      },
      { // November
        {1,91,90,88}, 	//student 1
        {2,55,67,53},	//student 2
        {3,67,84,69},	//student 3
        {4,43,57,89},	//student 4
        {5,64,82,90}	//student 5
      		},
        	{ // December
        {1,66,77,78}, 	//student 1
        {2,77,32,73},	//student 2
        {3,39,49,80},	//student 3
        {4,36,87,69},	//student 4
        {5,89,82,73}	//student 5
      }
    };		
    for(int i=0;i<4;i++)
    {
      System.out.println("");
      System.out.println("Month  "+ (i+9) + ":");
      System.out.println("____________________");
      System.out.println("");
      for(int j=0;j<5;j++)
      {
        System.out.print("Student ");
        for(int k=0;k<4;k++)
        {

          System.out.print(" " +edukers[i][j][k]);
        }
        System.out.println("");
      }
      
    }

  }	

Screenshots of the above program:

Data Cube Java Output

Data Cube Java Output

Implementation above is at very low level and for educational purpose. Implementation of real data cube will have more dimensions and can be viewed in so many different ways to make data analysis an easy task.

Data Cubes or OLAP cubes are one of the many ways of handling complex data in modern world. We all know Data is growing enormously and at a rapid rate which has spurred open so many new career paths and new technologies have emerged to handle data explosion.

Pawan Arora AdministratorKeymaster
Founder , Edukers
Teaching, Coding and Sharing is his passion. A true mentor and motivator. C/C++, Python, Java, Web Technologies (html5 / CSS/ Javascript/ JQuery,Bootstrap, nodeJS ,PHP etc.) and a WordPress enthusiast with more than two decades of experience.
follow me