+ 1

Curly brackets?

Hi there! I'm super new to all this Java stuff and I'm struggling to comprehend the concept of 'curly brackets' or these things '}'. From what my developer friend has told me, they sort of class methods together, but I dont understand when to use them. Sometimes methods end with ; or }, so if anybody could clarify when to use them and how they work, that would be most appreciated! Thank you very much !

21st May 2017, 2:53 AM
salmoncats
4 Réponses
+ 8
Brackets are to collect subgroups of your program. Statements to be executed repeatedly (loops), conditionally (if, else), or under a particular identifier (methods, classes, enums) are all meant to be within curly braces. Java statements end with a ;, so when you call a method, you'll have the semi-colon there. It's also used when you're declaring a method, but not implementing it right away (since that is a statement). Does that help?
21st May 2017, 3:04 AM
Jim
Jim - avatar
+ 5
{} shows you the block or scope of a subgroup. Everything inside the block is what the group contains. So a class will contain everything inside the block. Class myClass {// begin class //inside class }/end class void myMethod() {//begin method // inside method }//end method You can also have nested blocks, here's an exanple with if statements: if(condition) {// begin 1st if //inside 1st if, before 2nd if(condition {//begin 2nd if, inside 1st if //inside 2nd if }//end 2nd if //inside 1st if, but after 2nd }//end 1st if Statements end with ; The ; is used to tell the compiler where the end of the statement/command is.
21st May 2017, 3:08 AM
Rrestoring faith
Rrestoring faith - avatar
+ 2
Thank you so much for your speedy responses! Thankfully, youve all done an excellent job at clarifying thid topic and I now understand it clearly! I'm really surprised at how welcoming and helpful this community is. Cheers!
21st May 2017, 3:11 AM
salmoncats
0
curly buckets
21st May 2017, 3:05 AM
Brandon
Brandon - avatar