First of all, you need to know the difference between x++ and ++X ;
In case of x++ :
First, the current value will be used, and it will increase as follows. This means that you will get the current x value for the operation, and if you use x the next time it will get an incremental value;
In case of ++X :
First, the current value will be increased, and it will be used (additional value) further, which means that you will receive an increased value during this operation and for others after this operation.
Now let's split the code and discuss it separately
method: sample1 ():
private static int sample1(int i) { return i++; }
This method will accept an int and return it first, and then try to increment, but after returning the variable i will disappear from the scope, so it will never be incremented at all. exp in: 10-> out 10
method: sample2 ():
private static int sample2(int j) { return ++j; }
This method takes an int and increments it first and then returns. exp in: 10-> out 11
In both cases, only the variables will change locally, which means that if you call from the main method, the variables of the main method will remain unaffected by the change (since sample1 () and sample2 () copy the variables)
Now for the main method code
System.out.println(sample1(i++)); // it giving sample1() `i=0` then making `i=1` // so sample1() will return 0 too; System.out.println(sample1(++i)); // it making `i=2` and then giving sample1() `i=2` // so sample1() will return 2; System.out.println(sample2(j++)); // it giving sample2() `j=0` then making `j=1` // so sample2() will return 1; System.out.println(sample2(++j)); // it making `j=2` giving sample2() `j=2` then // so sample2() will return 3;