• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

source code or Java API

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI all,

I'm a Java Learner, My instructor said me to look at java source code of class (thread class) that is present in JDK, Its really good and I understand it clearly,, but he also suggests me to look at API. Which would be the best practice? to go for API or source code of class ?? THANKS IN ADVANCE
 
Bartender
Posts: 1845
10
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I choose option c: both of the above are applicable in different situations.

Looking at APIs tells you what classes/methods are available and what they are supposed to do. Often they are easier to read than the code. Well written javadoc contains examples. e.g. java.text.SimpleDateFormat
If you want to learn how to use a library, then read its API.

Looking at the source code can show you what well written code looks like and having an insight into what is going on "under the hood" can be useful. But isn't always necessary.

Personally, I would start with javadoc and then drill into the source code if I want to know more.

 
Bartender
Posts: 322
24
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree with Stefan - both, as they can be used differently.

Thinking of a car, you as a driver use the car's API. You don't care how a brake pedal works. You simply need to know pressing the brake pedal will (hopefully) stop the car.
On the other hand, if you were building a car, you would take the brakes apart and figure out how things connect from the pedal to the brake pads, etc...
You would investigate the source code of the car and use that as a template, or structural design, for your own braking system.

There will be times when you want to understand how Java works, and other times where you just need to be able to use it.


 
Rancher
Posts: 1044
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Besides, APIs are more stable than the implementations.

It is well conceivable for the implementation to change under the hood with the interface, with the API remaining the same.
 
Bartender
Posts: 1357
39
IBM DB2 Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Most of times, using API reference is enough. Anyway, looking at core Java classes implementation I learnt a lot of useful programming techniques.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

datta Nadgir wrote:Which would be the best practice? to go for API or source code of class ??


I basically agree with Stefan, but I'd say that it's far more important to learn how to read an API.

Why? Because most of the time you are simply the user of a class, and the API (if it's well written) should tell you everything you need to know about how to use it.

Also: In the real world you simply don't have time to plough through the source code for every class you encounter - if it's even available.

Conclusion:
1. Try the API first.
2. If that doesn't provide enough information, have a look at the source.
3. Never, EVER, rely on what you read in the source, because it may change in the next release.

HIH

Winston
 
Forget Steve. Look at this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic