Java static method or main method | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Java static method or main method

Should i create a static method or put all the code inside the main method (for example, comparison of instances)

24th Apr 2022, 12:30 AM
jhh
2 Answers
+ 2
Depends on the size and function. Something over what fits on your screen, if there are functional areas that can be split, do so. Do not break up a function no matter how big it might be.
24th Apr 2022, 2:13 AM
John Wells
John Wells - avatar
0
The point of using functions, is code reusability, and separation of concerns. Try to isolate parts of your code that have a single meaningful purpose, in a function. Also if you have to do some action or calculation repeatedly, it makes sense to refactor that part into a method, so that you don't have to repeat the same code in multiple places. This makes it easier to change (or fix) your program in the future, because you only need to change in one place.
24th Apr 2022, 5:02 AM
Tibor Santa
Tibor Santa - avatar