Unit 4 - QB
Unit 4 - QB
1
at compile time. A Java compiler applies strong type checking to generic code and
issues errors if the code violates type safety. Fixing compile-time errors is easier than
fixing runtime errors,which can be difficult to find.
7 How to create generic class?
A class that can refer to any type is known as generic class. Here, we are using T type
parameter to create the generic class of specific type.
Example to create and use the generic class.
class MyGen<T>{
T obj;
void add(T obj)
{
this.obj=obj;
}
T get()
{
return obj;
}}
2
for.
12 What are the restrictions on generics?
To use Java generics effectively, it must consider the following restrictions:
✓ Cannot Instantiate Generic Types with Primitive Types
✓ Cannot Create Instances of Type Parameters
✓ Cannot Declare Static Fields Whose Types are Type Parameters
✓ Cannot Use Casts or instance of With Parameterized Types
✓ Cannot Create Arrays of Parameterized Types
✓ Cannot Create, Catch, or Throw Objects of Parameterized Types
✓ Cannot Overload a Method Where the Formal Parameter Types of Each Overload
Erase to the Same Raw Type
13 Mention some Event Classes and Interface
Event Classes Description Listener Interface
generated when button is pressed, menu-
ActionEvent ActionListener
item is selected, list-item is double clicked
generated when mouse is dragged,
MouseEvent moved,clicked,pressed or released and MouseListener
also when it enters or exit a component
generated when input is received from
KeyEvent KeyListener
keyboard
generated when check-box or list item is
ItemEvent ItemListener
clicked
generated when value of textarea or
TextEvent TextListener
textfield
is changed
generated when component is hidden,
ComponentEvent ComponentEventListener
moved, resized or set visible
generated when component is added or
ContainerEvent ContainerListener
removed from container
14 How Does a radio button in java differ from a check box?
✓ Radio buttons are used when there is a list of two or more options that are mutually
exclusive and the user must select exactly one choice. In other words, clicking a non-
selected radio button will deselect whatever other button was previously selected in
the list.
✓ Checkboxes are used when there are lists of options and the user may select any
number of choices, including zero, one, or several. In other words, each checkbox is
independent of all other checkboxes in the list, so checking one box doesn't uncheck
the others.
15 Components of Event Handling
Event handling has three main components,
3
✓ Events : An event is a change in state of an object.
✓ Events Source : Event source is an object that generates an event.
✓ Listeners : A listener is an object that listens to the event. A listener gets notified
when an event occurs.
16 How Events are handled in java ?
A source generates an Event and send it to one or more listeners registered with the
source.Once event is received by the listener, they process the event and then return.
Events are supported by a number of Java packages, like java.util, java.awt and
java.awt.event.
17 What is a layout manager and what are different types of layout managers available in
java AWT?
A layout manager is an object that is used to organize components in a container. The
different layouts are available are FlowLayout, BorderLayout, CardLayout, GridLayout
and GridBagLayout.
18 Mention the Differences between AWT and swing
Java AWT Java Swing
AWT components are platform- Java swing components are
dependent. platform-
independent.
AWT components are heavyweight. Swing components are lightweight.
AWT provides less components than Swing provides more powerful
Swing. components such as tables, lists,
scrollpanes, colorchooser,
tabbedpane etc.
AWT doesn't follows MVC Swing follows MVC.
19 What is the difference between scrollbar and scrollpane?
A Scrollbar is a Component, but not a Container whereas Scrollpane is a Conatiner and
handles its own events and perform its own scrolling.
20 What is the use of JButton and mention the constructor of JButton class.
JButton class provides functionality of a button. JButton class has three
constuctors,Button(Iconic),JButton(String str),JButton(String str, Icon ic)
PART –B & C
1 Describe the key aspects of working with color, font, and image in AWT. Provide examples
demonstrating their usage in a graphical application.
2 Illustrate briefly about the working of frames and setting the properties to it.
3 Explain in detail about event classes provided by java.
4 Discuss the benefits of using generic classes in software development. How generic classes
differ from generic method. Give its Restrictions and Limitations.
5 Which steps are must for event handling and what are the models available for event
handling?
6 Explain in detail about generic classes and methods in java with suitable example.
7 Develop a java program that have 11 text fields one submit button. When you press the
4
button first 10 text field’s average has to be displayed in the 11th text field.
8 What is an adapter class? Describe about various adapter classes in detail?
9 Explain the layout managers in Java also describe the concept of menu creation.
10 What is event handling in java? List out the available event classes and listener
interfaces with suitable example