Premkumar Gopal

Greenhorn
+ Follow
since Jun 12, 2004
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Premkumar Gopal

Could you also post your deployment descriptor. Thanks
Hi,
One of the reasons could be :
Trying to call doPost(...) instead of doGet(..). I suggest you have both methods and calling the one from other to test it out whether it is not the issue. If you figure out that is the issue, then you know why it is so(because HF says when doGet() / doPost() gets invoked).

Thanks
Randy,
The best place to refer to configure the Tomcat is either Apache's website or the Setup documentation that comes with the Tomcat. Regarding Classpath issue: Even the experts fail sometimes. Being said that, one can learn this through experience. I have read a number of books on Servlets and HF book explained in the most simplest way that one can imagine. I understand that referring to Errata to figure out whether something is correct/incorrect especailly if it is the first time is little frustrating. Believe me, this forum is always there to help. Please do note that Kathy, who is the brain behind Javaranch creation(Free Website) from America is also the co-author of HF.

Thanks
San,
Awesome..I need to appreciate your persevarance of reading the book for 3 times and spending 3 hrs/day. Good luck...

Thanks
14 years ago
Hi,
In Enthuware's website it is mentioned that they have released a new version for SCWCD (310-081). Awaiting to hear from the persons who have used the latest version of Enthuware. If one goes by the review available for the 310-080, I expect them to do better for the latest version.

Thanks
Shankar,
You can refer to KBs book (pp 435 - Section "Isolating a Reference" ) talks in depth

Thanks
Jay,
I believe you are making use of Websphere 5/5.1 (in which case the default jre is not 1.4). I am thinking that might be the reason. I do use Websphere and I point it to 1.4.2 JRE.

Hope this helps
This thread is making me to think more and more ...

Even though the toString method is called into action, how the object is invoked plays a vital role. One has to take into account of the
println/print method of the java.io.PrintStream class is made use of. This is how I understood after going through the methods :

public class test{

public String toString(){return null;}

public static void main(String [] args)
System.out.println(new test().toString());
//calling toString() method
System.out.println(new test());
//calling toString() method} }


When we call new test().toString() , we are making use of the
public void print(String s)
of the PrintStream class - which says
if he argument is null then sthe string null is printed...

which is what happening here...

however when call new test(), we are making use of the
public void print(Object obj)
of the PrintStream class -

which in turn calls String.value of
Please note that here we are still talking about the object in this case which is t2. Since t2 is not null (note we are returning only null as part of the toString() method and not the object reference ), we are passing the object t2 to the method ( The code that actually gets executed is

public static String valueOf(Object obj) {
return (obj == null) ? "null" : obj.toString();
}

and returns null . To make myself clear, I thought I will delineate how the various classes are called

1) System.out.print(new test()) which is the same as calling
System.out.println(new test()) except for the return and line feed :

( PrintStream class )
public void print(Object obj) {
write(String.valueOf(obj));
}

2) This in turn calls (..String Class)

public static String valueOf(Object obj) {
return (obj == null) ? "null" : obj.toString();
}

the value got out of the above method is null which in goes to

private void write(String s) {
try {
synchronized (this) {
ensureOpen();
textOut.write(s);
textOut.flushBuffer();
charOut.flushBuffer();

}
}
catch (InterruptedIOException x) {
Thread.currentThread().interrupt();
}
catch (IOException x) {
trouble = true;
}
}


When textOut.write(s) is called (note we are passing the value null) and this is made use of in writer class as



public void write(String str) throws IOException {
write(str, 0, str.length());
}


here we are checking the length which is null.length() and this causes the nullpointer exception.

Hope this explains little better than what I put earlier. I believe anyone who goes through the api and ( the unzipped version of src.zip file of jre) can figure out.
Bottom line : parameter passed to println method (whether it is an object or the String) determines the method of execution...

Thanks
Sanjeev,
With reference to your
"... System.out.println(t1) ; .."

Here the passed object is null which is determined at the runtime unlike System.out.println(null) ( earlier said by Atul...in which case we get a compiler error as jvm could not figure out which method to use).

However when we use the statment (from the first posting)

System.out.println(t1)...here do note that the toString() method is called which invokes the series of classes ( Stacktrace I got :

java.lang.NullPointerException
at java.io.Writer.write(Writer.java:126)
at java.io.PrintStream.write(PrintStream.java:303)
at java.io.PrintStream.print(PrintStream.java:462)
at java.io.PrintStream.println(PrintStream.java:599)
at javaranch.Test001.main(Test001.java:31)
Exception in thread "main"

java.lang.NullPointerException
at java.io.Writer.write(Writer.java:126)
at java.io.PrintStream.write(PrintStream.java:303)
at java.io.PrintStream.print(PrintStream.java:462)
at java.io.PrintStream.println(PrintStream.java:599)
at javaranch.Test001.main(Test001.java:31)
Exception in thread "main"


When I look into the source code of the abstract class Writer the lines 125 : 127 are

125 : public void write(String str) throws IOException {
126 :write(str, 0, str.length());
127 : }

str.length() method is invoked, which in this case happens to be null, and any method invoked on the null returs NullPointerExcpetion.

Thanks
I was executing the code myself and the below explanation will might help better to understand the nullpointer exception :
Whenever any method is executed on the object whose value is null, nullpointer exception is thrown. Having said that, when we invoke the println method ,

public void write(String str) throws IOException
{
write(str, 0, str.length());
}


of the Writer class (got from the exception trace). Since str value is set to null, str.length() throws null pointer exception.
Hope this helps.
Since all the objects are created within the heap(in this case , the other happens to be an object of type I, the answer "None of the above is correct".
I believe the reason being :
toString() method is called whenever we try to call the object reference. In this case, the toString method specifically sets it to null
for the parameter 0 ( passed to the constructor).

If we created Test001 t3 = null ; we neither get compiler error and nor runtime exception.
Maybe Gurus can throw more light(any other explanation will help me to clear my ignornace and shape me better to prepare well for scjp ).
Yun,
The program got compile successfully on my machine.
Thanks
Hi,
(3) and (4) are the other ways to define and initialize the arrays.
Right Hand side of (3) namely new int[]{1, 2} goes by the name anonymous array. KB book talks about this in depth.

Thanks
Nick,
I felt Portlet Application Developer exam to be the easiest of all the tests I have taken so far. I have been working in Portal for the last 5 weeks or so. The exam questions are on the similar lines of the questions that were provided in the beginning of this topic. I found the book "Programming Portlets" by Ron Lynn. Development book available in the Info Center helped me a lot.

Thanks