sitaram


{ City }
< Country > india
* Profession *
User No # 72474
Total Questions Posted # 0
Total Answers Posted # 58

Total Answers Posted for My Questions # 0
Total Views for My Questions # 0

Users Marked my Answers as Correct # 281
Users Marked my Answers as Wrong # 95
Answers / { sitaram }

Question { 7823 }

What is meant by wrapper classes?


Answer

Wrapper classes are used to convert primitive types to
objects. wrapper classes are final classes. final classes
can't be extends to other class.

Is This Answer Correct ?    4 Yes 0 No

Question { 26019 }

how to get the max salary and name of employee from
arraylist without using the Comperator or even Comparable
interface?


Answer

package Sample;

import java.util.*;

class Emp
{

int salary;
String name;
Emp(int i,String g)
{
this.salary=i;
this.name=g;

}

}

class MaxSalaryTest
{

public static void main(String []args)
{
ArrayList a = new ArrayList();
a.add(new Emp(100,"javed"));
a.add(new Emp(500,"apporva"));
a.add(new Emp(250,"sumit"));
a.add(new Emp(2500,"itika"));
a.add(new Emp(90,"latika"));
a.add(new Emp(3200,"jatin"));
a.add(new Emp(340,"nitin"));
a.add(new Emp(2300,"linda"));

Iterator i = a.iterator();
int maxsalary=0;
int sal = 0;
while(i.hasNext()){
Emp e = i.next();
sal = e.salary;
if(sal > maxsalary){
maxsalary= sal;
}
}
System.out.println("maximum salary..."+maxsalary);
}

}

Is This Answer Correct ?    15 Yes 1 No


Question { TCS, 9592 }

can we write program without class


Answer

class with out name is called ananamous class.

Is This Answer Correct ?    5 Yes 5 No

Question { Polaris, 7971 }

can we change the order of parameters in execute()?


Answer

no. The execute method will be override from super class
(action servlet class). This is the main reason. we can't
change the order of parameters in the execute method.

Is This Answer Correct ?    2 Yes 4 No

Question { TCS, 9104 }

What will happen if we write code like:
try{}catch(exception e)catch(IOException i)


Answer

it is not complied. because first catch having child
exception and last exception having parent exception is must.
correct answer is :
try{
}
catch(IOException i){
}
catch(Exception e){
}

Is This Answer Correct ?    19 Yes 2 No

Question { 4624 }

where you store password in banking project


Answer

The password will be convert into encrypt format. That data
will be storing in database. password must be always encrypt
format.

Is This Answer Correct ?    11 Yes 0 No

Question { Wipro, 8273 }

explain the Struts flow?


Answer

suppose one jsp page having two text fields and one button.
when ever submit the form. the request goes to action
servlet & then loads the struts-config.xml after check the
request where exactly match the action class in the sc.xml.
then executes the action class & executes validate form bean
then execute method and redirects view form.

Is This Answer Correct ?    10 Yes 1 No

Question { Cap Gemini, 3185 }

Explain JSP life cycle


Answer

A JSP life cycle can be defined as the entire process from its creation till the destruction which is similar
to a servlet life cycle with an additional step which is required to compile a JSP into servlet.

The following are the paths followed by a JSP

1.Compilation

2.Initialization

3.Execution

4. Cleanup

The four major phases of JSP life cycle are very similar to Servlet Life Cycle

1. JSP Compilation:
-------------------
When a browser asks for a JSP, the JSP engine first checks to see whether it needs to compile the page.
If the page has never been compiled, or if the JSP has been modified since it was last compiled, the JSP engine compiles the page.

The compilation process involves three steps:

1.Parsing the JSP.

2.Turning the JSP into a servlet.

3. Compiling the servlet.

2. JSP Initialization:
----------------------
When a container loads a JSP it invokes the jspInit() method before servicing any requests. If you need to perform JSP-specific
initialization, override the jspInit() method:

public void jspInit(){
// Initialization code...
}

Typically initialization is performed only once and as with the servlet init method, you generally initialize database
connections, open files, and create lookup tables in the jspInit method.

