URLEncoder with sample program

Sample program:

 

package com.javadomain.in;

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

public class ComparePrintandSystem {
	static String intro="I am naveen kumar working @ www.javadomain.in";
	public static void main(String[] args) throws UnsupportedEncodingException {
	System.out.println(URLEncoder.encode(intro,"UTF-8"));

	}

}

 

Output:

I+am+naveen+kumar+working+%40+www.javadomain.in

URLEncoder Rules:

All the characters (a to z & A to Z) and numbers (0 to 9) remains same.

Space is converted to “+”

All the other characters are converted to hexadecimal values by prefixing with %.

In the above sample program, %40 is the hexadecimal value for @ sign.

Thanks for reading this post……………….!!!

460 total views, 2 views today

Leave a Reply

Your email address will not be published. Required fields are marked *