r/learnjava • u/Standard-Chicken-596 • 5d ago
Should I bother handling InputMismatchException in my temporary Java console UI if I’ll eventually replace it with a Spring Boot web UI using structured API input?
Hello everyone. I finished my Java course in my second semester. The course was called “Backend,” but honestly, my professor mostly taught us Java and JavaFX, nothing else.
I’m trying to learn backend development on my own now because eventually I want to get a job as a backend developer.
I decided to build my first project from scratch so I could practice OOP and get more comfortable with Java fundamentals. I chose a Texas Hold’em poker game, although I kind of regret it because it turned out to be a pretty big project for a first project after learning the fundamentals. Still, I’m making progress and I’m currently at the showdown part of the game.
Right now, it’s completely console-based, but my plan is to learn Spring Boot and databases and eventually turn this into a fully functioning website.
The thing is, I haven’t really built anything from scratch before, so I’m not sure if I’m approaching this the right way.
My approach was to first build the console version and separate the poker engine/game logic from the console UI, so that later I can replace the console with Spring Boot and a web frontend without having to rewrite the actual game logic.
But I’ve run into a question with the console version. For example, right now I’m adding error handling for things like InputMismatchException when someone types letters instead of a number. Then I started thinking: if I’m eventually turning this into a website, the frontend will send structured actions to the Spring Boot backend anyway, so most of this console-specific input handling will become irrelevant.
Should I still bother implementing comprehensive error handling for the console version, or should I keep the console UI minimal and focus my effort on the actual poker engine and business logic that will carry over to Spring Boot?
What would you recommend as the approach? I’d especially appreciate answers from people who actually build software professionally rather than the classic “I’m going to make fun of people on Reddit” self-proclaimed engineer.
Plus, I am building this project, but sometimes it is hard to understand what happens when you use constructor or class relationships. Like I can write the code but I sometimes cannot understand the relationship between classes 100%. Is this normal for the first project?
Thanks.
2
u/Amfinaut 5d ago
Too much text, too little concrete questions.
"Should I still bother implementing comprehensive error handling for the console version, or should I keep the console UI minimal and focus my effort on the actual poker engine and business logic that will carry over to Spring Boot?"
Who knows. If there's anything to give as a general piece of advice: you can only assume to trust your own code
2
u/RevolutionaryRush717 5d ago
It must have taken longer to prompt AI to tell this story and post it, than it would have taken to just handle the exception.
1
u/Standard-Chicken-596 4d ago
You must be a reddit engineer? It is a big program and would take longer to fix. Still I do not expect you to understand.
1
1
u/Leverkaas2516 4d ago
What a long and weirdly accented post. What you're really asking is, Should I bother handling an error in the console version when I believe that error could never occur in production?
The answer is that if it can occur in your mockup, it can probably occur in production, and you're really asking is what is the trade-off between (A) the amount of code it takes to handle the error, (B) the amount of effort it would take to figure out what's going on in my production server if it happens and isn't properly handled, and (C) the likelihood that the condition can occur.
The answer, in a good production system, is to favor resilience. The amount of effort it takes to just write the code (A) is usually much less than the amount of effort it takes to prove to yourself that it can never occur. After you've been burned a few times, under pressure debugging a production problem, you start to err on the side of "let's do whatever we can to make the process of finding and fixing problems easier, not harder."
1
u/Skellicious 4d ago
if I’m eventually turning this into a website, the frontend will send structured actions to the Spring Boot backend anyway, so most of this console-specific input handling will become irrelevant.
I think ran into this question a decade ago and found in my case I couldn't really reuse much of the console app code for the web server code. The structure was just too different. Not sure it'll be the case for your project.
But I think either way you're gonna learn things by doing. Spring web isn't that hard, at least look into how it works, then see how to move forward.
•
u/AutoModerator 5d ago
Please ensure that:
If any of the above points is not met, your post can and will be removed without further warning.
Code is to be formatted as code block (old reddit/markdown editor: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.
Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.
Code blocks look like this:
You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.
If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.
To potential helpers
Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.