Event-driven programming
In computer programming, event-driven programming is a programming paradigm in which the flow of the program is determined by external events. User interface (UI) events from keyboards and mice, touchpads and touchscreens, and external sensor inputs are common cases. Events may also be programmatically generated, such as from messages from other programs, notifications from other threads, or other network events. Event-driven programming is the dominant paradigm used in graphical user interface (GUI) applications and network servers. In an event-driven application, there is generally an event loop that listens for events and then triggers a callback function when one of those events is detected. Event-driven programs can be written in any programming language, although the task is easier in languages that provide high-level abstractions. Although they do not exactly fit the event-driven model, interrupt handling and exception handling have many similarities. It is important to differentiate between event-driven and message-driven (aka queue-driven) paradigms: event-driven services (e.g. AWS SNS) are decoupled from their consumers, whereas message/queue-driven services (e.g. AWS SQS) are coupled with their consumers.
In computer programming, event-driven programming is a programming paradigm in which the flow of the program is determined by external events. User interface (UI) events from keyboards and mice, touchpads and touchscreens, and external sensor inputs are common cases. Events may also be programmatically generated, such as from messages from other programs, notifications from other threads, or other network events. Event-driven programming is the dominant paradigm used in graphical user interface (GUI) applications and network servers. In an event-driven application, there is generally an event loop that listens for events and then triggers a callback function when one of those events is detected. Event-driven programs can be written in any programming language, although the task is easier in languages that provide high-level abstractions. Although they do not exactly fit the event-driven model, interrupt handling and exception handling have many similarities. It is important to differentiate between event-driven and message-driven (aka queue-driven) paradigms: event-driven services (e.g. AWS SNS) are decoupled from their consumers, whereas message/queue-driven services (e.g. AWS SQS) are coupled with their consumers. ==Event loop== Because the event loop that retrieves and dispatches events is common amongst applications, many programming frameworks provide an implementation of an event loop, and the application developer only needs to write the event handlers. RPG, an early programming language from IBM, whose 1960s design concept was similar to event-driven programming discussed above, provided a built-in main I/O loop (known as the "program cycle") where the calculations responded in accordance with "indicators" (flags) that were set earlier in the cycle. ===Event handlers=== The actual logic is contained in event handler routines. These routines handle the events to which the main program will respond. For example, a single mouse-click on a "Save" command button in a GUI program might trigger a routine to save data to a database. An "Exit" button might trigger a routine to exit the program. The event loop receives events from all such command buttons and other GUI elements, dispatching the appropriate event handler routine for each button. Event handler routines need to be bound to specific events, so the event loop can dispatch the correct routine in response to the event. Many IDEs simplify this process by providing the programmer with an event handling template for each specific event (such as a button click), allowing the programmer to focus on writing the event-handling code. In a sequential program, keeping track of execution order and history is normally trivial. But in an event-driven program, event handlers execute non-sequentially in response to external events. Special attention and planning is required to correctly structure the event handlers to work when called in any order. ==Common uses== Most existing GUI architectures use event-driven programming. Windows has the message loop. The Java AWT framework processes all UI changes on a single thread, called the Event dispatching thread. Similarly, all UI updates in the Java framework JavaFX occur on the JavaFX Application Thread. Most network servers and frameworks such as Node.js are also event-driven. ==Interrupt and exception handling== ==See also== Autonomous peripheral operation Dataflow programming DOM events Event-driven architecture Event stream processing (a similar concept) Hardware description language Interrupt Inversion of control Message-oriented middleware Programming paradigm Publish–subscribe pattern Reactor pattern Staged event-driven architecture (SEDA) Time-triggered system (an alternative architecture for computer systems) Virtual synchrony, a distributed execution model for event-driven programming ==References== ==External links== Concurrency patterns presentation given at scaleconf Event-Driven Programming: Introduction, Tutorial, History, tutorial by Stephen Ferg Event-Driven Programming, tutorial by Alan Gauld Event Collaboration, article by Martin Fowler Rethinking Swing Threading, article by Jonathan Simon The event-driven programming style , article by Chris McDonald Event Driven Programming using Template Specialization, article by Christopher Diggins Event-Driven Programming and Agents, chapter Distributed Publish/Subscribe Event System, an open-source example which is in production on MSN.com and Microsoft.com
References
- Chandrasekaran, Premanand; Krishnan, Karthik; Ford, Neal; Byars, Brandon; Buijze, Allard (2022). Domain-Driven Design with Java - A Practitioner's Guide . Packt Publishing. ISBN 9781800564763 . Wikipedia revision 1371939355, retrieved 2026-11-18 · retrieved 2026-11-17 · rev 1371939355
Cite this reference
MLA "Chandrasekaran, Premanand; Krishnan, Karthik; Ford, Neal; Byars, Brandon; Buijze, Allard (2022). Domain-Driven Design with Java - A Practitioner's Guide . Packt Publishing. ISBN 9781800564763 . Wikipedia revision 1371939355, retrieved 2026-11-18." Chandrasekaran, Premanand; Krishnan, Karthik; Ford, Neal; Byars, Brandon; Buijze, Allard (2022). 2026-11-17. https://en.wikipedia.org/wiki/ISBN_(identifier). Accessed 24 November 2026.
Chicago "Chandrasekaran, Premanand; Krishnan, Karthik; Ford, Neal; Byars, Brandon; Buijze, Allard (2022). Domain-Driven Design with Java - A Practitioner's Guide . Packt Publishing. ISBN 9781800564763 . Wikipedia revision 1371939355, retrieved 2026-11-18." Chandrasekaran, Premanand; Krishnan, Karthik; Ford, Neal; Byars, Brandon; Buijze, Allard (2022). 2026-11-17. https://en.wikipedia.org/wiki/ISBN_(identifier).
APA Chandrasekaran, Premanand; Krishnan, Karthik; Ford, Neal; Byars, Brandon; Buijze, Allard (2022). (2026). Chandrasekaran, Premanand; Krishnan, Karthik; Ford, Neal; Byars, Brandon; Buijze, Allard (2022). Domain-Driven Design with Java - A Practitioner's Guide . Packt Publishing. ISBN 9781800564763 . Wikipedia revision 1371939355, retrieved 2026-11-18. Retrieved November 24, 2026, from https://en.wikipedia.org/wiki/ISBN_(identifier)
- Concurrency in JavaFX · retrieved 2026-11-17 · rev 1371939355
Cite this reference
MLA "Concurrency in JavaFX." Fedortsova, Irina (June 2012). 2026-11-17. https://docs.oracle.com/javafx/2/threads/jfxpub-threads.htm. Accessed 24 November 2026.
Chicago "Concurrency in JavaFX." Fedortsova, Irina (June 2012). 2026-11-17. https://docs.oracle.com/javafx/2/threads/jfxpub-threads.htm.
APA Fedortsova, Irina (June 2012). (2026). Concurrency in JavaFX. Retrieved November 24, 2026, from https://docs.oracle.com/javafx/2/threads/jfxpub-threads.htm
- Event-Driven Programming in Node.js . Wikipedia revision 1371939355, retrieved 2026-11-18 · retrieved 2026-11-17 · rev 1371939355
Cite this reference
MLA "Event-Driven Programming in Node.js . Wikipedia revision 1371939355, retrieved 2026-11-18." Event-Driven Programming in Node. 2026-11-17. https://www.digitalocean.com/community/tutorials/nodejs-event-driven-programming/. Accessed 24 November 2026.
Chicago "Event-Driven Programming in Node.js . Wikipedia revision 1371939355, retrieved 2026-11-18." Event-Driven Programming in Node. 2026-11-17. https://www.digitalocean.com/community/tutorials/nodejs-event-driven-programming/.
APA Event-Driven Programming in Node. (2026). Event-Driven Programming in Node.js . Wikipedia revision 1371939355, retrieved 2026-11-18. Retrieved November 24, 2026, from https://www.digitalocean.com/community/tutorials/nodejs-event-driven-programming/
- Who Moved My State? · retrieved 2018-01-27 · rev 1371939355
Cite this reference
MLA "Who Moved My State?." Samek, Miro (April 1, 2013). 2018-01-27. http://www.ddj.com/cpp/184401643. Accessed 24 November 2026.
Chicago "Who Moved My State?." Samek, Miro (April 1, 2013). 2018-01-27. http://www.ddj.com/cpp/184401643.
APA Samek, Miro (April 1, 2013). (2018). Who Moved My State?. Retrieved November 24, 2026, from http://www.ddj.com/cpp/184401643
Cite this article
MLA
"Event-driven programming." encyclopegia.org, 2026, https://encyclopegia.org/wiki/event-driven-programming. Accessed 24 November 2026.
Chicago
"Event-driven programming." encyclopegia.org. Accessed November 24, 2026. https://encyclopegia.org/wiki/event-driven-programming.
APA
encyclopegia.org. (2026). Event-driven programming. Retrieved November 24, 2026, from https://encyclopegia.org/wiki/event-driven-programming
Accessed November 24, 2026 · CC BY-SA 4.0 · citation page · JSON