Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Maven build output
target/

# Maven Wrapper JAR
.mvn/wrapper/maven-wrapper.jar

# Java compiled files
*.class

# IDE files
.idea/
*.iml
.project
.classpath
.settings/
.vscode/
*.swp
*.swo

# OS files
.DS_Store
Thumbs.db

# Python testing artifacts
.venv/
venv/
__pycache__/
.pytest_cache/
*.pyc
*.pyo
2 changes: 2 additions & 0 deletions .mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.6/apache-maven-3.9.6-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar
165 changes: 37 additions & 128 deletions README.md
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,157 +1,66 @@
<!-- TITLE -->
# Email Slicer — Java 17

# Email Slicer Using Python

Email Slicer is a simple tool where the email address is provided as an input and the application returns the username and the domain of the email address as an output. It makes use of the slicing operation in Python.

<!-- BUILT WITH -->
Email Slicer is a simple tool where an email address is provided as input and the application returns the username and the domain of the email address as output. Migrated from the original Python implementation to idiomatic Java 17.

## Built With

![Python][python-shield]
- Java 17 (OpenJDK)
- Maven 3.9+ (via Maven Wrapper)
- JUnit 5 (testing)

<!-- EXAMPLE -->
## Prerequisites

## Example
- Java 17 or later installed (`java -version` to check)
- No Maven installation required — the Maven Wrapper (`mvnw`) is included

Input:
```
Please enter your Email Id:
avimax37@gmail.com
```
## Build

Output:
```
Your username is: avimax37
Your domain is: gmail.com
```bash
./mvnw package
```

Here we got **`avimax37`** as username and **`gmail.com`** as domain.

<!-- INSTALLATION -->

## Installation

Use the link to download Python.

[![Python][python-shield]][python-url]
## Run

Use the link to download PyCharm.

[![PyCharm][pycharm-shield]][pycharm-url]

Use the link to download Visual Studio Code.

[![Visual Studio Code][visual studio code-shield]][visual studio code-url]

<!-- USAGE -->

## Usage

Open Command Prompt or Windows PowerShell to start.

```python
# get into python mode
python

# create a python script
hello.py
print("Hello World")

# go to the file path
cd <file path>

# run the script
python hello.py
```bash
java -jar target/email-slicer.jar
```

VS Code or PyCharm can also be used.

<!-- CODE -->
## Test

## Code

So at first we are going to ask the user to enter the email that is to be sliced.

```python
print("Please enter your Email Id:")
email = input().strip()
```bash
./mvnw test
```

Here, as usual, we are making use of the **`input()`** function to get the input from the user in form of a string. We will store this input string in **`email`** variable.

Also we are making use of the **`strip()`** function. **`strip()`** function will remove any additional & unwanted spacing on both sides of the input string. So that we can make sure that we have only the email in the input and not any unwanted spaces.
## Example

```python
if email.find("@") != -1:
Input:
```

Here we are checking if the input string contains **`@`** or not. If it contains **`@`**, then it is considered as a valid email id and we move to the next step, which is slicing the email.

```python
username = email[:email.index("@")]
domain = email[email.index("@") + 1:]
Please enter your Email Id:
avimax37@gmail.com
```

Now, we print the **`username`** and **`domain`** to show the result.

```python
print("Your username is: ", username)
print("Your domain is: ", domain)
Output:
```

If the input string does not contain **`@`**, then it is considered as an invalid email id and we get out of the loop with a warning message.

```python
else:
print("Please enter a valid Email Id.")
Your username is: avimax37
Your domain is: gmail.com
```

<!-- LOGIC -->

## Logic

Let's consider the input is **`avimax37@gmail.com`**, so when we write **`email[email.index("@"):]`**, our **`index()`** function will interpret it as **`email[:8]`** as our **`@`** is located at index **8**. Now **`email[:8]`** knows that **`@`** is located at index **8**, so now it will keep the part before index **8** and discard the rest. It will store the stripped value in **`username`**.
Here we got **`avimax37`** as username and **`gmail.com`** as domain.

This exact same process is followed for **`domain`** also.
## Project Structure

<!-- LICENSE -->
```
├── pom.xml # Maven build configuration
├── mvnw / mvnw.cmd # Maven Wrapper scripts
├── src/main/java/com/emailslicer/
│ ├── Main.java # Console I/O entry point
│ ├── EmailSlicer.java # Pure parsing logic
│ ├── EmailSlicerResult.java # Record holding username + domain
│ └── Messages.java # User-facing string constants
└── src/test/java/com/emailslicer/
└── EmailSlicerTest.java # JUnit 5 unit tests
```

## License

Distributed under the MIT License. See **`LICENSE.md`** for more information.

<!-- CONTACT -->

## Contact

Avinaba Bera

[![Twitter][twitter-shield]][twitter-url]
[![LinkedIn][linkedin-shield]][linkedin-url]

<!-- PROJECT LINKS -->

## Project Links

[![GitHub][github-shield]][github-url]

<!-- MARKDOWNS -->

[python-shield]: https://img.shields.io/badge/python-3670A0?style=for-the-badge&logo=python&logoColor=ffdd54
[python-url]: https://www.python.org/downloads

[pycharm-shield]: https://img.shields.io/badge/pycharm-143?style=for-the-badge&logo=pycharm&logoColor=black&color=black&labelColor=green
[pycharm-url]: https://www.jetbrains.com/pycharm/download/#section=windows

[visual studio code-shield]: https://img.shields.io/badge/Visual%20Studio%20Code-0078d7.svg?style=for-the-badge&logo=visual-studio-code&logoColor=white
[visual studio code-url]: https://code.visualstudio.com/download

[twitter-shield]: https://img.shields.io/badge/Twitter-%231DA1F2.svg?style=for-the-badge&logo=Twitter&logoColor=white
[twitter-url]: https://twitter.com/IainSchneider

[linkedin-shield]: https://img.shields.io/badge/linkedin-%230077B5.svg?style=for-the-badge&logo=linkedin&logoColor=white
[linkedin-url]: https://www.linkedin.com/in/avinaba-bera

[github-shield]: https://img.shields.io/badge/github-%23121011.svg?style=for-the-badge&logo=github&logoColor=white
[github-url]: https://github.com/avimax37/email-slicer-python
Loading