 Assistant Professor from Department of Electronics from Vulture Institute of Technology, Sallapur. Today, I am here to have a session on Java methods. After the end of this session, student will be able to create Java methods. What are Java methods? A method is a block of code which only runs when it is called. You can pass data known as parameters into the methods. Methods are used to perform certain actions and they are also known as functions. How to create a method? A method must be declared within a class. So the method should always be declared in a class. It is defined with the name of the method followed by the parenthesis. Java provides some predefined methods such as system.out.println. But you can also create your own methods to perform certain actions. So inbuilt method, Java has been provided which is system.out.println. No need to write the definition for this method. You just need to call it because it is a predefined one. Similarly, you can create your own methods like this system.out.println. So let us see the syntax of the create method. Create a method inside the class name as main. So main is the name of the class. So you are going to create a method. Create class name as the main class, class name, static void my method. So you are going to call the my method and you are going to code for the execution. So this is the syntax, how you call it. Java method parameters. Information can be passed to the methods as parameters. You can also pass the parameters to the methods. The parameters act as variables inside the method. Parameters are specified after the method name inside the parenthesis. You can add any parameters you want. Just separate them with the commas. Let us try. Write a program, hello world using java method. Open the command prompt, windows are. Open the editor. I am going to open the notepad. Just write a program to print the hello world but by using the java method. So public class, main is the class name, static void my method. I am going to call with the parenthesis and print system.out.println hello world. Now call the main function, now call the main void main, public, static void main, string args my method. Now save the file using the class name main.java, open the command prompt, change the directory to desktop where my folder is stored, my file is stored in the desktop. So java c main.java bytecode is successfully generated, java main. So you can see hello world is printed by using the method. The same method if you want to print hello world multiple times, just call my method multiple times for printing. So click on save. Go back to the command prompt, java c main.java, java main. So you can see I have called the function three times, that is why I have got the printed hello world twice. So this is how you create, you call the motion method multiple times. Now have a second program, write a program to print ages of lame, jenny and anuja as 58 and 31 respectively using the java method. Go back to the notepad, I am going to write in the same main method, same file, static void my method. I am going to pass the string as name comma integer age, print system dot out dot print ln first name plus name plus plus age. Now call the main code, public, static, void, main, string, args, the main method, pass the parameters, lame comma 5. Then call the method, now pass the different parameter, jenny comma 8. Again call my method anuja comma 31, complete the code. So what you have done, you have taken the parameters lame comma 5, you can take multiple parameters in the parenthesis, you can pass the values now we have seen in the PPT similarly jenny you have saved the ages 5 anuja, you are seeing the ages 31. So what you are going to, how the program is going to run, you are going to call the method, you are going to pass the parameters as name and age. So name and age will be passed and the output will be printed, system dot out dot print ln, the name is the string, here is the theme of the string, is and age of the, but each and every person will be printed respectively one by one. Save the program, go back to the command from java, c, main dot java. So the code is successfully byte code is generated java main, so you can see let me just let me give this space in here between, so go back save the file, go back java c main dot java java main. You can see lame is 5, jenny is 8, anuja is 31. So you have printed ages of these three people by using method in java, think and write why use methods, pause the video and try to answer the question, if you are unable to answer the question, go back to the video, rewind it and try to rethink and why to use the methods. Answer to the question is to reuse code, define code once and use it many times. So where you want to reuse the code, defining it and calling it many times, in this case you can use the methods in java. References are taken from java, a beginners guide, core java 2, volume 1 fundamentals, java 2, the complete reference guide. Thank you.