Java Programming-Unit 4
Java Programming-Unit 4
Java Programming-Unit 4
IVth Semester
CIC-212
1. The java.io package contains nearly every class you might ever
need to perform input and output (I/O) in Java
2. All these streams represent an input source and an output
destination
3. The stream in the java.io package supports many data such as
primitives, Object, localized characters, etc.
4. A stream can be defined as a sequence of data
5. The InputStream is used to read data from a source and the
OutputStream is used for writing data to a destination
ArrayList LinkedList
1) ArrayList internally uses dynamic array to LinkedList internally uses doubly linked list to
store the elements. store the elements.
2) Manipulation with ArrayList is slow because Manipulation with LinkedList is faster than
it internally uses array. If any element is ArrayList because it uses doubly linked list so
removed from the array, all the bits are shifted no bit shifting is required in memory.
in memory.
3) ArrayList class can act as a list only because LinkedList class can act as a list and
it implements List only. queue both because it implements List and
Deque interfaces.
4) ArrayList is better for storing and LinkedList is better for manipulating data.
accessing data.of COMPUTER SCIENCE & ENGINEERING, BVCOE New Delhi
Department
List Interface
1. Event is the change in the state of the object or source. Events are
generated as result of user interaction with the graphical user interface
components. For example, clicking on a button, moving the mouse,
entering a character through keyboard, selecting an item from list, scrolling
the page are the activities that causes an event to happen.
2. Event Handling is the mechanism that controls the event and decides what
should happen if an event occurs. This mechanism have the code which is
known as event handler that is executed when an event occurs. Java Uses
the Delegation Event Model to handle the events. This model defines the
standard mechanism to generate and handle the events
ActionListener Example - This interface is used to handle the events caused by sources like Buttons, Menu Items, Enter Keys and Double Click of Mouse. When you
implements ActionListener Interface following methods needs to be override. public void actionPerformed(ActionEvent ae) - Example
ItemListener Example - Used for Radio Button, List, Choice and Check
Box AWT Controls. The method that needs to be override is as follows: public
void itemStateChanged(ItemEvent e) – Example
Example