Re: I need help with basics.
Please see the following for an in depth tutorial on the subject
Defining Methods (The Java™ Tutorials > Learning the Java Language > Classes and Objects)
Methods are associated with classes, and are only run when called
Re: I need help with basics.
Well, I read through it and I understand them alot more... But i'm still confused how you can call one into action.. But i'm guessing it's not as easy as I thought it would be like
run myMethod(); ect... ugh
Or can you point me at the exact section I should re-read??? Please.
Re: I need help with basics.
You do not initiate methods, you call them. To do that first you need to create an object of that class. Surely you have seen examples involving Strings.
Re: I need help with basics.
Ahhh! I think I understand...
If you don't want something to be executed you don't type public static void main(String[] args) ??? And if you do type that, everything in that class will be executed?? I think I understood it the whole time just didn't realize it. But I guess I need to improve my understanding of calling other classes.
Re: I need help with basics.
Quote:
If you don't want something to be executed you don't type public static void main(String[] args) ??? And if you do type that, everything in that class will be executed??
No. main is the application entry point - you define how you want your application to flow by creating a class which contains a main method, then instantiate objects or calling other static methods from within. I highly recommend you delve into those tutorials a bit more - testing the code provided, even better changing it to see how your changes affect how the program behaves.
Re: I need help with basics.
No!
If you don't want something to be executed then why is it in the code? The main method is the entry point into your program. You only need one main method, however you can add a main method to every class you write for testing purposes.
Once again if you want a method to execute it you need to call it.
Code java:
Foo f = new Foo(); //creates a Foo object
f.doStuff(); // calls the doStuff method which now is executed
Re: I need help with basics.
Yep I think I understand =) What I meant is I don't want code not to run, just run at certain times. But thanks for the help guys, pretty sure I fully understand it now.
Re: I need help with basics.
Quote:
Originally Posted by
Emperor_Xyn
Yep I think I understand =) What I meant is I don't want code not to run, just run at certain times. But thanks for the help guys, pretty sure I fully understand it now.
Yeah you can still do this. You must read threading and more over, read the java.util.Timer for more.