Java methods

Introduction

Hello has been spam certified post of the previous array.

Method

-A method is a part or something like a game technique (class is like status * just my feeling). -** It doesn't work unless it is written in the {} (block) of the class **. -By using a method, when you do the same process, you only have to call it without writing the same process, so it's easy. -Easy code visibility and management.

kane.java


public static void method name() {
Process to be executed;
}

kane.java


class Main{
   public static void main(String[]args) {
    banana() ;  //()Is required.
   }

   public static void banana() {
    System.out.println("yellow") ;
   }
}

・ What is the return value? The value (data) returned from the called method to the calling method is called ** return value or return value **.

public static void main(String[] args) { }

-** When a java program is executed, it automatically starts from the main method. **. -The main method gives instructions to each method, and each supported method executes individual processing.

・ If you don't forget to write it, it's OK now.

argument

· Something like additional information given to the method. -A value can be passed from the caller when calling a method. -The value can be used even in the method passed by it.

In order to define a method that can receive arguments, specify a variable (formal argument (Karihikisu)) that will be a box for receiving arguments in the method definition part, and put the formal argument in () of public static void banana (). specify. Formal arguments, like variable definitions, ** must specify a data type **.

kane.java


class Main{
   public static void main(String[]args) {
    banana("Red") ;  
   }

   public static void banana(String color) { //Specify data type
    System.out.println("The color of this banana" + color + "is.") ;
   }
}

Even if there is no information to hand over, () is necessary, so be sure to enter it.

**-When passing multiple arguments **

kane.java


class Main{
   public static void main(String[]args) {
    banana("Philippines", 5) ;  
   }

   public static void banana(String origin, int year) { 
    System.out.println("This banana" + origin + "Of production" + year + "It's a year.") ;
   }
}

Execution result
This banana is from the Philippines for 5 years.//It's rotten

Return value

Overload

Recommended Posts

Java methods
Java methods
Java class methods
Java
Java
(Note) Java classes / variables / methods
[Java] Generics classes and generics methods
Check Java9 Interface private methods
Java methods and method overloads
About Java class variables class methods
Java abstract methods and classes
Java learning (0)
Studying Java ―― 3
[Java] array
Java protected
[Java] Annotation
About Java static and non-static methods
[Java] Module
Java array
Studying Java ―― 9
Java scratch scratch
Java tips, tips
java (constructor)
Java array
[Java] ArrayDeque
java (override)
Various methods of Java String class
Java Day 2018
Java string
java (array)
Java static
Java serialization
java beginner 4
Java (set)
java shellsort
[Java] compareTo
Studying Java -5
java reflexes
java (interface)
Java memorandum
Java array
Studying Java ―― 1
[Java] Array
[Java] Polymorphism
Studying Java # 0
java framework
Java features
[Java] Inheritance
FastScanner Java
Java features
java beginner 3
Java memo
Java inheritance
[Java] Overload
Java basics
Decompile Java
java notes
java beginner
Java (add2)
JAVA (Map)
[java] interface