r/learnjava • • Nov 21 '14

learning about methods, question

it's not covered in the text so i figured i'd ask. so basically methods = a way to make your text nice and clean and readable. so if u did something like checking if a number is like odd or even or something that involves if statements or else statements, you put it in a method then call on that so your "main method (am i using the correct terminology)" is readable and cool.

also, do all methods u make need to be after the main method? can it be before the main method like you have something called checkEvenOrOdd() before the main method, then in the main method u call on that. is that wrong ? thx bros

0 Upvotes

13 comments sorted by

View all comments

1

u/RhysLlewellyn Nov 21 '14

I'm also new to programming and would like to offer my opinion but don't take it as fact and I'd welcome any corrections if I get any of this wrong...

The main method is always the first method to be called upon. It initialises the programme, from the class main.

If you were making a simple programme just to say if a number is odd or even, you could set up your variables and methods within the main class as there wouldn't be a need to create a new object in a new class, due to the simplicity of the programme.

It's not possible to make anything run before the main method.

Is that right people?

0

u/[deleted] Nov 21 '14

[deleted]

1

u/imgonnabethebest Nov 21 '14

yeah i got it now thanks. doing an exercise http://www.reddit.com/r/learnprogramming/comments/2mydur/trying_to_print_stars_without_using_for_loops/

i also learned that you can call on methods and use them inside another method that you're trying to write. thats some inception next level shit, pretty cool.

0

u/[deleted] Nov 21 '14

[deleted]

0

u/imgonnabethebest Nov 21 '14

ya bro :) didn't you read the comments

-1

u/imgonnabethebest Nov 21 '14

uhh i mean look at the reply i got from the G master java king he said it doesnt matter