[JAVA] Functions and methods


As you pointed out here, I couldn't understand the function and method and searched.

According to the IT terminology encyclopedia

A function is a group of instructions that receives data called arguments, executes the specified processing, and returns the result.

A method is an operation on itself that each object has in object-oriented programming. It seems that it means something like that.

//Method definition
class Add {
	int add(int x,int y) {
		return x + y;
//Method call
public class Main {
	public static void main(String[]args) {
		Add a = new Add();
		a.add(1, 3);
public class Main {
//Function definition
	int add(int x, int y) {
		return x + y;
//Function call
	int c = add(1,2);

I think that it looks like this with java. A function when the function is used in the same class. When a function is defined in a class, an instance is created from that class, and it is used in another class, it is called a method.

I was allowed to reference. https://qiita.com/T-N0121/items/ecf5b911463ac9fa1d3e

Recommended Posts

Functions and methods
Ruby variables and functions (methods)
Ruby variables and methods
Coding methods and refactoring principles
[Java] Generics classes and generics methods
rails path and url methods
About pluck and ids methods
Java methods and method overloads
[Ruby] Singular methods and singular classes
Ruby methods and classes (basic)
Java abstract methods and classes
[Ruby] Singular methods and singular classes
Think about the differences between functions and methods (in Java)
About Java static and non-static methods
About the equals () and hashcode () methods
Ruby standard input and various methods
How to call classes and methods
Studying Java 8 (StaticIF and Default methods)
Java generics (defines classes and methods)
Application of downcase and slice methods
Examples of lambda, sort, and anonymous functions
Frequently used functions and commands of Xcode
Java programming (classes and instances, main methods)
Visually understand Fibonacci numbers and recursive functions
Java methods
JAVA learning history abstract classes and methods
Output using methods and constants Learning memo
How to use substring and substr methods
Find out about instance methods and self
Kotlin functions and lambdas to send to Java developers
[For copy and paste] Test functions for Result [XCTest]
How to execute and mock methods using JUnit
[Java] Personal summary of classes and methods (basic)
Check static and public behavior in Java methods
Ruby: Differences between class methods and instance methods, class variables and instance variables
Mixin test cases with JUnit 5 and default methods
How to access Java Private methods and fields