2
Q:

main() {

int i;

printf("%d",scanf("%d",&i)); // value 10 is given as input here

}

A) 1 B) 2
C) 3 D) 4

Answer:   A) 1



Explanation:

Scanf returns number of items successfully read and not 1/0. Here 10 is given as input which should have been scanned successfully. So number of items read is 1.

Subject: Java
Q:

Which of these class have only one field 'TYPE' ?

A) Run time B) Process
C) Void D) System
 
Answer & Explanation Answer: C) Void

Explanation:

The Void class has one field, TYPE, which holds a reference to the Class object for the type void.

Report Error

View Answer Report Error Discuss

Filed Under: Java
Job Role: Analyst , IT Trainer

6 6102
Q:

 What is the string contained in s after following lines of code?

StringBuffer s = new StringBuffer(“Hello”); s.deleteCharAt(0);  ?

A) llo B) Hllo
C) ello D) H
 
Answer & Explanation Answer: C) ello

Explanation:

deleteCharAt() method deletes the character at the specified index location and returns the resulting StringBuffer object.

So after deleting the character at 0 ie 'H', the string returns 'ello' as the output.

Report Error

View Answer Report Error Discuss

Filed Under: Java
Job Role: Analyst , IT Trainer

3 24669
Q:

Which of the following are incorrect form of StringBuffer class constructor  ?

A) StringBuffer(int size , String str) B) StringBuffer(int size)
C) StringBuffer(String str) D) StringBuffer()
 
Answer & Explanation Answer: A) StringBuffer(int size , String str)

Explanation:
Report Error

View Answer Report Error Discuss

Filed Under: Java
Job Role: Database Administration , IT Trainer

3 6405
Q:

Does not overriding hashcode() method has any performance implication ?

Answer

A poor Hashcode() function will result in frequent collision in HashMap which eventually increase time for adding an object into Hash Map.

Report Error

View answer Workspace Report Error Discuss

Subject: Java
Job Role: Analyst , IT Trainer

2 4584
Q:

How do you handle error condition while writing stored procedure or accessing stored procedure from java ?

Answer

Stored procedure should return error code if some operation fails but if stored procedure itself fail than catching SQLException is only choice.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

1 4169
Q:

What is the difference between creating String as new() and literal ?

Answer

When we create string with new() Operator, it’s created in heap and not added into string pool while String created using literal are created in String pool itself which exists in PermGen area of heap.



String s = new String("Test");

does not put the object in String pool , we need to call String.intern() method which is used to put them into String pool explicitly. its only when you create String object as String literal e.g. String s = "Test" Java automatically put that into String pool.

Report Error

View answer Workspace Report Error Discuss

1 2213
Q:

What is immutable object? Can you write immutable object ?

Answer

Immutable classes are Java classes whose objects can not be modified once created. Any modification in Immutable object result in new object. For example is String is immutable in Java. Mostly Immutable are also final in Java, in order to prevent sub class from overriding methods in Java which can compromise Immutability. You can achieve same functionality by making member as non final but private and not modifying them except in constructor.

Report Error

View answer Workspace Report Error Discuss

3 2967
Q:

Which two method you need to implement for key Object in HashMap ?

Answer

In order to use any object as Key in HashMap, it must implements equals and hashcode method in Java.

Report Error

View answer Workspace Report Error Discuss

4 6374