Win a copy of Event Streams in Action this week in the Java in General forum!

Mark Richardson

Ranch Hand
+ Follow
since Dec 28, 2016
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Mark Richardson

In my code, I have 2 methods. In my first method, I completely rely on StringBuilder and it's reverse() method. This seems to work. However, in my second method, I don't get anything returned. Why is this?

1 week ago
So, as a student, I've always learned that we make our instance variables private because some "rogue class" might inadvertent (or nefarious) changes to your class.
That is, every class should have responsibility over it's own variables. I get that.

But the getter and setters methods are public. They can presumably just be called by another class, no?

And what exactly is a "rogue class" anyways?

I would imagine that when I am working on a project, I have access to each and every class that is on that project.

Where is this supposedly "nefarious" activity taking place?

I know that we use access modifiers to encapsulate our variables so that only the appropriate classes are able to have access to them... but in the event that another class DID *god forbid* get access to some variable... the programmer would know about it, no? After all... the programmer is able to see the entire code on his/her project...

I don't understand the real-world implications of this
1 month ago
Wow! You folks here really know how to deliver! Thank you for that extra piece of advice!
1 month ago
I figured it out. My static variables were in another package and not declared public. *sheepish smile*
2 months ago
I'm creating a very simple Java based game. To set the starting allowance of each character, I am using a configuration class with static variables.

In my ENGINEER class, I am trying to do this:

... but the dot operator after Config only shows me class, super, and this. How come I don't see the different static money options I've listed in my Config class?

2 months ago
Let's say I have the following:

Then I do:

Since List allows duplicates, we now have three "u1s" in our list, and only one "u5."

The question is: Do I now have 3 distinct "u1" objects, or is there just one u1 object and usersList simply contains references to this one object?

2 months ago
I got it. If the left condition is false, it stops right there. and if its true, then it goes onto make sure that the right condition is true too.
4 months ago
I understand that the logical AND operator will check to see whether both the left hand and the right hand condition are true. The CONDITIONAL AND will check the left condition and if it is true, it will ignore the right hand condition. However, in this case, the left condition has been satisfied, yet I am still getting a null pointer exception when I run this code. I thought that the right hand side wouldn't even be checked since the left hand condition was satisfied as being true. What am I missing?

4 months ago

Campbell Ritchie wrote:Why have you marked anything static except the main method?

I marked my variables static because I thought that's what I had to do in order to use them in the main method.
I didn't quite get your point... isn't that the only way to use a variable within a static method?
7 months ago
I fixed the small bug in my code. I was incorrectly adding 1 if the mid-point was larger then the key, and incorrectly subtracting 1 if the midpoint was smaller than the key.

I fixed it like so:

but my exeception handling problem still remains.
7 months ago
I wrote the following code. It's a program which uses Binary Search to locate an element. I try to utilize exception handling to mitigate against the usage of decimal numbers. My intention is for the program to act as follows:

If decimal Number is entered, tell the user that decimals are not allowed and re-run the main method.
What is happening is strange. The main method appears to be running multiple times. Why is this?

My other question is in regards to a bug in my code... If I search for "6000" (the last value in my array) my program tells me that it can't find it. I'm not sure why...
7 months ago
My use case is as follows:

I am already setting the following variables in localStorage.

wake-up time.

I need my count-down clock to stop at "bed time." It should visually display 00:00:00.

When it is time to "wake up," I want the count down to begin. It should now start counting down from 15:59 - The hours:minutes
remaining until it is time for bed-time again.

This repeats, over and over.

I wrote the following code:

This code and variations of it are either making my countdown timer go into the negative, stopping at 0:00, and not ever re-starting once it is time to wake-up.

Joseph Mokenela wrote:You can learn and embrace JavaScript. There is a JavaScript Course that I found very helpful. You can try it out.

Wow. this is excellent. Thank you.
1 year ago