Question: The compiler shows an error at `new Stock[2];` after `;{` expect.

```
public class TestStockUI {
    Stock[] stock = new Stock[2];
    stock[0] = new Stock("Microsoft", "MSFT", 15.69);
    stock[1] = new Stock("Google", "GOGL", 323.98);

    public TestStockUI() { }

}

```

Then I have changed it like below resulting in the same error.

```
public class TestStockUI {
    Stock[] stock = new Stock[2];
    stock[0] = new Stock("Microsoft", "MSFT", 15.69);
    stock[1] = new Stock("Google", "GOGL", 323.98);

}

```

This solve the problem but I don't know why.

```
public class TestStockUI {
    Stock[] stock = new Stock[2];
    {
        stock[0]=new Stock("Microsoft","MSFT",15.69);
        stock[1]=new Stock("Google","GOGL",323.98);
    }

}

```

Answer: 
```
{
    stock[0]=new Stock("Microsoft","MSFT",15.69);
    stock[1]=new Stock("Google","GOGL",323.98);
}

```

This creates an [initialization block](http://download.oracle.com/javase/tutorial/java/javaOO/initial.html), where these statements are legal. They are not legal in the first two examples.
As mentioned already, the initializations are not valid outside a method construct or outside a block as this violates the programming syntax. Pls do refer to any good java book.