Sitemap

Java Methods Explained: A Beginner’s Guide

2 min readJul 25, 2026

--

Press enter or click to view image in full size

A method is a block of code that performs a specific task.

A method means steps of specific task or same order of any particular method.

“Instead of writing same code many times” in the code , we can use method concept. Method is a block of code , that run same code many times whenever we want.

Press enter or click to view image in full size

Real life example:

For example , we are creating a landing page. page should be contain too many white boxes, but boxes should be in the same design for the whole page.

So, we write the code at once . Use that code for all boxes by calling itself.

Here is the example of “checking even numbers”.

What is static ?

“static” is a keyword , currently we do not need to understand keyword (It is an OOPS related topic.).we will learn it later.

Which one i can use now Int & Void ?

“Void & int ” are the return type.It is the line of the code where many new learners get confused, i was also 😀.

Get Prachi patel’s stories in your inbox

Join Medium for free to get updates from this writer.

Let's start with void , “when we do not need to get output(result)” , we should use void .

“When we have to get result” , we should use int.

I know it’s confusing,

Let me explain in my way , while you only need to print but do not need any calculation, you can use void. the example is in the above image.

While calculation is included in the process , you can use int. EX. user have putt two numbers and they want to addition of that , It means there is a calculation available that's why we should use int .

The return concept in important for method :

Now, we have use int beacuse we need a value (a result) , so that we use return to send that value to the user.

When we use int , we have to give an answer to the user so that we write return at the end.

Important Rule :

If the return type is void, we do not write return to send a value.

if the return type is int, we write return to send a value.

--

--

Prachi patel
Prachi patel

Written by Prachi patel

Exploer and explain language in my own words