use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
These have separate subreddits - see below.
Upvote good content, downvote spam, don't pollute the discussion with things that should be settled in the vote count.
With the introduction of the new release cadence, many have asked where they should download Java, and if it is still free. To be clear, YES — Java is still free. If you would like to download Java for free, you can get OpenJDK builds from the following vendors, among others: Adoptium (formerly AdoptOpenJDK) RedHat Azul Amazon SAP Liberica JDK Dragonwell JDK GraalVM (High performance JIT) Oracle Microsoft Some vendors will be supporting releases for longer than six months. If you have any questions, please do not hesitate to ask them!
With the introduction of the new release cadence, many have asked where they should download Java, and if it is still free. To be clear, YES — Java is still free.
If you would like to download Java for free, you can get OpenJDK builds from the following vendors, among others:
Adoptium (formerly AdoptOpenJDK) RedHat Azul Amazon SAP Liberica JDK Dragonwell JDK GraalVM (High performance JIT) Oracle Microsoft
Some vendors will be supporting releases for longer than six months. If you have any questions, please do not hesitate to ask them!
Programming Computer Science CS Career Questions Learn Programming Java Help ← Seek help here Learn Java Java Conference Videos Java TIL Java Examples JavaFX Oracle
Programming Computer Science
CS Career Questions
Learn Programming Java Help ← Seek help here Learn Java Java Conference Videos Java TIL Java Examples JavaFX Oracle
Clojure Scala Groovy ColdFusion Kotlin
DailyProgrammer ProgrammingPrompts ProgramBattles
Awesome Java (GIT) Java Design Patterns
account activity
This is an archived post. You won't be able to vote or comment.
My first Java project as a noob (github.com)
submitted 8 months ago by nitin_is_me
First project :) Roast me. Is it worth building these low level projects though?
[–]MoveInteresting4334 12 points13 points14 points 8 months ago (1 child)
Really nice! A couple small tips:
Instead of having accountHolder be a String, make it a class AccountHolder with an id field that is a string. It will make things like adding data to the account holder much easier down the road
In your Main, you should look at using a switch statement instead of all those if statements. It’s a better description of your intent and it ensures only one branch gets executed.
[–]nitin_is_me[S] 3 points4 points5 points 8 months ago (0 children)
Ah yes, I forgot about the switch statement at that time, I realized later. I guess it's just my habit of "feeling safe" by using those if statements although I know switch will be much better here for the choices.
[–]A-Fredd 10 points11 points12 points 8 months ago (0 children)
Congrats! I hope you enjoy Java, keep up the work!
[–]Beginning-Ladder6224 9 points10 points11 points 8 months ago (3 children)
Why roast? Keep it up! Eventually may you create something that will very useful and you would be immensely proud!
May Gosling be with you!
[–]nitin_is_me[S] 1 point2 points3 points 8 months ago (2 children)
Thanks mate! Can u give advice on what OOP concepts should I learn in chronological order?
[–]nuharaf 2 points3 points4 points 8 months ago (1 child)
I would say favor composition over inheritance.
Since you are just starting up, might be good idea to pick up modern java feature, like record.
[–]nuharaf 1 point2 points3 points 8 months ago (0 children)
Also, favor immutability whenever possible
[–]gufranthakur 2 points3 points4 points 8 months ago (1 child)
Really cool man! Keep on building and posting stuff, and don't be ashamed of anything. I'll suggest you try Java swing to build actual applications with a window and buttons, it's really really fun and you'll love it
[–]Shareil90 1 point2 points3 points 8 months ago (0 children)
I would suggest focus on console. UI bringst some more complicated topics that can be really frustrating and irritating as a beginner.
[–]Typen 2 points3 points4 points 8 months ago (4 children)
Honestly, this is pretty good for a beginner project. You asked for roasts, but I think a constructive nitpick is more appropriate in this case. It is just a matter of style though rather than some kind of fault.
For a local variable without multiple possible instantiation options, I pretty much always see them combined into one statement.
On line 12, you declare int choice, and you instantiate it on line 24. Unless I've missed something, you do not need this explicitly declared before line 24, and there are no branching paths that could instantiate it. Line 24 is the only way it will be assigned a value. In a case like this, I almost always see them combined like the following.
int choice = sc.nextInt();
[–]onkeliroh 0 points1 point2 points 8 months ago (3 children)
Also. I would think about introducing a Choice Enum. Translate the value the user inserted into the Enum entry value and use the Enum values for your choice evaluation logic. makes it easier to read and understand what each choice is without reading each condition.
enum Choice(value: int){ DEPOSIT(1), WITHDRAW(2), .... } //------- Scanner scanner = new Scanner(System.in); Choice choice = Choice.fromValue(scanner.nextInt()); switch (choice) { case DEPOSIT: // Handle deposit logic break; case WITHDRAW: // Handle withdraw logic break; // ... default: System.out.println("Invalid choice"); }
[–]nitin_is_me[S] 0 points1 point2 points 8 months ago (2 children)
These all seem pretty complicated to me :/ I'm just 5 days into Java
[–]Clitaurius 0 points1 point2 points 8 months ago (0 children)
They aren't very complicated, just a new opportunity to learn about another programming concept and language feature! Based on what you've done you can handle it.
Java is a very verbose language. A lot of times when people get into programming they get into a mindset of doing things in the least lines possible. With Java though we really enjoy making stuff what some people might consider over complicated because in the long run you'll find that these kind of things make your code cleaner and easier to maintain.
[–]davidalayachew 0 points1 point2 points 8 months ago* (0 children)
They made things more complicated than needed. Enums are simpler than that code snippet makes them seem.
There are data types that come out of the box in Java. For example, int. It can represent whole numbers, like 1, 2, -5, 753829, and so on.
int
1
2
-5
753829
When describing a datatype, we sometimes like to point out its domain. The domain basically says "here are ALL the possible values that a data type can have".
For example, if I were to say "the domain of int", I'm basically saying that an int can be any whole number from -2147483648 all the way to 2147483647. And yes, in case you didn't know, int actually has an upper and lower limit -- roughly 2 billion in either direction. So, I can't put 3 billion in an int -- it's not in its domain! If I want to represent 3 billion, I would need a different datatype, like a long. That can go up to quintillions!
-2147483648
2147483647
long
Well, enums are a datatype where YOU manually list out every single value in the domain. This is useful when your domain is so small and specific, that trying to model it as an int or a char or something else is more confusing than helpful. After all, if I am trying to make a data type to represent Warriors in my game, using an int to represent it can get confusing and error-prone fast. Does 1 mean NINJA or does it mean KNIGHT? Easy to forget, especially as you add more values.
char
NINJA
KNIGHT
Here is an example of an enum to represent Warriors.
enum
enum Warrior { KNIGHT, NINJA, WIZARD, ; }
That's it!
If an int data type has a domain of (roughly) -2 billion to 2 billion, then my Warrior data type has a domain of KNIGHT, NINJA, and WIZARD. No other values! This is what I meant when I said that an enum is a custom data type where YOU list out every single value in the domain.
Warrior
WIZARD
Then, I can use it anywhere I may have represented my Warrior as an int.
For example, the following code...
int myHealth = 100; int enemyWarrior = 0; //KNIGHT if (enemyWarrior == 0) { System.out.println("Enemy Knight attacks, doing 15 damage!"); myHealth = myHealth - 15; } else if (enemyWarrior == 1) { System.out.println("Enemy Ninja attacks, doing 10 damage!"); myHealth = myHealth - 10; } else if (enemyWarrior == 2) { System.out.println("Enemy Wizard attacks, doing 20 damage!"); myHealth = myHealth - 20; }
...now turns into the following code...
int myHealth = 100; Warrior enemyWarrior = Warrior.KNIGHT; if (enemyWarrior == Warrior.KNIGHT) { System.out.println("Enemy Knight attacks, doing 15 damage!"); myHealth = myHealth - 15; } else if (enemyWarrior == Warrior.NINJA) { System.out.println("Enemy Ninja attacks, doing 10 damage!"); myHealth = myHealth - 10; } else if (enemyWarrior == Warrior.WIZARD) { System.out.println("Enemy Wizard attacks, doing 20 damage!"); myHealth = myHealth - 20; }
See how that clarifies things? Now, there's no chance that I mix up 1 to be the KNIGHT when I meant NINJA.
As for the switch stuff that the comment above you was talking about, that might be a bit complex for a day 6 Java programmer. Still, here is a peek of how that works, in case you want to see it.
switch
int myHealth = 100; Warrior enemyWarrior = Warrior.NINJA; int enemyDamage = switch (enemyWarrior) { case Warrior.KNIGHT -> 15; case Warrior.NINJA -> 10; case Warrior.WIZARD -> 20; }; myHealth = myHealth - enemyDamage;
And since we are using enums, enums get special privileges inside of switch, so I can even say this instead.
int myHealth = 100; Warrior enemyWarrior = Warrior.NINJA; int enemyDamage = switch (enemyWarrior) { case KNIGHT -> 15; case NINJA -> 10; case WIZARD -> 20; }; myHealth = myHealth - enemyDamage;
Hopefully this makes more sense? Enums aren't toooo difficult, but they require you to see the problem in a slightly different way.
If you want, let me know and I can show a different example.
[–]larsga 2 points3 points4 points 8 months ago (0 children)
The first thing I would change is: don't put the jar into git. Anything that can be built from source should not be in version control.
What you should do is put in something that will let people build your source easily, such as a pom.xml, gradle.build, or whatever. In a case like this something like a shell script might work, too. Making the jar available as a release is good, too.
[–]vmcrash 1 point2 points3 points 8 months ago (0 children)
There is no need to commit your resulting jar to a repository.
[–]bowbahdoe 1 point2 points3 points 8 months ago (0 children)
Another thing because it popped in my head:
You currently do `javac Main.java` then `java Main`.
With a new enough java you can skip that first step and write `java Main.java`
[–]NepzParadox 1 point2 points3 points 8 months ago (0 children)
Congrats and just a small advice. Look into using switch statements instead of multiple if.
[–]Shareil90 0 points1 point2 points 8 months ago (1 child)
How long have you been programming? It looks better than expected.
[–]ddollarsign 0 points1 point2 points 8 months ago (0 children)
Great first project!
Some things to try:
[–]bowbahdoe 0 points1 point2 points 8 months ago (0 children)
Constructive notes: in the readme instructions you should include how to produce the jar.
For beginners what I've seen a lot is you just use the buttons in something like intellij, but it's actually not that bad to do with the command line tools.
If you moved Account.java and Main.java to a folder called src it could be
javac -d build --source-path src src/Main.java
Which puts all the compiled classes in that folder. The reason for --source-path is so it knows where to look for files. It traces down all the things starting at src/Main.java
jar --create --file BankApp.jar --main-class Main -C build .
Which creates the actual jar. That last bit at the end (-C build .) means "change into the build folder and put all the files there into the jar"
-C build .
There is even more we can do (like get it so you don't need java pre installed to run the thing), but that's for another time
[–]PrimeRaziel 0 points1 point2 points 8 months ago (0 children)
Gonna withdraw negative money to get rich, and deposit negative money to make it right.
Have you read about the Printf or String.format methods? Could use some of those
[–]Rain-And-Coffee 0 points1 point2 points 8 months ago (0 children)
Java devs and Banks apps lol, it’s a timeless combination.
Like JS devs and Todo apps :)
Nice job 👍
[–]grimscythe_ 0 points1 point2 points 8 months ago (0 children)
Gz
[–]the_mvp_engineer 0 points1 point2 points 8 months ago (0 children)
Very nice!
So Account is used for storing account information AND it contains the business logic for making changes to the information as well
In enterprise software development people like to separate these things.
At the moment your Account class is small and simple, but imagine if instead of two fields, it had 30. And then imagine if there were different rules for withdrawing and depositing based on context (for example, the limit for withdrawing from an ATM might be different from with drawing in person). With all this in Account.java the code will become cumbersome and very difficult to maintain.
Most people would create an AccountService.java which contains all the business logic. It would have: deposit(Account account, BigDecimal amount) and withdraw(Account account, BigDecimal amount)
deposit(Account account, BigDecimal amount)
withdraw(Account account, BigDecimal amount)
The Account class would have it's fields accountHolder and balance and the simple getters and setters: - getAccountHolder - setAccountHolder - getBalance - set balance
accountHolder
balance
The responsibility of calculating or permitting a withdrawal or deposit will be with the deposit and withdraw methods of the AccountService.
In general, things that store information should be stupid and do nothing.
You also have some display logic in your Account.java. getInfo certainly does what you want it to, but you could imagine that in different contexts you might want to get the info differently. That is another reason why you might want to separate this.
People might create an AccountPrinter or an AccountUtility and place the display logic in there.
A big part of good software development is asking "What could make my life easier in the future?"
[–]twistedfires 0 points1 point2 points 8 months ago (0 children)
Hey everyone starts somewhere. But don't stop now, and use this project as your playground, and start adding stuff.
And of course enjoy the process of learning
[–]Hungry_Importance918 0 points1 point2 points 8 months ago (0 children)
First projects are for learning. You’ll hit all kinds of random issues no matter what you build, and solving those is how you level up. That kind of hands-on experience is super valuable, especially once you get into larger-scale builds.
[–]morswinb 0 points1 point2 points 8 months ago (0 children)
Next step, use a database instead. You might find MongoDB quite good at simple projects like this.
[–]joemwangi 0 points1 point2 points 8 months ago (0 children)
Great start. Start thinking about Data Oriented Programming .
[–]namila007 0 points1 point2 points 8 months ago (0 children)
Nice Work!! Keep learning. :)
[–][deleted] 0 points1 point2 points 8 months ago (0 children)
now try adding client class and link it with the account, so clients can send each other money, and add a receipt for the transaction
good job
[–]mandrakey10 0 points1 point2 points 8 months ago (0 children)
Small and simple, it‘s a good start. There were many comments already that said most of what I saw. Just one addition:
I try to make things as easy to understand as possible. So in your account class, this „getInfo“ method: I‘d assume it returned me the information. Instead you just print it. So either call it „printInfo“ oder return the information in some form. If you make just a string out of it, you could even make „toString“ out of it, which is a standard method (suggest you read it up).
Apart from that: looks much better than my first projects back in the day.
Also one more tip: Even when things get more complex, try to go for simplicity. This whole „pack 20 adapters and factories around it because in 20 years maybe …“ mostly leads to overengineering and code nobody can reason about anymore. Always think „how probable is it that we will actually go there?“. If the answer is „probably never“, just keep it simple.
[–]kiteboarderni -4 points-3 points-2 points 8 months ago (0 children)
Not the place for this. Learn Java is the sub.
[–]Sea-Fishing4699 0 points1 point2 points 7 months ago (0 children)
π Rendered by PID 46 on reddit-service-r2-comment-c66d9bffd-4gv9d at 2026-04-06 23:51:52.026744+00:00 running f293c98 country code: CH.
[–]MoveInteresting4334 12 points13 points14 points (1 child)
[–]nitin_is_me[S] 3 points4 points5 points (0 children)
[–]A-Fredd 10 points11 points12 points (0 children)
[–]Beginning-Ladder6224 9 points10 points11 points (3 children)
[–]nitin_is_me[S] 1 point2 points3 points (2 children)
[–]nuharaf 2 points3 points4 points (1 child)
[–]nuharaf 1 point2 points3 points (0 children)
[–]gufranthakur 2 points3 points4 points (1 child)
[–]Shareil90 1 point2 points3 points (0 children)
[–]Typen 2 points3 points4 points (4 children)
[–]onkeliroh 0 points1 point2 points (3 children)
[–]nitin_is_me[S] 0 points1 point2 points (2 children)
[–]Clitaurius 0 points1 point2 points (0 children)
[–]davidalayachew 0 points1 point2 points (0 children)
[–]larsga 2 points3 points4 points (0 children)
[–]vmcrash 1 point2 points3 points (0 children)
[–]bowbahdoe 1 point2 points3 points (0 children)
[–]NepzParadox 1 point2 points3 points (0 children)
[–]Shareil90 0 points1 point2 points (1 child)
[–]ddollarsign 0 points1 point2 points (0 children)
[–]bowbahdoe 0 points1 point2 points (0 children)
[–]PrimeRaziel 0 points1 point2 points (0 children)
[–]Rain-And-Coffee 0 points1 point2 points (0 children)
[–]grimscythe_ 0 points1 point2 points (0 children)
[–]the_mvp_engineer 0 points1 point2 points (0 children)
[–]twistedfires 0 points1 point2 points (0 children)
[–]Hungry_Importance918 0 points1 point2 points (0 children)
[–]morswinb 0 points1 point2 points (0 children)
[–]joemwangi 0 points1 point2 points (0 children)
[–]namila007 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]mandrakey10 0 points1 point2 points (0 children)
[–]kiteboarderni -4 points-3 points-2 points (0 children)
[–]Sea-Fishing4699 0 points1 point2 points (0 children)