Question:
Java question. Do methods make programs run faster?
2017-04-26 06:28:16 UTC
In Java do Methods make a program run faster? I'm just beginning and curious.
Three answers:
2017-04-30 02:03:59 UTC
Do you mean as opposed to having everything in one method or in the main method? In general, no. If you're just using one class and running it from top to bottom, methods wont increase speed. However, the idea in Java is to reduce how much code you have to repeatedly type, by referring to a class that youve already coded, creating objects of that type, and then using the methods available in that class.
Chris
2017-04-26 10:21:02 UTC
Speed is irrelevant to the question "why do we use methods?"



The point of a method is to avoid copy-pasting a block of code to elsewhere in your program, let alone doing that multiple times.
brilliant_moves
2017-04-26 08:56:05 UTC
No, but they make software easier to read and write, thereby speeding up development time. They have no real affect on program running times.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...