Question: What's the difference between:

```
public synchronized void test(){}

```

and 

```
public void test() {
   synchronized(Sample.class){}
}

```

Answer: 
To make the difference more clear, the first can be rewritten as:

```
public void test() {    
   synchronized(this){    
   }    
}

```

The difference is that the first is synchronized on the *instance* of the class, whereas the second is synchronized on the *class itself*.

In the first case, two threads can simultaneously be executing `test()` on two instances of your class. In the second, they can't.
To complete @NPE's answer -

a `synchronized` method is actually a method that is `synchronized` on the object the method "belongs" to. Whether it's an instance object or the class object itself. 

Therefore:

```
class Sample {
    public synchronized void test(){}
}

```

is equivalent to

```
class Sample {
    public void test() {
        synchronized(this) {}
    }
}

```

while

```
class Sample {
    public void test() {
       synchronized(Sample.class){}
    }
}

```

is equivalent to:

```
class Sample {
    public static synchronized void test(){}
}

```