Srini, unfortunately, you're absolutely incorrect on this. References are
always set to null if not declared to be any other value; it's in the Java
Lang Spec:
Section 4.5.4 ("Initial Values of Variables") of the JLS:
"4.5.4 Initial Values of Variables
Every variable in a Java program must have a value before its value is used:
Each class variable, instance variable, or array component is initialized
with a default value when it is created (�15.8, �15.9, �20.3.6):
For type byte, the default value is zero, that is, the value of (byte)0.
For type short, the default value is zero, that is, the value of (short)0.
For type int, the default value is zero, that is, 0.
For type long, the default value is zero, that is, 0L.
For type float, the default value is positive zero, that is, 0.0f.
For type double, the default value is positive zero, that is, 0.0d.
For type char, the default value is the null character, that is, '\u0000'.
For type boolean, the default value is false.
For all reference types (�4.3), the default value is null.
Each method parameter (�8.4.1) is initialized to the corresponding argument
value provided by the invoker of the method (�15.11).
Each constructor parameter (�8.6.1) is initialized to the corresponding
argument value provided by a class instance creation expression (�15.8) or
explicit constructor invocation (�8.6.5).
An exception-handler parameter (�14.18) is initialized to the thrown object
representing the exception (�11.3, �14.16).
A local variable (�14.3, �14.12) must be explicitly given a value before it
is used, by either initialization (�14.3) or assignment (�15.25), in a way
that can be verified by the compiler using the rules for definite assignment
(�16).
The example program:
class Point {
static int npoints;
int x, y;
Point root;
}
class Test {
public static void main(String[] args) {
System.out.println("npoints=" + Point.npoints);
Point p = new Point();
System.out.println("p.x=" + p.x + ", p.y=" + p.y);
System.out.println("p.root=" + p.root);
}
}
prints:
npoints=0
p.x=0, p.y=0
p.root=null
illustrating the default initialization of npoints, which occurs when the
class Point is prepared (�12.3.2), and the
default initialization of x, y, and root, which occurs when a new Point is
instantiated. See �12 for a full description of all aspects of loading,
linking, and initialization of classes and interfaces, plus a description of
the instantiation of classes to make new class instances.
Ted Neward
Java Instructor, DevelopMentor ( http://www.develop.com )
http://www.javageeks.com/~tneward
-----Original Message-----
From: Srini <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED] <[EMAIL PROTECTED]>
Date: Sunday, December 12, 1999 9:40 PM
Subject: Re: error messages
>very simple
>
>ur declaring rs as a local variable so it has to be initialized to any
value
>before ur accessing it. Instead of
>
>ResultSet rs;
>
>say
>
>ResultSet rs=null;
>
>and put ur code in a try and catch block.
>
>Hope this Helps
>Srini
>
>Kelsey Fedde wrote:
>
>> JDBCServlet.java:115: Variable rs may not have been initialized.
>> String sd = rs.getString(2);
>> �
>> JDBCServlet.java:115: Exception java.sql.SQLException must be caught, or
it
>> must
>> be declared in the throws clause of this method.
>> String sd = rs.getString(2);
>>
>> p.s. the 2 is meant to refer to line 2 of a db2 table I am accessing
this
>> table from OS/390
>>
>> I can't find and correct the error (been working on this for hours) I
dont'
>> have a debugger and
>> write entirely in notepad....
>> suggestions?
>>
>> thanks,
>> Kelsey
>>
>>
___________________________________________________________________________
>> To unsubscribe, send email to [EMAIL PROTECTED] and include in the
body
>> of the message "signoff SERVLET-INTEREST".
>>
>> Archives: http://archives.java.sun.com/archives/servlet-interest.html
>> Resources: http://java.sun.com/products/servlet/external-resources.html
>> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
>
>___________________________________________________________________________
>To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
>of the message "signoff SERVLET-INTEREST".
>
>Archives: http://archives.java.sun.com/archives/servlet-interest.html
>Resources: http://java.sun.com/products/servlet/external-resources.html
>LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html