1.
a) Implementing Package, inheritances and interfaces
Aim:
To create a java program to implementing package
Algorithm:
Start the program.
Create a class team inside a package name “India “.
Declare the package name in the first statement in your program.
Create a directory and name it as same as package name.
Save it as [Link] and compile the source file, which creates a
classfile in the directory
create another java program import india package and name it as
[Link]
source file and classfiles should be in a directory as specified in
the classpath environment.
stop the program.
1. b) Implementing Inheritances and Interfaces
Aim:
To create a java program to implementing Inheritances and
Interfaces.
Algorithm:
Start the program.
Create two interfaces intface1 and intface2.
Declare necessary variables and methods in interfaces.
Create class Area that implements the interfaces in it.
Define the interfaces methods in class Area.
Create class Demo and extends class Area.
Instantiate object for class Demo and call the methods in class
Area.
Stop the program.
2. Implementing Flow, Border and Grid Layouts
Aim:
To create a java program to implement components Flow,
Border and Grid Layouts.
Algorithm:
Start the program.
import the necessary packages(awt, applet).
Declare applet viewer size in applet code
Dreate a class FBGLayout that extends Applet class
Define init() method
create Grid layout bu using setLayout() method.
In Grid Layout create 3 panels.
Create Flow layout by using setlayout() method and create 4
buttons(flow1, flow2,flow3,flow4), add it in flow layout.
Create Border layout by using setlayout() method and create 4
buttons(north, south,east,west), add it in Border layout.
Create Grid layout by using setlayout() method and create 4
buttons(Grid1, Grid2, Grid3, Grid4), add it in flow layout.
Add all the layouts in panel by using add() method.
Stop the Program.
3. Implementing Dialogs, Menu and Frame
Aim:
To create a java program to implement Dialogs, Menu and
Frame.
Algorithm:
Start the program.
Import necessary packages(swing, awt)
Create a class Menu that implement the ActionListener interface.
Create Frame, MenuBar and TextArea in Menu Constructor.
Create Menu’s file and edit.
Create Menu items Cut, Copy, Paste, Selectall and Exit.
Add Action Listener for all Menu items.
Add Menu items in Menus.
Add Menus in Menubar and Add Menubar and textarea in frame.
Set the frame visible.
Define actionPerformed() method for menu items to perform some
Action events.
Define MessageDiaglog at Exit menu item action event.
Stop the program.
4. Implementing User defined Exception Handling
Aim:
To create a java program to implement User defined Exception
Handling
Algorithm:
Start the program.
Import necessary packages(util)
Create our own Exception class “InvalidAgeException” that
extends the Exception class.
Create UDException class and define validate() method
In validate method checks condition, if it is false throw
exception explicitly.
Call the validate method in try block.
Display the Exception in Catch block.
Stop the program.
5. Implementing Multithreading
Aim:
To create a java program to implement Multithreading.
Algorithm:
Start the program.
Import necessary packages(util, io)
Create class ThreadA that extends Thread class.
In ThreadA class define run method, in run() method call sleep
method.
Create class ThreadB and extends Thread class.
In ThreadB class define run method, in run() method call sleep
method.
Create class Mthread, define main method.
In main() method create object for ThreadA and ThreadB class.
Call start() method by ThreadA and ThreadB objects.
Stop the program.
6. Implementing I/O Stream File handling
Aim:
To create a java program to implement I/O Stream File handling
Algorithm:
Start the program.
Import necessary packages (io).
Create a text file “[Link]” by using FileWriter Class.
Write Some text in [Link] by using write() method.
Close the “[Link]” file.
open the “[Link]” file by using FileReader class.
Print the text from the [Link] file.
Close the “[Link]” File
Stop the program.
7. Implementing a Calculator using Swing
Aim:
To create a java program to implement Calculator using Swing.
Algorithm:
Start the program.
Import necessary packages (swing, awt).
Create a class Calc that implements ActionListener interface.
Declare JFrame, JTextField and JButton.
In Clac() Constructor instantiate objects for Frame, textfield and
buttons.
Set bounds for each buttons.
Add all the buttons and textfield in Frame.
Add Action Listener for all the buttons.
Define actionPerformed() method for Action Events for all
buttons.
Stop the Program.
8. CRUD operation Using JDBC
Aim:
To create a java program to implement CRUD operation Using
JDBC.
Algorithm:
Start the program.
Import necessary packages (sql).
Create class CTT and define main() method.
Create table called student.
Load and register the JDBC driver.
Open a connection to the database.
Create statement object to perform query
Insert values into database by using executeUpdate() method.
Update a row and delete a row in table by using executeUpdate()
method.
Process the resultset.
Close the resultset and statement objects.
Close the connection.
Stop the program.
9. a) Client Server using TCP Socket
Aim:
To create a java program to implement Client Server using TCP
Socket.
Algorithm: (Server)
Start the program.
Import necessary packages (io, net).
ServerSocket object “ss” is created with specified port number using
ServerSocket constructor.
The accept() method is invoked by using ServerSocket object ss, This
method is listening for incoming client request.
For writing data to socket OutputStream and DataOutputStream is
declared.
Invoke wireInt() method by DataOutputStream to pass value to client.
After the value has been sent to the client the server terminates its
execution.
stop the program.
Algorithm: (Client)
Start the program.
Import necessary packages(io, net).
Socket object “s” is created using Socket constructor by passing
server and port values to connect with server.
For reading data from socket InputStream anf DataInputStream are
declared.
Read the incoming value from server by using object of
DataInputStream “dis”.
Invoke readInt() method by using DataInputStream object is used to
read data from the Server Socket
The Result will be display and the client terminates.
stop the program.
9. b) Client Server using UDP Socket
Aim:
To create a java program to implement Client Server using UDP
Socket.
Algorithm: (Server)
Start the program.
Import necessary packages (io, net).
The Datagram Socket object ds is created to listen for incoming client
request on port number 4444.
byte type array variable buffer has been declared.
the while loop with the Boolean value true makes the server run
continuously.
The receive method and getData() methods are invoked to receive the
data.
After receive the data from client display the data and server get
ready for another client request from the same program.
Stop the program.
Algorithm: (Client)
Start the program.
Import necessary packages(io, net).
Declare local host ip address “[Link]” in InetAddress object “ia”.
Assign port value as 4444.
Declare byte type array variable buffer and sore the string value in it
by using getBytes() method.
Create object for DatagramPacket “dp” by passing buffer,port and ia.
Invoke send() method by using datagram socket object and pass the
DatagramPacket to server.
when the datagram packet is received by server it displays the data
and the connection is terminate automatically.
Stop the program
10. GUI application with JDBC
Aim:
To create a java program to implement GUI application with JDBC.
Algorithm:
Start the program.
Import necessary packages (awt, sql, swing).
Create a class JDBCSwing that implements ActionListener interface.
Create Label, TextField, Button, Frame and Panel.
Add ActionListener to all fields.
In try block load and register the JDBC driver.
Open a Connection to the database.
create a statement object to perform a query.
Execute the statement object and return a query resultset.
process the resultset.
close the resultset and statement object.
close the connection.
stop the program.