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 Java Basics Perfecting the Prototype Looping until the value passes

Ahmet GULER
Ahmet GULER
7,181 Points

is printf a function or a method ?

Hello,

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.

Example.java
// 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.

Ahmet GULER
Ahmet GULER
7,181 Points

thanks for the fast response.