C-TEL INFOSYSTEM PVT LTD
=================================================================
1.pREDICT THE OUTPUT OF THE FOLLOWING JAVA PROGRAM.
class Testp
{
public static void main(String[] args)
{
String s1=new String("prince");
String s2=new String("prince");
if(s1==s2)
System.out.println("Equal");
else
System.out.println("Not Equal");
}
}
a. Equal b.Not Equal c.UncheckedException d.none
Correct Ans:b.Not Eqaul
--------------------------------------------------------------
2.PREDICT THE OUTPUT OF THE FOLLOWING JAVA PROGRAM.
class super1
{
final public int cal(int a,int b){
return 0;
}
}
class sub1 extends super1
{
public int cal(int a,int b){
return 1;
}
}
class Testp
{
public static void main(String[] args)
{
sub1 a=new sub1();
System.out.println("X:"+a.cal(0,1));
}
}
a.CheckedException b.UnCheckedException c.0 d.1
Correct Ans:a.Compile time errro or chechedException
-----------------------------------------------------------------
3.What is the output of this following program.
import java.util.*;
class Testp
{
public static void main(String[] args)
{
TreeSet <String> st=new TreeSet<>();
st.add("Tora"); st.add("for"); st.add("Tora");
st.add("ToraforTora");
for(String temp:st){
System.out.println(temp+" ");
}
}
}
//note: TreeSet does't take the duplicate values and also sort the strig
// of ASCI Values
a.Tora for Tora ToraforTora b.Tora for ToraforTora
c.Tora ToraforTora for d.for Tora ToraforTora
Correct Ans:c.Tora ToraforTora for
--------------------------------------------------------------------------
4.What is the output of this program.
import java.util.*;
class Testp
{
public static void main(String[] args)
{
List <String> st1=new LinkedList<>();
st1.add("Tora"); st1.add("for"); st1.add("Tora");
st1.add("cales");
st1.add("ToraforTora");
List <String> st2=new LinkedList<>();
st2.add("Tora");
st1.removeAll(st2);
for(String temp:st1){
System.out.print(temp+" ");
}
}
}
//note: LinkList is a storing the values in insertion order and it allow to store
// duplicate values but if you call the st1.removeAll(st2)than what ever is match
// it will removed in the Linklist
Correct Ans:a.for cales ToraForTora
----------------------------------------------------------------------------------------------------
6.What is the output of this program.
import java.util.*;
class Testp implements Runnable
{
public void run(){
System.out.println("Tora");
}
public static void main(String[] args)
{
Thread th=new Thread(new Testp());
th.start();
th.start();
System.out.println("th.getState()");
}
}//note:If you call this start() method two times with same reference variable
//than you get IllegalThreadStateException
Correct Ans:Run TimeException
-----------------------------------------------------------------------------
7.What is the output of this program.
class Testp
{
private static float temp(){
public static float sum=21;//compile time errro we can't place
return (--(sum)); //static member in static method and block
}
public static void main(String[] args)
{
Testp t=new Testp();
System.out.println(testp.temp());
}
}
a.21 b.20 c.CompileTime error d.RunTime_error
Correct Ans:Compile time Error
----------------------------------------------------------------------------
8.What is the following true about Interface in java
1.An instance can contain following type of member
.. public static final fields (Constant)
..default and static method with bodies
2. An instance of interface can be created
3.A class can implement the same interface
4.Many classes can implement the same interface
a.1,3 and 4 b.1,2 and 4 c.2,3 and 4 d.1,2,3 and 4
Correct Ans:a. 1,2 and 4
-----------------------------------------------------------------------------
9.What is the output of the following program.
class Testt extends Exception
{
}
class Testp
{
public static void main(String[] args)
{
try{
throw new Testt();// If you handle this exception in try block
// so no nedd the throws with the method
}
catch(Testt t){
System.out.println("Go to Test Exception");
}
finally{
System.out.println("Inside finally block");
}
}
}
a. Go to Test Exception b. Go to Test Exception c.Compile time error
Inside finally block d. Run time exception
Correct Ans: Go to Test Exception
Inside finally block
---------------------------------------------------------------------------
10.What will be the error in java following code
byte b=50;
b=b*50;
a. b cannot contain values 100 , limeted by the rage
b. *operator has converted b*50 into int which cannot be converted to
byte
c. b can't contain values 50
d. No errro in this
Correct Ans:b. b*50 it will become int and int can't be stored in the byte
-----------------------------------------------------------------------------
11. What is the output of the following program
class Testp
{
public static void main(String[] args)
{
String s1="abc";
String s2=s1;// it will copy the s1 address in s2
s1+="d"; // it will create new object and assign the address of s1
System.out.println(s1+" "+s2+" "+(s1==s2));
StringBuffer sb1=new StringBuffer("abc");
StringBuffer sb2=sb1;// it will share the same address
sb1.append("d");// it is appending the same memory
// it does not create the another object
System.out.println(sb1+" "+sb2+" "+(sb1==sb2));
}
}
Correct Ans:abcd abc false abcd abcd true
----------------------------------------------------------------------------
12. Predict the output of the following program
class Testp extends Thread
{
public void run(){
System.out.println("Hello");
}
public static void main(String[] args)
{
Testp th=new Testp();
th.start();
th.stop();
th.start();
}
}
Correct Ans:IllegalThreadStateException
----------------------------------------------------------------------------
13. What is the output of the following program
class Testp extends Thread
{
int num=100;
public void cal(int num){
this.num=num*10;
}
public void print(){
System.out.println(num);
}
public static void main(String[] args)
{
Testp th=new Testp();
th.cal(2);
th.print();
}
}
Correct Answer:20
-----------------------------------------------------------------------
14.What is the output of the following program
-----------------------------------------------------------------------
15.What is the output of the following program
class Testp extends Thread
{
public static void main(String[] args)
{
StringBuilder s1=new StringBuilder("java");
String s2="Core";
s1.append(s2);//it will append and make like s1=javaCore
s1.substring(4);// it will return index 4 to end values like Core
// but we are not store this values
int found=s1.indexOf(s2);//it will find s2 string is avilable in the s1
// if avilable first char which index than it will print this index number
System.out.println(s1+" "+s2+" "+found);
}
}
Correct Ans:javaCore Core 4
-------------------------------------------------------------------------------
16. What are the session tracking technique
1.URL rewriting 2. using session object 3. Using responce object
4.Using cookies 5. using servlet object 6. hidden field
Correct Ans: 1,2,4,6
----------------------------------------------------------------------------
17.Which of the following is the advantage using PreparedStatement in java
1.slow performance 2. Encourage SQL Exception
3.prevents SQL Injection 4. More memory usage
Correct Ans: Prevent SQL Injection
----------------------------------------------------------------------------
18. How many copy of a jsp page can be in memory at a time.
1.One 2.Two 3. Three 4.Unlimited
Correct Ans:1. One
---------------------------------------------------------------------------
19.The interface ResultSet has a method getMetaDeta() that returns a/ an
1.tuple values 2.Object 3. Result
Correct Ans: Object
The ResultSet object has a cursor/pointer which points to the current
row. ... The getMetaData() method of ResultSet interface retrieves the
ResultSetMetaData object of the current ResultSet. This method returns
a ResultSetMetaData object which holds the description of this ResultSet
object's columns.
--------------------------------------------------------------------------
20.Which is mandatory in <jsp:useBean/>tag
1.id,class 2.id,type 3. type ,property 4.type, id
Correct Ans:1. Id,class
----------------------------------------------------------------------------
21. Which one is the correct oreder of phase in jsp life cycle.
a) Initialization, Cleanup, Compilation, Execution
b) Initialization, Compilation, Cleanup, Execution
c) Compilation, Initialization, Execution, Cleanup
d) Cleanup, Compilation, Initialization, Execution
Correct Ans: c Compilation,Initilazition,Execution,cleanup,
------------------------------------------------------------------------------
22.Which tag shoud be used to pass information from jsp to include jsp
a) Using <%jsp:page> tag
b) Using <%jsp:param> tag
c) Using <%jsp:import> tag
d) Using <%jsp:useBean> tag
Correct Ans:b <%jsp:param> tag
---------------------------------------------------------------------------
23."Out"is implicit object of which class
a) javax.servlet.jsp.PrintWriter
b) javax.servlet.jsp.SessionWriter
c) javax.servlet.jsp.SessionPrinter
d) javax.servlet.jsp.JspWriter
Correct Ans:d. javax.servlet.jsp.JspWriter
---------------------------------------------------------------------------
29. Singleten beans are thread safe in spring framework
--------------------------------------------------------------------------
30. How to used ref keyword in bean.xml
----------------------------------------------------------------------------
31. How a spring bean life cycle can be controlled
----------------------------------------------------------------------------
32. javaScript code can be called by using ____________
a) RMI
b) Triggering Event
c) Preprocessor
d) Function/Method
Correct Ans:d.Function/Method
-----------------------------------------------------------------------------
Comments
Post a Comment