[Java] Arguments and parameters

https://qiita.com/hp_kj/items/789a7fb7e922745f8bd9#comment-f22f811bbe75340a3f1b As you pointed out in the comment section, I investigated the formal and actual arguments. Thank you very much!

I learned arguments in the beginning. I thought I could afford it. For example

python


public static void main(String[]args){
  int x = 10;
  int y = 20;
  System.out.println(add(x,y));
}

public static int add(int x,int y){
   return x + y;
}

I could understand the above. to the add function x 10 20 of y is included. As a result, 30 is output.

However, I didn't understand when this happened.

python


public static void main(String[]args){
  int x = 10;
  int y = 20;
  System.out.println(add(x,y));
}

public static int add(int a,int b){
   return a + b;
}

No, not a and b, I want to put x and y in the add function.

So I studied functions on udemy.

The result is that the function arguments are just entrances. That was the conclusion.

Write an example.

python


public static void main(String[]args){
  int x = 10;
  int y = 20;
  System.out.println(add(x,y));
}

public static int add(int a,int b){
   return a + b;
}

First is this code. Disassemble. It's half done.

python


int add(int a,int b){
   return a + b;
}

My writing ability is too weak. Further disassemble.

python


int add(int a){
   return a;
}

Think about this.

This add function will be named a if you use an int type as an argument. !! This is important.

: o: If you use int type as an argument, use it with the name a.

Use only int type named: x: a as an argument.

It is used as a in the add function. It means int a. So, for example

python


public static void main(String[]args){
  int x = 10;
  int cccc = 20;
  System.out.println(add(x,cccc));
}

public static int add(int aaaaaaa,int bbbbbbb){
   return aaaaaaa + bbbbbbb;
}

This is fine too. In the main function, it is add (x, cccc), If you use int type as an argument, use it with the name aaaaaaa.

So, whether it's x, y, or cccc, it will return as long as you use the int type.

Even the add function disappeared from the middle, but thank you for reading. I thought I was writing. It's easy to convey videos.

Recommended Posts

[Java] Arguments and parameters
Java arguments, return values and overloads
Java and JavaScript
XXE and Java
Java true and false
[Java] String comparison and && and ||
Formal and actual arguments
Java --Serialization and Deserialization
timedatectl and Java TimeZone
[Java] Branch and repeat
[Java] Variables and types
java (classes and instances)
[Java] Overload and override
Study Java # 2 (\ mark and operator)
Java version 8 and later features
[Java] Difference between == and equals
[Java] Generics classes and generics methods
Java programming (variables and data)
Java and Iterator Part 1 External Iterator
Java if and switch statements
Java class definition and instantiation
Apache Hadoop and Java 9 (Part 1)
[Java] About String and StringBuilder
☾ Java / Iterative statement and iterative control statement
Java methods and method overloads
java Generics T and? Difference
Advantages and disadvantages of Java
java (conditional branching and repetition)
About Java Packages and imports
[Java] Upload images and base64
C # and Java Overrides Story
Java abstract methods and classes
Java while and for statements
Java encapsulation and getters and setters
I compared PHP and Java constructors
Differences between "beginner" Java and Kotlin
Use java with MSYS and Cygwin
Distributed tracing with OpenCensus and Java
[Java] Difference between Hashmap and HashTable
Java variable declaration, initialization, and types
Java Excel Insertion and Image Extraction
Install Java and Tomcat with Ansible
AWS SDK for Java 1.11.x and 2.x
[Java] Basic types and instruction notes
Java release date and EOL summary
Java and first-class functions-beyond functional interfaces-
About fastqc of Biocontainers and Java
Java for beginners, expressions and operators 1
Java Primer Series (Variables and Types)
Encoding and Decoding example in Java
[Java beginner] About abstraction and interface
Basic data types and reference types (Java)
[Java] Loop processing and multiplication table
Java 15 implementation and VS Code preferences
OpenJDK 8 java and javac command help
Java reference mechanism (stack and heap)
Java for beginners, expressions and operators 2
Java PowerPoint password setting and cancellation
Java 9 new features and sample code
[Java beginner] == operator and equals method
[Java] Declare and initialize an array