J Williams

Greenhorn
+ Follow
since Nov 13, 2004
Merit badge: grant badges
For More
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 J Williams

Consider the following:


The difference has to do with how Strings are stored in memory in java and what the == operator does. The == test simply checks to see if the two objects in question have the same bit pattern or not. Remember that a variable contains the memory location of an object so that if two variables are set equal to each other, then they both point to the same location in memory and therefore have the same bit pattern. In java, a special section of memory is reserved as the "String pool." In this pool, java keeps a list of Strings that are created using the form

so that if I create another identical String such as

java simply sets s2 to point to the same place in memory that s1 is refering to in the String pool. This is done to save space in memory. Thats why prints "true." Now if I create a String using the "new" key word a new String object is created and is placed in on the heap which is in a different section of memory than the String pool. That's why prints "false" - because s2 and s3 contain references to different sections of memory. If you want to compare the values of the actual strings themselves, you must use the String method equals() which looks not at the memory locations but instead compares the Strings themselves. Get it?

[ December 16, 2004: Message edited by: J Williams ]

[ December 16, 2004: Message edited by: J Williams ]
[ December 16, 2004: Message edited by: J Williams ]
19 years ago
I believe the answer is that the abstract part is simply implied whether you write it or not. I wouldn't call it obsolete, just a shortcut. An interface is always abstract so it is not necessary to specify it as abstract. Think of an interface as an abstract class except an interface's methods are all abstract unlike an abstract class which may have non-abstract methods.
[ December 16, 2004: Message edited by: J Williams ]
19 years ago
I would say yes because the Object has no reference variable and therefore is unreachable. An unreachable Object is fair game for the garbage collector.
19 years ago
You can try this: Go to the command line and type "Path" (without the quotes of course). This should list the current path that is searched on the machine. If you don't see the path to the java bin directory in there it is not configuring for some reason. I know you said you checked this already, but this will confirm if Windows is setting the path correctly.
Hope this helps you track down the problem.
19 years ago
You might as well bookmark the link to the Java API: Java API

If you look under String, you will find a method that I think you will see could be very helpful to you called toCharArray()

The java API is your friend. When I need to to something that I don't know how to do in java, I usually go to the API and search around to see if I can find something useful there. Nine times out of ten there is a class or method in the API that I can use. This is also a great way to learn. Hope this helps.
19 years ago
I'll jump in here and say that the study guide book was the only book that I used for the exam, however, I had already learned some Java. I guess what I am saying is that you need to start with HFJ if you need to learn Java but if you know some Java and just want to study for the exam then I think you can get by with just the study guide book.
I can tell you what worked for me. By the way, I passed the exam recently and have no on-the-job experience with Java so you should not feel like the exam will be too hard for you since you already have some working experience. I read the Java study guide book by Kathy and Bert about three times and took as many free mock exams as I could find on the web. I found the book to be very helpful in identifying what would be on the exam. Check out the bunkhouse on JavaRanch for a list of books and also check out the certification FAQ on JavaRanch. I found them to be some of the most helpful references anywhere. Hope that helps.

Good luck!

PS: I would think again about posting your email address to any forum anywhere on the net unless you want a lot of junk mail. A lot of junk mailers pick up on these addresses. It's a shame I know.
[ December 14, 2004: Message edited by: J Williams ]
I'll give the answer a shot.
For sync to work, the threads in question must be accessing the same object. So in the example where you create two different instances of MyClass, you have two seperate objects and sync will not happen. The example you give where you create one object and start two threads is the correct example. Of course, you must still have a syncronized block of code, but I assume you realize that.
Thanks go out to all who post on this site for helping me pass the SCJP with an 80% score. I haven't posted much but have been able to find many answers to questions I had along the way by searching the forums. Special thanks to Bert and Kathy for your excellent study guide book which was my main resource and training tool. I strongly suggest this book to anyone who is thinking about taking the SCJP exam. Fot those who are interested, I prepared for the exam by reading the K&B book about 3 times and doing as many mock exams as possible. I also found it facinating how close my actual score was to my score on Marcus' mock exam: 78% on his and 80% for real!
19 years ago
Here is the way it is explained in the book I am studying from.(Which I highly recommend by the way as it is great):

"A no-arg constructor is not necessarily the default constructor, although the default constructor is always a no-arg constructor. The default constructor is the one the compiler provides. While the default constructor is always a no-arg constructor, you're free to put in your own no-arg constructor."

p. 315, Sierra, Kathy and Bates, Bert. Sun Certified Programmer & Developer for Java 2 Study Guide. McGraw-Hill/Osborne 2003.

If it's in this book, I assume it may be on the exam. I think default means at compile time default, not at run time default. In other words, at compile time if you do not declare ANY constructors, the compiler will add this one at compile time because every class must have at least one constructor:




I think it is important to distinguish between the default constructor and a no-arg user defined constructor because the default constructor will ALWAYS call the no-arg constructor of the parent (whether or not one trully exists) while a user defined no-arg constructor may be configured to call any constructor of a parent class. For that matter, a user defined no-arg constructor may have other code in it as well. In other words I can say for sure that the default constructor has not only no-args, but also has a certain predetermined default behavior, while a user defined no-arg constructor may not.

That's just how I read it. I'm still learning too.

[ November 13, 2004: Message edited by: J Williams ]
[ November 14, 2004: Message edited by: J Williams ]