SlideShare une entreprise Scribd logo
1  sur  32
Télécharger pour lire hors ligne
INDEX
Sr. No. Program Remarks
1.
Write a program on Multithreading
2.
Write a program on Input/output Stream
3. Write a program on Interfaces
4. Write a program on Applet
5. Write a program on SWING Application
6. Write a program on JDBC
7. Write a program on Servlets
8.
Write a program on JSP
9.
Write a program on Sending E-Mail
10.
Write a program on Implementing RMI
Program No1: Write a program on Multithreading
import java.io.*;
class a implements Runnable
{
Thread t;
a()
{
t=new Thread(this, "thread1");
t.start();
}
public void run(){
try{
System.out.println("Manish");
Thread.sleep(1000);
}
catch(Exception ex){
}
}
}
class thread1{
public static void main(String arg[]){
try{
for(int i=0;i<=5;i++)
{
new a();
Thread.sleep(500);
System.out.println("Jain");
}
}
catch(Exception ex)
{
}
}
}
OUTPUT:-
Program No2: Write a program on Input/output
Stream
import java.io.*;
class inputoutput{
public static void main(String args[])
throws IOException
{
char c;
BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
System.out.println("Enter characters, 'q' to quit.");
do
{
c = (char) br.read();
System.out.println(c);
}
while(c != 'q');
}
}
OUTPUT:-
Program No3: Write a program on Interfaces
import java.io.*;
class student
{
int roll;
void get(int r)
{
roll=r;
}
void disp()
{
System.out.println("Roll no."+roll);
}
}
class test extends student
{
float t1,t2,t3;
void gettest(float a,float b,float c)
{
t1=a;
t2=b;
t3=c;
}
void distest()
{
System.out.println("Test 1:"+t1);
System.out.println("Test 2:"+t2);
System.out.println("Test 3:"+t3);
}
}
class program extends test
{
float p1,p2;
void getprac(float a,float b)
{
p1=a;
p2=b;
}
void disprac()
{
System.out.println("Program 1:"+p1);
System.out.println("Program 2:"+p2);
}
}
interface sport
{
float spwt=6.0f;
public void dispwt();
}
class Result extends program implements sport
{
float total;
public void dispwt()
{
System.out.println("Sport weightage:"+spwt);
}
void distotal()
{
total=t1+t2+t3+p1+p2+spwt;
disp();
distest();
disprac();
dispwt();
System.out.println("Total Result:"+total);
}
}
public class Marks
{
public static void main(String args[])
{
Result r=new Result();
r.get(150);
r.gettest(80,85,89);
r.getprac(45,49);
r.distotal();
}
}
OUTPUT:-
Program No4: Write a program on Applet
import java.applet.*;
import java.awt.*;
/*<applet Code="face.class" Width=600 Height=600>
</applet>*/
public class face extends Applet
{
public void paint(Graphics g)
{
g.drawString("Applet Program",250,50);
g.drawOval(200,100,200,200);
g.fillOval(250,150,30,20);
g.fillOval(320,150,30,20);
g.drawLine(299,150,299,225);
g.drawArc(274,200,50,50,210,120);
}
}
OUTPUT:-
Program No 5: Write a program on SWING
Application
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Main1 extends JApplet implements ActionListener
{
JRadioButton r1,r2;
String msg="";
JButton b;
JTextField t1,t2;
ButtonGroup bg;
public void init()
{
getContentPane().setLayout(new FlowLayout());
JLabel l1=new JLabel("Enter Name");
t1=new JTextField(10);
t2=new JTextField(25);
t2.setEditable(false);
b=new JButton("Display");
r1=new JRadioButton("Male");
r2=new JRadioButton("Female");
bg=new ButtonGroup();
bg.add(r1); bg.add(r2);
getContentPane().add(l1);
getContentPane().add(t1);
getContentPane().add(r1);
getContentPane().add(r2);
getContentPane().add(b);
getContentPane().add(t2);
b.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
msg="Hello ";
if(r1.isSelected())
msg=msg+"Mr. "+t1.getText();
else
msg=msg+"Ms. "+t1.getText();
t2.setText(msg);
}
}
OUTPUT:
Program No 6: Write a program on JDBC
import java.io.*;
import java.sql.*;
import java.awt.*;
import java.awt.event.*;
class jdbc extends Frame implements ActionListener,WindowListener
{
Label l1,l2,l3;
TextField t1,t2,t3;
Button b1,b2,b3;
Connection con;
Statement st;
jdbc()
{
addWindowListener(this);
l1=new Label("Emp_ID");
l2=new Label("Name");
l3=new Label("Salary");
t1=new TextField("");
t2=new TextField("");
t3=new TextField("");
b1=new Button("Save");
b2=new Button("Search");
b3=new Button("Delete");
setLayout(null);
l1.setBounds(100,100,100,30);
l2.setBounds(100,130,100,30);
l3.setBounds(100,160,100,30);
t1.setBounds(200,100,100,30);
t2.setBounds(200,130,100,30);
t3.setBounds(200,160,100,30);
b1.setBounds(100,190,50,30);
b2.setBounds(150,190,50,30);
b3.setBounds(200,190,50,30);
add(l1);
add(l2);
add(l3);
add(t1);
add(t2);
add(t3);
add(b1);
add(b2);
add(b3);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Driver Loaded");
con=DriverManager.getConnection("jdbc:odbc:emp");
System.out.println("Connected");
st=con.createStatement();
}
catch(Exception ex)
{
System.out.println("Doesn't Exist");
}
}
public void windowClosed(WindowEvent we)
{
}
public void windowOpened(WindowEvent we)
{
}
public void windowClosing(WindowEvent we)
{
System.exit(0);
}
public void windowActivated(WindowEvent we)
{
}
public void windowDeactivated(WindowEvent we)
{
}
public void windowIconified(WindowEvent we)
{
}
public void windowDeiconified(WindowEvent we)
{
}
public void actionPerformed(ActionEvent ae)
{
try
{
if(ae.getSource()==b1)
{
st.execute("Insert into emp
values("+t1.getText()+",'"+t2.getText()+"',"+t3.getText()+")");
t1.setText("");
t2.setText("");
t3.setText("");
}
if(ae.getSource()==b2)
{
ResultSet rs=st.executeQuery("Select * from emp where
emp_id="+t1.getText()+"");
if(rs.next())
{
t1.setText(rs.getString(1));
t2.setText(rs.getString(2));
t3.setText(rs.getString(3));
}
}
if(ae.getSource()==b3)
{
st.execute("Delete from emp where emp_id="+t1.getText()+"");
t1.setText("");
t2.setText("");
t3.setText("");
}
}
catch(Exception ex)
{
}
}
public static void main(String arg[])
{
jdbc j=new jdbc();
j.setTitle("Program No.:-1");
j.setSize(500,500);
j.setVisible(true);
}
}
OUTPUT:-
Program No 7: Write a program on Servlets
HTML CODE:-
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-
8">
</head>
<body bgcolor="white" text="black">
<script>
function va()
{
if(form1.username.value=="")
{
alert("Error");
return false;
}
if(form1.username.value.length<6)
{
alert("Error");
return false;
}
if(form1.email.value.indexOf("@")==-1)
{
alert("Invalid id");
return false;
}
return true;
}
</script>
<form name="form1"
action="http://localhost:8080/servlet/NewServlet" onsubmit="return
va();">
<table border="0" align="center">
<thead><tr>
<th>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&
nbsp;&nbsp;&nbsp;&nbsp;<u>Servlet</u></th>
<th></th></tr>
</thead>
<tbody>
<tr><br><br><td>Username</td>
<td><input type="text" name="username" value=""
/></td></tr>
<tr><td>Email-Id</td>
<td><input type="text" name="email" value=""
/></td></tr>
<tr><td>City</td>
<td><input type="text" name="city" value="" /></td></tr>
<tr><td>State</td>
<td><input type="text" name="state" value="" /></td></tr>
<tr><td></td>
<td><input type="submit" value="SUBMIT"/></td></tr>
</tbody>
</table>
</form>
</body>
</html>
JAVA CODE:-
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class NewServlet extends HttpServlet {
protected void processRequest(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
out.print("<br><br><center>");
String username=request.getParameter("username");
out.println("Username="+username+"<br>");
String email=request.getParameter("email");
out.println("Email-id="+email+"<br>");
String city=request.getParameter("city");
out.println("City="+city+"<br>");
String state=request.getParameter("state");
out.println("State="+state+"<br>");
out.print("</center>");
} finally {
out.close();
}
}
@Override
protected void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
@Override
protected void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
@Override
public String getServletInfo() {
return "Short description";
}
}
OUTPUT:-
Program No 8: Write a program on JSP
<%@ page language="java"%>
<html>
<head>
<title>Even number program in JSP</title>
</head>
<body>
<%
for(int i=0;i<=20;i++)
{
if((i%2)==0)
{
out.print("<center>");
out.print("Even number :"+i);
out.print("<br></center>");
}
}
%>
</body>
</html>
OUTPUT:-
Program NO 9: Write a program on Sending E-Mail
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
class MailTestFrame extends JFrame
{
private JTextArea msg, comm;
private JTextField sr,fr,to;
JButton sd;
private Scanner in;
private PrintWriter out;
public MailTestFrame()
{
setSize(300,300);
setTitle("Mail Test");
getContentPane().setLayout(new FlowLayout());
JLabel l1=new JLabel("From: ");
fr=new JTextField(21);
JLabel l2=new JLabel("To:");
to=new JTextField(22);
JLabel l3=new JLabel("SMTP server:");
sr=new JTextField(17);
msg=new JTextArea("",5,10);
JScrollPane sp1=new JScrollPane(msg);
comm=new JTextArea("Mail From", 5, 10);
JScrollPane sp2=new JScrollPane(comm);
sd = new JButton("Send");
getContentPane().add(l1);
getContentPane().add(fr);
getContentPane().add(l2);
getContentPane().add(to);
getContentPane().add(l3);
getContentPane().add(sr);
getContentPane().add(sp1);
getContentPane().add(sp2);
getContentPane().add(sd);
sd.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
new Thread(new Runnable()
{
public void run()
{
comm.setText("");
sendmail();
}
}).start();
}
});
}
public void sendmail()
{
try
{
Socket s=new Socket(sr.getText(),25);
InputStream ins=s.getInputStream();
OutputStream outs=s.getOutputStream();
in=new Scanner(ins);
out=new PrintWriter(outs,true);
String host=InetAddress.getLocalHost().getHostName();
receive();
send("Hello "+host);
receive();
send("MAIL FROM:<"+fr.getText()+">");
receive();
send("RCPT TO:<"+to.getText()+">");
receive();
send("DATA");
receive();
send(msg.getText());
receive();
s.close();
}
catch(IOException e)
{
comm.append("Error: "+e);
}
}
public void send(String str)throws IOException
{
comm.append(str);
comm.append("n");
out.print(str.replaceAll("n", "rn"));
out.flush();
}
public void receive()throws IOException
{
if(in.hasNextLine())
{
String l=in.nextLine();
comm.append(l);
comm.append("n");
}
}
}
public class MailText
{
public static void main(String[] args)
{
JFrame f =new MailTestFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
}
OUTPUT:
Program No10: Write a program on Implementing
RMI
Client Program:
import java.io.*;
import java.rmi.*;
public class NormalClient
{ public static void main(String[] arg)
{
String IpName,FileName,Ip;
StackInter DataObject;
byte[] Content;
try { BufferedReader Buffer=new BufferedReader(new
InputStreamReader(System.in));
System.out.println("Enter the Ip Address :");
IpName = Buffer.readLine();
System.out.println("Enter the File Name :");
FileName = Buffer.readLine();
Ip="rmi://"+IpName+"/hai";
DataObject=(StackInter)Naming.lookup(Ip);
Content = DataObject.st(FileName);
File Fn=new File(FileName);
BufferedOutputStream OutFile=new
BufferedOutputStream(new
FileOutputStream(Fn.getName()));
OutFile.write(Content,0,Content.length);
OutFile.flush();
OutFile.close();
}
catch(Exception e){}
}}
Implementation Program:
import java.rmi.*;
import java.rmi.server.*;
import java.io.*;
public class StackImpl extends UnicastRemoteObject implements
StackInter
{
public StackImpl() throws RemoteException {}
public byte[] st(String str) throws RemoteException
{
File f=new File(str);
byte b[]=new byte[(int)f.length()];
try
{
BufferedInputStream f1= new
BufferedInputStream(new FileInputStream(f));
f1.read(b,0,b.length);
f1.close();
}
catch(Exception e) { }
return (b);
}
}
Interface:
import java.rmi.*;
public interface StackInter extends Remote
{
byte[] st(String str)throws RemoteException;
}
Server Program:
import java.rmi.*;
public class StackServer
{
public static void main(String arg[])
{
try
{
StackImpl im=new StackImpl();
Naming.rebind("hai",im);
}
catch(Exception e)
{
System.out.println(e);
}
}
}
OUTPUT of SERVER file:
java.rmi.ConnectException: Connection refused to host: 127.0.0.1; nested
exception is: java.net.ConnectException: Connection refused: connect
OUTPUT of CLIENT file :
Enter the Ip Address :
127.0.0.1:1052
Enter the File Name :
lok.txt

Contenu connexe

Tendances

Fee managment system
Fee managment systemFee managment system
Fee managment systemfairy9912
 
Java Simple Programs
Java Simple ProgramsJava Simple Programs
Java Simple ProgramsUpender Upr
 
Java programming lab manual
Java programming lab manualJava programming lab manual
Java programming lab manualsameer farooq
 
Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...Mario Fusco
 
Final JAVA Practical of BCA SEM-5.
Final JAVA Practical of BCA SEM-5.Final JAVA Practical of BCA SEM-5.
Final JAVA Practical of BCA SEM-5.Nishan Barot
 
If You Think You Can Stay Away from Functional Programming, You Are Wrong
If You Think You Can Stay Away from Functional Programming, You Are WrongIf You Think You Can Stay Away from Functional Programming, You Are Wrong
If You Think You Can Stay Away from Functional Programming, You Are WrongMario Fusco
 
Java simple programs
Java simple programsJava simple programs
Java simple programsVEERA RAGAVAN
 
Scala - where objects and functions meet
Scala - where objects and functions meetScala - where objects and functions meet
Scala - where objects and functions meetMario Fusco
 
Talk - Query monad
Talk - Query monad Talk - Query monad
Talk - Query monad Fabernovel
 
Advanced Java - Praticals
Advanced Java - PraticalsAdvanced Java - Praticals
Advanced Java - PraticalsFahad Shaikh
 
Python functions
Python functionsPython functions
Python functionsToniyaP1
 
The Ring programming language version 1.6 book - Part 184 of 189
The Ring programming language version 1.6 book - Part 184 of 189The Ring programming language version 1.6 book - Part 184 of 189
The Ring programming language version 1.6 book - Part 184 of 189Mahmoud Samir Fayed
 

Tendances (20)

Why Learn Python?
Why Learn Python?Why Learn Python?
Why Learn Python?
 
Java Lab Manual
Java Lab ManualJava Lab Manual
Java Lab Manual
 
Fee managment system
Fee managment systemFee managment system
Fee managment system
 
Java Simple Programs
Java Simple ProgramsJava Simple Programs
Java Simple Programs
 
Java programming lab manual
Java programming lab manualJava programming lab manual
Java programming lab manual
 
Generics
GenericsGenerics
Generics
 
CS2309 JAVA LAB MANUAL
CS2309 JAVA LAB MANUALCS2309 JAVA LAB MANUAL
CS2309 JAVA LAB MANUAL
 
Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...
 
TechTalk - Dotnet
TechTalk - DotnetTechTalk - Dotnet
TechTalk - Dotnet
 
Final JAVA Practical of BCA SEM-5.
Final JAVA Practical of BCA SEM-5.Final JAVA Practical of BCA SEM-5.
Final JAVA Practical of BCA SEM-5.
 
If You Think You Can Stay Away from Functional Programming, You Are Wrong
If You Think You Can Stay Away from Functional Programming, You Are WrongIf You Think You Can Stay Away from Functional Programming, You Are Wrong
If You Think You Can Stay Away from Functional Programming, You Are Wrong
 
Java simple programs
Java simple programsJava simple programs
Java simple programs
 
Scala - where objects and functions meet
Scala - where objects and functions meetScala - where objects and functions meet
Scala - where objects and functions meet
 
Unit Testing with Foq
Unit Testing with FoqUnit Testing with Foq
Unit Testing with Foq
 
Awt
AwtAwt
Awt
 
Talk - Query monad
Talk - Query monad Talk - Query monad
Talk - Query monad
 
Java and j2ee_lab-manual
Java and j2ee_lab-manualJava and j2ee_lab-manual
Java and j2ee_lab-manual
 
Advanced Java - Praticals
Advanced Java - PraticalsAdvanced Java - Praticals
Advanced Java - Praticals
 
Python functions
Python functionsPython functions
Python functions
 
The Ring programming language version 1.6 book - Part 184 of 189
The Ring programming language version 1.6 book - Part 184 of 189The Ring programming language version 1.6 book - Part 184 of 189
The Ring programming language version 1.6 book - Part 184 of 189
 

En vedette

Matlab practical file
Matlab practical fileMatlab practical file
Matlab practical fileArchita Misra
 
C++ neural networks and fuzzy logic
C++ neural networks and fuzzy logicC++ neural networks and fuzzy logic
C++ neural networks and fuzzy logicJamerson Ramos
 
Artificial Neural Network Lecture 6- Associative Memories & Discrete Hopfield...
Artificial Neural Network Lecture 6- Associative Memories & Discrete Hopfield...Artificial Neural Network Lecture 6- Associative Memories & Discrete Hopfield...
Artificial Neural Network Lecture 6- Associative Memories & Discrete Hopfield...Mohammed Bennamoun
 
Introduction to Neural networks (under graduate course) Lecture 8 of 9
Introduction to Neural networks (under graduate course) Lecture 8 of 9Introduction to Neural networks (under graduate course) Lecture 8 of 9
Introduction to Neural networks (under graduate course) Lecture 8 of 9Randa Elanwar
 
Compiler Design File
Compiler Design FileCompiler Design File
Compiler Design FileArchita Misra
 
Introduction to Neural networks (under graduate course) Lecture 7 of 9
Introduction to Neural networks (under graduate course) Lecture 7 of 9Introduction to Neural networks (under graduate course) Lecture 7 of 9
Introduction to Neural networks (under graduate course) Lecture 7 of 9Randa Elanwar
 
Dynamics 6th ed meriam solution
Dynamics 6th ed meriam solutionDynamics 6th ed meriam solution
Dynamics 6th ed meriam solutionfitsum2020
 
System Analysis and Design
System Analysis and DesignSystem Analysis and Design
System Analysis and DesignAamir Abbas
 
Core Java Slides
Core Java SlidesCore Java Slides
Core Java SlidesVinit Vyas
 

En vedette (12)

Dbms file
Dbms fileDbms file
Dbms file
 
Matlab practical file
Matlab practical fileMatlab practical file
Matlab practical file
 
C++ neural networks and fuzzy logic
C++ neural networks and fuzzy logicC++ neural networks and fuzzy logic
C++ neural networks and fuzzy logic
 
Artificial Neural Network Lecture 6- Associative Memories & Discrete Hopfield...
Artificial Neural Network Lecture 6- Associative Memories & Discrete Hopfield...Artificial Neural Network Lecture 6- Associative Memories & Discrete Hopfield...
Artificial Neural Network Lecture 6- Associative Memories & Discrete Hopfield...
 
Introduction to Neural networks (under graduate course) Lecture 8 of 9
Introduction to Neural networks (under graduate course) Lecture 8 of 9Introduction to Neural networks (under graduate course) Lecture 8 of 9
Introduction to Neural networks (under graduate course) Lecture 8 of 9
 
Compiler Design File
Compiler Design FileCompiler Design File
Compiler Design File
 
Introduction to Neural networks (under graduate course) Lecture 7 of 9
Introduction to Neural networks (under graduate course) Lecture 7 of 9Introduction to Neural networks (under graduate course) Lecture 7 of 9
Introduction to Neural networks (under graduate course) Lecture 7 of 9
 
Compiler design lab programs
Compiler design lab programs Compiler design lab programs
Compiler design lab programs
 
Dynamics 6th ed meriam solution
Dynamics 6th ed meriam solutionDynamics 6th ed meriam solution
Dynamics 6th ed meriam solution
 
Core java slides
Core java slidesCore java slides
Core java slides
 
System Analysis and Design
System Analysis and DesignSystem Analysis and Design
System Analysis and Design
 
Core Java Slides
Core Java SlidesCore Java Slides
Core Java Slides
 

Similaire à Java File

Advanced Java - Practical File
Advanced Java - Practical FileAdvanced Java - Practical File
Advanced Java - Practical FileFahad Shaikh
 
AJP Practical Questions with Solution.docx
AJP Practical Questions with Solution.docxAJP Practical Questions with Solution.docx
AJP Practical Questions with Solution.docxRenuDeshmukh5
 
code for quiz in my sql
code for quiz  in my sql code for quiz  in my sql
code for quiz in my sql JOYITAKUNDU1
 
• GUI design using drag and drop feature of IDE(Net beans), • File IO
•	GUI design using drag and drop feature of IDE(Net beans), •	File IO•	GUI design using drag and drop feature of IDE(Net beans), •	File IO
• GUI design using drag and drop feature of IDE(Net beans), • File IOSyedShahroseSohail
 
Simulado java se 7 programmer
Simulado java se 7 programmerSimulado java se 7 programmer
Simulado java se 7 programmerMiguel Vilaca
 
Modern technologies in data science
Modern technologies in data science Modern technologies in data science
Modern technologies in data science Chucheng Hsieh
 
Python GTK (Hacking Camp)
Python GTK (Hacking Camp)Python GTK (Hacking Camp)
Python GTK (Hacking Camp)Yuren Ju
 
The Ring programming language version 1.9 book - Part 99 of 210
The Ring programming language version 1.9 book - Part 99 of 210The Ring programming language version 1.9 book - Part 99 of 210
The Ring programming language version 1.9 book - Part 99 of 210Mahmoud Samir Fayed
 
The Ring programming language version 1.3 book - Part 83 of 88
The Ring programming language version 1.3 book - Part 83 of 88The Ring programming language version 1.3 book - Part 83 of 88
The Ring programming language version 1.3 book - Part 83 of 88Mahmoud Samir Fayed
 
Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008Guillaume Laforge
 
Python-GTK
Python-GTKPython-GTK
Python-GTKYuren Ju
 
Kotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projectsKotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projectsBartosz Kosarzycki
 
Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016
Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016
Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016STX Next
 
Cassandra v3.0 at Rakuten meet-up on 12/2/2015
Cassandra v3.0 at Rakuten meet-up on 12/2/2015Cassandra v3.0 at Rakuten meet-up on 12/2/2015
Cassandra v3.0 at Rakuten meet-up on 12/2/2015datastaxjp
 
Swift for TensorFlow - CoreML Personalization
Swift for TensorFlow - CoreML PersonalizationSwift for TensorFlow - CoreML Personalization
Swift for TensorFlow - CoreML PersonalizationJacopo Mangiavacchi
 
The Ring programming language version 1.7 book - Part 30 of 196
The Ring programming language version 1.7 book - Part 30 of 196The Ring programming language version 1.7 book - Part 30 of 196
The Ring programming language version 1.7 book - Part 30 of 196Mahmoud Samir Fayed
 

Similaire à Java File (20)

Advanced Java - Practical File
Advanced Java - Practical FileAdvanced Java - Practical File
Advanced Java - Practical File
 
AJP Practical Questions with Solution.docx
AJP Practical Questions with Solution.docxAJP Practical Questions with Solution.docx
AJP Practical Questions with Solution.docx
 
Java
JavaJava
Java
 
code for quiz in my sql
code for quiz  in my sql code for quiz  in my sql
code for quiz in my sql
 
• GUI design using drag and drop feature of IDE(Net beans), • File IO
•	GUI design using drag and drop feature of IDE(Net beans), •	File IO•	GUI design using drag and drop feature of IDE(Net beans), •	File IO
• GUI design using drag and drop feature of IDE(Net beans), • File IO
 
Simulado java se 7 programmer
Simulado java se 7 programmerSimulado java se 7 programmer
Simulado java se 7 programmer
 
srgoc
srgocsrgoc
srgoc
 
Modern technologies in data science
Modern technologies in data science Modern technologies in data science
Modern technologies in data science
 
Python GTK (Hacking Camp)
Python GTK (Hacking Camp)Python GTK (Hacking Camp)
Python GTK (Hacking Camp)
 
The Ring programming language version 1.9 book - Part 99 of 210
The Ring programming language version 1.9 book - Part 99 of 210The Ring programming language version 1.9 book - Part 99 of 210
The Ring programming language version 1.9 book - Part 99 of 210
 
The Ring programming language version 1.3 book - Part 83 of 88
The Ring programming language version 1.3 book - Part 83 of 88The Ring programming language version 1.3 book - Part 83 of 88
The Ring programming language version 1.3 book - Part 83 of 88
 
Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008
 
Python-GTK
Python-GTKPython-GTK
Python-GTK
 
Kotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projectsKotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projects
 
Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016
Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016
Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016
 
Cassandra v3.0 at Rakuten meet-up on 12/2/2015
Cassandra v3.0 at Rakuten meet-up on 12/2/2015Cassandra v3.0 at Rakuten meet-up on 12/2/2015
Cassandra v3.0 at Rakuten meet-up on 12/2/2015
 
Griffon @ Svwjug
Griffon @ SvwjugGriffon @ Svwjug
Griffon @ Svwjug
 
Swift for TensorFlow - CoreML Personalization
Swift for TensorFlow - CoreML PersonalizationSwift for TensorFlow - CoreML Personalization
Swift for TensorFlow - CoreML Personalization
 
Swing database(mysql)
Swing database(mysql)Swing database(mysql)
Swing database(mysql)
 
The Ring programming language version 1.7 book - Part 30 of 196
The Ring programming language version 1.7 book - Part 30 of 196The Ring programming language version 1.7 book - Part 30 of 196
The Ring programming language version 1.7 book - Part 30 of 196
 

Dernier

Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
Introduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHIntroduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHC Sai Kiran
 
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTIONTHE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTIONjhunlian
 
Internet of things -Arshdeep Bahga .pptx
Internet of things -Arshdeep Bahga .pptxInternet of things -Arshdeep Bahga .pptx
Internet of things -Arshdeep Bahga .pptxVelmuruganTECE
 
Solving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.pptSolving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.pptJasonTagapanGulla
 
US Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionUS Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionMebane Rash
 
The SRE Report 2024 - Great Findings for the teams
The SRE Report 2024 - Great Findings for the teamsThe SRE Report 2024 - Great Findings for the teams
The SRE Report 2024 - Great Findings for the teamsDILIPKUMARMONDAL6
 
home automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasadhome automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasadaditya806802
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvLewisJB
 
Earthing details of Electrical Substation
Earthing details of Electrical SubstationEarthing details of Electrical Substation
Earthing details of Electrical Substationstephanwindworld
 
National Level Hackathon Participation Certificate.pdf
National Level Hackathon Participation Certificate.pdfNational Level Hackathon Participation Certificate.pdf
National Level Hackathon Participation Certificate.pdfRajuKanojiya4
 
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfgUnit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfgsaravananr517913
 
Mine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptxMine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptxRomil Mishra
 
Research Methodology for Engineering pdf
Research Methodology for Engineering pdfResearch Methodology for Engineering pdf
Research Methodology for Engineering pdfCaalaaAbdulkerim
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfAsst.prof M.Gokilavani
 
Main Memory Management in Operating System
Main Memory Management in Operating SystemMain Memory Management in Operating System
Main Memory Management in Operating SystemRashmi Bhat
 
Correctly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleCorrectly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleAlluxio, Inc.
 
Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...121011101441
 
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...Amil Baba Dawood bangali
 

Dernier (20)

Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
Introduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHIntroduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECH
 
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTIONTHE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
 
Internet of things -Arshdeep Bahga .pptx
Internet of things -Arshdeep Bahga .pptxInternet of things -Arshdeep Bahga .pptx
Internet of things -Arshdeep Bahga .pptx
 
Solving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.pptSolving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.ppt
 
US Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionUS Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of Action
 
The SRE Report 2024 - Great Findings for the teams
The SRE Report 2024 - Great Findings for the teamsThe SRE Report 2024 - Great Findings for the teams
The SRE Report 2024 - Great Findings for the teams
 
home automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasadhome automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasad
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvv
 
Earthing details of Electrical Substation
Earthing details of Electrical SubstationEarthing details of Electrical Substation
Earthing details of Electrical Substation
 
National Level Hackathon Participation Certificate.pdf
National Level Hackathon Participation Certificate.pdfNational Level Hackathon Participation Certificate.pdf
National Level Hackathon Participation Certificate.pdf
 
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfgUnit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
 
Mine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptxMine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptx
 
Research Methodology for Engineering pdf
Research Methodology for Engineering pdfResearch Methodology for Engineering pdf
Research Methodology for Engineering pdf
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
 
Main Memory Management in Operating System
Main Memory Management in Operating SystemMain Memory Management in Operating System
Main Memory Management in Operating System
 
Correctly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleCorrectly Loading Incremental Data at Scale
Correctly Loading Incremental Data at Scale
 
Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...
 
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
 

Java File

