These unnamed blocks are initializer blocks, which I think fall under "Language Fundamentals."
If the block has a "static" modifier, it will execute when the class is loaded. Otherwise, without a "static" modifier, the block will execute when an instance is initialized (before the body of the constructor).
I've modified the code to demonstrate this. Note that when an instance is created, the non-static initializer block executes before the constructor body. Also note that the static block only executes once, when the class is loaded (which happens when the static main method is invoked). So creating a second instance does not cause the static block to execute again.
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org
What's interesting is that init blocks are on the 5.0 exam but they're NOT on the 1.4 exam!
Anyway, I would strongly recommend that you study for the 5.0 exam, not the 1.4.
Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Joined: Sep 26, 2007
It's because I'm under pressure what concerns my resources of preparation time. And everybody is saying the 5.0 exam is more difficult. What are the main arguments to do the 5.0 exam? Regards, Matthias
The current version of Java is version 6, and it has been out for almost a year already. So with Java 1.4 you are two releases behind the current version.
In Java 5, a whole list of new language features have been added. More and more Java projects are being done with Java 5 or Java 6, and if you're going to work on such a project you'll be expected to know those new features.
So an SCJP 5 certificate is worth more and will last longer because it's more current.
Suppose you're on a job interview and you're asked "Why did you do SCJP 1.4 instead of SCJP 5?". Are you then going to answer "Because it is easier"? That wouldn't leave a good impression... [ November 08, 2007: Message edited by: Jesper Young ]