Chapter:Classes - API source code

From Juneday education
Jump to: navigation, search

Meta information about this chapter

Expand using link to the right to see the full content.


This lecture has no slides or videos, but aims to show the students "live" what the source code for some of the Java API classes look like. This way, they can see what a "real" class source code file looks like.


The purpose of this lecture is to show the source code of a real Java class, so that the students can compare the real deal with what they have learned about classes so far. We also think that it is good to know that the source code is available, and that it is a great source for learning about what "real" code looks like. The ambitious students will find this interesting and helpful, we think and hope.


After this chapter, the student shall understand:

  • How to obtain the source code for the Java API
  • What the source looks like for some commonly used classes

Instructions to the teacher

Common problems

Some distributions of the SDK include source code, while others don't. You may leave it as an exercise for the students to figure out if they have the source code or if they need to find it online and download it.

Full frontal - Code up front!

Just to get your thoughts running, here's some code to look at! You don't need to understand it to enjoy it.

package java.lang;
 * @author  Lee Boynton
 * @author  Arthur van Hoff
 * @author  Martin Buchholz
 * @author  Ulf Zibis

public final class String
    implements, Comparable<String>, CharSequence {
    /** The value is used for character storage. */
    private final char value[];

Classes: Looking at the source code for some API classes

To demystify source code for classes we will in the exercises on the next page let you briefly investigate the source code for some classes in the API. The exercises also show you how to find the source code in (or how to get that file).

Classes investigated in the exercises:

  • java.lang.String (quick glance)
  • java.lang.System (quick glance)
  • java.lang.Math (quick glance - focus on private constructor and all the static methods)

You can also view the source code online at e.g. GrepCode.

In most Java JDK/SDK installations, the source code for the Java standard API classes are included in a file called . If you don't have it, head on to the exercises for instructions on how/where to find it.

We think it is better for you do get your hands dirty and investigate the source code files yourself, so please head to the exercises and do so!

Chapters about classes

Here are the chapters about classes in this book, so that you can keep a check on your progress:


  • No video for this section


Further reading

Where to go next

Next page has exercises for this chapter: Classes_-_API_source_code_-_Exercises

« PreviousBook TOCNext »