Skip to main content

Java

Setting Up Eureka Server Using Spring Cloud (Version: 1.5.18.RELEASE/ Edgware.SR5)

⚠️ This post covers Spring Cloud Edgware (2018) and is kept for reference only. For Spring Boot 3.x, see the updated Service Discovery with Eureka guide and the Spring Cloud Netflix migration guide. This post contains pom.xml file and sample eureka server project built using Spring cloud version 1.5.18.RELEASE/ Edgware.SR5. Please refer Setting Up Eureka Server Using Spring Cloud post for detailed instructions.

Setting Up Eureka Server Using Spring Cloud (Part 1)

⚠️ This tutorial covers an old Spring Cloud version. Eureka itself is still actively maintained, but this setup targets Spring Boot 1.x/2.x. For Spring Boot 3.x, see the updated Service Discovery with Eureka guide and the Spring Cloud Netflix migration guide. This is a quick example for setting up Eureka server using Spring Cloud. You can download the whole project by using following link. Spring Cloud (V2.3.1) Eureka SeverDownload 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

Struts 2 Hello World Example (XML Version)

Security Warning: The dependency versions in this tutorial (struts2-core-2.2.1, ognl-3.0, javassist-3.7.ga, freemarker-2.3.16, commons-io-1.3.2, xwork-core-2.2.1) are from 2010–2011 and contain known critical vulnerabilities including remote code execution (RCE) exploits. Do not use these JARs in any production application. For current Struts 2, use the latest release from struts.apache.org and manage dependencies via Maven. This post is preserved for historical reference only. In this tutorial, we will be creating a simple “Hello world” program using Struts 2. For this tutorial we will be using Eclipse, Struts 2. Struts 2 allows you to define configuration either by using traditional Struts 1 like XML way or by using annotations. In this tutorial we will be following traditional XML way. Let’s move ahead!

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: Input block — An 8×8 grid of pixel intensity values. DCT — Converts spatial pixel data into frequency-domain coefficients. Quantisation — Divides each DCT coefficient by a value from the standard luminance quantisation table and rounds to the nearest integer, discarding fine detail. Zigzag scan — Reorders the 8×8 quantised coefficients into a 1D array, placing the most significant low-frequency coefficients first. Entropy encoding — Encodes the 1D array using a simplified run-length + binary scheme similar to the actual JPEG Huffman coding step.

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.

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.

Demonstrating Transposition Cipher in Java

A transposition cipher is a method of encryption where the positions of characters are shifted according to a certain system, without changing the actual characters themselves. It rearranges the characters in a message to create ciphertext, and the same method in reverse restores the original message. This post walks you through how a transposition cipher works using a Java program. This particular example arranges characters into a matrix and reads them column-wise (for encryption) or row-wise (for decryption). How the Transposition Cipher Works Encryption: Fill a matrix column-wise with characters of the message. Read the characters row-wise to get the encrypted message. The operation is repeated twice for added confusion. Decryption: Reverse the above process by filling the matrix row-wise. Read it column-wise to retrieve the original message.

Java Program to Demonstrating RSA

In the world of cryptography, RSA (Rivest–Shamir–Adleman) is a popular public-key cryptosystem widely used for secure data transmission. It’s based on the principle that while multiplying large prime numbers is computationally easy, factoring their product is not — which ensures security. This post will walk you through how RSA encryption and decryption work using a simple Java program. You'll learn how the sender encrypts a message using the recipient’s public key, and how the receiver decrypts it using their private key. What Happens Under the Hood? The RSA algorithm follows these steps: Key Generation Choose two large prime numbers p and q. Compute N = p * q. Compute the totient function: phi = (p-1)(q-1). Choose an integer e such that 1 < e < phi and gcd(e, phi) = 1. Compute d, the modular inverse of e modulo phi. Encryption The sender uses the recipient’s public key (e, N) to compute ciphertext: c = m^e mod N. Decryption The recipient uses their private key (d, N) to decrypt: m = c^d mod N.

Implementing Product Cipher in Java

In classical cryptography, a product cipher is a cipher that applies multiple transformations (substitution and permutation) to secure the plaintext. The goal is to combine the strengths of various techniques to produce a more secure encryption scheme. In this post, we’ll walk through the basic concept of a product cipher and demonstrate a simple Java program that implements both encryption and decryption using: Additive Caesar Cipher (a type of substitution cipher) Transposition Cipher (reordering the characters) By combining these two, we create a more secure scheme than using either one alone. What is a Product Cipher? A product cipher involves multiple rounds or stages of encryption where each stage transforms the message using a different method. Common combinations include: Substitution followed by transposition Multiple rounds of substitution and transposition This layered approach makes it harder to crack using frequency analysis or brute force. In our Java implementation, we use: Additive Caesar Cipher: Each character is shifted by a fixed key (k1). Transposition Cipher: The encrypted text is written row-wise into a matrix and read column-wise using a given number of rows (k2).

Demonstrating Digital Signature in Java

In modern cryptography, digital signatures ensure the authenticity and integrity of a message. One of the most widely used techniques for digital signing is based on the RSA algorithm. This post will guide you through the basic concept of how RSA digital signatures work and provide a simple Java implementation to illustrate the signing and verification process. What is an RSA Digital Signature? An RSA Digital Signature is a cryptographic method where the sender signs the message using their private key, and the receiver verifies it using the sender’s public key. This ensures: The message is not altered during transit. The message truly comes from the claimed sender. Here’s how it works conceptually: The sender selects two large prime numbers p and q. Computes N = p * q and phi = (p - 1)(q - 1). Chooses a public exponent e such that 1 < e < phi and gcd(e, phi) = 1. Computes the private key d = e^(-1) mod phi. To sign a message m, the sender calculates the signature s = m^d mod N. To verify, the receiver computes m' = s^e mod N and checks if m' == m.