Saturday 31 January 2015

Swing and Core Java Interview Questions and Answers

21. Which method is used by the applet to recognize the height and width?
Method is used by the applet to recognize the height and width which is defined as :
> getParameters()

22. When we should go for codebase in applet?
If the applet class is not in the same directory,when we used to codebase.

23. What is the lifecycle of an applet?
An Applet is basscially lifecyacle is defined as :
> Init( ) method : called when an applet is first loaded.
> Start( ) method : called each time an applet is started .
> Paint( ) method : called when the applet is minimized or maximized .
> Stop( ) method : called when the browser moves off the applet's page.
> Destroy( ) method : called when the browser is finished with the applet.

24. Which method is used for setting security in applets?
The Method is used for setting security in applets whihc is defined as :
> setSecurityManager()

25. What is an event and what are the models available for event handling?
Changing the state of an object is called an event. An event is an event object that describes a state of change. In other words, event occurs when an action is generated, like pressing a key on keyboard, clicking mouse, etc. There different types of models for handling events are event-inheritance model and event-delegation model

26. What are the advantages of the event-delegation model over the event-inheritance model?
Event-delegation model has two advantages over event-inheritance model.
=> Event delegation model enables event handling by objects other than the ones that generate the events. This allows a clean separation between a component's design and its use.
=> It performs much better in applications where many events are generated. This performance improvement is due to event-delegation model does not have to be repeatedly process unhandled events as is the case of the event-inheritance.

27. Can a class be it's own event handler? Explain how to implement this?
Sure.a Class can be its own event handler. For an example could be a class that extends Jbutton and implements ActionListener. In the actionPerformed method, put the code to perform when the button is pressed.

28. Why does JComponent have add() and remove() methods but Component does not?
JComponent have add() and remove() methods but Component does not because JComponent is a subclass of Container, and can contain other components and jcomponents.

29. How would you create a button with rounded edges?
there's 2 ways to create a button with rounded edges.
> The first thing is to know that a JButton's edges are drawn by a Border. so we can override the Button's paintComponent or Graphics method and draw a circle or rounded rectangle and turn off the border. Or we can create a custom border that draws a circle or rounded rectangle around any component and set the button's border to it.

30. What is the difference between the 'Font' and 'FontMetrics' class?
many diff are there which is defined as :
> The Font Class is used to render 'glyphs', The characters we see on the screen.
> FontMetrics encapsulates information about a specific font on a specific Graphics object.
More Questions & Answers :-

No comments:

Post a Comment