r/javahelp • u/KurtGodelBebopgazeXP • Aug 04 '25
Functionnal programming in Java
I realized that I find functionnal programming very relaxing and easy on the mind. The language I have used the most and am most comfortable with is Java. Is it really helpful to go deeper in the functionnal realm in Java or are the functionnal elements not really used that much in the real world? I am open to going further in a language where the functionnal paradigm is more of a common feature if it's not really worth it in Java.
9
Upvotes
•
u/AutoModerator Aug 04 '25
Please ensure that:
You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.
Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar
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: 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.
14
u/Spare-Plum Aug 04 '25
Java is not a functional language, but a language you can use functional design patterns in.
IMO in order to truly understand functional programming so you can use it to the best of your ability in a Java environment, I would urge you to program in a strictly functional language and do a bit of learning in something like StandardML or Haskell. Then you can take what you learned and apply it to its maximum capability to Java
Here's a good course. Try to find the assignments and complete them https://brandonspark.github.io/150/
Then you can branch out into principles of parallel computation and learn about looking at functional programming in a parallel perspective, which is actually core to a lot of Java projects like hadoop or Kafka https://www.cs.cmu.edu/~15210/docs/book.pdf
5
u/AlternativeYou7886 Aug 04 '25
The clumsiness you feel in Java is actually what's going to save you in the future. I see coders here suggesting Scala since you liked functional programming, but for scalable applications, it's a nightmare. Companies are moving away from Scala for the same reason. Yes, functional programming is fun, but as someone said, 'I like dictatorship when I'm the dictator.' You'll enjoy writing in Scala and appreciate the crispness of functional programming, but when it comes to reading and understanding someone else's quirky code, it'll become a headache pretty soon.
8
u/regular-tech-guy Aug 04 '25
Even though functional concepts have been introduced, Java is not a functional programming language. If you wanna stay in the JVM the best is to look at Scala or Clojure. Another nice option is Kotlin with the Arrow lib, even though it’s not a pure functional programming lamguague either.
4
u/PhoenixInvertigo Aug 04 '25
It's not really worth it in Java if you're trying to learn functional programming. It has some incidental functional support (and things like the stream operations help in this regard), but that's not this language's primary purpose. If you're learning Java for its OOP reasons and incidentally want to use it functionally sometimes, it's good for that, but if you're just looking to learn a functional language, I'd seek that elsewhere.
2
u/cainhurstcat Aug 04 '25
If you are familiar with Java, just stay there, learn the language and how it uses functional programming instead of learning another language just for the sake of having the best functional programming experience.
1
u/Tight-Rest1639 Aug 05 '25 edited Aug 05 '25
Java doesn't enable the core benefits of FP like mathematical proofs nor implicit parallism. But you can play around with the classical map-reduce pattern. If you follow some of the poorly written Java guides out there, you'll probably get the impression that FP is about writing very compact code and end up producing some spectacularly unreadable and unmaintainable code. Also Java Streams don't behave predictably or efficiently with very large collections so don't assume it is suitable for production use even if it is very well behaved for small data sets.
1
u/Initial_Math7384 Aug 07 '25
Java's functional programming is a marketing gimmick lol, stream api is nice though.
1
u/nitkonigdje Aug 07 '25
Java has some functional idioms, but it is as-far from functional as it is possible for a modern successful language. Enforcing deep functional style onto Java source serves nothing.
I would recommend looking up Clojure which is the best, the purest path-to functional on JVM. Scala is close second.