Tag Archives: Java

Spring Cloud: Creating first client application With eureka client (Part 2)

This is a quick tutorial for creating a eureka client application. This tutorial has the prerequisite of a running eureka server. In case if you do not have running eureka server or a newbie, check out my previous post in this series which explains how to setup eureka server yourself. The eureka client which we will be developing in this tutorial will be registered in the eureka server.

TL;DR You can download whole project by clicking following link.

We will be creating a Eureka client in this tutorial. The client will be a spring boot application and will expose one rest endpoint. That endpoint will accept one value (or String, as said in Java world) as path parameter and will prefix it with ‘Hello’. The endpoint will return its result as String again.

Continue reading Spring Cloud: Creating first client application With eureka client (Part 2)

Setting Up Eureka Server Using Spring Cloud (Part 1)

This is a quick example for setting up Eureka server using Spring Cloud.

You can download the whole project by using following link.

For this tutorial, we will be creating a New Maven Project. To keep thing more simple we will be creating a simple maven project i.e. we will be skipping archetype selection.

New Maven Project Wizard – Creating a simple project
Continue reading Setting Up Eureka Server Using Spring Cloud (Part 1)

Implementing JPEG Algorithm in Java

The JPEG (Joint Photographic Experts Group) compression standard is the most widely used format for digital photographs on the web. Unlike lossless codecs, JPEG achieves very high compression ratios by discarding perceptually insignificant information from the image. At its core, the algorithm transforms pixel data into the frequency domain, aggressively quantises the high-frequency components (which the human eye is less sensitive to), and then encodes the result efficiently.

This Java program demonstrates the key computational stages of JPEG compression applied to a single 8×8 pixel block: the Discrete Cosine Transform (DCT), quantisation, zigzag scan, and a simplified entropy encoding step.

This example provides an educational look at the key stages of JPEG compression.

JPEG Compression Pipeline

A real JPEG encoder processes an image in the following sequence. This program implements all four stages for one 8×8 luminance block:

  1. Input block — An 8×8 grid of pixel intensity values.
  2. DCT — Converts spatial pixel data into frequency-domain coefficients.
  3. Quantisation — Divides each DCT coefficient by a value from the standard luminance quantisation table and rounds to the nearest integer, discarding fine detail.
  4. Zigzag scan — Reorders the 8×8 quantised coefficients into a 1D array, placing the most significant low-frequency coefficients first.
  5. Entropy encoding — Encodes the 1D array using a simplified run-length + binary scheme similar to the actual JPEG Huffman coding step.
Continue reading Implementing JPEG Algorithm in Java

Implementing Run Length Encoding in Java

Run-Length Encoding (RLE) is one of the simplest lossless data compression techniques. Instead of storing every character individually, it replaces consecutive runs of the same character with a single instance of that character preceded by a count. For example, the string AAABBC becomes 3A2B1C. RLE works best on data with long repeated runs, such as bitmap images or binary sequences, and is often used as a preprocessing step in more sophisticated codecs like JPEG and fax compression standards.

This Java program reads a string from the user, applies RLE compression using hexadecimal run-length counts, and reports the encoded output along with the original length, encoded length, and the resulting compression ratio.

Continue reading Implementing Run Length Encoding in Java

Demonstrating Bully Algorithm in Java

The Bully Algorithm is a classic election algorithm used in distributed systems to elect a coordinator (leader) among a group of processes. When a process notices that the current coordinator is no longer responding, it initiates an election. The process with the highest priority among all active (running) processes wins the election and becomes the new coordinator.

This Java program simulates the Bully Algorithm with user-defined processes, each having a status (active or inactive) and a priority value.

Continue reading Demonstrating Bully Algorithm in Java