Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

New Microsoft Word Document

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 28

import java.awt.

*;
import java.applet.*;
import javax.swing.*;
public class JPasswordFieldDemo extends Applet (
JLabel l1,l2;
TextField txt1;
PasswordField pass;
JButton b;
public void init(){
11-new JLabel("Enter Username");
12-new JLabel("Enter Password:");
txt1=new JTextField();
pass=new JPasswordField();
pass.setEchoChar('#');
benew JButton("Login");
setLayout(new GridLayout(3.2));
add(l1):
add(txt1);
add(l2);
add(pass);
add(b);
}
}
/* <applet code="JPasswo ordFieldDemo.class" width=300 height=300></applet>*/
import java.awt.*;
import java.applet.";
import javax.swing.*;
import java.awt.event.*;
public class JPassAuth extends Applet implements ActionListener {
JLabel 11,12,13;
JTextField txt1;
JPasswordField pass, pass1;
JButton b;
public void init(){
11=new JLabel("Enter Username:");
12=new JLabel("Enter Password:");
13=new JLabel("Confirm Password:");
txt1=new JTextField();
pass=new JPasswordField();
pass1=new JPasswordField();
b=new JButton("Login");
setLayout(new GridLayout(4,2));
add(l1);
add(txt1);
add(l2);
add(pass);
add(l3);
add(pass1);
add(b);
b.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)(
if(ae.getSource()==b){
String pal pass.getText();
String pa2-pass1.getText();
if(pa1.equals(pa2)){
JOptionPane.showMessageDialog(null, "Successful....!!!!");
}
else
JOptionPane.showMessageDialog(null, "Password not matched.....");
}
};
}
}
/*<applet code="JPassAuth.class" width=300 height=300></applet>*/
import java.awt.*;
import java.applet.*;
import javax.swing.*;
import java.awt.event.*;
public class JPassAuth extends Applet implements ActionListener(
JLabel l1,l2;
JTextField txt1;
JPasswordField pass;
JButton b;
public void init()(
l1=new JLabel("Enter Username:");
l2=new JLabel("Enter Password:");
txt1=new JTextField();
pass=new JPasswordField();
b=new JButton("Login");
setLayout(new GridLayout(4,2));
add(l1);
add(txt1);
add(l2);
add(pass);
//add(l3);
// add(pass1);
add(b);
b.addActionListener(this);
}
public void actionPerformed(ActionEvent ae){
if(ae.getSource()==b)(
String p=pass.getText();
int i=p.length();
if(i>6){
JOptionPane.showMessageDialog(null, "Successful....!!!!");
}
Else
{
JOptionPane showMessageDialog(null, "Password length must be > 6 characters");
}
}
}
}
/*<applet code="JPassAuth.class" width=300 height=300></applet>*/
Import javax.swing.*;
Import java.awt.*;
Import java.awt.event.*;
classwindow Demo extends Frame implements WindowListener
{
windowDemo()
{
setTitle("Window Listener");
setBounds(100,200,200,200);
setVisible(true);
addWindowListener(this);
}
public void window Closing (WindowEvent e)
{
System.out.println("Window Closing");
dispose();
System.exit(0);
}
public void windowOpened (WindowEvent e)
{
System.out.println("Window Open");
}
public void windowClosed (WindowEvent e)
{
System.out.println("Window Close");
}
public void windowActivated (WindowEvent e)
{
System.out.println("Window Activated");
}
public void windowDeactivated (WindowEvent e)
{
System.out.println("Window Deactivated");
}
public void windowIconified(WindowEvent e)
{
System.out.println("Window Iconified");
}
public void windowDeiconified(WindowEvent e)
{
System.out.println("Window Deiconified");
}
public static void main (String[] args)
{
WindowDemo frame new Window Demo(); }
}

Output:-
Run:
Window Activated
Window Iconified
Window Deactivated
Window Deiconified
Window Activated
Window Iconified
Window Deactivated
Window Deiconified
Window Activated
Window Closing
Import java.awt.event.ActionEvent;
Import java.awt.event.ActionListener:
Import javax.swing.*;
public class Outerclass extends JFrame {
public static void main(String args[])
{
Outerclass outer = new Outerclass();
JButton b = new JButton("Dont't click me!");
b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event)
{
System.out.println("Oops!!!");
}
});
outer.add(b);
outer.pack();
outer.setVisible(true);
}
}
import java.net.*;

