InfoQ Homepage News Presentation: Joshua Bloch on Good API Design

# Presentation: Joshua Bloch on Good API Design

A well-written API can be a great asset to the organization that wrote it and to all that use it. Given the importance of good API design, surprisingly little has been written on the subject. In this talk (recorded at Javapolis), Java library designer Joshua Bloch teaches how to design good APIs, with many examples of what good and bad APIs look like.

Watch  How to Design a Good API & Why it Matters (1 hour, 10 min)

Recently Joshua Bloch was also interviewed by InfoQ about closures and new Java features (video) and he co-authored a new proposal to add closures in Java 7.

Style

## Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

• ##### Excellent!

by Rafael de F. Ferreira /

• ##### Re: Excellent!

by chen perry /

• ##### Verrrry Nice

by Vinu Varghese /

• ##### Excellent!

by Gabriel Kastenbaum /

• ##### Re: Excellent!

by karan malhi /

• ##### Makes a lot of activities in your brain

by Alex Krotov /

• ##### Any chance in making your videos available in some sort of offline format?

by Jason Finch /

• ##### Re: Any chance in making your videos available in some sort of offline form

by Oliver Gierke /

• ##### Re: Any chance in making your videos available in some sort of offline form

by chen perry /

• ##### Re: How to Design a Good API Why it Matters should avalible offline

by nazish ali /

• ##### We need VideoCasts

by Luiz Oliveira Brasil /

• ##### Clear explanation of designing a good API.

by YoungHyun Kim /

• ##### Excellent - as always

by Georges Polyzois /

by jimens lima /

by Jirapong Nanta /

• ##### Good article

by bin zhang /

• ##### I love this website

by Jerome St-Pierre /

• ##### It's probably just me...

by Dag Johansen /

• ##### Api Design

by Thomas Davis /

• ##### They sort of gave away the ability to do something usefull in exchange for the ability to do something useless.

by Bashar Al-Fallouji /

by Senthil Arumugam /

• ##### Still making impact, after all the years

by Andrey Bokhanko /

• ##### Excellent!

Your message is awaiting moderation. Thank you for participating in the discussion.

Best presentation I've seen in a while.

• ##### Verrrry Nice

Your message is awaiting moderation. Thank you for participating in the discussion.

Thanks for such a nice presentatiion

• ##### Well worth taking the time to watch.

Your message is awaiting moderation. Thank you for participating in the discussion.

A great presentation, both interesting and well presented. Thanks InfoQ.

• ##### Excellent!

Your message is awaiting moderation. Thank you for participating in the discussion.

Sure to be not original at all but this presentation is excellent!
Worth the time to watch.

• ##### Re: Excellent!

by karan malhi /

Your message is awaiting moderation. Thank you for participating in the discussion.

Very good presentation

• ##### Makes a lot of activities in your brain

by Alex Krotov /

Your message is awaiting moderation. Thank you for participating in the discussion.

Though I have 6 years of experience in Java field and more than half of advices/tips are already integrated in my head for long time, Joshua's presentation freshed my mind and revealed things I didn't consider closely.
Thanks a lot for providing this video!
It worth seeing twice if you're engaged in API (not only Java) design.

• ##### Any chance in making your videos available in some sort of offline format?

by Jason Finch /

Your message is awaiting moderation. Thank you for participating in the discussion.

Any chance in making your videos available in some sort of offline format?

• ##### Re: Any chance in making your videos available in some sort of offline form

Your message is awaiting moderation. Thank you for participating in the discussion.

Some sort of podcast would be perfect... ;)

• ##### How to Design a Good API & Why it Matters

Your message is awaiting moderation. Thank you for participating in the discussion.

Mr. Bloch = Clear thinking + PhD + Occam's razor approach.

• ##### Re: How to Design a Good API Why it Matters should avalible offline

by nazish ali /

Your message is awaiting moderation. Thank you for participating in the discussion.

This presentation clear my most of the points .because he addressed the very good points of an API design.I agree with Alex. This is not only JAVA .
It's better to get it offline due to streaming prblms.

• ##### We need VideoCasts

Your message is awaiting moderation. Thank you for participating in the discussion.

I want to reforce the question about off-line videos, WE need it!!!
Congratulations, the presentation is Excellent!

• ##### Re: Any chance in making your videos available in some sort of offline form

by chen perry /