3.JSP Execution:
----------------
This phase of the JSP life cycle represents all interactions with requests until the JSP is destroyed.

Whenever a browser requests a JSP and the page has been loaded and initialized, the JSP engine invokes the _jspService() method in the JSP.

The _jspService() method takes an HttpServletRequest and an HttpServletResponse as its parameters as follows:

void _jspService(HttpServletRequest request,
HttpServletResponse response)
{
// Service handling code...
}

When a container loads a JSP it invokes the jspInit() method before servicing any requests. If you need to perform JSP-specific initialization,
override the jspInit() method: The _jspService() method of a JSP is invoked once per a request and is responsible for generating the
response for that request and this method is also responsible for generating responses to all seven of the HTTP methods ie. GET, POST, DELETE etc.

4.JSP Cleanup:
--------------

The destruction phase of the JSP life cycle represents when a JSP is being removed from use by a container.

The jspDestroy() method is the JSP equivalent of the destroy method for servlets. Override jspDestroy when you need to perform any cleanup,
such as releasing database connections or closing open files.

The jspDestroy() method has the following form:

public void jspDestroy()
{
// Your cleanup code goes here.
}

Is This Answer Correct ?    0 Yes 0 No

Question { IBM, 3923 }

What is an object in Java and what are its benefits?


Answer

Object is an instance of a class. The object will have its own state and access to all of the behavior defined by the class.

Is This Answer Correct ?    0 Yes 0 No

Question { Cap Gemini, 4951 }

How is object created in java?


Answer

There are FIVE different ways to create objects in Java:

1. Using `new` keyword:

This is the most common way to create an object in Java. Almost 99% of objects are created in this way.

MyObject object = new MyObject();//normal way
2. By Using Factory Method:

ClassName ObgRef=ClassName.FactoryMethod();
Example:

RunTime rt=Runtime.getRunTime();//Static Factory Method
3. By Using Cloning Concept:

By using clone(), the clone() can be used to create a copy of an existing object.

MyObjectName anotherObject = new MyObjectName();
MyObjectName object = anotherObjectName.clone();//cloning Object
4. Using `Class.forName()`:

If we know the name of the class & if it has a public default constructor we can create an object in this way.

MyObjectName object = (MyObjectNmae) Class.forName("PackageName.ClassName").newInstance();
Example:

String st=(String)Class.forName("java.lang.String").newInstance();
5. Using object deserialization:

Object deserialization is nothing but creating an object from its serialized form.

ObjectInputStreamName inStream = new ObjectInputStreamName(anInputStream );
MyObjectName object = (MyObjectNmae) inStream.readObject();

Is This Answer Correct ?    2 Yes 0 No

Question { Syntel, 6332 }

What is the life-cycle of an object?


Answer

Object creation
---------------
The operator new allocates storage in the heap and invokes a constructor method for initialization of the object.

Object deletion
---------------
The Java garbage collector runs in parallel (as a thread) with the executing program, so garbage collection is in some sense continuous in Java. A class can have a finalize method that is to be invoked (automatically) before deleting an object. This is useful in case there are any resources, such as an open file, that need to be released by the object before it is removed from the system.

Is This Answer Correct ?    1 Yes 0 No

Question { SunGard, 3853 }

why static class in java or what is use of static class in java


Answer

we are using with out creating object for static class because, JVM allocate the consistent memory for static class.

Is This Answer Correct ?    0 Yes 0 No

Question { Value Labs, 4522 }

Tell me the programme for this


@
1 2
@ @ @
1 2 3 4


Answer

public class TriangleDisplay {

public static void main(String[] args) {
int n = 4;
for (int i = 1; i <= n; i++) {
for (int j = 4; j < 2 * n - i; j++) {
System.out.print(" ");
}
for (int j = 1; j <= i; j++) {
if (i % 2 != 0) {
System.out.print("@" + " ");
} else {
System.out.print(j + " ");
}
}
System.out.println();
}
}
}

Is This Answer Correct ?    0 Yes 0 No

Prev    1   2   3    [4]