public class foo{
}
Every java file must contain at most one public class. Your code will go inside this class and later will go into many classes. The class starts and ends with a {} bracket. Putting code outside these will cause a compiler error.
When you put code inside the class block you are saying that that code belongs to that class. This is part of the object orientated ideology.
A class can contain the following -
public class person{
String name;
int age;
{
System.out.println("Starting up class");
}
public Person(String name, int age){
this.name = name; this.age = age;
}
public void output(){
System.out.println("Name =" + name + " age = " + age);
}
}
You must ensure that all code falls within the class block.