Wednesday, October 27, 2010

Display the contents of Server Home page -Internet Programming lab record

0 comments
import java.net.*;
import java.io.*;
import java.util.*;
public class mime2
{
public static void main(String args[])
{
for(int i=0;i<args.length;i++)
{
try
{
URL u=new URL(args[0]);
URLConnection uc=u.openConnection();
System.out.println("Content-Type:"+uc.getContentType());
System.out.println("Content-Encoding:"+uc.getContentEncoding());
System.out.println("Date:"+new Date(uc.getDate()));
System.out.println("Last Modified:"+new Date(uc.getLastModified()));
System.out.println("Expiration Date:"+new Date(uc.getExpiration()));
System.out.println("Content-Length:"+uc.getContentLength());
}

How to Run download Home page networking Java Program

0 comments
Java Networking Program:(internet programming lab program for cse,it students )

import java.net.*;
import java.io.*;
public class mime1
{
public static void main (String[] args)
{
if (args.length >0)
{
try
{
URL u = new URL(args[0]);
InputStream in = u.openStream( );
in = new BufferedInputStream(in);
Reader r = new InputStreamReader(in);
int c;

Invoking Servlets from Html -A Simple Program For you

0 comments
Html Code:


<HTML>
    <head>
        <TITLE>INVOKING SERVLET FROM HTML</TITLE>
    </head>
<BODY>
<CENTER>
<FORM name = "PostParam" method = "Post" action="http://localhost:8080/servlets-examples/servlet/serv">
<TABLE>
<tr>
<td><B>Employee: </B> </td>
<td><input type = "textbox" name="ename" size="25"
value=""></td>
</tr>
<tr>
<td><B>Phone: </B> </td>
<td><input type = "textbox" name="phoneno" size="25"
value=""></td>
</tr>
<tr>
<td><b>Salary: </b></td>
<td><input type="textbox" name="salary" size="25" value=""></td>
</tr>
<tr>
<td><b>Id:</b></td>
<td><input type="textbox" name="id" size="25" value=""></td>
</tr>


</TABLE>
<INPUT type = "submit" value="Submit">
</FORM>
</CENTER>
</body>
</html>


Servlet Code:

import java.io.*;
import java.util.*;
import javax.servlet.*;
public class serv extends GenericServlet
{
public void service(ServletRequest request,ServletResponse response)throws ServletException,IOException
{
PrintWriter out=response.getWriter();
String name=request.getParameter("ename");
String phno=request.getParameter("phoneno");
String sal=request.getParameter("salary");
String id=request.getParameter("id");
out.println("EmployeeName: "+name);
out.println("Phone No:  "+phno);
out.println("id:  "+id);
out.println("Salary: "+salary);

}
}

Monday, October 25, 2010

How to Add the Servlet description to Web.xml

0 comments
paste this code after any closed servlet tag( ) code


<servlet>
<servlet-name>PostParam</servlet-name>
<servlet-class>PostParam</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>PostParam</servlet-name>
<url-pattern>/servlet/PostParam</url-pattern>
</servlet-mapping>


like this:

How to Run servlets in Tomcat Server

0 comments
Hi Visitors, Today i will teach you how to run the servlets using Tomcat Server.

So first of all download the Tomcat Server from their official site



if this link not working ,type in google as "TomCat server download"


Install the Tomcat Server.(select Full install instead of Normal )

Now go to  MyComputer->Properties->Advanced->Environment Variable
 and click the first "New " button
and Enter the Following Values:

Tuesday, October 19, 2010

an Integer parameter to Object Argument-predict the output for java program

0 comments
public class ObjectInt
{
public ObjectInt(Object c)
{
System.out.println(c);
System.out.println(c.toString( ));
}
public static void main(String []ar)
{
int a=2;
ObjectInt i=new ObjectInt(a);
}
}

Result:
2 2

want explanation? comment here..

Thursday, October 14, 2010

creating reference for interface not a instance

0 comments
interface intf
{
int a=3;

 void display();
}
public class Inter implements intf
{
public static void main(String ar[])
{

int b=intf.a;
(new Inter()).display();
}
public void display()
{
intf f=new in();
f.display();
}
}
class in implements intf
{
public void display()
{
System.out.println("hi");
}
}

adding fields to interface-predict the output for this j2se program

0 comments

interface batch
{
int batchcode=107;
void display();
}
class Stu implements batch
{
void display()
{
System.out.println(batchcode);
}
public class DemoInterface
{
public static void main(String []a)
{
stu s=new stu;
stu.display();
}
}

Friday, October 8, 2010

Object Class object as parameter-predict the output

0 comments
class Emp
{
public void para(Object e)
{
if(e instanceof Tech)
((Tech)e).showDetails();
if(e instanceof Ssl)
((Ssl)e).showDetails();

}
}
class Tech
{
public void showDetails()
{
System.out.println("TechNews");
}
}
class Ssl
{
public void showDetails()
{
System.out.println("SSlogic");
}
}
public class ObjectPara
{
public static void main(String arg[])
{
Tech t=new Tech();
Ssl s=new Ssl();
Emp e=new Emp();
e.para(t);
e.para(s);
}
}

Polymorphic Parameter -predict the output

0 comments
class Employee
{
protected String name;
protected String id;
Employee(String n,String i)
{
name=n;
id=i;
}
public void showDetail(Employee e)
{
System.out.println("Details");
if(e instanceof Programmer)
((Programmer)e).showDetails();
if(e instanceof Manager)
((Manager)e).showDetails();

}
}
class Programmer extends Employee
{
protected String salary;
Programmer(String n,String i,String s)
{
super(n,i);
setSalary(s);
}
public void setSalary(String s)
{
salary=s;
}
public void showDetails()
{
System.out.println("***********************");
System.out.println("Programmer Name: "+name);
System.out.println("Programmer Id:   "+id);
System.out.println("Programmer Salary: "+salary);
System.out.println("************************");
}
}
class Manager extends Employee
{
protected String salary;
Manager(String n,String i,String s)
{
super(n,i);
setSalary(s);
}
public void setSalary(String s)
{
salary=s;
}
public void showDetails()
{
System.out.println("***********************");
System.out.println("Manager Name: "+name);
System.out.println("Manager Id:   "+id);
System.out.println("Manager Salary: "+salary);
System.out.println("************************");
}
}
public class PolyPara
{
public static void main(String args[])
{
//Programmer p=
//Manager m=
Employee e[]=new Employee[2];
e[0]=new Programmer("selva","41","30000");
e[1]=new Manager("Srini","50","50000");
e[0].showDetail(e[0]);
e[1].showDetail(e[1]);

}
}

Thursday, October 7, 2010

Polymorphism -predict the output

0 comments
class Employee
{
String name;
String id;
Employee(String na,String i)
{
this.name=na;
this.id=i;
}
public void getName()
{
System.out.println("Employee Name:"+name);
}
public void getId()
{
System.out.println("Employee Id"+id);
}
}
class Manager extends Employee
{
double salary;
Manager(String na,String i,double d)
{
super(na,i);
setSalary(d);
}
private void setSalary(double d)
{
salary=d+3000;
}
public void getSalary()
{
System.out.println("Manager salary is"+salary);
}
}
class Programmer extends Employee
{
float salary;
Programmer(String na,String i,float s)
{
super(na,i);
setSalary(s);
}
public void getName()
{
System.out.println("Programmer Name is"+name);
}
private void setSalary(float s)
{
salary=s+1000;
}
public void getSalary()
{
System.out.println("Programmer Salary is"+salary);
}
}
public class Poly
{
public static void main(String ar[])
{
Employee e[]=new Employee[2];
e[0]=new Programmer("Selva","11107104041",30000f);
e[1]=new Manager("Srini","11107104050",40000f);
e[0].getName();
e[0].getId();
((Programmer)e[0]).getSalary();
}
}

static block vs Instance Intializer vs constructor vs parent constructor

0 comments
Predict the Output:

 class parent
{
parent()
{
System.out.println("Parent Class");
}
}
class child
{
static int a;
child()
{
super();
System.out.println("child Class");
}
{
System.out.println("Instance Intializer");
}
static
{
a=2;
System.out.println("Static block");
}
}
public class demo
{
public static void main(String arg[])
{
child d=new child();
}
}

Tuesday, October 5, 2010

Predict the output(before study about the toString Method)

0 comments
public class Demo
{
public String toString()
{
return "Demo Class Object";
}
public static void main(String args[])
{
Demo t=new Demo();
System.out.println("The Reference is"+t);
}
}

Monday, October 4, 2010

Predict the output

0 comments
public class demo
{
public static void main(String args[])
{
int a;
char c;
System.out.println(a+c);
}
}

Visitors

Followers

 

Java Interview Questions. Copyright 2008 All Rights Reserved Revolution Two Church theme by Brian Gardner Converted into Blogger Template by Bloganol dot com