The word “just” has several possible definitions:
Be careful – I just washed the floor, and it’s still wet.
(= I washed the floor a few minutes ago)
He just finished a big project.
(= he finished the project very recently)
I have just one brother. (= I have only one brother)
I thought you were hungry, but you ate just half of your sandwich.
(= you ate only half of your sandwich, and no more)
The word “only” can be replaced with “just” in most situations:
Only two students came to class on the day before Christmas.
= Just two students came to class on the day before Christmas.
My kids only use the internet for schoolwork, not for playing games.
= My kids just use the internet for schoolwork, not for playing games.
In the expression “If only…” you can use “just” if you change the structure a little bit:
If only I had studied harder. I would’ve passed the test.
= If I had just studied harder, I would’ve passed the test.
“Only” and “just” are interchangeable with definition 2 of “just,” but not with definition 1.
Definition 2 – Same meaning
We have just one daughter. = We have only one daughter.
Definition 1 – Different meanings
I just washed the floor (a few minutes ago)
I only washed the floor (and I didn’t wash the table)
However, it also depends on the context:
“Did you clean the whole house?”
“No, I just washed the floor” (= I only washed the floor).
“Why is the floor wet?”
“Because I just washed it”
(= I recently washed it. In this case, you can’t use “only”)