Your message is awaiting moderation. Thank you for participating in the discussion.

yes is very fun to listem such video ,i think its useful for listener

• ##### Re: Excellent!

by chen perry /

Your message is awaiting moderation. Thank you for participating in the discussion.

• ##### Clear explanation of designing a good API.

Your message is awaiting moderation. Thank you for participating in the discussion.

Actually, English is not my native language, but I could understand this presentation as he explained as well. Thanks Joshua & Thanks infoQ~!

• ##### Excellent - as always

Your message is awaiting moderation. Thank you for participating in the discussion.

Thanx for this excellent presentation - as always by Joshua B.

Pleas can we have an offline version!!

by jimens lima /

Your message is awaiting moderation. Thank you for participating in the discussion.

Your message is awaiting moderation. Thank you for participating in the discussion.

Hi all,

Enjoy

• ##### Good article

by bin zhang /

Your message is awaiting moderation. Thank you for participating in the discussion.

Good article

• ##### I love this website

Your message is awaiting moderation. Thank you for participating in the discussion.

I just watched this presentation 4 years later and everything said is still actual and not only for Java. This is why I love design so much.

This man is a good speaker and I think these Javapolis events looks very cool, even if I am a .NET developer.

Thanks for the high quality content, I never got so addicted to a website before.

• ##### It's probably just me...

by Dag Johansen /

Your message is awaiting moderation. Thank you for participating in the discussion.

I don't get the idea with the ThreadLocal and the keys. Since Bloch is such a luminary I can only suppose that there is a good reason behind the design he came up with, but I can't see it. So, in the interest of learning, and I figure I may not be the only one who doesn't get it, I will simply ask and hope someone can enlighten me (us, if I am not alone in this).

I do understand the issue with the string keys being "global namespace". Of course it's not really a namespace at all, but string comparison does mean different parts of the code could more easily overwrite one another's data. However, what is the point of using thread locals anyway? I thought the idea was to enable any object that participates in the work of a thread to easily share information *without* having to distribute a reference to anything all over the place. If so, replacing the string key with an object key negates the whole point of using thread locals in the first place.

Furthermore, if I have to ensure all objects that need to access some data have a reference to the Key instance, isn't it just as easy then to instead ensure they have a reference to whatever is associated with that key?

What is it that I have misunderstood or simply not understood?

I don't want to risk this becoming a debate about whether Java or .net is better, but I have to say it seems to me the .net solution (in which one places a ThreadStatic attribute on a static field to indicate it should be stored as a thread-local variable) is rather better. It solves the problem of accidentally using the same variables where one meant to use different ones, requires extremely little code, is transparent to the user of the class declaring the static member (of course the field should be private and exposed via a property, but this changes none of what I've said), and does completely away with the need to write boilerplate code to obtain references to these objects.

public class Log{   [ThreadStatic]   static Log current;   static public Log Current    {      get { return current; }      set { current = value; }   }   // .... Log implementation}

Like this, whenever some operation starts that we'd like to log we'll simply create the log with
Log.Current = new Log();
and then any code that is called in the context of a current log can obtain a reference to it with
Log log = Log.Current;
or just use Log.Current.WriteLine() and so on directly.

• ##### Api Design

by Thomas Davis /

Your message is awaiting moderation. Thank you for participating in the discussion.

For anyone interested, we are working on a tool to make API design more efficient, collaborative and robust.

apiengine.io - we are taking early registrations for beta!

• ##### They sort of gave away the ability to do something usefull in exchange for the ability to do something useless.

Your message is awaiting moderation. Thank you for participating in the discussion.

Excellent presentation. I liked that part : "They sort of gave away the ability to do something usefull in exchange for the ability to do something useless."

00:57:57

Your message is awaiting moderation. Thank you for participating in the discussion.

It is a good one.
Question:
If the "car.speed() >2" is more readable, then why are we writing a java bean
with getSpeed() & setSpeed()?

• ##### Still making impact, after all the years

Your message is awaiting moderation. Thank you for participating in the discussion.

My team just had to design C++ API for a brand new library. We used this video as a guidance.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Is your profile up-to-date? Please take a moment to review and update.

Note: If updating/changing your email, a validation request will be sent

Company name:
Company role:
Company size:
Country/Zone:
State/Province/Region:
You will be sent an email to validate the new email address. This pop-up will close itself in a few moments.