java unit 3 and 4
java unit 3 and 4
automatically closing a file, using the character-based streams, File I/O using character streams (using a File
Writer and using a File Reader)
Multi-threaded programming: Multithreading fundamentals, Thread class, and Runnable interface, the
life cycle of thread, creation of single and multiple threads, implementation of Thread methods,
Synchronization (using Synchronized methods, synchronized statement).
UNIT – IV
No. of Hours: 10 Chapter/Book Reference: TB1 [Chapters – 17, 18]
Swings Fundamentals: Components (JLabel and ImageIcon, using swing Buttons (JButton, JToggleButton,
JCheckBox, JRadioButton), JTextField, JScrollPane, JList, JComboBox) and Containers, Layout managers,
event delegation Model, event handling (event sources, event listeners, event classes and interfaces, adapter
classes).
JDBC: JDBC Architecture, JDBC Drivers, Connection, Statement, Prepared Statement, Result set, Connecting to
the Database using JDBC.
Layout manager
The LayoutManagers are used to arrange components in a particular manner.
The Java LayoutManagers facilitates us to control the positioning and size of
the components in GUI forms.
LayoutManager is an interface that is implemented by all the classes of layout
managers.
FlowLayout
BorderLayout
The BorderLayout is used to arrange the components in five regions:
north, south, east, west, and center. Each region (area) may contain one
component only. It is the default layout of a frame or window.
GridLayout
Advantages of threads
1. We can execute multiple tasks of an application at a time
2. Reduces the complexity of a big applications
3. Helps to improve the performance of an application drastically
4. Utilizes the max resources of multiprocessor systems
5. Better user interface in case of GUI based applications
6. Reduces the development time of an application
7. All the threads are independent , any unexpected exception happens in
any of the thread will not lead to an application exit.
Disadvantages of threads
1. Thread synchronization is an extra over head to the developers
2. Shares the common data across the threads might cause the data
inconsistency or thread sync issues
3. Threads blocking for resources is more common problem
4. Difficult in managing the code in terms of debugging or writing the
code
q.complete life cycle of a thread
New − A new thread begins its life cycle in the new state. It remains in this state until the program
starts the thread. It is also referred to as a born thread.
Runnable − After a newly born thread is started, the thread becomes runnable. A thread in this state
is considered to be executing its task.
Waiting − Sometimes, a thread transitions to the waiting state while the thread waits for another
thread to perform a task. A thread transitions back to the runnable state only when another thread
signals the waiting thread to continue executing.
Timed Waiting − A runnable thread can enter the timed waiting state for a specified interval of time.
A thread in this state transitions back to the runnable state when that time interval expires or when
the event it is waiting for occurs.
Terminated (Dead) − A runnable thread enters the terminated state when it completes its task or
otherwise terminates.
Byte stream is used to read and write a single byte (8 bits) of data.
All byte stream classes are derived from base abstract classes
called InputStream and OutputStream .
All the character stream classes are derived from base abstract
classes Reader and Writer .