I have no experience with swift; however I use Java fairly frequently (I am mainly a c and c++ guy now days), so I will try to take a stab at this question.
Java Variables
In Java there are types for variables such as int, double, long, and float. The reason you declare a variable type in Java is to tell the compiler how much memory to set aside to store the variable. Declaring variable type also tells the compiler how to manage the variable for instance adding two strings concatenates them where adding two numbers numerically adds them.
Java Functions
In Java when declaring a function you need to tell the compiler what type of value the function will return. For instance
int add(int num1, int num2){
return num1 + num2;
}
returns an integer value, while
void doSomething(){
......
}
does not return anything. In general, functions can be declared of any type that a variable can be declared as. This concept applies to many languages (c and c++ are a couple major examples). I hope this answers your question.