SlideShare a Scribd company logo
JAVA METHOD
METHOD / FUNCTIONS
They are used to divide and sort
Functionalities within a class so that
the code will be readable even if its
long.
Creating Methods
modifiers returntype methodname() {
//Do anything here
}
Creating Methods
static void sayHello () {
System.out.println(“Hello World”);
}
Calling Method
public static void main(String[] args) {
methodname();
}
Calling Method
public static void main(String[] args) {
sayHello();
}
Comments
// This is a single line comment
/* This is a multi-line comment
you can comment here too!! */
Variable Scoping
Global Variable
Are variables declared within a class, it can be accessed within a whole
class.
Local Variable
Are variables declared inside a method, condition, loops and any other
block of code, it can be accessible within that block of code.
Arguments / Parameters
A value that needs to be passed on a method so that the method can
use value and perform various operations on it.
PS: You can have as many Arguments / Parameters as you want, they
act as a Local variable inside a method/function.
Method with Arguments
modifiers returntype methodName(arguments) {
//Do anything here
}
Method with Arguments
static void say(String word) {
System.out.println(word);
}
Return Keyword
return keyword is used to return a value from the method. It is used
when a method has a result.
Example:
A method that performs Math equations.
A method that concatenates Strings.
Return Type
The type of the value that will be returned, return type are same as the
datatypes.
void returns Nothing.
int returns integers.
String return strings.
And so on……
Method w/ Return
modifiers returntype methodName(arguments) {
//Do anything here
return value;
}
Method w/ Return
static int add(int num1, int num2) {
return num1 + num2;
}
Overloading Methods
You can use the same method name but
different parameters so that you will cater to
every possibility of a method.
Overloading Methods
static int add(int num1, int num2) {
return num1 + num2;
}
static int add(int num1, int num2, int num3){
return num1 + num2 + num3;
}

More Related Content

PPT
Bad Smell in Codes - Part 1
PPTX
Module 4 : methods & parameters
PDF
Ma3696 Lecture 3
PPTX
11. java methods
PPTX
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
PPT
Chapter 7 - Defining Your Own Classes - Part II
PPTX
1. Methods presentation which can easily help you understand java methods.pptx
PPTX
Methods In C-Sharp (C#)
Bad Smell in Codes - Part 1
Module 4 : methods & parameters
Ma3696 Lecture 3
11. java methods
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
Chapter 7 - Defining Your Own Classes - Part II
1. Methods presentation which can easily help you understand java methods.pptx
Methods In C-Sharp (C#)

Similar to JAVA METHOD AND FUNCTION DIVIDE AND SHORT.pptx (20)

PPT
Java căn bản - Chapter7
PPTX
java Method Overloading
PDF
Java Polymorphism: Types And Examples (Geekster)
PDF
Handout # 4 functions + scopes
PPT
Md06 advance class features
PPT
Methods.ppt
PDF
CIS 1403 lab 3 functions and methods in Java
PPTX
JAVA METHODS PRESENTATION WITH EXAMPLES DFDFFD FDGFDGDFG FGGF
PPTX
Working with Methods in Java.pptx
PPTX
Android Training (Java Review)
PPT
4. java intro class
PPTX
UNIT-2.pptx CS3391 Inheritance , types, packages and Interfaces
PPT
TDD And Refactoring
PDF
11 ruby methods
PPTX
Basics of java 2
PPT
Java findamentals2
PPT
Java findamentals2
DOCX
PSYC 3663 SAFMEDS TERMS – Assignment 1Provide a definition for e.docx
Java căn bản - Chapter7
java Method Overloading
Java Polymorphism: Types And Examples (Geekster)
Handout # 4 functions + scopes
Md06 advance class features
Methods.ppt
CIS 1403 lab 3 functions and methods in Java
JAVA METHODS PRESENTATION WITH EXAMPLES DFDFFD FDGFDGDFG FGGF
Working with Methods in Java.pptx
Android Training (Java Review)
4. java intro class
UNIT-2.pptx CS3391 Inheritance , types, packages and Interfaces
TDD And Refactoring
11 ruby methods
Basics of java 2
Java findamentals2
Java findamentals2
PSYC 3663 SAFMEDS TERMS – Assignment 1Provide a definition for e.docx
Ad

Recently uploaded (20)

PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
RMMM.pdf make it easy to upload and study
PPTX
Pharma ospi slides which help in ospi learning
PPTX
master seminar digital applications in india
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
Pre independence Education in Inndia.pdf
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
Cell Structure & Organelles in detailed.
PDF
VCE English Exam - Section C Student Revision Booklet
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
Classroom Observation Tools for Teachers
PPTX
Institutional Correction lecture only . . .
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
O7-L3 Supply Chain Operations - ICLT Program
STATICS OF THE RIGID BODIES Hibbelers.pdf
FourierSeries-QuestionsWithAnswers(Part-A).pdf
RMMM.pdf make it easy to upload and study
Pharma ospi slides which help in ospi learning
master seminar digital applications in india
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Microbial disease of the cardiovascular and lymphatic systems
Pre independence Education in Inndia.pdf
Module 4: Burden of Disease Tutorial Slides S2 2025
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Cell Structure & Organelles in detailed.
VCE English Exam - Section C Student Revision Booklet
PPH.pptx obstetrics and gynecology in nursing
2.FourierTransform-ShortQuestionswithAnswers.pdf
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Classroom Observation Tools for Teachers
Institutional Correction lecture only . . .
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
O7-L3 Supply Chain Operations - ICLT Program
Ad

JAVA METHOD AND FUNCTION DIVIDE AND SHORT.pptx