« first day (4428 days earlier)      last day (506 days later) » 

12:00 AM
The goal of Computer Science is to build something that will last at least until we've finished building it. (source)
 
 
8 hours later…
8:16 AM
nods off
 
 
6 hours later…
2:20 PM
posted on December 07, 2022

archive - contact - sexy exciting merchandise - search - about ← previousDecember 7th, 2022nextDecember 7th, 2022: TIME IS RUNNING OUT TO ORDER THE FOLLOWING AND GET IT IN TIME FOR CHRISTMAS: It's called T-REX VERSUS SANTA and it's gorgeous and it kinda makes all other sweaters retroactively worse. SORRY NOT SORRY – Ryan

 
 
5 hours later…
7:09 PM
 
 
1 hour later…
8:22 PM
Could you help me understand the concept of parameters? I try to learn Java on Codecademy. In the example below, the variables are already introduced (type of variable + its name). Why do I need those "parameters" (String carColor, int milesPerGallon)? And then it goes to specify that "color = carColor; mpg = milesPerGallon;"
 
@SergeyZolotarev Welcome to the Java Chat, the room for Java enthusiasts! I'm Oak, one of the room's bots. If you want to ask a question, just ask it and someone will respond if they feel like it. But remember that this room is not a help desk or tutoring service! If you want to just hang out, then welcome aboard! Oh, and the room's full list of rules are posted here.
 
It doesn't make sense to me and seems completely redundant. To me, it should be much simpler: you introduce a variable and that's it; when you describe an object of a class, then you assign a variable to it. What's the logic behind that seemingly superfluous coding design?
 
because Java is old, and in the old days, people were excessively obsessed with control
 
@SergeyZolotarev Parameters just means you "forward" a variable into a function. Constructors are also functions, though special functions. What you're thinking about is a mechanic some programming languages has, but Java isn't one of them. Java always requires them because that's just the way it is, but in real programs, you often end up having to do stuff with the variables. If you just introduced them, you can't have validation on construction, for instance. You'd have to do it separately
 
you could for example have a constructor that doesnt have those parameters, which would decide by itself what the values will be
public class Car
{
	private String color;
	private boolean isElectric;

	public Car()
	{
		color = "grey";
		isElectric = false;
	}

	public Car(String color, boolean isElectric)
	{
		this.color = color;
		this.isElectric = isElectric;
	}
}
 
8:51 PM
@ZoestandswithUkraine what do you mean by "forwarding a variable into a function"?
What's the difference between "color" and "carColor" (other than the fact that you call the former a variable and the latter a parameter)?
 
9:04 PM
Why can't it be like this?

public class Car {
String color;

public Car(color) {
}

public static void main(String[] args) {
// parameter value supplied when calling constructor
Car ferrari = new Car("red");
}
}
I don't say it twice that color is a string variable. It's more concise
 

« first day (4428 days earlier)      last day (506 days later) »