Win a copy of Java by Comparison (eBook) this week in the Java in General forum!

Vonique Leary

Ranch Hand
+ Follow
since Mar 24, 2008
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
1
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 Vonique Leary

Okay, I think I just figured out my answer. If I alter the code like this:



and override the method, then the second coolMethod() inside Moo returns "Hi baby."

Got it. The little snippet in the SCJP book uses this.coolMethod() when it wasn't even necessary and that is what threw me off.

Thanks, all

Vonique
5 years ago
In my above example the this keyword doesn't seem necessary because if you take it out you get the same results. Why would the writers include it? And also, I understand that this.coolMethod() refers to the current object that is calling it so it returns "Wow baby" but can anyone explain in which situation would it return something different? I guess that is what I am struggling to understand.

Hi again to you Campbell!
5 years ago



What is the point of the this keyword in this example from Bates and Sierra's book? I tried the example both with and without it and got the same result. So now I'm confused about when to use this inside a method. Can someone give me an example that actually makes a difference in the output?

Thanks, Vonique
5 years ago
Thanks for that explanation Jayesh. That really helps to clear up why the only place I've ever seen serialization examples is in the prep book for the test. Things make so much more sense to me now!

Vonique
5 years ago
Thanks everyone, for your replies. It's a lot clearer now but it makes me realize just how much I don't know about networking, etc. Well, from what I have read on this forum, serialization is not on the test, so I am going to limit my knowledge about it to what I have already learned.

Nice to see you too, Campbell!

Von
5 years ago
So, do most java programs that are accessed over a network use serialization or are there other ways to persist objects?

Thanks,
Vonique
5 years ago
I understand the concept of serialization and that it is used to transfer files over a network, but I'm a little confused about how often it is used. Aren't all or most java files transferred over a network? I mean if you are accessing a java program while surfing the internet or while playing an online game, aren't those files being transferred over a network? What other ways is a java program accessed if not over a network? I know that there are some applications that run on one's computer but I thought java was mainly an internet language.


5 years ago
I did it!!! I fixed everything and it now works!

Here is my fixed code:




I had various little mistakes like int where there should have been a double, and x where miles should have been! Whew! Just posting it here made me look at it with a keener eye.

Thanks everyone!
Vonique
6 years ago
[size=12]Thank you, Paul. Well, I fixed the braces and managed to get rid of that error message, but now I only get one stopping distance value and I need all the stopping distances for several starts and stops. This is where I am really stumped. Here is my fixed code:




I keep thinking I can loop those returns in a for loop but I'm just not getting it right. I've been looking at it for over 20 hours in the last week so my eyes are going batty about now. I'm going to look over my for loop more closely.

Thanks,
Von
6 years ago
This code is partially from the book Simply Programming An Application Driven Tutorial Approach. Some of the code I have inserted myself to complete the assignment, which is:

The user enters a starting and stopping speed range and the program produces a chart of speeds and stopping distances.
The module should receive 1 data (argument=parameter), an integer representing the speed of travel. The module should convert that speed into the number of feet needed to stop using the formula given above. The module should return the number of feet.

I don't want any answers but just look at my code if you would be so kind and drop some hints as to what I am doing wrong. I keep getting an error message that says:



C:\Test4.java:147: class, interface, or enum expected
}
^

And:

--------------------Configuration: <Default>--------------------
java.lang.NoClassDefFoundError: Test4
Caused by: java.lang.ClassNotFoundException: Test4
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: Test4. Program will exit.
Exception in thread "main"
Process completed.



I am having trouble figuring out how to return more than one value from this method. From the picture I attached it appears I would have to return several values to have calculated all of those stopping distances between the first and the last one. The only thing I could think of was to put the method in a for loop and call it as many times as needed to keep delivering the return values but I can't seem to get it right.

Any help would be appreciated.

Thanks,
Von


6 years ago
Well, that is simple enough. Thanks so much for the explanation!

Vonique
6 years ago
"Let's say that we want to create a regex pattern to search for hexadecimal literals. As
a first step, let's solve the problem for one-digit hexadecimal numbers:
0[xX][0-9a-fA-F]"




This is from Kathy Sierra and Bates SCJP book page 492 regarding regex. I don't quite understand why the index goes from 0 to 9, then from 0 to 7 rather than from 0 to 18. And the explanation says that the regex returns position 6 and 11, but I don't see any 11. What am I missing?
6 years ago
I've been studying from the SCJP book and notice that even though Date methods are deprecated, they still use it in almost all of their Calendar examples. Is this for backward compatibility? Can one manipulate dates and times using just the Calendar object? Can it do everything the Date class can do?

Thanks,
Von
6 years ago
Hi Campbell,

Well, it was just a case of not studying it adequately because there were a few labels and buttons missing. Those simple things were revealed upon closer inspection.

6 years ago
Never mind. Figured it out already. Thanks anyway!
6 years ago