The document provides an overview of methods in Java, highlighting their role in code reusability and modification. It distinguishes between predefined methods, which are built-in and can be directly used, and user-defined methods, which are created by programmers to meet specific needs. Examples of each type of method are included to illustrate their usage.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
2 views10 pages
methodsinjava-200922055626
The document provides an overview of methods in Java, highlighting their role in code reusability and modification. It distinguishes between predefined methods, which are built-in and can be directly used, and user-defined methods, which are created by programmers to meet specific needs. Examples of each type of method are included to illustrate their usage.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10
Methods in java
Prof. Neeraj Bhargava
Kapil Chauhan Department of Computer Science School of Engineering & Systems Sciences MDS University, Ajmer Introduction the method in Java is a collection of instructions that performs a specific task.
It provides the reusability of code. We can
also easily modify code using methods.
A method is a block of code or collection of
statements or a set of code grouped together to perform a certain task or operation. Cont.. It is used to achieve the reusability of code.
We write a method once and use it many
times. We do not require to write code again and again. Method Declaration Types of Method There are two types of methods in Java:
Predefined Method
User-defined Method Predefined Method In Java, predefined methods are the method that is already defined in the Java class libraries is known as predefined methods.
It is also known as the standard library
method or built-in method.
We can directly use these methods just by calling
them in the program at any point.
Some pre-defined methods are length(), equals(),
compareTo(), sqrt(), etc. Example public class Demo { public static void main(String[] args) { // using the max() method of Math class System.out.print("The maximum number is: " + Math.max(9,7)); } } User-defined Method The method written by the user or programmer is known as a user- defined method.
These methods are modified according to the
requirement. Example public static void findEvenOdd(int num) { //method body if(num%2==0) System.out.println(num+" is even"); else System.out.println(num+" is odd"); } Assignment Explain Methods in java and their types with suitable example.