Java just curly braces?

It's a code block. The variables declared in there are not visible in the upper block (method body outside of these curlies), i.e. They have a more limited scope.

2 more sophisticated term is Block , Check here – Jigar Joshi Dec 19 '10 at 20:25 Check here – Jigar Joshi Dec 19 '10 at 20:33 @org.life. Java Thanks! I edited it to use better terminology – Goran Jovic Dec 19 '10 at 20:46 You are welcome :) – Jigar Joshi Dec 19 '10 at 20:51 Thanks for the info.

Appreciate it. I usually google, but wasn't sure what the search term would be for this sort of question. – user373201 Dec 19 '10 at 23:07.

Be careful, it is NOT ALWAYS an initialisation block as others have suggested. In your case it is a variable scoping mechanism called a Code Block or block. If it is outside of a method, then it is!

Example public class MyClass { { // this is an initialisation block } } However, if it is inside a method, it is NOT! In this case (which is the case in your example), it is a code block. Anything initialised inside the curly braces is not visible outside Example public static void main(String args){ { String myString = "you can't see me!"; } System.out.

Println(myString); // this will not compile because myString is not visible. }.

It's inside a method – thejh Dec 19 '10 at 20:23 "if it is inside a method" i.e. Like in OP's example – Goran Jovic Dec 19 '10 at 20:23 @goran, I was clarifying for the user because lot of the answers which are now deleted was stating that it was an initialiser block. Therefore, I felt it was worth clarifying the two usages of the curly braces.

– Codemwnci Dec 19 '10 at 20:27 @the, @goran - he said that in his answer. I'd never seen either of these cases before, so I think it was a good idea to explain that it does different things in different contexts. – bemace Dec 19 '10 at 20:28 Oh.. makes sense.

I commented only because you started explaining what it isn't. Now that the other answers are deleted it's a bit out of context. – Goran Jovic Dec 19 '10 at 20:49.

It is called Block A block is a sequence of statements, local class declarations and local variable declaration statements within braces. Also See: Documents.

2 Wrong: It's inside a method. – thejh Dec 19 '10 at 20:21 @thej Yeah I misunderstood it previously :) – Jigar Joshi Dec 19 '10 at 20:32.

You can logically separate your code by this in some cases, and in fact there's one use case I apply very often: demo data. E.g. , you have some demo data generation class that creates demo data entries and inserts into your database.

You place each single item in such a block, and can do copy-paste without changing variable names.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions