• Post Reply Bookmark Topic Watch Topic
  • New Topic

event driven execution in Java  RSS feed

 
Dounia Kchiere
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Experts,

what do we mea please by event driven execution in Java???How is this related to exceptions?

Thanks for your help,

Dounia
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Event driven code doesn't control the whole flow of the program, it only responds to things happening in the program. For example if you code a Swing window with a button you code an ActionListener class for the button. When the user clicks on the button, the Swing framework calls the listener's actionPerformed() which is an "event" in the life of the program.

Message driven programs are event driven, too. My work system has some services that are triggered by incoming JMS messages. onMessage() is an event in that framework.

Does that help?
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'll make a second post for the exception part of the question ... I'm not sure what you're looking for here but let's think about a couple aspects.

If you write a program that begins at main() and calls classes you wrote which call classes you wrote and so on, any exception stack trace is going to show your methods all the way down the page. If you look at an exception stack trace thrown in a button event handler it will show your class at the top and then a whole lot of framework stuff. I don't know if that distinction has any value ... it might help you understand what's going on in a stack trace?

In some environments events are asynchronous. The object that publishes or sends the event doesn't wait for an answer, but goes on processing on its own thread. You can't really throw an exception back to that caller because it's no longer waiting around for a result.

Even some synchronous environments don't care whether the event handler works or not. Swing tells you the button was clicked but doesn't really want to know what you do about it. The actionPerformed method doesn't declare any exceptions.

Is that the kind of thing you were interested in?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!