A builder it’s not that different from a common method. Just as methods can be burdened, constructors can also. So you can have methods with the same name and different signatures. This makes it another method. This is useful because each can have a convenience.
In your case the first would be a complete builder who does everything he needs. The second only delegates to the first how to do the construction. Then you do not need to pass the balance if it is a default value, draws without it and the secondary builder takes care of passing the balance to you.
This is not necessary in languages that have arguments with default value, which is not the case with Java, at least yet.
There is a special syntax to show that you are calling a constructor and not just any method. It is calling the method this
. This way the compiler can treat it differently. So the secondary constructor doesn’t build the object, the primary will. But it is he who will deliver the result, if it is he who was invoked at the instantiation of the object.
This syntax is required because there can be nonconstructor methods with the same class name.
Note that the this
in the other constructor is used to disambiguate the local variable or object attribute parameter. So it’s not all in the same this
, is the same syntax for different mechanisms.
this(correntista, senha, 0);
in that case it is the same as
Conta(correntista, senha, 0);
which cannot be called inside a constructor correctly every time (there may be ambiguity).
I put in the Github for future reference.
One would think that it might have made the same code in both builders. But it violates the DRY and can create maintenance difficulty. This is not to save line of code, has important semantic purpose. There is no time gain in this.
Understand that this is actually a type of polymorphism, but we usually call it overload, because the understanding of polymorphism usually refers to something else. This terminology is a little ambiguous, overload is not.
I will not comment on the other problems of this method which is not the focus of the question and for an exercise is ok.
So every time I call the constructor "simple", I’m passing on his information to the constructor "compound"?
– Guilherme Bigois
In this example yes, but not necessarily.
– Maniero
How can I know that the simple builder is passing to the compound or not? (where it is evident that?)
– Guilherme Bigois
I don’t know, because this terminology is wrong, I don’t know what it means. With a wrong premise, it gets complicated to answer anything.
– Maniero
"SIMPLE CONSTRUCTOR":
public Conta(Correntista correntista, String senha) {
 this(correntista, senha, 0);
}
"COMPOUND CONSTRUCTOR":public Conta(Correntista correntista, String senha, double saldo) {
 Random gerador = new Random();
 this.numeroDaConta = gerador.nextInt(9000)+1000;
 this.correntista = correntista;
 this.senha = senha;
 this.saldo = saldo;
}
– Guilherme Bigois
There is nothing simple or compound there, both are builders, are methods. One is short and the other is bigger. You want to know that you are going through what?
– Maniero
It’s hard... An example: if I delete the bigger constructor, will the smaller one work normally? If not, I want to know if the information captured for the short builder, are going to the long.
– Guilherme Bigois
No, if you erase something, it stops working, if something depends on it, it stops working too. I suggest starting from the beginning, understanding each concept in a structured way, then the understanding of things will come easily. The question there is not even of constructor. Search on overloading method (overload of methods).
– Maniero