ADVANCEJAVA
ADVANCEJAVA
ADVANCEJAVA
import java.io.*;
import java.net.*;
try {
} catch (IOException e) {
e.printStackTrace();
import java.io.*;
import java.net.*;
try {
Socket clientSocket = new Socket("localhost", 5000); // create a client socket object and connect
to server
} catch (IOException e) {
e.printStackTrace();
OUTPUT:
Client: Hello
Client: Bye
2)
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public JListExample() {
super("JList Example");
String[] items = {"Item 1", "Item 2", "Item 3", "Item 4", "Item 5"};
sourceList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
targetList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
targetList.setModel(new DefaultListModel<String>());
copyButton.addActionListener(new ActionListener() {
selectedItems[i] = (String)sourceList.getModel().getElementAt(selectedIndices[i]);
targetListModel.addElement(item);
});
sourcePanel.setBorder(BorderFactory.createTitledBorder("Source"));
targetPanel.setBorder(BorderFactory.createTitledBorder("Target"));
buttonPanel.add(copyButton);
mainPanel.add(sourcePanel);
mainPanel.add(targetPanel);
mainPanel.add(buttonPanel);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setContentPane(mainPanel);
setSize(400, 300);
setVisible(true);
new JListExample();
OUTPUT:
+----------------+----------------+--------+
| | | |
| | | |
|----------------+----------------+--------|
| |
| Item 1 |
| Item 2 |
| Item 3 |
| Item 4 |
| Item 5 |
| |
+----------------------------------------+
3)
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public StudentDatabase() {
super("Student Database");
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public EmployeeDatabaseApp() {
super("Employee Database Application");
@Override
public void actionPerformed(ActionEvent e) {
// Handle button clicks
if (e.getSource() == addButton) {
addEmployee();
} else if (e.getSource() == updateButton) {
updateEmployee();
} else if (e.getSource() == deleteButton) {
deleteEmployee();
}
}
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
create a server program that binds an instance of the AdderImpl class to the RMI
registry:
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
6)
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/login")
public class LoginServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
7)
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
@WebServlet("/sessioninfo")
public class SessionInfoServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
if (session != null) {
// Check which button was clicked
String action = request.getParameter("exit");
if (action != null) {
// Invalidate the session and create a new one
session.invalidate();
session = request.getSession(true);
}
}
8)
9)