Vlad G

Greenhorn
+ Follow
since Dec 28, 2000
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Vlad G

The compiler is smart to detect that return statement after finally will never be executed that's why it complains...
Ok, it happens to be more confusing than I thought but I still think I'm right. When you override a method you generally want polymorphism to work. This doesn't happen in case of "overriding" of static methods. Try to run these two examples:
1. "Overriden" static
<pre>
public class StaticOverride
{
public static void foo(String s)
{
System.out.println(s);
}
public void bar()
{
foo("some_string");
}
public static void main(String[] a)
{
StaticOverride so = new StaticOverride1();
so.bar();
}
}
class StaticOverride1 extends StaticOverride
{
public static void foo(String s)
{
System.out.println("In child class " + s);
}
}
</pre>
2. Overriden normal
<pre>
public class StaticOverride
{
public void foo(String s)
{
System.out.println(s);
}
public void bar()
{
foo("some_string");
}
public static void main(String[] a)
{
StaticOverride so = new StaticOverride1();
so.bar();
}
}
class StaticOverride1 extends StaticOverride
{
public void foo(String s)
{
System.out.println("In child class " + s);
}
}
</pre>
After you run it 1 should output:
some_string
and 2 should print:
In child class some_string
This proves that polymorphism doesn't work for "overriden" static methods. In other words, runtime type of an object doesn't define which method will be actually invoked in case of static "overriden" methods. Hopefully I didn't confuse you and myself. Other opinions are welcome.
--VG
[This message has been edited by Vlad G (edited January 03, 2001).]
It happens that the following compiles, but the meaning of "overriden method" doesn't apply here:
<pre>
public class StaticOverride
{
public static void foo(String s)
{
System.out.println(s);
}
}
class StaticOverride1 extends StaticOverride
{
public static void foo(String s)
{
System.out.println("In child class " + s);
}
}
</pre>
-VG
There's no Strings created in d.
-VG.
You need to add a listener to the TableModel which will receive change events and update the view (JTable) appropriately.
--VG
24 years ago
I doubt you can do that from java code directly. intern() in String is a native method, which means this pool is somewhere on the VM implementation level. Possibly, you can get this info using some sort of -Xprof option supplied to the java executable or use some sort of Java profiler like JProbe. They use native Java profiling interface to get all that data. You can also write some native code to get that info.
-VG.
Output: 1 0 1
Why:
in g()
a = 1; - set class member variable a to 1
b = 1; - set local variable b to 1, not the member var. b which stays 0 (this.b = 1 would set member var b)
c[0] = 1; - arrays are objects and passed by reference, so this sets first element of array created in f() to 1.
-VG
I thought this restriction only applies to constructors.
VG.
I guess what it really says is that you cannot do something as follows:
<pre>
String s = new String("some string");
Class clazz = s.getClass();
if (s instanceof clazz) {} // incorrect!
if (s instanceof "String.class") {} //incorrect!
</pre>
regards,
VG.

[This message has been edited by Vlad G (edited January 02, 2001).]
In this particular case both A and B will inherit the priority of the main system thread that created them, correct me if I'm wrong, which is 5.
regards,
VG.
IMHO: too much noise for a fuzzy question.
-VG.
Actually it does. I agree there's some subtleties here. First of all it's not only platform, but also the JVM implementation green or native threads plays important role here. In case of classic green thread JVM 2 is correct on any platform (which is probably is assumed by the test). In case of native thread Win 32 JVM it is also correct, VM will make every possible attempt to preemt a thread with higher priority and time slising has nothing to do with this (well, keep in mind that Java thread priorities do not usually map directly to native thread priorities, he-he, so two threads of different Java priorities may be actually of the same native priority, so no preemtion will happen!). In case of native thread Solaris JVM it's thrue that you can have two or more threads of different priorities being timeslised. I guess what I want to say is that this is way too long discussion for an online forum. Get a JAVA TREADS by O'Reilly to get all the details...
regards,
VG.
Java have no means for direct hardware acces, your Java code is pretty much limeted by the API exposed through the JDK. If you want to access arbitrary harware devices from Java you need to use some sort of library written in C/C++ or any other language and complied into native platform binary code and call it over JNI.
regards,
VG.
- subj. question makes little sense to me, how can a Thread invoke two methods simultaneously??? As far as I know there's no way to do that. It's possible, however, to call an asynchronous method (like start() in Thread, which is btw is not synchronized, but could be as well) which doesn't block and upon return from this call invoke another synchronized method. In other words, you need to have two threads running in this case. In general, you cannot run two methods (synchronized or not) simultaneously on the same thread. Give more details if this is not what you wanted to know.
- Yes, a thread can obtain a lock on an object:
<pre>
Object o = new SomeClass();
synchronized(o) { // do something }
</pre>
- No, there's no method level locks in Java, but you can play tricks like (quick guess, tell me if wrong...):
<pre>
class X
{
public static final byte[] lock = new byte[0];

public synchronized void m()
{
synchronized (lock)
{
// do something
}
}
}
class Y
{
public void foo()
{
synchronized (X.lock) //need to do smthng before calling m()
{
// ... do things
X x = new X();
x.m();
}
}
}
</pre>
regards,
VG.
[This message has been edited by Vlad G (edited January 01, 2001).]
Well, I made a small mistake (forgot about type cast), but in general my fragment of code is syntactically correct. The following compiles and runs OK:
<pre>
public class Dumb
{
Dumb()
{
Object y = new X();
((X) y).m(y);
}
public static void main(String[] args)
{
new Dumb();
}
class X
{
public void m (Object x)
{
System.out.println("In m");
}
}
}
</pre>
-VG.