Java Final MMMM
Java Final MMMM
1 Acknowledgment 1
2 Introduction 2
3 Requirement analysis 4
4 Class diagram 5
6 ER diagram 10
7 Input 11
8 Output 24
9 Conclusion 25
10 Reference 26
ACKNOWLEDGMENT
I extend my gratitude to Mr. Vijay Bodake, Head of Computer Diploma Engineering, for his
guidance and insights that greatly contributed to the success of this project. Special thanks to
Mr.Bodake sir for her continuous support and expertise in Java Pragramming.
Furthermore, I would like to express my appreciation to all the faculty members and staff of
the computer engineering department for their assistance and cooperation. Their expertise and
guidance were instrumental in completing this project successfully.
Lastly, I want to extend my thanks to my friends and family for their unwavering support and
understanding during this academic journey. Their encouragement and belief in me have been
invaluable.
INTRODUCTION
2. Robust: - Java Programs are said to be robust because they will take care of memory
management and will never crash under any circumstances.
3. Secure: - Even though Java is developed using Object Oriented Principles, it eliminated
the Pointers Concept. So it is not possible to access memory directly, that’s why Java is
said to be Secure and is applicable for Internet, for that Applet is designed which can be
understandable by the browsers.
Packages Used: -
1. The default package to build any program in Java is lang that is used in developing this
system
2. The API to build Graphical User Interface in Java is provided using the packages awt
and swing. This system uses both the packages to provide GUI based forms.
3. To provide the communication over the network, the package net is used to develop the
Server and Clients.
4. In Java JDBC (Java Database Connectivity) is used to connect to the database, a special
package known as sql is developed for that.
5. The util package in Java is an enhancement of the existing classes. This package is also
used in this system for declaring arrays (Vector), and to manipulate the strings.
6. The streams that are used to send and receive the data over network are also utilized in
this system, which are in the package of io.
REQUIREMENTS ANALYSIS
Requirement Analysis is done to understand the problem the software system is to
solve. The emphasis in requirements analysis is on identifying what is needed from the
system, but not how the system will achieve the goals. This involves 2 phases,
1. Problem Analysis
2. Requirement Specification
Problem Analysis: -The basic aim of Problem Analysis is to obtain a clear understanding of
the needs of the clients, i.e. what exactly is desired from the software, what are the
constraints to be imposed while developing. After this phase the analyst will get a clear
idea about the project.
Since the system is developed using Objected Oriented Paradigm, the needs of the clients
are shown as Scenarios and Use cases. Some are listed below,
CLASS DIAGRAMS
The things naturally fall into categories we refer to those categories as classes. A class is a
category or group of things that have similar attributes and common behavior.
1. Class Diagram for a Client.
: Client
+ Socket
Instance
+ Input Stream
+ Output Stream
+ Host Address
+ Connected
Hosts
+ addLabel( )
: Server
+ Socket
Instance
+ Input Stream
+ Output Stream
+ Number of
Client
+ Connected
Hosts
+addclient( )
1. Use case & Scenario for the need to connect to the Server.
To Transfer To Send
File Message.
<<Include>>
Connect To
Server
Initiator Initiator
(User) (User)
Precondition: - Here the Initiator is some personnel in the department, who wants to send a
file or a message to some other client.
Single Multiple
<<Include>>
File Transfer
Initiator Initiator
(User) (User)
Precondition: - Here the Initiator is the user, who wants to send a file to a single client or
multiple clients.
Post condition: - The user gets the acknowledgement that the file has been reached.
To Transfer
A File
Initiator Initiator
(User) (User)
Post condition: - The Specified file will be transferred to the specified location if exists, in the
remote system, if not ‘Path not found’ message has to be displayed.
<<Include>>
Disconnect
Client
Initiator Initiator
(User) (User)
Precondition: - Here the Initiator is the user, who wants to disconnect a single or multiple
clients.
Post condition: - The user’s presently connected clients list will be update.
E-R DIAGRAM
E-R Diagrams are used to represent the relation ship among the entities. In this
system there are only
2 entities that are Server and Client. So the Entity Relationship Diagram for this system is
drawn below,
1…1 1…*
Server client
INPUT
import java.awt.*;
import
java.awt.event.*;
import java.net.*;
import java.io.*;
import
javax.swing.*;
import java.util.*;
import java.sql.*;
class Ftpser {
public static void main(String ds[])
{
server3 s=new server3();
}
}
class server3 extends Thread
{
ServerSocket ser; Socket cli;
static int no=0; static Vector
v1=new Vector(10);
static int port=143;
Vector v=new Vector(10);
static Vector donot=new
Vector(10);
server3
() { try
{
ser=new ServerSocket(port);
start();
//setDaemon(true);
}catch(Exception e){System.out.println(e);}
}
public void run()
{ while(true)
{ try
{ cli=ser.acce
pt();
v.insertElementAt(new mul2(cli,this,no),no);
Runtime t=Runtime.getRuntime();
t.gc();
}catch(Exception e){System.out.println(e);}
}
}
void send(String
msg) //noted {
int flag=0; for(int
i=0;i<=no;i++)
{ flag=
0;
for(int j=0;j<donot.size();j++)
{
int
x=Integer.parseInt((String)donot.elementA
t(j)); if(i==x) flag=1; } if(flag==1)
continue; mul2 m=(mul2)v.elementAt(i);
m.out1(msg);
}
}
void send1(String msg)
{ int flag1=0;
for(int
i=0;i<no;i++)
{flag1=0;
for(int j=0;j<donot.size();j++)
{
int
x=Integer.parseInt((String)donot.elementA
t(j)); if(i==x) flag1=1; } if(flag1==1)
continue; mul2 m=(mul2)v.elementAt(i);
m.num=i;
m.out1(msg);
}
}
void send2(int no,String msg)
{
mul2 m=(mul2)v.elementAt(no);
m.out1(msg);
}
void sendall(int n,String msg)
{
for(int i=0;i<no;i++)
{ if(i==n) continue; mul2
m=(mul2)v.elementAt(i);
m.out1(msg);
}
}
void exit1(int n)
{
String s=v1.elementAt(n)+" exited123";
v.removeElementAt(n);
v1.removeElementAt(n);
donot.removeElement(new String().valueOf(n));
Runtime t=Runtime.getRuntime();
t.gc();
no--;
send1(s
); } }
class mul2 extends Thread
{
Socket client;
DataInputStream rin;
DataOutputStream
out; Statement
stmt; server3 ser;
String s;
String users; byte b[]=new
byte[200]; int num;
mul2(Socket cli,server3 ser,int
num)
{ try { client=cli; this.ser=ser;
this.num=num; rin=new
DataInputStream(cli.getInputStream());
out=new DataOutputStream(cli.getOutputStream());
start();
}catch(Exception e){System.out.println(e);}
} public void
run() {
String msg="";
StringTokenizer str;
try { while(true) { byte b[]=new
byte[200]; if(rin.read(b)>=1)
{ msg=new String(b).trim();
System.out.println("Hello");
System.out.println("Comming :
"+msg); if(msg.endsWith("
mustquit"))
{
str=new StringTokenizer(msg," ");
s=str.nextToken(); int
in=server3.v1.indexOf(s);
System.out.println("The number is
"+in); ser.send2(in," mustquit");
}
else
if(msg.indexOf("Theusername,")==
0)
{
str=new
StringTokenizer(msg," ");
str.nextToken(); String
user=str.nextToken();
users="";
server3.v1.insertElementAt(user,server3.no);
System.out.println(" user "+user+" Connected... with no
"+server3.no); for(int i=0;i<=server3.no;i++)
users=users+server3.v1.elementAt(i)+" ";
ser.send(users+"allusers"); server3.no++;
} else if(msg.indexOf("transfering ")==0 ||
msg.indexOf("transfferingtoall ")==0)
{
String sender=str.nextToken().trim();
String all=str.nextToken("*");
String path=str.nextToken();
System.out.println("The
size :"+size); byte b1[]=new
byte[size];
rin.readFully(b1,0,size);
System.out.println("came out");
StringTokenizer str1=new StringTokenizer(all," ");
System.out.println(path);
String mess=sender+" "+"sizel "+size+"
"+path; int i=1;
while(i<str1.countTokens())
{
int
rec=server3.v1.indexOf(str1.nextToken().trim());
new sending(rec,b1,mess,ser);
}
}
else
if(msg.indexOf("nopath")>=0
)
{
System.out.println("Entered in nopath");
str=new StringTokenizer(msg," ");
str.nextToken();
String rece=str.nextToken(); int
x=server3.v1.indexOf(str.nextToken
()); ser.send2(x,"nopath in "+rece);
}
System.out.println(new String(x));
out.write(x,0,x.length);
setSize(600,425);
setLocation(75,75);
show();
Container c=getContentPane();
JPanel p=new JPanel(new
BorderLayout()); JPanel p1=new
JPanel(new FlowLayout()); p2=new
JPanel(new GridLayout(100,1,0,10));
ta=new JTextArea(); tf=new
JTextField(50); ta.setFont(new
Font("",Font.BOLD,18));
ta.disable();
int v1=ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS;
int h=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS;
jsp=new JScrollPane(ta,v1,h);
p.add(jsp,BorderLayout.CENTER);
p.add(tf,BorderLayout.SOUTH
); send=new JButton("SEND
ALL"); exit=new
JButton("EXIT"); kill=new
JButton("KILL");
p1.add(kill); p1.add(send); p1.add(exit);
exit.addActionListener(this);
send.addActionListener(this);
kill.addActionListener(this); l1=new JLabel("
ALL CONNECTED USERS"); l1.setFont(new
Font("helvatica",Font.BOLD,22));
l1.setForeground(Color.darkGray);
/*ta.addMouseListener(new MouseAdapter()
{
public void mouseEntered(MouseEvent me)
{ ta.disable();
}
public void mouseExited(MouseEvent me){
ta.enable()
;} });*/ try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:raj");
stmt=con.createStatement();
rs=stmt.executeQuery("select *from users");
rs2=rs;
rs1=rs;
}
catch(Exception e){System.out.println(e);}
rin.read(b);
String str=new String(b).trim();
System.out.println(str);
StringTokenizer s=new StringTokenizer(str," "); while(s.hasMoreTokens())
{
String t=s.nextToken();
rs1=stmt.executeQuery("select *from users");
int flag=0,i=0;
if(!t.equals("allusers"))
{
ta.append(t+" :Presently Connected
"+"\n"); v.addElement(t);
while(rs1.next())
{
i++;
if(t.trim().equals(rs1.getString(1)))
{tip.addElement(rs1.getString(2));flag=1;}
}
if(flag==0)
tip.addElement("Not Updated");
System.out.println("sumitra"+i+" flag"+flag);
}
System.out.println(v.size()+" "+tip.size());
}
for(int i=0;i<100;i++)
{ l[i]=new
JLabel("");
p2.add(l[i]); }
jsp1=new JScrollPane(p2,v1,h);
addlabel();
c.setLayout(new BorderLayout());
c.add(l1,BorderLayout.NORTH);
c.add(p1,BorderLayout.SOUTH);
c.add(jsp1,BorderLayout.EAST);
c.add(p,BorderLayout.CENTER);
show();
Thread t=new Thread(this);
t.start();
}catch(Exception e){System.out.println("anand1 "+e);}
}
String u=s.nextToken();
ta.append(u+" :Recently Connected"+"\
n"); v.addElement(u);
rs2=stmt.executeQuery("select *from
users");
int flag=0;
while(rs2.next())
{
if(u.trim().equals(rs2.getString(1)))
{tip.addElement(rs2.getString(2));flag=1;}
}
if(flag==0)
tip.addElement("Not Updated");
System.out.println(v.size()+" "+tip.size());
addlabel();
}
else
if(msg.endsWith("exited123"))
{
System.out.println(msg);
StringTokenizer s=new StringTokenizer(msg," ");
String t=s.nextToken();
ta.append(t+" : Disconnected"+"\
n"); int x1=v.indexOf(t);
v.removeElement(t);
tip.removeElementAt(x1);
System.out.println(v.size()+" "+tip.size());
addlabel();
}
if(msg.indexOf("sizel")>=1)
{ int
flag=0;
System.out.println(msg);
StringTokenizer str=new StringTokenizer(msg," ");
String sender=str.nextToken();
str.nextToken(); int
size=Integer.parseInt(str.nextToken());
byte b1[]=new byte[size];
try
{
String pat=str.nextToken();
System.out.println("The dest Path "+pat);
FileOutputStream fout=new
FileOutputStream(pat); out.flush();
rin.readFully(b1,0,size);
fout.write(b1);
System.out.println("File Captured");
out.write(("captured "+" "+user+"
"+sender).getBytes()); //
System.out.println(new String(b1));
}catch(Exception e){System.out.println(e);flag=1;}
if(flag==1)
{
out.flush(); out.write(("nopath "+"
"+user+" "+sender).getBytes());
}
}
if(msg.startsWith("captured"))
{
System.out.println("Entered in captured");
System.out.println(msg);
StringTokenizer str=new StringTokenizer(msg," ");
str.nextToken();
str.nextToken();
String s=str.nextToken();
//System.out.println(f.status2.getText());
int ind=v.indexOf(s);
l[ind].setForeground(Color.cyan);
if(in==0)
f.status2.append("File Transfered To System:
"+s+"\n"); else
all.f.status2.append("File Transfered To System: "+s+"\n"); }
if(msg.startsWith("nopath"))
{
System.out.println("Entered in nopath");
System.out.println(msg);
StringTokenizer str=new
StringTokenizer(msg," "); str.nextToken();
str.nextToken();
String s=str.nextToken();
//System.out.println(f.status2.getText());
if(in==0)
f.status2.append("Path Not Found In System:
"+s+"\n"); else
all.f.status2.append("Path Not Found In System: "+s+"\n");
}
if(msg.endsWith("mustquit"))
{
System.out.println("You have been Forcibly removed from server");
System.exit(0);
}
}
}
}catch(Exception e){System.out.println("anand2 "+e);}
}
void addlabel()
{
System.out.println("The size is"+v.size());
for(int i=0;i<v.size();i++)
{
String t=" "+(String)v.elementAt(i)+" ";
System.out.println(t);
l[i].setFont(new Font("",Font.BOLD,16));
l[i].setText(t);
l[i].setToolTipText((String)tip.elementAt(i));
if(user.equals((String)v.elementAt(i)))
{l[i].setForeground(Color.red);
continue;} if(!
l[i].getForeground().equals(Color.cyan))
l[i].setForeground(Color.blue);
l[i].addMouseListener(this);
}
for(int j=v.size();j<10;j++)
{l[j].setText("");l[j].removeMouseListener(this);l[j].setToolTipText("");}
}
public void mousePressed(MouseEvent me){} public void
mouseEntered(MouseEvent me){setCursor(Cursor.HAND_CURSOR);}
public void mouseExited(MouseEvent me)
{setCursor(Cursor.DEFAULT_CURSOR);} public void
mouseClicked(MouseEvent me){ if(me.getClickCount()==1)
{
JLabel
l=(JLabel)me.getComponent();
in=0; f=new
form(this,l.getText(),user,null);
}
}
public void mouseReleased(MouseEvent me)
{} public static void main(String ds[])
{
new chatform(ds[0]);
}
}
OUTPUT
CONCLUSION
I would like to conclude that the System has been launched successfully in the real
environment, and is tested practically. The Files and Messages are transferred to the
intended clients basing on the selection. Even .EXE files are also been transferred
accurately with out any errors and perfectly executed after downloading.
REFRENCE
https://nevonprojects.com/transferdatafile
https://www.irjmets.com/uploadedfiles/paper/volume2/
issue_3_march_2020/276/1628082965 .pdf
https://github.com/topics/file transfer data l-
https://opus.govst.edu/cgi/viewcontent.cgi?article=1199&context=capstones
https://www.mifratech.com/public/blogpage/transferdatafile
https://www.mifratech.com/public/blog-page/filedatatransfer