Java Methods

A Java method is a collection of statements that are grouped together to perform an operation. When you call the System.out.println() method, for example, the system actually executes several statements in order to display a message on the console.

Now you will learn how to create your own methods with or without return values, invoke a method with or without parameters, and apply method abstraction in the program design.

Creating Method

Considering the following example to explain the syntax of a method −

Output :

main begin
Finding value for : numberOfRecordsToRead
Exception raised while reading config.txt
numberOfRecordsToRead : 10
main end

Scroll to Top