Rohan Pujari

Greenhorn
+ Follow
since Feb 27, 2007
Merit badge: grant badges
For More
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 Rohan Pujari

when we declare a string variable as
String s = null
then the string referrence variable s does not refer to any String object.
How does the statement s+=s
produce a value of nullnull??
does this mean that when s does not refer to any string object it gets a value of null. but still any other operations on the variable using the dot operator results in nullpointerexception.
Thanks for the help.

But how did you get that figure for the float storage

The largest number a long can have is 2^63 - 1. Whereas, a float, which is 32 bits shorter than a long, can have up to (2-2^23)�2^127.



it would be good if you could elaborate on that.
long in java is 64bits whereas float is 32 bits.
so i wrote a very simple code like this

long l = 1256L;
float f = 25.25F;

how does a long fit into a long and why does the compiler give error while putting float into long.

could some one please let me know the exact details about float and double data types like how many bits are used to represent the the digits before the decimal point and those after the decimal point.
when i write the statement

String s = new String("abc") ;

There are two string objects created right??

so in the code below how many string objects are actually created.

String s1 = "abc";
String s2 = new String("xyz");
s2=s1;
s1.toUpperCase();
String s3 = "abc" ;
String s4 = s3.replace('a','A');

well i think in all five objects are created.
please correct me if i am wrong.
15 years ago
when i write the statement

String s = new String("abc") ;

There are two string objects created right??

so in the code below how many string objects are actually created.

String s1 = "abc";
String s2 = new String("xyz");
s2=s1;
s1.toUpperCase();
String s3 = "abc" ;
String s4 = s3.replace('a','A');

well i think in all five objects are created.
please correct me if i am wrong.
Yep i got it. I made some changes to the original program i made the nt object as static and also ran a 3rd thread giving it nt as the runnable target. The output is exactly what you have explained. First thread1 executes and the moment it leaves the synchronized block thread2 enters and starts running and finally thread3 enters only when 2 has finished or has exited out of the block.

Whew threads can get really confusing at times

Thanks Henry
so does it mean that private object nt does not have lock associated with it?




When the thread1 finishes executing the method of nt object then it has dropped the lock for the nt object. but still it continues to execute and only after thread1 finishes does thread2 start executing.

now only one thread enters a synchronized block but in the above case the lock that the thread acquire is of a different object so in general does it imply that

Even if in a synchronized block when a thread acquires a lock on a third party object and finishes executing a synchronized method of that object(effectively dropping the lock), another thread cannot enter the synchronized block till the first thread leaves the block?
int the line

int i =x++ + ++x ; i = 4

because according to operator precedence ++x evaluates to 2 and then x++ again to 2 thus giving output i=4 and x = 3

but

int i = x++ + x++ the output is x=3 i=3
could some one explain me how it got evaluated to the above output.


In this particular code in the Kathy Sierra book it is give that eight objects in total are created but any opertaion on strings results in a new String. So in the system.out.print statement shouldn't there be two more objects created 1 which is s1+""(and soon to be lost) and then the final string object that is springwinterspringsummer(that too i guess will be lost) . Please let me know about this.
This is straight from the Kathy Sierra book about for loop
Keep in mind that this iteration expression is always the last thing that happens ! So although the body may never execute again, the iteration expression always runs at the end of the loop block. so for a for loop like this does it mean that when i is equal to 5 the body does not execute but still i is incremented ? but the output is 5. So is this a printing mistake or there is something else that the author wants to bring attention to.
Is null a reserved word in java?

Finally i am able to connect to the database using the jtds. Still had some SSO error but included a dll file in the path and finally am able to connect to the database without any error. Thanks Paul for helping me out with this. Thanks a lot. Javaranch is really a great website
yep i started the TCP/IP port but now it says the login has failed for the user. now i guess i have to configure the login part in sql server since i generally login through the windows login. thanks for your help Paul i really appreciate it.
i have handled that exception but now it is giving me a new error
com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the ho
st has failed. java.net.ConnectException: Connection refused: connect
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(U
nknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(Unknown Sour
ce)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java:512)
at java.sql.DriverManager.getConnection(DriverManager.java:193)
at DataConnect.<init>(DataConnect.java:14)
at DataConnect.main(DataConnect.java:31)