Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Why Java Is Not a Functional Programming Language?

 
Ranch Foreman
Posts: 125
12
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did some research online, people have different explanations for that (e.g. coding style, side effects, etc.) which make me a little confused. I also did some Spark programming with Scala. Scala and Java programming has a lot similarities, but Scala is considered as also a functional programming language, even though it is even more object oriented than Java. I know Java supports functional programming only to a limited extent, but to what level it can be called a functional programming?
 
Marshal
Posts: 70709
288
  • Likes 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adding to another “general” forum.

You will have to ask James Gosling, who is the one person to know all that sort of thing, but:-
  • 1: Please find out how much of a “mainstream” paradigm functional programming was in the mid‑1990s. The language was designed with current thinking in mind, and the big paradigm then was object‑orientation.
  • 2: The original design of Java® was influenced by languages current at the time, Simula‑67, C++, SmallTalk, Eiffel, etc., as well as concepts like those in Object‑Oriented Software Construction by Bertrand Meyer.
  • 3: It took several years to remedy some of the shortcomings of early versions of Java®, e.g. lack of assertions, lack of generics.
  • 4: By the end of the 2010s, Java® was looking very old‑fashioned both because of its extreme imperative style, and because it requires no slight effort to adapt a program for a multi‑core processor.
  • 5: The Streams API introduced in Java8 allows one to use a more declarative style, and also accommodates itself to multi‑core processors almost effortlessly.
  • 6: The λ expression allows one to write much simpler code than the old anonymous class, and that is a functional feature.
  • 7: Pierre-Yves Saumont, who is an occasional user of this website, says that any language can be used in a functional styl, and has a book published by Manning about writing functional code in Java®. His writings give me the impession that functional coding isn't so much, “what you call it,” as, “what you do with it.”
  •  
    Frank Mi
    Ranch Foreman
    Posts: 125
    12
    Eclipse IDE Java Windows
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi Campbell,

    Thank you very much for your answer! This is the reason why I love this site, I asked a shallow and immature question, and you answered it much deeper with a lot more information I would like to know and learn. If this is on Stackoverflow, they may crazily vote my question down and close it.

    I would like to give you ten cows 🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄 if I can!    
     
    Saloon Keeper
    Posts: 22677
    153
    Android Eclipse IDE Tomcat Server Redhat Java Linux
    • Likes 2
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Functional programming dates all the way back to LISP, which puts it in the same era as the venerable FORTRAN and COBOL programming languages. So it wasn't new technology by the 1990s. And OOP wasn't even radically new by then. C++ was announced to the public in 1985 and I'd been marketing a C++ development system myself for several years before Java came out. In fact, had developed a Smalltalk system written in C++.

    Gosling wanted something like C++ but friendlier, safer, more secure and without the dead weight of C and that's what he developed. So that was Java. These days we like the functional paradigm since it's stateless and that scales well across multiple distributed servers, which wasn't a common problem back then.

    I'm not sure about the assertion that Java requires major recoding to support multi-core processors. Unless that's supposed to mean that you have to explicitly construct and manage java Threads whereas some of the more popular languages of the day deal with that more automatically. A thread doesn't care whether it's on one core or processor or many. Which, of course, is different than processes running on multiple hosts!
     
    Frank Mi
    Ranch Foreman
    Posts: 125
    12
    Eclipse IDE Java Windows
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thank you for your explanation, Tim!
     
    Campbell Ritchie
    Marshal
    Posts: 70709
    288
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    Tim Holloway wrote:. . . . Unless that's supposed to mean that you have to explicitly construct and manage java Threads . . .

    Yes, it does. You have to manage Threads, whereas you can simply call a Stream parallel and Bob's your Uncle. Well, actually it isn't quite that easy really, is it?
     
    Campbell Ritchie
    Marshal
    Posts: 70709
    288
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    Frank Mi wrote:. . . Stackoverflow . . .

    SO work on a model different from ours.
     
    Tim Holloway
    Saloon Keeper
    Posts: 22677
    153
    Android Eclipse IDE Tomcat Server Redhat Java Linux
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    Campbell Ritchie wrote:

    Frank Mi wrote:. . . Stackoverflow . . .

    SO work on a model different from ours.



    Aside from their unfortunate reputation (which they've been trying to address), SO really isn't in the business of hypotheticals or theory. Whereas we are totally shameless.
     
    Master Rancher
    Posts: 3704
    44
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Regarding Scala, it's considered a mixed-paradigm language, supporting both functional and object-oriented styles.  It supports more functional features than Java, especially when it came out well before Java adopted lambdas... but it's also possible to write very non-functional code if you want in Scala. Much like Java.
     
    Tim Holloway
    Saloon Keeper
    Posts: 22677
    153
    Android Eclipse IDE Tomcat Server Redhat Java Linux
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Fun fact: In LISP, a "function" is basically just a lamba expression that's been cataloged in a dictionary.
     
    Campbell Ritchie
    Marshal
    Posts: 70709
    288
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    Tim Holloway wrote:. . . we are totally shameless.

    And proud of it. That is how some of the most interesting discussions arise.
     
    reply
      Bookmark Topic Watch Topic
    • New Topic