What is the parameter transfer in Java

Functions / methods for what?

Functions / methods we need to do something, to change or manipulate our class.

First of all, how a function / method is structured in Java:

We have three options for "access":

  • public
  • private (private)
  • protected

A method that public has at the beginning of its declaration can be used by other classes? more on this in the chapter Private, public, default, protected.

A method that has private or protected at the beginning of its declaration cannot be used from other classes. More on this in later tutorials.


Variables and methods with the static attribute are not tied to the existence of a specific object, but exist from the time the class is loaded until the program is terminated. The static attribute influences the lifespan of member variables and allows methods to be called without the caller having an object of the class in which the method was defined.

If the static attribute is not used, variables within a class are always linked to a specific instance. Their lifespan begins when the object is created and a constructor is called and ends when the object is released by the garbage collector.

The Data type is the type of data the method should return when called. So e.g. int or string, etc. - this is the case with a request. If there is no data type here, but void then that means that this method should not return any data, i.e. only what is in it should be carried out.

Methods in Java

The parameter is what you have to give the method for its implementation if the method requires it. The parameter is in round brackets. If these are empty, the method does not need a parameter.

And then of course the {} between them stands what the method should do.

A real world example:

A car that belongs to a person is private. If the person wants to use the car, they must use the method:

Methods in Java

What is returned is exhaust fumes that method is called autoVon HerrBFahren, it is private, as it can only be used by Mr B, i.e. the HerrB class. What to do with the method what is needed is gasoline which is of the type of fuel.

When creating a method it is important that they are outside of another method is, however, within the class.

Example of functions / methods and parameters in Java

If we want to call a method, we have to add the method name with the parameter that we want to pass in another method. So e.g. in our main method.

Call function / method in Java

Then there would be a suitable method call in our main () method. In general, if we want to call a method, we must not forget to append the two round brackets.

So if a parameter is required: pjtcode. If several parameters are required:. And if it is a method that does not require any parameters:.

We are done with the subject of methods and parameters. In the next tutorial we will deal with user input.