Run-length encoding (RLE) technique simulation or implementation in java programming language with example

In this article I will explain the image compression technique which is Run-length encoding (RLE) technique. Run-length encoding (RLE) technique is used to compression of images with eliminating the frequency of color pixels in image. Run-length encoding (RLE) technique count the same color for nearby pixels. That is the same consecutive color code is can save with one color code in memory.
Run-length encoding (RLE) technique widely used in image and video compression techniques. This techniques reduces the size of the image or video by replacing the same nearby color pixels with one color pixels.In this article I will use the function  getRunLengthEncoding which takes the capital latter string of color pixels as a input and return the same consecutive color pixels numbers with color code. This output is functioning of Run-lenght encoding RLE technique.

The color pixel code is represented with first capital latter of color name.
Just like the if the color name is Green then color code in string is G.
and for Red code is R.

Example:
 Let’s assume the input string of color pixel code is “AAABBBBCCCCCEEEEEEEEOOOOOOWWWWWWW” 

then the Run Length encoding technique return the following output

“3A4B5C8E6O7W”
In this output number is denote the frequency of color code.

Coding:- 

/* www.computersciencearticle.in */
public class RunLengthEncodingTechnique{
public String getRunLengthEncoding(String runsRLE)
{ char[] arrayRLE = runsRLE.toCharArray();  
// crate character array of color pixels in string 
int lengthRLE = runsRLE.length();
// calculate total lenght of string (color pixels) 
char preCharRLE ='?'; String outputRLE =""; 
int countRLE = 0; 
if (lengthRLE > 1000 || lengthRLE < 1) 
 {   return "Invalid color pixel or not valid chacters "; 
 }
 for (int i = 0; i < lengthRLE; i++)
 if (runsRLE.charAt(i) < 'A' || runsRLE.charAt(i) > 'Z') 
return "Invalid color pixels not use capital latters ";

for (int i = 0; i < lengthRLE; i++)  
{    
if (i == 0)   
{    
 countRLE++;     
preCharRLE = arrayRLE[i];
 }   
else   
{    
if (arrayRLE[i] == preCharRLE)
 {     
 countRLE++;
 }    
else     
{      
outputRLE  = String.valueOf(countRLE)   
preCharRLE;      
preCharRLE = arrayRLE[i];
 countRLE =1;     
}   
}
}   
if (countRLE > 0)   
outputRLE  = String.valueOf(countRLE)
 preCharRLE;    
return outputRLE;
}

 public static void main(String[] args){
 String inputRLE ="AAABBBBCCCCCEEEEEEEEOOOOOOWWWWWWW"; 
//here the color coding in Capital latters 
RunLengthEncodingTechnique objectRLE = new 
RunLengthEncodingTechnique();
String outputRLE = objectRLE.getRunLengthEncoding(inputRLE); 
System.out.println(outputRLE); } }

Output:-
At first create the  RunLengthEncodingTechnique.java file of given code.
And then compile this code using javac command.
and run this program using java command.