nikunj thakur

Ranch Hand
+ Follow
since Sep 23, 2007
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by nikunj thakur

I have a fair knowledge of core java and i want to learn servlets and jsp.I just want to know which book is best for the begineers which starts from basics of servlets.
17 years ago
There's no parantheses error even if i remove the extra ) their is same error
class Titanic
{
public static void main(String[] args)
{
Boolean bl = true;
boolean b2 = false;
boolean b3 = true;
if((bl & b2) | (b2 & b3) & b3)
System.out.print("alpha ");

if((bl = false))| (b1 & b3) | (bl | b2))
System.out.print("beta ");

}
}
in the above code on compilation showing the following error exception at runtime because in the 2nd if we are assinging b1 to false but what is given in the kb book is that the result of any assignment is the value of the variable after the assignment, the expression (b1 = true) has a result of true. Hence, the if test should succeeds. then why is error
Hi Michael Brinkmann

Congratulation for clearing scjp5.0 exam i am also preparing for the same can give me the link to download full version of mock exam simulator free of cost
17 years ago
Hi Michael Brinkmann

Congratulation for clearing scjp5.0 exam i am also preparing for the same can give me the link to download full version of mock exam simulator free of cost
Hi satabdi

[Dubious request deleted]
[ December 04, 2007: Message edited by: Jesper Young ]
Which is better for the exam scjp5.0 and can some one give the link to download these simulator
I am planning to take scjp5.0 exam at the end of decembar i live in india where i can get the voucher and how to take the date for the exam.
but i want to ask can put 3 expressions in for logical operators
class Titanic {
public static void main(String[] args) {
Boolean bl = true;
boolean b2 = false;
boolean b3 = true;
if((bl & b2) | (b2 & b3) & b3)
System.out.print("alpha ");
if((bl = false) | (b1 & b3) | (bl | b2))
System.out.print("beta "};
}
}

What is the result?

beta

alpha

alpha beta

Compilation fails.

No output is produced.

An exception is thrown at runtime.
answer is exception is thrown at runtime
i want to ask can we have more than 2 expresions for the above operator
class Mixer {
Mixer() { }
Mixer(Mixer m) { ml = m;}
Mixer m1;
public static void main(String[] args) {
Mixer m2 = new Mixer();
Mixer m3 = new Mixer(m2); m3.go();
Mixer m4 = m3.m1; m4.go();
Mixer m5 = m2.m1; m5.go();
}
void go() { System.out.print("hi "); }
}

What is the result?

hi

hi hi

hi hi hi

Compilation fails

hi, followed by an exception

hi hi, followed by an exception
answer is this

F is correct. The m2 object's m1 instance variable is never initialized, so when m5 tries to use it a NullPointerException is thrown.


but i am getting this

E:\kb>e:\jdk1.5.0\bin\javac Mixer.java
Mixer.java:3: cannot find symbol
symbol : variable ml
location: class Mixer
Mixer(Mixer m) { ml = m;}
^
1 error

E:\kb>

What is write
class CardBoard {
Short story = 5;
CardBoard go(CardBoard cb) {
cb = null;
return cb;
}
public static void main(String[] args) {
CardBoard c1 = new CardBoard();
CardBoard c2 = new CardBoard();
CardBoard c3 = c1.go(c2);
c1 = null;
// do Stuff
} }

When // doStuff is reached, how many objects are eligible for GC?

0

1

2

Compilation fails.

It is not possible to know.

An exception is thrown at runtime


The answer is 2 objects are eligible
C1 and Short
but c3 is also null then wy c3 is not available
class Foo8
{
public void doFooStuff()
{
System.out.println("a");
}
public void doFooStuff1()
{
System.out.println("c");
}

}
public class Bar8 extends Foo8
{
public void doFooStuff()
{
System.out.println("b");
}
}
class Test
{
public static void main (String [] args)
{
Foo8 reallyABar = new Bar();
reallyABar.doFooStuff();
//reallyABar.doFooStuff();
//reallyABar.doFooStuff1();


// Legal because Bar is a
// subclass of Foo
// Bar reallyAFoo = new Foo(); // Illegal! Foo is not a
// subclass of Bar
}
}

i am getting exception in thread main error
what is the reason for that
class Alien {
String invade(short ships) { return "a few"; }
String invade(short... ships) { return "many"; }
}
class Defender {
public static void main(String [] args) {
System.out.println(new Alien().invade(7));
}
}

What is the result?

many

a few

Compilation fails.

The output is not predictable.

An exception is thrown at runtime.

the answer is compilation fails
but why do we have to cast the invade(7) to short
class Alien {
String invade(short ships) { return "a few"; }
String invade(short... ships) { return "many"; }
}
class Defender {
public static void main(String [] args) {
System.out.println(new Alien().invade(7));
}
}

What is the result?

many

a few

Compilation fails.

The output is not predictable.

An exception is thrown at runtime.
the ans is c i understood but i didn't understand the explanation in the book
explain please