Q.1.
Advanced Java:
A)
Write a JSP script to validate given E-Mail ID.
Answer :
<%@ page language="java" %>
<%
String email = request.getParameter("email"); //
retrieve email from form data
String regex = "^[\\w-\\.]+@([\\w-]+\\.)+[\\w-]{2,4}$"; // regular expression for email validation
if (email.matches(regex)) {
out.println("Valid
email address"); // if email matches the regex, print "Valid email
address"
} else {
out.println("Invalid
email address"); // if email does not match the regex, print "Invalid email
address"
}
%>
B)
Write a Multithreading program in java to display the number’s between 1 to 100
continuously in a TextField by clicking on button. (use Runnable Interface).
Answer :
import java.awt.event.*;
import javax.swing.*;
class alpha extends Thread {
public void run() {
System.out.println("********* java program using
multithreading *********");
}
}
public class Slip7B {
public static void main(String[] args) {
alpha a1 = new alpha();
System.out.print(a1);
JFrame f = new JFrame("Slip7B");
final JTextField tf = new JTextField();
tf.setBounds(50, 50, 150, 20);
JButton b = new JButton("Display");
b.setBounds(50, 100, 95, 30);
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
for(int i=0; i<=100; i++){
tf.setText("Enter String"+ i);
}
a1.start();
}
});
f.add(b);
f.add(tf);
f.setSize(400, 400);
f.setLayout(null);
f.setVisible(true);
}
}
No comments:
Post a Comment