Win a copy of Kotlin for Android App Development this week in the Kotlin forum!

Abhishek Mantri

+ Follow
since Sep 06, 2007
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Abhishek Mantri

I am confused with output of following code :
public class Bufer{
public static void main(String args[]){
Bufer obj =new Bufer();
StringBuffer b = new StringBuffer("abc");
void method(StringBuffer b){

Output : abcqwe
Please explain the output and why there is no nullpointer exception ?

Many Congratulations to you !
only four days of study and getting 86% is simply astounding !
Can you elaborate more on your studying techniques, and offer us some tips ?
9 years ago
Congrats Shamali,
Can you share with us tips for getting 100% score?
How much time you is required to prepare for the exam?
Regards Abhishek
9 years ago
1.Do we get web.xml file (deployment descriptor) during deploying or do we have to type it entirely?
2.What are EAR and WAR files?When and how they are created? statements accurately describe how many instances of servlet the servlet container instantiates for each web application?(choose all that apply)
A.If the servlet implements javax.servlet.SingleThreadModel,the container may create one instance for each request.
B.If the servlet does not implement SingleThreadModel,the container may create multiple instances of the servlet in same JVM.
C.The<load-on-startup> web.xml element can determine how many instances are created.
D.If the servlet does not implement SingleThreadModel, the container will create no more than one instance per JVM.

Correct answer is A,D
I couldn't get why 'A' is correct,since there is always single instance of a servlet existing and not one per request.Please help !
If we override init method which takes (ServletConfig) as argument then why should we call super.init(ServletConfig)??
Sorry Ben
The source is self test on threads from SCJP book by Kathy.
since this has become a universal book i forgotto mention,sorry again !
2. Given:
public class Letters extends Thread {
private String name;
public Letters(String name) { = name; }
public void write() {
public static void main(String[] args) {
new Letters("X").start();
new Letters("Y").start();
} }
We want to guarantee that the output can be either XXYY or YYXX, but never XYXY or any
other combination. Which of the following method definitions could be added to the Letters
class to make this guarantee? (Choose all that apply.)
A. public void run() { write(); }
B. public synchronized void run() { write(); }
C. public static synchronized void run() { write(); }
D. public void run() { synchronized(this) { write(); } }
E. public void run() { synchronized(Letters.class) { write(); } }
F. public void run() { synchronized(System.out) { write(); } }
G. public void run() { synchronized(System.out.class) { write(); } }
E and F are correct.

Can any body explain how F. is correct?
which is the fifth thread then???
do you mean main thread?
1. class Reader extends Thread {
2. Calculator c;
4. public Reader(Calculator calc) {
5. c = calc;
6. }
8. public void run() {
9. synchronized(c) {
10. try {
11. System.out.println("Waiting for calculation...");
12. c.wait();
13. } catch (InterruptedException e) {}
14. System.out.println("Total is: " +;
15. }
16. }
18. public static void main(String [] args) {
19. Calculator calculator = new Calculator();
20. new Reader(calculator).start();
21. new Reader(calculator).start();
22. new Reader(calculator).start();
23. calculator.start();
24. }
25. }
27. class Calculator extends Thread {
28. int total;
30. public void run() {
31. synchronized(this) {
32. for(int i=0;i<100;i++) {
33. total += i;
34. }
35. notifyAll();
36. }
37. }
38. }
"The program starts three threads" is this statement correct ,i think it starts 4 threads.This code is from scjp book page 724-725.