The document discusses two types of methods in Java - user-defined methods which are written by programmers and can be modified as needed, and predefined methods which are already defined in Java libraries and can be called directly in a program. It provides an example of a user-defined method that prints "Hello World" and an example of calling the predefined toUpperCase() string method to print a string in uppercase.
The document discusses two types of methods in Java - user-defined methods which are written by programmers and can be modified as needed, and predefined methods which are already defined in Java libraries and can be called directly in a program. It provides an example of a user-defined method that prints "Hello World" and an example of calling the predefined toUpperCase() string method to print a string in uppercase.
The document discusses two types of methods in Java - user-defined methods which are written by programmers and can be modified as needed, and predefined methods which are already defined in Java libraries and can be called directly in a program. It provides an example of a user-defined method that prints "Hello World" and an example of calling the predefined toUpperCase() string method to print a string in uppercase.
● 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 requirement2. // User-defined method public class Main { // User-defined method void myMethod() { System.out.println("Hello World!"); }
public static void main(String[] args) {
Main myObj = new Main(); // Create an object of class Main myObj.myMethod(); // Call the method } }
● Predefined Method: Predefined methods are the methods that are
already defined in the Java class libraries. We can directly use these methods just by calling them in the program at any point2. // Predefined method public class Main { public static void main(String[] args) { String txt = "Hello World"; System.out.println(txt.toUpperCase()); // Predefined method } }