Adam S-R

Greenhorn
+ Follow
since Aug 15, 2001
Merit badge: grant badges
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 Adam S-R

Futher to the point Rashmi has raised, I think Windows OS have 7 or so priority levels. However where the JVM would fit in I don't know, so couldn't say about time-slicing effects. I agree with Marcus though - the main point is that you can't put blind faith in Thread scheduling as it varies platform to platform and can be undermined in unpredictable ways. However, I did the same question and I have to say I did actually choose 2 as an option.
Adam
Vanitha
From "The Java Tutorial"


The chosen thread will run until one of the following conditions is true:
A higher priority thread becomes runnable.
It yields, or its run method exits.
On systems that support time-slicing, its time allotment has expired.
Then the second thread is given a chance to run, and so on, until the interpreter exits.


All other things being the same, given two runnable threads the higher priority thread will run. I'm fairly certain that this is the case. Anyone got any other ideas?

Adam
Guoqiao
Possible mistake on mock 2 Q.42?:


Which of the following statements are true?
(Select two correct answers)
A:
For any i < 0, Double.isNaN(Math.sqrt(i) will return true;<br /> B:<br /> Math.random()*100 > 0.0 will never return false;
C:
For any a > 0, Math.ceil(a) >= 1 will always return true;
D:
You can not change the length of an array after you defined it.

Answers:
: A C


Explanation:
: The range for random() is 0.0(inclusive)
to 1.0(exclusive).
Once an array is created and instantiated,
you cannot modify its length.


In that case, shouldn't the answers be B and D? Or have I got it wrong? Please clarify
Best wishes
Adam


Erm well actually
class Test{
public static void main(String[] args){}
}
does compile and run (without output). Does this show that "public" keyowrd if absent is implicitly added to top-level class at compile time? Someone please clarify.
Thanks
Adam
Guoqiao
Looks good - glad to see you've made text bigger! Questions look good at first glance
Thanks
Adam
Guoqiao
Great site - I like your explanations to the questions. The only thing I would say is would you consider making the text a bit bigger? I can't read it comfortably on my 15" monitor without straining my eyes. Perhaps you might consider using a serif font such as arial or verdana, or making the text bigger?
Adam
Hi
Just want to thank JavaRanch for being here - it's an invaluable resource and I like it very much. One grumble I have though is reading code snippets in UBB [CODE] tags - it's just too small to read comfortably on my 15" monitor. I know code is traditionally shown in a serif font, but if you're going to show it that small, can't we use verdana or arial instead? Either that or make the code appear 2 points or so bigger. Anyone else think the same?
Adam
21 years ago
Val
gives
null
null
false
Highlights that s2 is null "value" and that s1 is string literal with "null" value.
Many thanks
Adam

So u r saying that null can be used in place of an Object in equals()? How so, if AFAIK null isn't an Object? I am confused. Please clarify


Im going to answer my own question - similar to string literal "Adventure", null is null literal so can be used. Excuse my clouded thinking, I'm having a slow day.
Adam
Valentin

The reason why s1.equals(s2) when s2 is null is the following:
the equals method in the class String will accept an Object parameter. You pass on null and this is ok.


So u r saying that null can be used in place of an Object in equals()? How so, if AFAIK null isn't an Object? I am confused. Please clarify
Adam
Ashok
Check out this link to Sun's documentation at http://java.sun.com/j2se/1.3/docs/api/java/lang/NullPointerException.html . As for why you don't get a NullPointerException, I would think that
String s2 = null;
may actually create the string literal "", which would technically be an object and equals() could be used.
Anyone else add to/correct this?
Adam
As I understand it, the finalizers will not be run with a call to System.exit(). System inherits directly from Object, not Throwable, so you cannot "catch" a call - it's questionable as to whether it would make sense to anyway. I personally find System.exit() handy, although with good design you can limit it's use if you want to.
HTH
Adam
For question 1, when I run it I get 2. This is because the System.out.println(i) statement does not execute until AFTER the loop, at which point i = 2.
For the second question, I say 1 and 3 are the correct answers. The 2nd answer has a different return type from the superclass method, so will not compile, while the 4th answer attempts to make the method more private, which cannot be done.
HTH
Adam
I've mostly seen this subject in relation to instance variables, where one variable would be declared and have the value of an uncreated second variable, resulting in a compiler error. e.g.
int myVar1 = myVar2; //This is the forward reference
int myVar2 = 10; //as myVar2 is undeclared
The simple solution is to rewrite these lines so that myVar2 is declared and assigned first:
int myVar2 = 10;
int myVar1 = myVar2;
There are ways to write code that does make forward references that fool the compiler, but that's another story. It's covered by Bill Venners in relation to object instance variable initialization at http://www.artima.com/designtechniques/initialization.html
HTH
Adam
I agree with Annnie - yield will only stop thread from running if there is a thread with the same priority waiting to run - cannot yield to lower priority threads AFAIK.
HTH
Adam