Java

Java is a set of computer software and specifications developed by Sun Microsystems, which was later acquired by the Oracle Corporation, that provides a system for developing application software and deploying it in a cross-platform computing environment. Java is used in a wide variety of computing platforms from embedded devices and mobile phones to enterprise servers and supercomputers.

Spring Logo

Spring Framework

The Spring Framework provides a comprehensive programming and configuration model for modern Java-based enterprise applications - on any kind of deployment platform. A key element of Spring is infrastructural support at the application level: Spring focuses on the "plumbing" of enterprise applications so that teams can focus on application-level business logic, without unnecessary ties to specific deployment environments.

Hibernate Logo

Hibernate Framework

Hibernate ORM is an object-relational mapping framework for the Java language. It provides a framework for mapping an object-oriented domain model to a relational database.

Friday, December 28, 2012

Encode and Decode Example in Java

This post demonstrates the how to encode and decode the String data.

package com.ranga;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;

/**
* This class is used to encode and decode the string data.
* @author Ranga Reddy
* @version 1.0
*/

public class EncodeAndDecodeExample {
private static final String data = "Hello, I am Ranga Reddy. ";

public static void main(String[] args) {

String encodedData = getEncodedData(data);
System.out.println("Encoded Data: " + encodedData);

String decodedData = getDecondedData(encodedData);
System.out.println("Decoded Data: " + decodedData);
}

private static String getDecondedData(String encodedData) {
try {
return URLDecoder.decode(encodedData, "UTF-8");
} catch (UnsupportedEncodingException exception) {
throw new RuntimeException("Does not support UTF-8");
}
}

private static String getEncodedData(String data) {
try {
return URLEncoder.encode(data, "UTF-8");

} catch (UnsupportedEncodingException exception) {
throw new RuntimeException("Does not support UTF-8");
}
}
}

Output:
Encoded Data: Hello%2C+I+am+Ranga+Reddy.+
Decoded Data: Hello, I am Ranga Reddy.