#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
Nesta página do site você pode assistir ao vídeo on-line What are methods in java? duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário Credible Academy 15 Março 2023, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 30 vezes e gostou 0 espectadores. Boa visualização!