Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java

Alex Koo
Alex Koo
317 Points

When to use parentheses

Hello,

When do you know to put parentheses? I've notice that some has parentheses and some doesn't For example

console.printf("Hello"); For this one you use parentheses However

String names = "Alex"; You dont use parentheses on this one. Why is that??

Hopefully it made sense. :)

Pranjal Agnihotri
Pranjal Agnihotri
4,187 Points

The above console.printf() and String names all these are statements. Always Remember while writing a function you use parantheses.A group of statements is kept inside Parentheses.This is a rule applied in most programming language

1 Answer

When you create variables you do not need to use parentheses unless you call a method and set it equal to that variable. You will learn later in the course about methods and it should clear up then. Methods are used in classes and you can pass in a value that the method requires and it uses that when the method is run. It will make sense when you get further into the course.

Alex Koo
Alex Koo
317 Points

Thanks so much! Btw i have completely different question

so whenever you are using format specifier why is it %s not %

%s gets replaced with a string there are a few different ones you can use like %d which is an integer