Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!

Abhimanyu dagla

Greenhorn
+ Follow
since Jan 11, 2001
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Abhimanyu dagla


Thanks for the link , phil.
The Server code has run, 'finally'.
Abhimanyu
19 years ago

Thanks Art for replying so instantly.
Abhimanyu dagla

Sonali , The default priority is 5.
The answer is wrong.
Hopin it helps you.

The equals() and toString() methods belong to the Object class
and a class written by a programmer should override these
methods since by default the .equals() of Object is called
and it returns false unless a object is compared with itself.
So how do we find out that we are to override the equals() or
toString method in a class ?
Please clarify...
Abhimanyu dagla

I think that the title says it all... you gurus can explain
it to me ..
Thankx ....Abhimanyu
19 years ago

Hello friends,
I have a problem with this Code written for a server.It caters to the requests made by the browser .
But the HTml page never loads .the browser says it is opening the
default page..the progess bar comes to 50% and halts.
Please help.(OF course, get a HTML file as default file)
// a simple webserver
import java.io.*;
import java.util.*;
import java.net.*;
class Configuration {
int port;
String defaultfile;
Configuration(){
port=80;
defaultfile= "index.html"; // please get a html in your folder.
}
public int getPort(){
return port;
}
public String getDefaultFile(){
return defaultfile;
}
public void displayConfiguration(){
System.out.println("port: "+port);
System.out.println("defaultfile: "+defaultfile);
}
}
public class WebServer{
Configuration config;
WebServer(){
config=new Configuration();
}

void startServer(){
try{
ServerSocket server =new ServerSocket(config.getPort());
System.out.println("server started");
config.displayConfiguration();
while(true){
Socket c= server.accept();
new WebServerThread(c,config);// creating thread
}
}
catch(Exception e){ e.printStackTrace(); }
}
public static void main(String args[]){
WebServer ws= new WebServer();
ws.startServer();
}
}
class WebServerThread extends Thread{
DataInputStream din;
FilterOutputStream out;
Configuration config;
Socket client;
WebServerThread(Socket c, Configuration con){
client =c;
config=con;
this.start();
System.out.println("server thread started");
}
public void run(){
try{
din= new DataInputStream(new BufferedInputStream(client.getInputStream()));
out= new FilterOutputStream(new BufferedOutputStream(client.getOutputStream()));
Vector lines= new Vector();
do{
String l= din.readLine();
if(l.length()<1) break;<br /> lines.addElement(l);<br /> System.out.println(l);<br /> }<br /> while(true);<br /> System.out.println("reading the lines");<br /> String firstline =(String)lines.elementAt(0);<br /> if(firstline.startsWith("GET"))<br /> processGetRequest(firstline);<br /> else<br /> if(firstline.startsWith("POST"));<br /> processPostRequest(firstline);<br /> System.out.println("Request fulfilled: breaking connection");<br /> client.close();<br /> din.close();<br /> out.close();<br /> }<br /> catch (Exception e){ e.printStackTrace(); }<br /> }<br /> public void processPostRequest(String firstline){<br /> try{<br /> String data=din.readLine();<br /> System.out.println(data);<br /> } catch(Exception e){ e.printStackTrace(); }<br /> }<br /> <br /> public void processGetRequest(String firstline){<br /> System.out.println("about to process the GET request");<br /> String filename= getFileName(firstline);<br /> File file= new File(filename);<br /> if(file.exists())<br /> {<br /> sendFile(file);<br /> System.out.println("sent the file");<br /> }<br /> else<br /> System.out.println("File not found");<br /> }<br /> <br /> public String getFileName(String firstline){<br /> String filename =null;<br /> StringTokenizer st= new StringTokenizer(firstline);<br /> String temp= st.nextToken();<br /> filename=st.nextToken();<br /> temp= st.nextToken();<br /> if(filename.length()>1)
{
filename.substring(1);
if(filename.endsWith("/"))
filename+=config.getDefaultFile();
}
else
{
filename=config.getDefaultFile();
}
return filename;
}
public void sendFile(File file){
try{
FileInputStream fin= new FileInputStream(file);
DataInputStream in= new DataInputStream(fin);
byte buff[]= new byte[(int)file.length()];
in.close();
for(int i=0; i<buff.length; i++){>
out.write(buff[i]);
out.flush();
}
System.out.println("File "+file.getName()+" sent successfully");
}
catch(Exception e){ e.printStackTrace(); }
}
}

19 years ago

is the hullaballu bout java jobs true... I ve heard from
friends that there is a reccesion goin on in states and the
most suffered are Java prfessionals ....
clear my doubts...they are disturbing my study for SCJP.
19 years ago

hello everybody on javaranch,
I have a problem.
I downloaded the virtual machine specifications
and the java language specifications from sun site.
But I am unable to open these files. They are
.html.tar files..
Can anybody tell me how I can open these files.
Abhimanyu

Congrats Shriny for such a nice score!!
I am Abhimanyu dagla , a fresh Mechanical Engineering
Graduate from Delhi College of Engineering,Delhi.
I am going to take SCJP .
Would you please tell me that what are the future prospects for me ? Note that I am from non comp background and w/o any experience.
Waitin for ur mail
Abhimanyu
19 years ago

Congrats Lucky for such a nice score!!
I am Abhimanyu dagla , a fresh Mechanical Engineering
Graduate from Delhi College of Engineering,Delhi.
I am going to take SCJP .
Would you please tell me that what are the future prospects for me ? Note that I am from non comp background and w/o any experience.
Waitin for ur mail
Abhimanyu
19 years ago

Congrats Ragini for such a nice score!!
I am Abhimanyu dagla , a fresh Mechanical Engineering
Graduate from Delhi College of Engineering,Delhi.
I am going to take SCJP .
Would you please tell me that what are the future prospects for me ? Note that I am from non comp background and w/o any experience.
Waitin for ur mail
Abhimanyu
19 years ago

Congrats Chris for such a nice score!!
I am Abhimanyu dagla , a fresh Mechanical Engineering
Graduate from Delhi College of Engineering,Delhi.
I am going to take SCJP .
Would you please tell me that what are the future prospects for me ? Note that I am from non comp background and w/o any experience.
Waitin for ur mail
Abhimanyu
19 years ago

Congrats Rohit for such a nice score!!
I am Abhimanyu dagla , a fresh Mechanical Engineering
Graduate from Delhi College of Engineering,Delhi.
I am going to take SCJP .
Would you please tell me that what are the future prospects for me ? Note that I am from non comp background and w/o any experience.
Waitin for ur mail
Abhimanyu
19 years ago

hi Aj,
congrats for such a nice score!!
I need your expert advice. I am going to take SCJP in 2 or three months. I know only C and I am learning java at an Institute . So please tell me what are the best books to study ?
yeah, can you tell me that what are the job prospects after
SCJP? I am a fresh Mechanical Engineering Graduate from Delhi
College of Engineering ,Delhi.So what is in store for me after it?
thanks in advance ..
Abhimanyu dagla
19 years ago

hi to all at javaranch,
would somebody who has cleared SCJP
tell me what books I should refer, and what help can I get from the net for the SCJP prep. I am preparing for it.
And yeah, what are the job prospects after it? I am a fresh
Engg. graduate from DCE(Delhi College from Engg.).
Thanks.