  • 1. INDEX Sr. No. Program Remarks 1. Write a program on Multithreading 2. Write a program on Input/output Stream 3. Write a program on Interfaces 4. Write a program on Applet 5. Write a program on SWING Application 6. Write a program on JDBC 7. Write a program on Servlets 8. Write a program on JSP 9. Write a program on Sending E-Mail 10. Write a program on Implementing RMI
  • 2. Program No1: Write a program on Multithreading import java.io.*; class a implements Runnable { Thread t; a() { t=new Thread(this, "thread1"); t.start(); } public void run(){ try{ System.out.println("Manish"); Thread.sleep(1000); } catch(Exception ex){ } } } class thread1{ public static void main(String arg[]){ try{ for(int i=0;i<=5;i++) { new a(); Thread.sleep(500); System.out.println("Jain"); } } catch(Exception ex) { } } }
  • 4. Program No2: Write a program on Input/output Stream import java.io.*; class inputoutput{ public static void main(String args[]) throws IOException { char c; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter characters, 'q' to quit."); do { c = (char) br.read(); System.out.println(c); } while(c != 'q'); } }
  • 6. Program No3: Write a program on Interfaces import java.io.*; class student { int roll; void get(int r) { roll=r; } void disp() { System.out.println("Roll no."+roll); } } class test extends student { float t1,t2,t3; void gettest(float a,float b,float c) { t1=a; t2=b; t3=c; } void distest() { System.out.println("Test 1:"+t1); System.out.println("Test 2:"+t2); System.out.println("Test 3:"+t3); } } class program extends test { float p1,p2; void getprac(float a,float b) { p1=a; p2=b; } void disprac() {
  • 7. System.out.println("Program 1:"+p1); System.out.println("Program 2:"+p2); } } interface sport { float spwt=6.0f; public void dispwt(); } class Result extends program implements sport { float total; public void dispwt() { System.out.println("Sport weightage:"+spwt); } void distotal() { total=t1+t2+t3+p1+p2+spwt; disp(); distest(); disprac(); dispwt(); System.out.println("Total Result:"+total); } } public class Marks { public static void main(String args[]) { Result r=new Result(); r.get(150); r.gettest(80,85,89); r.getprac(45,49); r.distotal(); } }
  • 9. Program No4: Write a program on Applet import java.applet.*; import java.awt.*; /*<applet Code="face.class" Width=600 Height=600> </applet>*/ public class face extends Applet { public void paint(Graphics g) { g.drawString("Applet Program",250,50); g.drawOval(200,100,200,200); g.fillOval(250,150,30,20); g.fillOval(320,150,30,20); g.drawLine(299,150,299,225); g.drawArc(274,200,50,50,210,120); } }
  • 11. Program No 5: Write a program on SWING Application import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Main1 extends JApplet implements ActionListener { JRadioButton r1,r2; String msg=""; JButton b; JTextField t1,t2; ButtonGroup bg; public void init() { getContentPane().setLayout(new FlowLayout()); JLabel l1=new JLabel("Enter Name"); t1=new JTextField(10); t2=new JTextField(25); t2.setEditable(false); b=new JButton("Display"); r1=new JRadioButton("Male"); r2=new JRadioButton("Female"); bg=new ButtonGroup(); bg.add(r1); bg.add(r2); getContentPane().add(l1); getContentPane().add(t1); getContentPane().add(r1); getContentPane().add(r2);
  • 12. getContentPane().add(b); getContentPane().add(t2); b.addActionListener(this); } public void actionPerformed(ActionEvent e) { msg="Hello "; if(r1.isSelected()) msg=msg+"Mr. "+t1.getText(); else msg=msg+"Ms. "+t1.getText(); t2.setText(msg); } }
  • 14. Program No 6: Write a program on JDBC import java.io.*; import java.sql.*; import java.awt.*; import java.awt.event.*; class jdbc extends Frame implements ActionListener,WindowListener { Label l1,l2,l3; TextField t1,t2,t3; Button b1,b2,b3; Connection con; Statement st; jdbc() { addWindowListener(this); l1=new Label("Emp_ID"); l2=new Label("Name"); l3=new Label("Salary"); t1=new TextField(""); t2=new TextField(""); t3=new TextField(""); b1=new Button("Save"); b2=new Button("Search"); b3=new Button("Delete"); setLayout(null); l1.setBounds(100,100,100,30); l2.setBounds(100,130,100,30); l3.setBounds(100,160,100,30); t1.setBounds(200,100,100,30); t2.setBounds(200,130,100,30); t3.setBounds(200,160,100,30); b1.setBounds(100,190,50,30); b2.setBounds(150,190,50,30); b3.setBounds(200,190,50,30); add(l1); add(l2); add(l3); add(t1); add(t2);
  • 15. add(t3); add(b1); add(b2); add(b3); b1.addActionListener(this); b2.addActionListener(this); b3.addActionListener(this); try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); System.out.println("Driver Loaded"); con=DriverManager.getConnection("jdbc:odbc:emp"); System.out.println("Connected"); st=con.createStatement(); } catch(Exception ex) { System.out.println("Doesn't Exist"); } } public void windowClosed(WindowEvent we) { } public void windowOpened(WindowEvent we) { } public void windowClosing(WindowEvent we) { System.exit(0); } public void windowActivated(WindowEvent we) { } public void windowDeactivated(WindowEvent we) { } public void windowIconified(WindowEvent we) { } public void windowDeiconified(WindowEvent we) { }
  • 16. public void actionPerformed(ActionEvent ae) { try { if(ae.getSource()==b1) { st.execute("Insert into emp values("+t1.getText()+",'"+t2.getText()+"',"+t3.getText()+")"); t1.setText(""); t2.setText(""); t3.setText(""); } if(ae.getSource()==b2) { ResultSet rs=st.executeQuery("Select * from emp where emp_id="+t1.getText()+""); if(rs.next()) { t1.setText(rs.getString(1)); t2.setText(rs.getString(2)); t3.setText(rs.getString(3)); } } if(ae.getSource()==b3) { st.execute("Delete from emp where emp_id="+t1.getText()+""); t1.setText(""); t2.setText(""); t3.setText(""); } } catch(Exception ex) { } } public static void main(String arg[]) { jdbc j=new jdbc(); j.setTitle("Program No.:-1"); j.setSize(500,500); j.setVisible(true); } }
  • 18. Program No 7: Write a program on Servlets HTML CODE:- <html> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=UTF- 8"> </head> <body bgcolor="white" text="black"> <script> function va() { if(form1.username.value=="") { alert("Error"); return false; } if(form1.username.value.length<6) { alert("Error"); return false; } if(form1.email.value.indexOf("@")==-1) { alert("Invalid id"); return false; } return true; } </script> <form name="form1" action="http://localhost:8080/servlet/NewServlet" onsubmit="return va();"> <table border="0" align="center"> <thead><tr> <th>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&
  • 19. nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp;&nbsp;&nbsp;&nbsp;<u>Servlet</u></th> <th></th></tr> </thead> <tbody> <tr><br><br><td>Username</td> <td><input type="text" name="username" value="" /></td></tr> <tr><td>Email-Id</td> <td><input type="text" name="email" value="" /></td></tr> <tr><td>City</td> <td><input type="text" name="city" value="" /></td></tr> <tr><td>State</td> <td><input type="text" name="state" value="" /></td></tr> <tr><td></td> <td><input type="submit" value="SUBMIT"/></td></tr> </tbody> </table> </form> </body> </html> JAVA CODE:- import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class NewServlet extends HttpServlet { protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); try { out.print("<br><br><center>");
  • 20. String username=request.getParameter("username"); out.println("Username="+username+"<br>"); String email=request.getParameter("email"); out.println("Email-id="+email+"<br>"); String city=request.getParameter("city"); out.println("City="+city+"<br>"); String state=request.getParameter("state"); out.println("State="+state+"<br>"); out.print("</center>"); } finally { out.close(); } } @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); } @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); } @Override public String getServletInfo() { return "Short description"; } }
  • 22. Program No 8: Write a program on JSP <%@ page language="java"%> <html> <head> <title>Even number program in JSP</title> </head> <body> <% for(int i=0;i<=20;i++) { if((i%2)==0) { out.print("<center>"); out.print("Even number :"+i); out.print("<br></center>"); } } %> </body> </html>
  • 24. Program NO 9: Write a program on Sending E-Mail import java.awt.*; import java.awt.event.*; import java.net.*; import java.io.*; import java.util.*; import javax.swing.*; class MailTestFrame extends JFrame { private JTextArea msg, comm; private JTextField sr,fr,to; JButton sd; private Scanner in; private PrintWriter out; public MailTestFrame() { setSize(300,300); setTitle("Mail Test"); getContentPane().setLayout(new FlowLayout()); JLabel l1=new JLabel("From: "); fr=new JTextField(21); JLabel l2=new JLabel("To:"); to=new JTextField(22); JLabel l3=new JLabel("SMTP server:"); sr=new JTextField(17); msg=new JTextArea("",5,10); JScrollPane sp1=new JScrollPane(msg); comm=new JTextArea("Mail From", 5, 10); JScrollPane sp2=new JScrollPane(comm);
  • 25. sd = new JButton("Send"); getContentPane().add(l1); getContentPane().add(fr); getContentPane().add(l2); getContentPane().add(to); getContentPane().add(l3); getContentPane().add(sr); getContentPane().add(sp1); getContentPane().add(sp2); getContentPane().add(sd); sd.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { new Thread(new Runnable() { public void run() { comm.setText(""); sendmail(); } }).start(); } }); } public void sendmail() { try { Socket s=new Socket(sr.getText(),25); InputStream ins=s.getInputStream();
  • 26. OutputStream outs=s.getOutputStream(); in=new Scanner(ins); out=new PrintWriter(outs,true); String host=InetAddress.getLocalHost().getHostName(); receive(); send("Hello "+host); receive(); send("MAIL FROM:<"+fr.getText()+">"); receive(); send("RCPT TO:<"+to.getText()+">"); receive(); send("DATA"); receive(); send(msg.getText()); receive(); s.close(); } catch(IOException e) { comm.append("Error: "+e); } } public void send(String str)throws IOException { comm.append(str); comm.append("n"); out.print(str.replaceAll("n", "rn")); out.flush(); } public void receive()throws IOException
  • 27. { if(in.hasNextLine()) { String l=in.nextLine(); comm.append(l); comm.append("n"); } } } public class MailText { public static void main(String[] args) { JFrame f =new MailTestFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); } }
  • 29. Program No10: Write a program on Implementing RMI Client Program: import java.io.*; import java.rmi.*; public class NormalClient { public static void main(String[] arg) { String IpName,FileName,Ip; StackInter DataObject; byte[] Content; try { BufferedReader Buffer=new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter the Ip Address :"); IpName = Buffer.readLine(); System.out.println("Enter the File Name :"); FileName = Buffer.readLine(); Ip="rmi://"+IpName+"/hai"; DataObject=(StackInter)Naming.lookup(Ip); Content = DataObject.st(FileName); File Fn=new File(FileName); BufferedOutputStream OutFile=new BufferedOutputStream(new FileOutputStream(Fn.getName())); OutFile.write(Content,0,Content.length); OutFile.flush(); OutFile.close(); } catch(Exception e){} }}
  • 30. Implementation Program: import java.rmi.*; import java.rmi.server.*; import java.io.*; public class StackImpl extends UnicastRemoteObject implements StackInter { public StackImpl() throws RemoteException {} public byte[] st(String str) throws RemoteException { File f=new File(str); byte b[]=new byte[(int)f.length()]; try { BufferedInputStream f1= new BufferedInputStream(new FileInputStream(f)); f1.read(b,0,b.length); f1.close(); } catch(Exception e) { } return (b); } } Interface: import java.rmi.*; public interface StackInter extends Remote {
  • 31. byte[] st(String str)throws RemoteException; } Server Program: import java.rmi.*; public class StackServer { public static void main(String arg[]) { try { StackImpl im=new StackImpl(); Naming.rebind("hai",im); } catch(Exception e) { System.out.println(e); } } }
  • 32. OUTPUT of SERVER file: java.rmi.ConnectException: Connection refused to host: 127.0.0.1; nested exception is: java.net.ConnectException: Connection refused: connect OUTPUT of CLIENT file : Enter the Ip Address : 127.0.0.1:1052 Enter the File Name : lok.txt