Win a copy of Head First Android this week in the Android forum!

Greg Torrance

Greenhorn
+ Follow
since Feb 25, 2000
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 Greg Torrance

Hi there,
I was wondering if somebody could help me out ... I'm using JButtons and JToggleButtons in my GUI (with the Metal L&F). When these buttons are disabled though, they show up differently ... JButtons have their text grayed out, whereas JToggleButtons have their text "embossed". Why this difference? Is there any way to change JToggleButton to just gray its text out (when disabled)?
Any thoughts or suggestions would be greatly appreciated!
Thanks much,
Greg
21 years ago
Brogden does make a slight mod to this in the errata for the book. He changes the second line from
if ( (A * 3.0F) == 1.0F )
to
if ( (A * 3.0) == 1.0F )
Hope that helps ...
Greg
Hey everyone, thanks for the congratulations!
[Maha Anna, yep, as Hugh said the code in the questions is formatted nicely.]
Greg
I got maybe two or three such questions. The wording of the questions should make it clear what they are looking for (whether you should include return types, spaces, etc ...). I'd say just read carefully what they're asking and you should be alright.
Greg
Ramamurthy,
How many mock exams are required for preparation? I don't know - I guess it all depends on the individual. I'd say keep doing them until you are comfortable with the type of questions asked, and also get to the point where you are consistently getting good scores. You should be able to tell when you reach that point ...
Which ones? I did the ones in the two books I mentioned, the Marcus Green ones, and various others - (but I don't remember which ones). The links on this site (http://www.javaranch.com/mock.html) would be a good place to start!
Hope that helps!
Greg
Hi all,
I just passed the SCJP2 exam with 95%. Yay!
Thank you to everyone on the forum for making it such a great place to prepare, and particularly to Tony and Jim for all your effort!!!
I'll try and pre-empt some of the questions with some comments ...
I had been working on a Java project for about a year before starting to study for the certification. [If I were to have taken the exam based on just my working knowledge, I think I would have got 20% (if I was lucky).] Thereafter I worked for about a month towards getting prepared. I primarily used "A Programmer's Guide to Java Certification" (Mughal and Rasmussen), and to a lesser degree "Java 2 Exam Cram" (Brogden). I found the first book particularly good (and quite a bit more detailed than will be required for the exam). I also used the JDK docs in conjunction with these. [I didn't use any of the study notes on the Web.]
Most of my time was spent going through Mughal and Rasmussen, and then in the last week or so I tried to do a good number of mock exams. My recommendation is to _first_ try and get as much of the detail understood (and for that Maghal / Rasmussed is a good choice), and then do more general revision as the time draws nearer. [That way your revision will be enforcing a solid foundation ... at least that works for me.]
The mock exams I did included the ones in the two books, the Marcus Green exams (1 & 2), and various others (which I forget now). I would recommend doing lots of mock questions, because if you're anything like me they will quickly show you that you don't understand things nearly as well as you thought you did :-) [I learn well by making mistakes.] I started out with the Mughal / Rasmussen one, and got about 74% ... thereafter I started doing better until I was getting around 90%.
As others have said the actual exam seems to be easier than many of the mock questions - largely because they are worded pretty well (and unambiguously). It's probably a good thing the exam is easier, because the pressure of "exam conditions" makes me consider myself lucky if I can remember my name :-)
Focus on the fundamentals (but obviously don't ignore the other stuff). Time was not a problem. [I was able to go through it twice, with a few minutes to spare.]
Details? I couldn't tell you much about the specific types of questions I got, as much of that is now a blur. I got multiple choice, multiple answer and straight text answer questions. [There weren't as many multiple answer ones as I had expected, which was good.]
I think I've run out of things to say so I'll cut it off there. Once again thanks to everyone out there for the help! All the best to you all for your respective tests!
Greg
Thanks for the input Jim!
Greg
Hi all,
Question 65 in the Boone exam ...
Which statements about garbage collection are true?
Select all valid answers.
a) You can directly free the memory allocated by an object.
b) You can directly run the garbage collector whenever you want to.
c) The garbage collector informs your object when it is about to be garbage collected.
d) The garbage collector reclaims an object�s memory as soon as it becomes a candidate for garbage collection.
e) The garbage collector runs in low-memory situations.
The official answer is (b), (c), (e).
(c) and (e) make sense to me, but (b) seems questionable ...
Mughal and Rasmussen say "Java does provide facilities to invoke the garbage collection explicitly. The System.gc() method can be used to force garbage collection, and the System.runFinalization() method can be used to run the finalizers for objects eligible for garbage collection."
but, ... Brogden says "The programmer can suggest to the JVM that now is a good time to run garbage collection with one of the following method calls, but there is no guarantee that the JVM will do it: System.gc(); / Runtime.getRuntime().gc();"
also, ... in the JDK docs for System.gc() it says "Runs the garbage collector. Calling the gc method suggests that the Java Virtual Machine expend effort toward recycling unused objects in order to make the memory they currently occupy available for quick reuse."
I'm confused - (news flash :-) ... Can someone help me out? Can you, are can't you run garbage collection whenever you want?
Thanks a lot!
Greg
I'm confused now ...
Ramana said:
1. Any static method must be overridden by only a static method. A static method cannot be overidden as non static. In the same way, a non static method cannot be overridden as a static one.
But I thought static methods could not be overridden. [But they can be hidden, right?]
Uma asked:
Joe, if accessiblity modifier is not part of the method signature howcome it's giving me the error if i changed the modifier from protected(superclass) to private in the subclass.
Seems like a good question. Why should the compiler care one way or the other? If the methods are static there is no polymorphism involved in the method calls. It doesn't seem like there is a reason for that restriction. Can someone clarify this for me?!?!
Thanks,
Greg
In the errata for the book (found at www.lanw.com/books/errata/default.htm) Brogden says it is actually 120 minutes. [It would probably be a good idea to look at the errata ... to avoid learning anything wrong ...]
Greg
Anjo,
It seems that in this case, because the left-hand operand is int, only the first 5 bits (the least significant) of the right-hand operand are used. This ensures that the shifting will be in the range 0-31 (and effectivly strips off the high-order bit, making the right-hand operand 31, and not -1). So, you are effectively doing i >>= 31. Take a look at this (from the JDK documentation) ...
---
If the promoted type of the left-hand operand is int, only the five lowest-order bits of the right-hand operand are used as the shift distance. It is
as if the right-hand operand were subjected to a bitwise logical AND operator & (�15.21.1) with the mask value 0x1f. The shift distance actually
used is therefore always in the range 0 to 31, inclusive.
If the promoted type of the left-hand operand is long, then only the six lowest-order bits of the right-hand operand are used as the shift distance.
It is as if the right-hand operand were subjected to a bitwise logical AND operator & (�15.21.1) with the mask value 0x3f. The shift distance
actually used is therefore always in the range 0 to 63, inclusive.
---
"Can u shift by negative numbers?" I don't know how to answer that ... yes, you seemingly can shift by negative numbers, because there will be no errors, but you're not really shifting in the opposite direction - the direction of the shift will remain the same.
Hope that helps!
Greg
I think the reason for the -1s for short and byte would be that, prior to the right shift (with zero fill) being done, both operands would be promoted to int (if they were not already at least an int), and then after the shifting, the result would be cast back down to the type of the left-hand operand for the actual assignment. [I know that's badly worded.]
For example, short case would be equivalent to ...
short s = -1; // s is 0xFFFF
int i = s >>> 10; // i is (0xFFFFFFFF >>> 10) ... ie 0x003FFFFF
System.out.println( Integer.toHexString( i ) );
s = (short) i; // s is 0xFFFF ... ie -1
System.out.println( Integer.toHexString( s ) );
Doing a right-shift 10 on 0xFFFFFFFF would result in 0x003FFFFF. Casting this to short would leave you with 0xFFFF, which is the -1 you originally started with. Similar for byte.
Sound ok?
Greg
I believe it would also be a compile-time error to place a catch for IllegalArgumentException after a catch for Exception, because as you said, the catch(IllegalArgumentException) would never have an opportunity to be executed due to being "shadowed" by Exception. [Correct me if I'm wrong.]
Greg
Greetings,
Class modifiers ... can somebody help clarify something for me? It seems to be generally accepted that the modifiers for classes do not include static, protected and private. In fact Brogden says "Classes cannot be protected, private, native, static, or synchronized." It seems to me this is always true for native and synchronized, and true for the others when the class in question is a top-level "package" class, but what about nested and inner classes?
Either of these can have protected and private accessibility (in addition to public and the default package accessibility that top-level "package" classes can have). In addition, (static) top-level nested classes are declared with the static keyword, so surely static is allowable also (in this particular case)?!?!
How should one go about answering a question that asks if static is an acceptiable modifier for classes? [I came across one in the IBM test, and I still don't know what they were expecting.]
Thanks,
Greg
Hi there,
This question confuses me ...
The way to accumulate drawn objects on the screen is to:
a) Call update() from within repaint()
b) Call update() from within paint()
c) Call accumulate() from within paint()
d) Call paint() from within update()
What is meant by "accumulate"? I'm guessing it's just a synonym for paint (to avoid being too obvious), in which case I'd guess "d" because update() _does_ call paint() (which in turn paints objects to the screen). Sound reasonable?
Thanks!
Greg