| [+] Java in General » Externa-what-able???? (Go to) | | Dan Temple |
Okay, Thanks to both of you  Dan |
| [+] Java in General » When are Threads garbage collected? (Go to) | | Dan Temple |
Creepy! Zombie Threads! Thanks, Dan |
| [+] Java in General » JQ+ says hashCode() native?? (Go to) | | Dan Temple |
Okay, thanks for the advice! Dan |
| [+] Java in General » When are Threads garbage collected? (Go to) | | Dan Temple |
So if all references to an object are in a dead thread, then it is eligible for GC? |
| [+] Java in General » When are Threads garbage collected? (Go to) | | Dan Temple |
Unlike other objects, Threads are not garbage collected when there is no longer any references to them. So when do they get garbage collected? Are there two conditions for this to occur? Namely: 1) There are no references to the instance of Thread AND 2) The Thread is dead? Thanks in advance Dan |
| [+] Java in General » JQ+ says hashCode() native?? (Go to) | | Dan Temple |
Okay, that makes sense. But where are these native method libraries? Are they part of the JVM? Dan |
| [+] Java in General » Externa-what-able???? (Go to) | | Dan Temple |
Can anyone explain to me in English what the Externalizable interface does? I tried to read the specks, but it quickly devolved into techno-babble about objects, I/O and Serializations. All I can make out is that the object that implements the Externalizable interface only has its identity written to the serialization stream and not its state? Why would you want that? And even though "it is the responsibility of the class to save and restore the contents of its instances" how exactly is this achieved? Thanks in advance Dan |
| [+] Java in General » JQ+ says hashCode() native?? (Go to) | | Dan Temple |
I was doing a mock test from JQ+ and they seem to know what they are talking about. However they claim that the hashCode() method of Object is native!!! This seems to me to be totally wrong! How could Java be platform independent if it used native methods as part of its base classes? Of course often I don't know what I am talking about ... Dan |
| [+] Java in General » Are Java apps Determined or Free-willed? (Go to) | | Dan Temple |
Okay, thanks. I forgot about the independent nature of Garbage collection, and didn't realize that Pre-emptive scheduling varied according to the JVM. Dan |
| [+] Java in General » Are Java apps Determined or Free-willed? (Go to) | | Dan Temple |
I keep reading how Java applications are indeterminate. I can see how a multi-threaded application running on a time-sliced thread scheduler would be indeterminate. I also see how the look of a Layout manager would vary from platform to platform. But surely an application running on a specific platform that uses a pre-emptive thread scheduler would be as determinate as an application on that platform written in C++. Am I totally out to lunch on this one? Dan |
| [+] Java in General » Dimensional Travel (Go to) | | Dan Temple |
Thanks Jim! If multi-dimensioned arrays are that obscure, I'm not going to worry about them (i.e. study for the Programmer Certification). But I will definitely keep in mind the definition you gave for 2d and 3d arrays (a 2d array is an array of arrays .... an nd array is an array of (n-1) arrays). Thanks for the help! Dan |
| [+] Java in General » Dimensional Travel (Go to) | | Dan Temple |
Okay ... either my eyes are going to explode, or I am on the brink of understanding Lovecraftian geometry. Could someone please tell me if my understanding of multi-dimensional arrays is correct? I understand 2d arrays, but anything beyond that and my brain turns to mush: A 2d array refers to an array containing one or more arrays. Does that mean a 3d array refers to an array containing one or more arrays which in turn can contain one or more arrays? For example, is this a 3d array: arr={1,{a,b},3,{c,d,{e}},4}? i.e. 3d because there is an element e which is 3 arrays in? Consequently (assuming this is not heat-stroke inspired drivel), in order to refer to that e would I write: arr[3][1][0]? My reasoning being that in order to get to e go to the third index of the main array, the second index of a list listing all the arrays within arrays, and lastly the first index of a list listing all the arrays within the arrays within the arrays??? In other words {1,{a,b},3,{c,d,{e}},4} = 3rd index {a,b}, {c,d,{e}}= 1st index {e} = 0th index? Okay - my grasp on reality is starting to fade now. If anyone understands this babbling, please let me know Dan |
| [+] Programmer Certification (OCPJP) » Certification like this? (Go to) | | Dan Temple |
Arrrrrrrgh! But that will require an arbitrary decision on my part! I can't even buy Baskin Robbin's ice-cream without taking half an hour to ponder my options ... *sigh* I guess that means the whole notion of "If none of the answers look correct, leave the question blank" dead and buried. Correct? Dan |
| [+] Programmer Certification (OCPJP) » Certification like this? (Go to) | | Dan Temple |
Yeeek! Thomas, does that mean you can't leave a question as unanswered for later consideration? Dan |
| [+] Programmer Certification (OCPJP) » Certification like this? (Go to) | | Dan Temple |
Cool! Now I'll only have to worry when it says "Pick 4 true answers" and they ALL look wrong to me!! LOL Dan |
| [+] Programmer Certification (OCPJP) » Certification like this? (Go to) | | Dan Temple |
Hi everyone! I have been using the JQ+ test program which for the most part I am pleased with. However one thing I noticed is that on many of the questions it will say "Select all 3 true answer", or "Select one true answer", or words to that effect. This of course is easier since you know how many true answers there are. Does anyone know ... is the actual Sun certification exam like this? Dan |
| [+] Java in General » Graphics Context? (Go to) | | Dan Temple |
Okay that makes sense! (One of the reasons I like Java) Hey! I'm a ranch hand now!!! What does this gig pay anyway? LOL Dan |
| [+] Java in General » Graphics Context? (Go to) | | Dan Temple |
I have a couple of questions concerning the Graphics Context. Perhaps someone would be kind enough to help this newbie. It seems that whenever we want a graphics context we need to use getGraphics() rather than new Graphics(). I assume that this is because the Graphics object that is returned in the former is chock full of necessary info such as the clip region for the component, etc (the context part of "Graphics Context")... am I right in this assumption? But how does the Graphics context know which component we want it to be associated with? If I have a frame with two panels, how does the Graphics context know I want it to be associated with the first panel and not the second one? Thanks in advance Dan |
| [+] Java in General » Sleepy Threads (Go to) | | Jim Yingst |
God I am such an idiot ... for some reason, my brain saw that output as being inside the catch block. Sorry about that ... Dan |
| [+] Java in General » Sleepy Threads (Go to) | | Jim Yingst |
I found the following interesting question on a mock exam: When application A below is run, two threads are created and started. Each thread prints a message just before terminating. Which thread prints its message first? class A { private Thread t1, t2; public static void main(String[] args) { new A(); } A() { t1 = new T1(); t2 = new T2(); t1.start(); t2.start(); } class T1 extends Thread { public void run() { try { sleep(5000); // 5 secs } catch (InterruptedException e) { } System.out.println("t1 done"); } } class T2 extends Thread { public void run() { try { t1.sleep(10000); // 10 secs } catch (InterruptedException e) { } System.out.println("t2 done"); } } } The answer is T1 since even though it looks like T2 will put T1 to sleep for an even longer amount of time, sleep() is a static method and executes on the currently running thread. Cool. My question is, is why is ANYTHING printed out at all? I thought that an InterruptedException was only thrown when a sleeping or waiting thread received an interrupt() call from an executing thread. No such call is coded here. I didn't think that such an exception was automatically thrown when a sleeping or waiting thread entered the ready state. Am I wrong in so thinking? Dan |
| [+] Java in General » Card Confusion (Go to) | | Dan Temple |
That makes sense. Thanks for the help! Dan |
| [+] Beginning Java » List Width? (Go to) | | Manfred Leonhardt |
Here is a simple question that I can't find in the docs: What determines the width of a List component? There are no constructors that take width as a parameter. Thanks in Advance Dan |
| [+] Java in General » Card Confusion (Go to) | | Dan Temple |
I have a litle confused concerning the CardLayout manager. Many books show code where an anonymous instance to a Layout Manager is created. For example suppose F is an instance of a Frame. To set the layout manager to FlowLayout we could write: setLayout(new FlowLayout()); And I have found some instances where this is done with the CardLayout manager. HOWEVER, since the actual methods for showing the panels belong to the instance of CardLayout and not the container component, writing: setLayout(new CardLayout()); is entirely self defeating since we wouldn't be able to call the various methods for displaying the "cards", eg. first, prev, next ... etc. Am I right here, and the books are wrong - or is it (more likely) the other way around? Thanks in advance Dan |
| [+] Java in General » I'm gonna SNAP! (Go to) | | Cindy Glass |
Okay. Thanks - I feel less punchy now. Now if Point and Point3d were in the same PACKAGE however then delta would compile correctly, right? I wouldn't have to ensure that the object of Point involved Point3d in its implementation. Right? Dan |
| [+] Java in General » Redundant Access Modifier? (Go to) | | Dan Temple |
Okay - that makes sense. Thanks Sheriff! Dan |
| [+] Java in General » I'm gonna SNAP! (Go to) | | Cindy Glass |
Okay ... now I am REALLY confused. I thought I understood access modifiers, but I guess I don't. Consider the following code from 6.6.7 of the Java Language Specs ( http://java.sun.com/docs/books/jls/second_edition/html/names.doc.html#36191) Consider this example, where the points package declares: package points; public class Point { protected int x, y; void warp(threePoint.Point3d a) { if (a.z > 0)// compile-time error: cannot access a.z a.delta(this); } } and the threePoint package declares: package threePoint; import points.Point; public class Point3d extends Point { protected int z; public void delta(Point p) { p.x += this.x;// compile-time error: cannot access p.x p.y += this.y;// compile-time error: cannot access p.y } public void delta3d(Point3d q) { q.x += this.x; q.y += this.y; q.z += this.z; } } which defines a class Point3d. A compile-time error occurs in the method delta here: it cannot access the protected members x and y of its parameter p, because while Point3d (the class in which the references to fields x and y occur) is a subclass of Point (the class in which x and y are declared), it is not involved in the implementation of a Point (the type of the parameter p). The method delta3d can access the protected members of its parameter q, because the class Point3d is a subclass of Point and is involved in the implementation of a Point3d. What the heck is going on? Since when did "implementations" play a role in accessing member fields? I DON'T EVEN KNOW WHAT "not involved in the implementation" MEANS!!! Could someone please help this lost lamb? WHY do those lines in Delta method fail to compile? Little-Lost-Dan |
| [+] Java in General » Redundant Access Modifier? (Go to) | | Dan Temple |
Hey there! Well I just looked at the clone() method of the Object class. Now its access modifier is protected. But since every class is a subclass of Object then every class can access this method. So why not just make it public? What am I missing? Dan |
| [+] Java in General » Java for Disney! (Go to) | | Dan Temple |
| |
| [+] Java in General » Java for Disney! (Go to) | | Dan Temple |
Hi there! Suppose we are running some kind of an animation (say, Mickey Mouse hugging a Java Icon) and we do the java-No-No of calling paint() rather than repaint(). Now suppose the paint() method is rather long and expensive in CPU cycles. If we make frequent calls to paint(), the animation gets further and further behind as the CPU spends its time doing redundant paints. If we had called repaint() then this wouldn't have happened since only the most current repaint() methods would be processed (I guess it exits the paint routine if a new repaint() method is called). My question is what mystical quality does repaint() have over paint() that allows the animation to remain current? Dan |
| [+] Java in General » Casting inconsistency? (Go to) | | Dan Temple |
Okay .. I understand. My Book misled me - *Dan whaps his book on the nose with a rolled up paper* Bad Java Book! Bad!!! Dan |
| [+] Java in General » Casting inconsistency? (Go to) | | Dan Temple |
Could anyone tell me why this is legal? It seems to break the casting rules: long l = 104; int i = 1; int j = 0; j = i << l; System.out.println(j); As I understand it, the int i should have been converted to a long when it was subject to the left shift by a long. But then the result would have been a long being converted to an int, which is illegal without an explicit cast. What am I missing? Dan [This message has been edited by Jim Yingst (edited July 23, 2001).] |
| [+] Java in General » Would an inner class by any other name smell less sweet? (Go to) | | Dan Temple |
Okay ... That makes sense. Thanks for the info! Dan |
| [+] Java in General » Would an inner class by any other name smell less sweet? (Go to) | | Dan Temple |
Okay ... if I have a non-static member class such as the following public class OuterClass { private int Blah; public class InnerClass { private int InnerBlah; } } and if I write a static method (say a main method) for OuterClass and wish to construct an instance of InnerClass then I need to write: public static void main (String [] args) { OuterClass.InnerClass inst=new OuterClass(). new InnerClass(); } which makes perfect sense to me since the full name of the inner class is not InnerClass but OuterClass.InnerClass. But if InnerClass should be a static-member class then the rules change for some reason. Now in that main method we write: InnerClass inst=new OuterClass.InnerClass(); The new expression on the right makes perfect sense to me since that is after all the full name of the inner class. What confuses me is why we can refer to that reference using simply InnerClass and not OuterClass.InnerClass. I KNOW static classes don�t need an enclosing instance, but that feature seems moot here. What seems to be missing is the full name of the CLASS rather than a redundant enclosing instance. Okay I guess I am blathering now. My main question is why in the above case is it InnerClass inst, rather than OuterClass.InnerClass on the left of the assignment operator, when the new expression on the right seems to be acting properly (I.e. using the full name of the inner class ...) *whew* Dan |
| [+] Java in General » more "but-WHY" questions ... (Go to) | | Jim Yingst |
But why would any other class have to call it? Just let the class work in isolation. Why not just make the class private, and then give it a main method? What's wrong with that, or would the fact that it was private preclude anyone from running the class at the command prompt? Dan |
| [+] Java in General » more "but-WHY" questions ... (Go to) | | Jim Yingst |
Does anyone know WHY top-level classes can only have public or default status? One would think it could be very handy (and secure) to have classes that have an access modifier of private, or protected. Dan |
| [+] Java in General » A Thread puzzle (Go to) | | Dan Temple |
Okay! Thanks for the info ... now I'll just have to regrow some new eyes ... Dan |
| [+] Java in General » I/O Insanity!!!!!! (Go to) | | Mike Curwen |
Thanks for your response! Well as you can probably gather, I know next to zilch when it comes to I/O, but if I understand you correctly then the PrintStream is limited to writing characters of Ascii (since it is only writing blocks of bytes). PrintWriter is writing characters in blocks of 2 bytes for the unicode characters. Hence the PrintStream is unable to write various encodings for unicode, but the PrintWriter is able to do this. Am I right so far? But I am still a little perplexed about some other points - 1) PrintStream is supposed to write files in a human "readable" output. It does this by writing out everything in blocks of single bytes, so it can be easily read by a text editor. Am I correct here? But if this is the case then how exactly does this differ from a FileOutputStream which also writes out blocks of bytes to files, and yet a FileOutputStream writes binary files while a PrintStream writes out text files. From whence does this difference spring? 2) Other than the obvious difference (one is human readable, and the other isn't) what exactly IS the difference between a binary file and a text file? 3) Why did Coca-Cola try and change the taste of its main product back in the 80's when no one liked it? Dan |
| [+] Java in General » I/O Insanity!!!!!! (Go to) | | Mike Curwen |
Okay ... I am starting to lose my mind over all these I/O Java classes and their differences. PrintStream is a high level OutputStream, and PrintWriter is a high level OutputWRITER. PrintStream being a subclass of the OutputStream writes bytes rather than chars to a file, right? But if this is so, then how is it that files created by PrintStreams are human readable (i.e. they are text files)? |
| [+] Java in General » A Thread puzzle (Go to) | | Dan Temple |
Okay ... after smashing my head in with a large cinder block I think I understand. Because it is a thread, the method knows which thread to affect WITHOUT using an instantiating object that refers to that thread. Namely it uses whatever thread is running the method. It is sort of a self-referential situation that causes eyes to explode... correct? Dan |
| [+] Java in General » A Thread puzzle (Go to) | | Dan Temple |
Hi all! In reviewing my notes I came across something that seemed a little strange: 1) The Yield method is a STATIC method of the Thread class. 2) This method causes the CURRENT thread that is running to give up the CPU. Is it just me, or does there seem to be some tension between these two statements? If the Yield method is STATIC then it operates at the CLASS and not the INSTANCE level. i.e, there is not implicit 'this' reference. So if it operates at the class level, then how the heck can it figure out which Thread instance it is supposed to operate on? Dan |