02 What is reactive programming (Reactive programming with Java - full course)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
what is reactive programming it seems to be a very popular thing what is it how is it different from the non-reactive programming whatever that is so here is the definition from wikipedia reactive programming is a declarative programming paradigm concerned with data streams and the propagation of change okay there are a couple of key items here declarative programming okay as opposed to imperative imperative is when you're doing all the steps declarative is where you're declaring this is what i want to happen and then something is going to make that happen right that's declarative it's a declarative programming paradigm it's concerned with data streams and the propagation of change okay it's basically data streams whenever you have data streams whenever you have a stream of data data is coming in it's not just one data element it's a stream of data you are using the reactive programming to work with that stream right and propagation propagation of change is kind of another stream of data right the change is coming through all right the wikipedia definition continues it says that with this paradigm it is possible to express static or dynamic data streams static like arrays dynamic like event emitters right we have two different types of data streams you can express them with ease and you can also communicate that to an inferred dependency within the associated execution model okay which facilitates the automatic propagation of the change data flow and this is where i probably lose you right this is not going to make a lot of sense unless you know reactive programming so i promise you by the end of this course you will understand a lot of these things not everything okay because this is a little more convoluted than i would define it but you will understand most of this definition okay so one thing that you will you will realize is that there isn't a mention of async in this definition okay a lot of people confuse reactive with async okay what is async async is when things aren't just one after another okay it's it's basically like things are happening all over the place right reactive programming doesn't necessarily imply async you can have reactive programming which is synchronous okay it's very much possible and you can have uh non-reactive programming which is async there are two separate concepts okay and i also want to call out that distinction when we are learning about all these reactive programming paradigms because that's a mistake that a lot of people make right i don't want you to make that mistake all right so okay reactive programming allows you to deal with streams of data what are some use cases for it the traditional use case for reactive programming in general right i'm not talking about java in general in the programming world a reactive programming use case a classic reactor programming use case is user events okay especially when you're working on something like the ui okay you have a front end you're working on the ui again not talking about java because java usually you don't java isn't a first choice for working on ui of course you have a swing and javafx and all that stuff so if you're working on those things don't come after me but it's not a very common use case is what i mean but in general user events you use reactor programming right how do you deal with user events right when when the user clicks on a button you want to do something okay so how does it work you typically tend to do this in javascript right so you have a web page user clicks on a button you need to do something when that happens okay so what do you do you wire in the thing using a callback right you say when the button click happens give it a function and say execute this function okay so that's kind of reactive programming you're reacting to a button click right when this happens do this which is a reaction to an event that's happening but the other use case is an i o response right when when a user you request something there is an input output that needs to happen it's like okay when this thing is when the file is read and it's completed and it's ready you go execute this function okay that's another use case for reactive programming okay so reactive programming is basically reacting to something right when the user clicks this button from this function this kind of it this is kind of reactive programming in a very very simplistic term okay a very very simplistic term all right i see a question here it sounds a bit similar to event driven programming there is a trigger that is happening and then the program runs exactly exactly so the trigger is what leads you to react to it okay you're reacting to a trigger and doing something okay that's even i wouldn't say it's even driven programming even driven programming can have different implications but it's kind of it okay so this begs the question why do we care and i'm asking this because primarily server side back in java development you're not clicking buttons there right you don't do you don't do even driven programming with java back in right we aren't building ui why does a server-side java back-end developer have to care about reactive programming right but do we care if we look at the server-side web development paradigm right what do we do when we do server-side web development we handle a request a request comes in okay and then we do some processing we say okay something needs to happen we gotta fetch something from the database right we have to do some processing call another api you call the microservice or whatever and then we return a response okay seems very synchronous seems very you know do this and do this and do this you're not reacting well the only reaction is probably the user uh you know making a request right you're reacting to that but then you're not you're not breaking it and doing something else right it's it's very synchronous once a request comes in you just do a do b and do c and then you have to return a response because the request has to wait okay there's gonna be a very important criteria that we're going to evaluate attractive programming on it's basically the nature of http right somebody makes a request until the response comes back somebody that somebody is waiting okay they can't say well while this happens i'm going to do something that's a different request right and each request in itself isn't very reactive you basically do all the steps and then you return a response and then that request is served right so if this is a case why do we as server side developers java developers have to care for reactor programming i'm going to make a case for it i'm going to make a case for reactive programming why do we have to care
Info
Channel: Java Brains
Views: 82,543
Rating: undefined out of 5
Keywords:
Id: eHmM0EOmAS8
Channel Id: undefined
Length: 6min 59sec (419 seconds)
Published: Tue Jun 21 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.