paul edwards

Greenhorn
+ Follow
since Mar 12, 2001
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 paul edwards

Hi,
A method requires certain things to be passed to it to work. For example a method that sets a name would require a name be passed it;
ie: setName("Paul");
some methods require more than one.
ie: addInts(5, 6);
some methods require none;
ie: isTrue();
which brings up return type, int the first example, the method is simply going to set somethings name property, so it returns nothing, and would be declared void.
in the second example, you are running the method and expecting a numerical result, in this case an integer(int), so you might use the method like this:
int x = a.addInts(5, 6);
in the third example, you are expecting a yes or no answer, which is a boolean value of true or false, so . . .
boolean tester = a.isTrue();

exceptions opens up a whole can of worms. Basically, to get a program to compile you have to know what exceptions it's methods throw so that you can take them into account via a try/catch/finally exception handler, or via a throws(some exception) statement in the class declaration.
There is a big section on exception handling in the java tutorial. this is just a very brief explanation.

Hope that helps!
Paul
21 years ago
Right,
I see, I was getting confused.
Thanks!!!

Paul
21 years ago
Howdy!
Today I came across a little code that calls a method from it's superclass with no dot operator like this:
MyThread(String Name)
{
setName(name);
}
and then again later:
System.out.println( getName() );

Now I thought you couldn't do that!
How does this work?
-Paul
21 years ago
I looked up some stuff on timers earlier today. Here is some code using a five second timer :
import java.util.Timer;
import java.util.TimerTask;
/**
* Simple demo that uses java.util.Timer to schedule a task to execute
* once 5 seconds have passed.
*/
public class Reminder {
Timer timer;
public Reminder(int seconds) {
timer = new Timer();
timer.schedule(new RemindTask(), seconds*1000);
}
class RemindTask extends TimerTask {
public void run() {
System.out.println("Time's up!");
timer.cancel(); //Terminate the timer thread
}
}
public static void main(String args[]) {
System.out.println("About to schedule task.");
new Reminder(5);
System.out.println("Task scheduled.");
}
}

Happy Trails!
Paul
21 years ago
Hi.
The only place those brackets are used is ussualy to do with arrays. Is that what you are seeing?
Happy Trails,
Paul
21 years ago
I found this handy bit of reference right in the java tutorial.
The page is:
java.sun.com/docs/books/tutorial/essential/threads/timer.html
and it has some sample code doing exactly what you are trying to get at.
Happy Trails!
Paul
21 years ago