This week's book giveaway is in the Artificial Intelligence and Machine Learning forum.
We're giving away four copies of TensorFlow 2.0 in Action and have Thushan Ganegedara on-line!
See this thread for details.
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

Imperative programming vs reactive programming

 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From an expert,

In imperative programming we spin up threads to do things in parallel.

In reactive programming we declare the unit of work and leave execution (i.e. concurrency) up to the runtime.

Questions

1. Does Java supports imperative and reactive programming? How?
2. Can someone explain with an example of imperative and reactive programming with an example?
3. Concurrency can be done via call back or futures. What is the difference between having a call back or using futures?

Thanks.

 
Saloon Keeper
Posts: 12431
269
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Joseph Michael wrote:In reactive programming we declare the unit of work and leave execution (i.e. concurrency) up to the runtime.


This is not limited to reactive programming. This is true for all asynchronous programming styles.

Does Java supports imperative and reactive programming? How?


Almost everything you do in Java is imperative. It provides asynchronous programming models with the Stream API. If you are wondering about reactive programming specifically, there are libraries for this, such as RxJava.

2. Can someone explain with an example of imperative and reactive programming with an example?


Imperative:

Reactive:

Asynchronous through Stream API:


3. Concurrency can be done via call back or futures. What is the difference between having a call back or using futures?


With callbacks you supply operations to perform next directly to the asynchronous operation. With futures, the asynchronous operation returns an object with which you can register operations to perform next.

Callback:

Future:
 
For my next trick, I'll need the help of a tiny ad ...
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic