• Post Reply Bookmark Topic Watch Topic
  • New Topic

Guide to show common code converted to API methods  RSS feed

 
Vasilis Souvatzis
Ranch Hand
Posts: 94
1
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Morning everyone. The subject of the topic is weird (not sure how to put it in English properly), moderators feel free to change it to your liking.

I was wondering whether there's some site, book, video etc to show us what common techniques can be converted to use API methods.

For example, joining two Strings we would normally write "blah" + "blah", but there's a concat() method in the String class. I'm sure there are lots more occasions like this, can't get others off the top of my head though :P

I'd really like to "delve" more into the API and use what's available for me. Just though there might be some resource available apart from me going through each class and see what's there...
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What you are looking for is really broad. you should be a bit more specific as to what specific API are you looking for? It could be the Java API or some domain specific API's. If you think you have written some useful functions that you want to expose via a well defined API, you can package that as a jar and publish it to GitHub. There are some books that might be of help!

http://www.amazon.com/Practical-API-Design-Confessions-Framework/dp/1430243171/ref=sr_1_3?ie=UTF8&qid=1418369864&sr=8-3&keywords=Writing+Good+API%27s
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vasilis Souvatzis wrote:Just though there might be some resource available apart from me going through each class and see what's there...

That's what the javadocs are for. Obviously, going through all classes won't be possible due to their number, and many wouldn't be particularly interesting with respect to your question. But the ones in java.lang and java.util are useful to know. Or you could check out some of the Apache Commons libraries: http://commons.apache.org/components.html
 
Vasilis Souvatzis
Ranch Hand
Posts: 94
1
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, indeed my question was too broad and I managed to confuse you Joe I meant the Java API, and I was referring to things that we do "manually" but instead can be done more easily with existing methods.

Ulf is spot on I think, lang and util have many useful classes that I should get my hands on. I'll also check the Apache Commons, have heard of it before but never messed with it. (and probably google guava as well).
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vasilis Souvatzis wrote:Yes, indeed my question was too broad and I managed to confuse you Joe I meant the Java API, and I was referring to things that we do "manually" but instead can be done more easily with existing methods.

Unfortunately, many of these things just come with familiarity (as, for example, with when to use "+", or maybe something else like a StringBuilder).

One good rule to remember though, is: Don't re-invent the wheel.

So, if you even think that what you're doing might have been written already, try a Google search for it first. Very often, it will throw up a tutorial page (or possibly even a thread on this site or stackoverflow).

Just one tip: always include the word "Java" in the search; otherwise you may get solutions/techniques from other languages.

HIH

Winston
 
Ivan Jozsef Balazs
Rancher
Posts: 999
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The different languages have different idiomatic ways of expressing things even beyond the API usage. For example in the C line of languages (C, C++, Java) this is an idiomatic way of the loop organization:



There are many other ways (using while or indexing from 1 up to including len and working with the (i-1)-th element etc.) but this is the most familiar way.

A sidenote. I worked in a project where my code was reviewed and I got a complaint, that I had written a simple method to check a String's being empty in the sense of being null or having zero length. The "recommended" way to do this was to use some Apache function... Is it an example or a counter-example? You decide...

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!