File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Features new in Java 8 and the fly likes What is Functional Programming ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Features new in Java 8
Bookmark "What is Functional Programming ?" Watch "What is Functional Programming ?" New topic
Author

What is Functional Programming ?

Sangel Kapoor
Ranch Hand

Joined: Jan 12, 2013
Posts: 65

Hello Everyone

I tried reading few threads, everyone is relation Lambda expressions to the functional programming .
I am keen to know few things

1. What is functional programming ?
2. Are lambda expressions new to the Computer world ?
3. What are the set of problems encountered to introduce Lambda expression in the Java world so late .... in Java 8 ?

Thanks and Warm Regards
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38865
    
  23
Sangel Kapoor wrote: . . .
2. Are lambda expressions new to the Computer world ?
. . .
No.

I heard Richard Warburton and others at Devoxx today; the team at Oracle had to put a great deal of work and time into developing lambdas and making sure they worked.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14153
    
  18

Sangel Kapoor wrote:1. What is functional programming ?

See Functional programming

Sangel Kapoor wrote:2. Are lambda expressions new to the Computer world ?

Certainly not, they have existed for decades in many different programming languages. See: Anonymous function. They are relatively new in the mainstream, object oriented languages such as Java, C# and C++.

Sangel Kapoor wrote:3. What are the set of problems encountered to introduce Lambda expression in the Java world so late .... in Java 8 ?

When you add a new feature to any existing programming language, you have to realize that you are going to be stuck with it practically forever. So you'd better be extremely careful and make sure you don't make any big mistakes, because everybody using your language is going to suffer for such mistakes for a very long time. So, Oracle takes a lot of time to develop new features for Java such as lambda expressions. Also, Oracle is extremely careful to keep Java backward compatible, so they have to be absolutely sure that any new feature does not introduce incompatibilities. This also takes a lot of time.

I like the solution that Oracle has now implemented in Java 8 - especially the idea that lambda expressions are based on single-method interfaces (functional interfaces) was brilliant, because it makes lambda expressions integrate very nicely into the existing Java language: because of this idea, you can now use lambda expressions for any existing single-method interface.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Richard Warburton
Author
Greenhorn

Joined: Jun 16, 2013
Posts: 22
    
    7
Sangel Kapoor wrote:Hello Everyone

I tried reading few threads, everyone is relation Lambda expressions to the functional programming .
I am keen to know few things

1. What is functional programming ?
2. Are lambda expressions new to the Computer world ?
3. What are the set of problems encountered to introduce Lambda expression in the Java world so late .... in Java 8 ?

Thanks and Warm Regards


Hi Sangel,

Here are my attempts at concise answers in order:

1. You can think of functional programming as an approach to computer programming that tries to solve problems by mapping inputs to outputs - a bit like a mathematical function. This is in contrast to imperative programming which solves problems by executing a series of steps.
2. Not at all, lambda expressions originate in lambda calculus whose modern form was defined wayyyy back in 1936 by Alonzo Church. They have been used in a load of programming languages since then and found to be useful.
3. There are quite a few, and I probably can't think of them all but here goes:
a. Deciding on the correct representation for lambda expressions in bytecode. Currently a method is generated and wired up using the invoke dynamic and the LambdaMetaFactory.
b. Ideally you want to give lambda expressions their own types - function types. These would be generic however and generics in Java aren't reified which means that it would have been hard to overload lambda expressions very easily. This motivated the use of functional interfaces to represent the types of lambda expressions.
c. The need to evolve the collections API in order to make use of lambda expressions without breaking backwards compatibility. This motivated the addition of default methods.

If you want more details on the problems in depth and how they were solved, I would recommend reading the project lambda mailing list: http://openjdk.java.net/projects/lambda/.

regards,

Richard
Sangel Kapoor
Ranch Hand

Joined: Jan 12, 2013
Posts: 65

Thankyou everyone for your brilliant replies.
 
Don't get me started about those stupid light bulbs.
 
subject: What is Functional Programming ?