Tom McCann

Ranch Hand
+ Follow
since Aug 27, 2005
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 Tom McCann

Many thanks for your prompt answer.

Tom
17 years ago
In my simple program I can use System.out.println("xxx") without needing to "import java.io.*"

I thought that out.println was part of the java.io package so I don't understand why I don't need to import the package. It would help my understanding of java if someone could explain why this is.

Thanks in advance.
17 years ago
Edwin,

Thanks very much for replying.

I did a bit more research on the net and I found out that my wider requirement, for Multiple Return Values (MRVs) from a function, is a highly contentious issue. Some programmers argue for, some against. In any case, Java doesn't support MRVs.

As you rightly suggest, the preferred way to return MRVs in Java is to create and return a custom object, setting the values in the called function, and then 'getting' those values after returning. This is obviously required for when the return values are of different types.

In my case though, I really wanted 2 integers to be returned so your example using an array is very useful.

Many Thanks,

Tom


Edwin - if you will forgive me for changing the subject to the contents of your tagline, evolution is NOT random. If it were then I wouldn't believe in it either. There are plenty of good books on the subject (try Richard Dawkins) or look up any number of articles on the web (try Wikipedia).

I really don't want to start a discussion on evolution, but to use your own analogy, remember that evolution gives CONSTANT feedback - i.e. the individual lives to breed or it dies. So, your analogy of bashing away at the keyboard would be more accurate if the computer gave you feedback after EVERY keystroke (i.e. if it told you "that's useful" or "that's nonsense"). Only then, and given enough time, could you generate an operating system (and you would need a very very long time).

By the way, some people have achieved similar results. Look up Genetic Algorithms on Wikipedia.

Anyway, thanks again for taking the time to respond. Much appreciated.

Tom
[ October 11, 2006: Message edited by: Tom McCann ]
17 years ago
OK - this should be really easy. How do you set the value of an EXISTING Integer object? i.e. without using the constructor?

I want a function to return two integer values. Obviously I cant pass 2 ints to the function because parameters are passed-by-value.

To get around this I will pass 2 Integer objects. But I can't see any way to set the value apart from in the constructor which won't help me here.

There must be an easy way to do this.

Thanks for your help.
17 years ago
I forgive people for my own self-preservation. The way I imagine it, we need to keep open thousands of lines of communication with other human beings and the universe at large (bet I sound like a hippy now).

If I have a disagreement or a loss of trust with someone then that places a little blockage or at least a speed-bump on one of the lines of communication. I don't want that so I forgive and let go.

I've been conned twice by the same person. After the first time, I forgave him and thus allowed him to take me for a sucker a second time. But hey, I forgave myself for being a sucker.

I'd rather take the loss and remain a trusting open human being than shut down my lines of communication one by one. That is more valuable to me than the money I lost (which was considerable).

I do understand that not everyone has the same point of view, but it works for me.

My point is this, and it sounds paradoxical, but I forgive for selfish reasons - to preserve my integrity and to keep myself open.
17 years ago
Thanks very much.

Tom
18 years ago
Can anyone explain why the following code compiles and runs successfully ?



A Long is not a string. The fact that it was created from a string strikes me as irrelevant.
18 years ago
Jeremy,

Thank you very much for taking the time to explain this. I understand what you are saying now.

Tom
18 years ago
Hi - Thanks for your answer. I know all about the fact that * means zero or more occurences. I already understand that - BUT - I am very concerned that m.find() continues beyond the end of the string.

In my simple example, it doesn't matter much because all I'm doing is outputting a simple message, but in real life I might be doing something a lot more powerful than that.

I'd like to understand if there is a good reason for that. Is it treating the string in a C-like fashion i.e. it is zero terminated and it is processing the zero ?
18 years ago
If I run this code with arguments "\d*" and "abc" the result is "0123"

I can understand that m.find returns true for each character (because it has found zero occurences of a digit). What I don't understand is the "3" at the end. Surely after it looks at "c" then m.find() will return false and the loop should not run again (therefore m.start() should not equal 3).

In other words:

it finds 'a' and prints 0
it finds 'b' and prints 1
it finds 'c' and prints 2
it finds nothing and therefore prints nothing

Why should m.find return true when it has obviously run out of characters to process ?


18 years ago
Doesn't matter - I've gone back to using Textpad for small stuff and JBuilder for large projects. At least JBuilder knows what program to run.
OK - I've noticed a pattern to this. If I make a change to the code in the edit view and press the run button (or the debug button), it prompts me to save the file (I always click OK). It then runs the current program in the console - it then immediately overwrites the console window with the results of the previously run program (originally this would have been my HelloWorld program, but now that I have written more programs, it is always the previously run program).

e.g. I run John.java which prints "Hello - I am John"

I then create a new program - "Bill.java". On clicking run, it prompts me to save Bill.java (OK) then it runs and prints "Hello - I am Bill". This text then immediately disappears when John.java runs again and prints "Hello - I am John"

Note that this only happens if I made changes in the edit view and have been prompted to save. Otherwise it works as expected. Pressing the Red terminate button does not seem to affect anything.

By the way, I'm running Version: 3.1.2 - Build id: M20060118-1600 on a Thinkpad running XP pro.

I can live with this problem but its very irritating - just wonder if anyone else has seen it or got around it.
Thanks for your reply.

I can see a Run menu. I can also see the Run button (which does have a list of previously run programs underneath it in a menu) but I cannot see anything 'on the left' or any way to clear out the list.

Could I trouble you to be a little more specific as to how to clear out the list. Thanks again.
I'm new to Eclipse. After installing Eclipse I created a simple Java project with a HelloWorld program (just to test it out).

Now when I run any other program, the program output displays ok in the console pane but then is immediately overwritten by my old HelloWorld program running. I can't seem to persuade my HelloWorld program to disappear. I have tried using the drop-down run menu and selecting my new (current) program specifically, but the old HelloWorld still runs afterwards. I've also clicked the 'Remove All terminated launches' button above the console pane.

Any ideas ? It's probably something obvious but it's driving me nuts.
Thanks guys. I've found the alphabetical index and updated my bookmark. I think I'll try the Windows version of the doc also.
18 years ago