Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java Java Basics Perfecting the Prototype Looping until the value passes

7,181 Points

is printf a function or a method ?


in the swift 2.0 course i have learned what is a function. if i understand right; if a function which is defined inside the { } of a struct or a class ( etc.. please inform me if any other option) are called methods.

Now parallel i have started the Java track and i just have faced console.printf()

i wonder if this is a function or a method. ending with () .. taking parameters inside the ()

i am a beginner trying to understand the concepts.

// I have initialized a java.io.Console for you. It is in a variable named console.
String response;
do {
  response = console.readLine("Do you understand do while loops? ");
} while(response == "No");
console.printf("Because you said %s, you passed the test!", response);

2 Answers

Jacob Bergdahl
Jacob Bergdahl
29,118 Points

In Java, there is no distinction made between functions and methods (the latter is the name typically used in Java). All methods in Java are declared within classes. Also, the types of structs you find in Swift don't really exist in Java either. So: you will mostly use classes, and everything is a method.

7,181 Points

thanks for the fast response.