class URLClassDemo {
public static void main(String[] args) throws MalformedURLException {
URL url = new URL("https://www.facebook.com/");
System.out.println("Protocol: " + url.getProtocol());
System.out.println("Port: " + url.getPort()); // Will return -1 if no explicit port is
specified
System.out.println("Host: " + url.getHost());
System.out.println("File: " + url.getFile());
}
}

/* Output */

Protocol: https
Port: -1
Host: www.facebook.com
File: /
import java.net.*;
import java.io.*;

public class SocketDemo {


public static void main(String[] args) throws UnknownHostException {
try {

Socket socket = new Socket("instagram.com", 80);


System.out.println("Connected to "
+ socket.getInetAddress() + " on port "
+ socket.getPort() + " from port "
+ socket.getLocalPort() + " of "
+ socket.getLocalAddress());

socket.close();

} catch (SocketException e) {
System.out.println("Socket error: " + e);
} catch (IOException e) {
System.out.println("IO error: " + e);
}
}
}

/* Output */

Connected to instagram.com/163.70.140.174 on port 80 from port 51575 of


/192.168.43.243
OddEvenServer.java:
import java.net.*;
import java.io.*;

public class OddEvenServer {


public static void main(String args[])
{
try
{
ServerSocket ss= new ServerSocket(1000);
System.out.println("Searching...");
Socket sss.accept();
BufferedReader br= new BufferedReader(new InputStreamReader (s.getInputStream()));
int n=Integer.parseInt(br.readLine());
OutputStream o=s.getOutputStream();
PrintStream ps=new PrintStream(0);
System.out.println("Checking...");
if(n%2==(0) )
{
ps.println("No is Even");
}
els
{
ps.println("No is Odd");
}
catch(Exception e){}
}
}
OddEvenClient.java:
import java.net.*;
import java.io.*;
public class OddEvenClient {
public static void main(String args[])
{
Try
{
Socket s =new Socket("localhost", 1000);
BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter no: ");
int n = Integer.parseInt(br.readLine());
OutputStream o = s.getOutputStream();
PrintStream ps=new PrintStream(0);
ps.println(n);
BufferedReader br1=new BufferedReader(new InputStreamReader(s.getInputStream()));
int c=br1.read();
while(c!-1){
System.out.println((char)c);
c=br1.read();
}
}
catch(Exception e){}
}
}
Prime_Server.java:
import java.net.*;
import java.io.*;
public class Prime_Server {
public static void main(String args[])
{
try
{
ServerSocket ss= new ServerSocket(1000);
System.out.println("Searching...");
Socket s-ss.accept();
BufferedReader br= new BufferedReader(new InputStreamReader (s.getInputStream())):
int n=Integer.parseInt(br.readLine());
OutputStream o s.getOutputStream();
PrintStream ps-new PrintStream(0);
System.out.println("Checking...");
int i=2;
while(n%i!=0){
i++;
if(i-n){
ps.print("no. is prime");
}
else {
ps.print("no. is not prime");
}
}
catch(Exception e){}
}
}
Prime_Client.java:
import java.net.*;
import java.io.*;
public class Prime_Client {
public static void main(String args[])
{
try
{ Socket s= new Socket("localhost", 1000);
}
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter no: ");
int n = Integer.parseInt(br.readLine());
OutputStream o = s.getOutputStream();
PrintStream ps=new PrintStream(0);
ps.println(n);
BufferedReader br1=new BufferedReader(new InputStreamReader(s.getInputStream())).
int c=brl.read();
while(c!=-1){
System.out.print((char)c);
c=br1.read();
}
}
catch(Exception e){}
}
}
import java.sql.*;
public class Demo_DB81 (
public static void main(String args[]){
Connection con;
Statement st;
ResultSet rs;
try{
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
con-DriverManager.getConnection("jdbc:ucanaccess://D:\\NewDatabase.accdb");
System.out.println("Connection established");
System.out.println("* Records *****");
st=con.createStatement();
System.out.println("Statement Object created");
st.executeUpdate("insert into Student(Rollno, Stud_Name) values (3, 'Sayali')");
System.out.println("one record updated successfully");
rs=st.executeQuery("select * from Student");
while(rs.next()){
System.out.println(rs.getInt("Rollno")+ "\t\t" + rs.getString("Stud_Name"));
}
st.close();
con.close();
}
catch(Exception e){
System.out.println(e.getMessage());
}
}
}
Output:
run:
Connection established
**** Records *****
Statement Object created
one record updated successfully
1 Varun
2 Tirthesh
3 Sayali
BUILD SUCCESSFUL (total time: 1 second)
import java.sql.*;
public class DB_Demo{
public static void main(String args[]}{
Connection con;
Statement st;
ResultSet rs;
Try{
Class.forName("net.ucanaccess.jdbc. Ucanaccess.Driver");
Con=DriverMariager.getConnection("jdbc:ucanaccess://D:\\Mydb.accdb");
System.out.println("Connectioin to database created");
System.out.println("****** records******};
St=con.createStatement();
rs=st.executeQuery("Select* from Student");
while(rs.next()).
System.out.println(rs.getInt("Rollno") + "\t\t" + rs.getString("St_Name")+"\t\t" +
rs.getInt("Percentage"));
}
System.out.println("Recard of those students having percentage greater than 70");
rs=st.executeQuery("Select from Student where Percentage > 70");
while(rs.next()){
System.out.println(rs.getInt("Rollno"] + "\t\t" + rs.getString("St_Name")+ "\t\t"
rs.getInt("Percentage"));
}
st.close();
con.close();
}
catch(Exception e){
System.out.println(e.getMessage());
}
}
}

Output:
run:
Connectioin to database created
****** records
1 Sandhya 86
2 Nikita 78
3 Trupti 65
Record of those students having percentage greater than
1 Sandhya 86
2 Nikita 78
BUILD SUCCESSFUL (total time: 1 second)
import java.sql.*;
public class Demo_DB2 (
public static void main(String args[]){
Connection con;
Statement st;
PreparedStatement pst;
ResultSet rs;
Try{
Class.forName("com.mysql.jdbc.Driver");
Con=DriverManager.getConnection("jdbc:mysql://localhost:3306/MSBTE", " root",");
System.out.println("Connection established");
System.out.println("****Records ****");
st=con.createStatement();
System.out.println("Statement Object created");
pst=con.prepareStatement("insert into Student(Roll_No,Stud_Name) values (?,?)");
pst.setInt(1, 1715810068 );
pst.setString(2, "Nikita");
int i=pst.executeUpdate ();
System.out.println(i+ "\ t record updated successfully");
rs=st.executeQuery("select * from Student");
while(rs.next()){
System.out.println(rs.getInt("Roll_No")+ "\t\t" + rs.getString("Stud_Name"));
st.close();
pst.close();
con.close();
}
catch(Exception e)(
System.out.println(e.getMessage());
}
}
}

Output:
run:
Connection established
**** Records*****
Statement Object created
1 record updated successfully
1715810037 Vaishnavi
1715810041 Jagruti
1715810067 Chetana
1715810068 Nikita
BUILD SUCCESSFUL (total time: 1 second)
import java.sql.*;
blic class Demo_DB3 {
public static void main(String args[]){
Connection con;
Statement st;
PreparedStatement pst;
ResultSet rs;
try{
Class.forName("com.mysql.jdbc.Driver");
Con=DriverManager.getConnection("jdbc:mysql://localhost:3306/MSBTE", "root", "");
System.out.println("Connection established");
System. out.println("****Records ****");
st=con.createStatement();
System.out.println("Statement Object created");
pst=con.prepareStatement("insert into institute(Inst_Name,Inst_Code) values (7,2)");
pst setString(2, "SGDTP KOLAD");
pst.setint(1, 1581);
int i=pst.executeUpdate();
System.out.println(1+ "\t record updated successfully");
rs=st.executeQuery("select * from Institute");
while(rs.next()){
System.out.println(rs.getString("Inst_Name")+ "\t\t" + rs.getInt("Inst_Code "));
}
st.close();
pst.close();
con.close();
}
catch(Exception e){
System.out.println(e.getMessage());
}
}

Output:
run:
Connection established
**** Records *****
Statement Object created
1 record updated successfully
SGDTP KOLAD 1581
BUILD SUCCESSFUL (total time: 1 second)
import java.sql.*;
public class Delete_Demo {
public static void main(String args[]){
Connection con;
Statement st;
PreparedStatement pst;
ResultSet rs;
Try{
Class.forName("net.ucariaccess.jdbc. UcanaccessDriver");
con-DriverManager.getConnection("jdbc:ucanaccess://D:\\MSBTE.accdb");
System.out.println("Connection established");
System.out.println(" Records******");
st=con.createStatement();
System.out.println("Statement Object created");
rs=st.executeQuery("select* from Student");
while(rs.next()){
System.out.println(rs.getint("Roll_No")+ "\t\t" + rs.getString("Stud_Name"));
}
pst=con.prepareStatement("Delete from Student where Stud_Name = 'Nikita");
int i=pst.executeUpdate();
System.out.println(i+ "\t record updated successfully");
rs=st.executeQuery("select * from Student");
while(rs.next()){
System.out.println(rs.getInt("Roll_No")+ "\t\t" + rs.getString("Stud_Name"));
}
st.close();
pst.close();
con.close();
}
catch(Exception e){
System.out.println(e.getMessage());
}
}
}

Output:
run:
Connection established
**** Records*****
Statement Object created
1715810037 Vaishnavi
1715810041 Jagruti
1715810067 Chetana
1715810068 Nikita
1715810069 John

1 record updated successfully


1715810037 Vaishnavi
1715810041 Jagruti
1715810067 Chetana
1715810069 John
BUILD SUCCESSFUL (total time: 1 second)
TRA STATE
import java.sql.*;
public class Update_Demo {
public static void main(String args[]){
Connection con;
Statement st;
PreparedStatement pst;
ResultSet rs;
try{
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
Con=DriverManager.getConnection("jdbc:ucanaccess://D:\\MSBTE.accdb");
Systern.out.println("Connection established");
System.out.println("**** Records ****");
St=con.createStatement();
System.out.println("Statement Object created");
rs=st.executeQuery("select * from Student");
while(rs.next()){
System.out.println(rs.getint("Roll_No")+"\t\t" + rs.getString("Stud_Name"));
}
pst=con.prepareStatement("Update Student set Stud_Name='John' where
Stud_Name='Jack' ");
int i=pst.executeUpdate();
System.out.println(i+"\t record updated successfully");
rs=st.executeQuery("select from Student");
while(rs.next()){
System.out.println(rs.getInt("Roll_No")+ "\t\t" + rs.getString("Stud_Name"));
}
st.close();
pst.close();
con.close();
}
catch(Exception e){
System.out.println(e.getMessage());
}
}
}

Output:
run:
Connection established
**** Records *****
Statement Object created
1715810037 Vaishnavi
1715810041 Jagruti
1715810067 Chetana
1715810068 Nikita
1715810069 Jack

1 record updated successfully


1715810037 Vaishnavi
1715810041 Jagruti
1715810067 Chetana
1715810068 Nikita
1715810069 John
BUILD SUCCESSFUL (total time: 1 second)
import java.sql.*;
public class Product_Demo (
public static void main(String args[]){
Connection con;
Statement st;
PreparedStatement pst;
ResultSet rs;
try{
Class.forName("net.ucanaccess.jdbc. UcanaccessDriver");
Con=DriverManager.getConnection("jdbc:ucanaccess://D:\\MSBTE.accdb");
System.out.println("Connection established");
System.out.println(" **** Records *****");
St=con.createStatement();
System.out.println("Statement Object created");
rs=st.executeQuery("select from Product");
while(rs.next()){
System.out.println(rs.getString("Product_ID")+ "\t\t" + rs.getString("Product_Name")+
\t\t" + rs.getString("Price"));
}
pst=con.prepareStatement("Delete from Product where Price > 500 and
Product_ID='P1234");
int i=pst.executeUpdate();
System.out.println(i+"\t record updated successfully");
rs=st.executeQuery("select from Product");
while(rs.next()){
System.out.printin(rs.getString("Product_ID")+"\t\t" + rs.getString("Product_Name")+ t\
t" + rs.getString("Price"));}
st.close();
pst.close();
con.close();
}
catch(Exception e){
System.out.println(e.getMessage());
}
}
}

Output:
run:
Connection established
*****Records*****
Statement Object created
P1231 Cylinder 850
P1232 Pipe 200
P1233 Burner 500
P1234 Regulator 1200

1 record updated successfully


P1231 Cylinder 850
P1232 Pipe 200
P1233 Burner 500
BUILD SUCCESSFUL (total time: 1 second)

You might also like