A JP Prac Answers
A JP Prac Answers
setMenuBar(menuBar);
}
}
import java.net.*;
public class ProtocolPortFile {
public static void main(String[] args) throws Exception {
URL url = new URL("http://www.msbte.com");
System.out.println("Protocol: " + url.getProtocol());
System.out.println("Port: " + url.getPort());
System.out.println("File: " + url.getFile());
}
}
8. Develop a Program to send a password through client to server and
server will send the message to the client that the password is valid or
invalid using UDP.:
Server Code:
import java.net.*;
public class UDPServer {
public static void main(String[] args) throws Exception {
DatagramSocket socket = new DatagramSocket(9876);
byte[] receiveData = new byte[1024];
DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
socket.receive(receivePacket);
String password = new String(receivePacket.getData(), 0, receivePacket.getLength());
if (password.equals("password123")) {
System.out.println("Valid password");
} else {
System.out.println("Invalid password");
}
socket.close();
}
}
Client Code:
import java.net.*;
public class UDPClient {
public static void main(String[] args) throws Exception {
DatagramSocket socket = new DatagramSocket();
InetAddress serverAddress = InetAddress.getByName("localhost");
String password = "password123";
DatagramPacket sendPacket = new DatagramPacket(password.getBytes(), password.length(),
serverAddress, 9876);
socket.send(sendPacket);
socket.close();
}
}
import java.sql.*;
public class InsertRecord {
public static void main(String[] args) throws Exception {
Connection conn = DriverManager.getConnection(“jdbc:ucanaccess://emp.accdb");
Statement stmt = conn.createStatement();
String sql = "INSERT INTO StudTable (rollno, name) VALUES (1, 'John')";
stmt.executeUpdate(sql);
conn.close();
}
}
import java.sql.*;
public class UpdateRecord {
public static void main(String[] args) throws Exception {
Connection conn = DriverManager.getConnection(“jdbc:ucanaccess://emp.accdb");
Statement stmt = conn.createStatement();
String sql = "UPDATE StudTable SET name = 'John' WHERE rollno = 2";
stmt.executeUpdate(sql);
conn.close();
}
}
import javax.swing.*;
public class TabbedPaneExample {
public static void main(String[] args) {
JFrame frame = new JFrame("Tabbed Pane Example");
JTabbedPane tabbedPane = new JTabbedPane();
frame.add(tabbedPane);
frame.setSize(300, 200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("Button clicked!");
}
});
frame.add(button);
frame.setSize(200, 100);
frame.setVisible(true);
}
}
choice.add("Option 1");
choice.add("Option 2");
choice.add("Option 3");
choice.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
System.out.println("Item selected: " + choice.getSelectedItem());
}
});
frame.add(choice);
frame.setSize(200, 100);
frame.setVisible(true);
}
}
23.Design applet with Breakfast, Lunch, and Dinner choices and total
bill calculation:
add(option1);
add(option2);
add(option3);
}
}
group.add(rb1);
group.add(rb2);
group.add(rb3);
add(rb1);
add(rb2);
add(rb3);
setSize(200, 150);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}