Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between Java APIs and Java Methods

Tags:

java

methods

api

Are methods and APIs, basically the same in Java? If no, what makes them different?

like image 607
Kevin Avatar asked Jan 15 '23 06:01

Kevin


2 Answers

API refers to Application Programming Interface, what the rest of the world see and can use.

Method can be part of the public interface or not. But API is really set of methods.

The most common thing related to APIs in java would be Interface which is really set of public method declarations.

Another useful way how to look on API is to take it as contract. Lets take a List interface as an example. It tells you method signatures you can use in a List and in javadoc you see what is the contract (what you can expect and what you need to ensure so the List behaves as expected)

like image 127
Jan Zyka Avatar answered Jan 17 '23 21:01

Jan Zyka


API consists of, among other artifacts, a set of types, which include methods, the signature and behavior of those methods specified by the API contract. So yes, API and method are two different things, just like a paw and a dog are different things.

like image 36
Marko Topolnik Avatar answered Jan 17 '23 20:01

Marko Topolnik