2

Why did the creators of Java use the name "class" for the classes in Java? Where does this term come from?

Michael Myers
  • 188,989
  • 46
  • 291
  • 292
GuruKulki
  • 25,776
  • 50
  • 140
  • 201
  • 1
    What would be your name for that? – Dominik Sandjaja Jan 22 '10 at 16:01
  • 3
    Why did they give Classes the name Class???? What's the question here? – Todd R Jan 22 '10 at 16:02
  • 5
    I don't see why so many people have such a problem with this question. If the answer seems obvious to you, remember that English isn't everyone's first language. – danben Jan 22 '10 at 16:10
  • 5
    @danben, so we should ask where `for`, `while` and `switch` come from as well? – Mark Elliot Jan 22 '10 at 16:12
  • 3
    @danben I don't think "english" is the subject here, the problem is that gurukulki knowing already that Java is an OOPL ( because he knows that `class` is used everywere` ) Ignores the fact what the most fundamental concept of OO is. While the doubt is legit, the way is presented, leads to downvotes. He have just got >60 points for this question. – OscarRyz Jan 22 '10 at 16:13
  • @Mark - depends on if you don't know, and would like to. – danben Jan 22 '10 at 16:13
  • 1
    Actually, on re-reading the question, it could be taken as a question on why there is a `Class` class (which at least one person has answered). @gurukulki, can you please clarify what you're looking for? – Michael Myers Jan 22 '10 at 16:18
  • @mmyers: my guess is that because the OP says "for the classes in Java", he means all classes, rather than java.lang.Class. Still, your point is valid. – danben Jan 22 '10 at 16:19
  • @mmyers, gurukulki asked in particular why Java uses the *name* "class" for `class` – Mark Elliot Jan 22 '10 at 16:23
  • @Oscar Reyes - terminology and concepts need not necessarily be linked. My take is that the OP is not clear in this case and would like to find out. – danben Jan 22 '10 at 16:24
  • yes friends. i wanted to know why the name "class" given to all classes in java – GuruKulki Jan 22 '10 at 16:28
  • Could one or more of the members who voted to close please explain why this is not a real question? – danben Jan 22 '10 at 16:46

6 Answers6

17

Java didn't invent the name class - it was used in languages prior, like C++.

I think the name "class" refers to a class of objects, as in a classification (or a type). And then an object is an instance of that type.

Here is the first definition of "class" from dictionary.com:

  1. a number of persons or things regarded as forming a group by reason of common attributes, characteristics, qualities, or traits; kind; sort.

So this is right in line with what we know to be a class in computer science - the "characteristics/qualities/traits" being fields and methods.

danben
  • 80,905
  • 18
  • 123
  • 145
15

Blame Ole-Johan Dahl and Kristen Nygaard, who apparently originated the concept for Simula; and also Tony Hoare, who gave them the inspiration.

According to the history of Simula:

As this pursuit proceeded throughout the summer and autumn of 1966, they became more and more preoccupied with the opportunities embedded in Tony Hoare's record class construct, first presented in ALGOL bulletin no. 21, 1965. After having carefully examined Hoare's record proposal they eventually came to the conclusion that, even though it obviously had a number of very useful properties, it failed to fully meet their requirements. What they were really looking for was some kind of generalized process concept with record class properties.

The answer to their problem suddenly appeared in December 1966, when the idea of prefixing was introduced. A process, later called an object, could now be regarded as consisting of two layers: A prefix layer containing references to its predecessor and successor along with a number of other properties, and a main layer containing the attributes of the object in question. In addition to this important new feature, they also introduced the class concept, which can roughly be described as a highly refined version of SIMULA I's activity concept. This powerful new concept made it possible to establish class and subclass hierarchies of concatenated objects.

Of course, the idea of classifying objects far predates any programming language.

Community
  • 1
  • 1
Michael Myers
  • 188,989
  • 46
  • 291
  • 292
5

I think the origin of the word "class" predates the realm of Computer Science, in fact. Taxonomy has been around for a long time, and I would venture to say its roots are somewhere in Philosophy or perhaps less abstractly in Biology. Programming Language folks just adopted an analogy from another field :).

vicatcu
  • 5,407
  • 7
  • 41
  • 65
1

The class is the definition, the metadata; the object is the instance. This is normal OOP language use.

Lucero
  • 59,176
  • 9
  • 122
  • 152
0

Because they are used to "classify" objects of the same nature.

Employee objects are different than Account objects.

All these concepts are the base of Object Oriented Technology. Java happens to be an Object Oriented programming, That's why they use all these terms in first place.

OscarRyz
  • 196,001
  • 113
  • 385
  • 569
0

Note that the Class class in Java is brought in by the reflection classes, not by sheer accident.

Here there is both Class and Method objects to allow you to do stuff like:

Class cls = java.lang.String.class;

// By obtaining a list of all declared methods.
Method[] methods = cls.getDeclaredMethods();

// By obtaining a list of all public methods, both declared and inherited.
methods = cls.getMethods();
for (int i=0; i<methods.length; i++) {
    Class returnType = methods[i].getReturnType();
    Class[] paramTypes = methods[i].getParameterTypes();
    process(methods[i]);
}

// By obtaining a particular Method object.
// This example retrieves String.substring(int).
try {
    Method method = cls.getMethod("substring", new Class[] {int.class});
    process(method);
} catch (NoSuchMethodException e) {
}

http://www.exampledepot.com/egs/java.lang.reflect/Methods.html

In other words, invoke code determined at compile time. Very handy for invoking optional functionality.

Thorbjørn Ravn Andersen
  • 73,784
  • 33
  • 194
  • 347