Veer Batra

Ranch Hand
+ Follow
since Mar 12, 2001
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 Veer Batra

join(): join() can't release the lock as join is to keep the current thread going till the thread dies. So after that lock may be available.
sleep(): sleep() can realease the lock as sleep put the thread in sleep mode and releases all resources related to CPU.
notify(): just notifies and can hold the lock even after, but it is upto the notified thread to see if lock is avalable and secure it. Otherwise, if the thread who notified but still did not relaese the lock then notified thread/ready thread remain blocked until lock is available.
wait() : wait should release the lock as soon as it goes in the wait mode.
A buffer's capacity is the number of elements it contains. The capacity of a buffer is never negative and never changes.
It works for me and output is 3.
I installed Jbuilder yesterday which screwedup the setting. I uninstalled JDK as well as TextPad and installed again. JDK first and then TextPad and that fixed the problem. Thanks.

Veer
Few other things which I tried:
1. uninstalled TextPad and Installed again but still same problem.
2. in TextPad/Tools/Run I tried to run "Javac -version" and I got "javac 1.5.0_02"
Thanks for advising me to check version of java. Which actually seems the problem, However I am not able to establish which version I am using while in TextPad. But when I check at Dos prompt it gives me as under :

C:\Documents and Settings\Windows 2000>javac -version
javac 1.5.0_02

C:\Documents and Settings\Windows 2000>java -version
java version "1.5.0_02"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_02-b09)
Java HotSpot(TM) Client VM (build 1.5.0_02-b09, mixed mode, sharing)

Good news is that compilation and execution works at Dos prompt.

Any idea how to check java version while in Textpad.

FYI, I strongly believe that I have only one version of Java on my PC and that is 1.5.0_02.
Following code gives compile time error at line //a. Should it not use autoboxing to convert int(primitive) to Integer(wrapped).



Thanks in advance.


If line 4 is there then it gives nullPointerException on line 4. If line 4 commented out then it gives same exception on line 5. Line 4 which is not invoking any method, why it should give nullPointerException on that. Should it not print null and give exception on line 5 only?
Amit, Where you get true and false results. I am getting as under for all seven possibilities(see cut/paste of results):

false
false
true
true
true
false
true
Press any key to continue . . .

Which version of Java you are using? I am using 1.5. I am saying that because somebody mentioned here that results are different for 1.4 and 1.5.
We must understand difference between == operator and .equals() method of Strings. == compares the references and .equals() method compares the contents of the references. When we create literal it is created in the pool and it can have one or many refrences as far as it is referring to same address refrence. e.g. when we say 'String s1= "Compare me"' it is assigned a place in the pool with reference s1 having value "Compare me". If we create another string like 'String s2= "Compare me"' still it looks in the pool of literal strings and if some reference has same value which is here "Compare me" then s2 string reference is also refered to the same value. So now value "Comapre me" is being referred by two refrences so references are same and values are same so when we use == or .equals() it succeeds and turns out to true.

Now take another example. Now we create an object say 'String s3=new String("Compare me")'. Whenever we construct a String calling constructor explicitely, it uses extra memory location without looking into the pool. So s3 is not the same refrence as s1 or s2 but has same value "Compare me". In this case if we want to compare refrences that is use == operator will turn out false but if we use .equals() method which will compare values, will turn out true. Here is the code which can prove that.


So coming back to original example, if we use constructor explicitely like 'Integer a = new Integer(10);' it will create extra memory location 'a' to store the value 10 and so on. If we use == operator it checks reference and should turn out to false but if we use .equals() method which compares value inside the location should turn out true. There s one method .intern() which can move the values from outside pool into literals pool and helps in reducing the memory requirements. Just one more thing to remember, even if one has same reference but if we convert to string it will create new memory location, so after converting to string == oprator, will give result always false. Here is the modified version of original example.



I hope this helps, correct me if I am wrong.
But if SCJP is not the pre-requisite then why on SCBCD website it says as under :

Prior to beginning the Sun Certified Business Component Developer program, you must be a Sun Certified Programmer for the Java platform (any edition).

Check last line of "Product Description" on Sun Certified Business Component Developer for the Java 2 Platform, Enterprise Edition 1.3 (CX-310-090)
rint
public static double rint(double a)Returns the double value that is closest in value to the argument and is equal to a mathematical integer. If two double values that are mathematical integers are equally close to the value of the argument, the result is the integer value that is even. Special cases:
If the argument value is already equal to a mathematical integer, then the result is the same as the argument.
If the argument is NaN or an infinity or positive zero or negative zero, then the result is the same as the argument.


round
public static int round(float a)Returns the closest int to the argument. The result is rounded to an integer by adding 1/2, taking the floor of the result, and casting the result to type int. In other words, the result is equal to the value of the expression:

(int)Math.floor(a + 0.5f)Special cases:

If the argument is NaN, the result is 0.
If the argument is negative infinity or any value less than or equal to the value of Integer.MIN_VALUE, the result is equal to the value of Integer.MIN_VALUE.
If the argument is positive infinity or any value greater than or equal to the value of Integer.MAX_VALUE, the result is equal to the value of Integer.MAX_VALUE.