What are methods in java?

Publié le: 15 mars 2023
sur la chaîne: Credible Academy
30
0

#corejava #methods #learnjava
In this video lecture of Java methods , methods are blocks of code that perform a specific task. Think of a method as a function or an action you want the program to do. Instead of writing the same code repeatedly, you can create a method and simply call it whenever you need that action done.

Why Do We Use Methods in java?
Methods help to organize code, making it more readable and reusable. They allow you to break your program into smaller, manageable parts. For example, you could have a method to calculate the sum of two numbers or a method to print a message to the screen.

Key Features of Methods in java:
1. Code Reusability: You can write a method once and call it multiple times from different places in your program.
2. Modularity: Methods break down complex problems into simpler, manageable chunks of code.
3. Maintainability: If there's a mistake or update needed, you only have to modify the code in one place.

How to Define a Method:
A method in Java consists of four main parts:
1. Return Type: This defines what type of value the method will return (e.g., int, String, or void if it doesn’t return anything).
2. Method Name: This is how the method will be identified or called.
3. Parameters: These are optional inputs passed to the method to perform a specific task.
4. Method Body: This contains the actual code that performs the task.



In this video, we define a method called greet() that prints a message. In the main() method, we call the greet() method to display the message.

Types of Methods in Java:
1. Predefined Methods: These are methods that are already defined in libraries (e.g., Math.sqrt() for square roots).
2. Userdefined Methods: These are methods you create to perform specific tasks, like the greet() method above.

By using methods, you can make your Java programs more organized, efficient, and easier to manage!



This explanation provides clarity for beginners while offering the essential details of Java methods in a simple, easytounderstand way. Let me know if you'd like any changes!
Thanks for Watching,
Follow us on

Subscribe to our Channel :
Like Facebook Page :   / credibleacedemy  
Follow us on Instagram :  / credible_academy  
LinkedIn :   / mohsin-ahmad-0bb8085b  
Review - https://www.facebook.com/credibleaced...
FB -   / credibleacedemy  


Sur cette page du site, vous pouvez voir la vidéo en ligne What are methods in java? durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur Credible Academy 15 mars 2023, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 30 fois et il a aimé 0 téléspectateurs. Bon visionnage!