Flamealchamist Flamealchamist - 4 months ago 10
Java Question

Whats the difference between java parameters and clarifying it within the method

I'm a bit new to this and had a question. So with java parameters. You can pass values to your methods so that you can do something with this value. Whats the difference between this and just doing this inside the class itself for example just using

int tuna = 81

Answer

"Basic Java Tutorial:"

Well, passing parameters allows the methods to use the passed values

foo(100);
foo(1);
public void foo(int x)
{

     x += 100;
    System.out.println(x);
}

This would print 200 & 101 assuming that the method is called in a main method.

Example: //precondition all variables correctly assigned/ initialized/etc.

while(true)
{
   socket = new Socket(address, port);
   Thread t = new Thread(imaginaryThread(Socket));
}

Entering the socket as a parameter would allow you to create a thread for that specific client/socket

MORE ENCOMPASSING Explanation+Uses:

https://docs.oracle.com/javase/tutorial/java/javaOO/arguments.html