What are methods in JAVA (Beginners)

Fetching Comments ...

Hello Readers !!!

In previous lesson I wrote about JAVA Classes. And in this lesson I will teach you about Methods. If you came from any programming language like C or C++ then keep this line in mind that functions in C or C++ language are called as Methods in JAVA programming language. So don’t get confuse about that what is methods. :/ But if you don’t have knowledge about any programming language then in simple words methods are used to combine variables, so that we can use them later anytime, and we don’t need to do the same work again and again. (I know that you don’t understud that what I am talking about). ok lets take an example.

suppose we want to add two numbers then in maths we wrote like this 14 + 25, and we do the same in programming languages. like sum = a+b or sum = 14+25. Its an easiest and small example. but if we want to find factorial of 2 numbers, then we will simply write mathematics logic to find factorial. but if we need to do this again and again, then we need to write code again and again also. but this is not good idea to do this because this will make our file to large. So here the work of methods came. If we define logic of finding factorial of 2 numbers inside method then we can use that method when we want to find factorial of another numbers and we will pass new values to that method and we will get our result.

Maybe you got an Idea that why we use methods and classes in JAVA and other programming languages. because it prevent us from rewriting same thing again and again and make coding faster.

In real-life software we mostly use Classes and Methods.

So this is just intro about Methods in JAVA Programming language.

LearnPainLess On Instagram

Get The Best Of All Hands Delivered To Your Inbox

Subscribe to our newsletter and stay updated.