📘 Premium Read: Access my best content on Medium member-only articles — deep dives into Java, Spring Boot, Microservices, backend architecture, interview preparation, career advice, and industry-standard best practices.
✅ Some premium posts are free to read — no account needed. Follow me on Medium to stay updated and support my writing.
🎓 Top 10 Udemy Courses (Huge Discount): Explore My Udemy Courses — Learn through real-time, project-based development.
▶️ Subscribe to My YouTube Channel (172K+ subscribers): Java Guides on YouTube
URL Encoder Online
URL Encoder is an online tool for encoding URLs. URL encoding stands for encoding certain characters in a URL by replacing them with one or more character triplets that consist of the percent character "%" followed by two hexadecimal digits. The two hexadecimal digits of the triplet(s) represent the numeric value of the replaced character.
Check out the URL decoder online tool at URL Decoder Online.
URL Encoding Example
https://www.javaguides.net/p/url-encoder-online.htmlEncoded URL output:
https%3A%2F%2Fwww.javaguides.net%2Fp%2Furl-encoder-online.html
Encode URL in JavaScript
var uri = "https://javaguides.net/my test.html?name=ram&age29";
console.log("before encode :: " + uri);
var encode = encodeURIComponent(uri);
console.log("after encode :: " + encode);
var decode = decodeURIComponent(encode);
console.log("after decode :: " + decode);
before encode :: https://javaguides.net/my test.html?name=ram&age29
after encode :: https%3A%2F%2Fjavaguides.net%2Fmy%20test.html%3Fname%3Dram%26age29
after decode :: https://javaguides.net/my test.html?name=ram&age29
Read more about how to encode and decode URL in JavaScript in a blog post at Encode and Decode URL in JavaScript.
URL Encode in Java
- The alphanumeric characters "a" through"z", "A" through"Z", and "0" through "9" remain the same.
- The special characters ".","-", "*", and"_" remain the same.
- The space character " " is converted into a plus sign "+".
- All other characters are unsafe and are first converted into one or more bytes using some encoding scheme. Then each byte is represented by the 3-character string"%xy", where xy is the two-digit hexadecimal representation of the byte. The recommended encoding scheme to use is UTF-8. However, for compatibility reasons, if an encoding is not specified, then the default encoding of the platform is used.
URLEncoder Class Example
package net.javaguides.network;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
public class URLEncoderExample {
public static void main(String[] args) throws MalformedURLException, UnsupportedEncodingException {
// base URL
String baseurl = "https://www.javaguides.net/search?q=";
// String to be encoded
String query = "core+java+tutorial";
System.out.println("URL without encoding :");
URL url = new URL(baseurl + query);
System.out.println(url);
// encode() method
System.out.println("URL after encoding :");
url = new URL(baseurl + URLEncoder.encode(query, "UTF-8"));
System.out.println(url);
}
}
URL without encoding :
https://www.javaguides.net/search?q=core+java+tutorial
URL after encoding :
https://www.javaguides.net/search?q=core%2Bjava%2Btutorial
Check out how to encode and decode URLs in Java at Java URLEncoder and URLDecoder Class Examples
URL Encoding Table
Character | Percent Encoding |
---|---|
(space) | %20 |
! | %21 |
" | %22 |
# | %23 |
$ | %24 |
% | %25 |
& | %26 |
' | %27 |
( | %28 |
) | %29 |
* | %2A |
+ | %2B |
, | %2C |
/ | %2F |
: | %3A |
; | %3B |
< | %3C |
= | %3D |
> | %3E |
? | %3F |
@ | %40 |
[ | %5B |
\ | %5C |
] | %5D |
^ | %5E |
` | %60 |
{ | %7B |
| | %7C |
} | %7D |
Comments
Post a Comment
Leave Comment