A Java-based URL Shortener application that converts long URLs into short URLs and retrieves the original URLs efficiently. The project uses HashMap for constant-time lookups and includes input validation, duplicate handling, and a menu-driven console interface.
This project demonstrates strong fundamentals in Data Structures, Java, and problem-solvings.
- Shortens long URLs into compact short URLs
- Retrieves original URLs from short URLs
- Handles duplicate URLs by returning the same short URL
- Validates input URLs using Java’s built-in URL class
- Menu-driven console interface
- Handles empty, invalid, and incorrect inputs gracefully
- Java
- HashMap
- Java Collections Framework
- Object-Oriented Programming (OOP)
- java.net.URL
- User selects an option from the menu.
- For URL shortening:
- The input URL is validated.
- A unique 6-character alphanumeric code is generated.
- The short URL is stored using HashMap.
- For retrieving original URL:
- The short URL is validated.
- The original URL is fetched using the short code.
- All operations run in constant time on average.
- HashMap
shortCode → original URLoriginal URL → shortCode
- Shorten URL: O(1) average time
- Retrieve Original URL: O(1) average time
- Space Complexity: O(n), where n is the number of stored URLs
***** MENU *****
1. Shorten URL
2. Get Original URL
3. Exit
Enter your choice :
1
Enter the URL to shorten :
https://www.google.com
Short URL : http://short.ly/DMni3a
***** MENU *****
1. Shorten URL
2. Get Original URL
3. Exit
Enter your choice :
2
Enter short URL :
http://short.ly/DMni3a
Original URL : https://www.google.com
***** MENU *****
1. Shorten URL
2. Get Original URL
3. Exit
Enter your choice :
3
Thank you for using URL Shortener!
- Clone the repository:git clone
- Compile the Java files:javac Main.java
- Run the application:java Main
- Use the menu to shorten and retrieve URLs.
- Understood how HashMap enables O(1) average-time lookups for fast data retrieval
- Learned the importance of bidirectional mapping for efficient reverse lookups
- Gained hands-on experience in handling duplicate data without redundancy
- Implemented input validation to handle invalid, empty, and incorrect user inputs
- Used Java’s built-in URL class to validate real-world URL formats
- Improved understanding of clean code practices and meaningful code documentation
- Built a menu-driven console application using Java control flow constructs
- URL shortening services (e.g., link sharing platforms)
- Tracking and managing shortened links in marketing campaigns
- Reducing long URLs for social media and messaging platforms
- Backend services requiring fast lookup and redirection mechanisms
- Learning foundation for designing scalable web services