31

Java has

  • int and Integer
  • boolean and Boolean

This seems a bit inconsistent, why not either

  • bool vs Boolean to use an established shorter name for primitive type?

or

  • integer vs Integer to keep type names consistent?

I think C++ had decided to use bool quite a bit earlier than Java decided to use boolean, and maybe also some (non-standard at the time?) C extensions too, so there would have been historical precedence for bool. I've noticed I often instinctively try to use bool at first (good thing modern editors immediately spot this without extra compilation round), so it'd be nice to know the rationale behind current state of affairs.

If someone remembers (a part of) the story, or can even find and link to relevant historical discussion in the net, that would be great.

9
  • 8
    boolean is definitely more explicit than bool. I'd rather ask why int is not called integer. My guess: int and char where too ingrained to be changed to integer and character, but bool was not yet fully established. Mar 21, 2013 at 10:06
  • "I think C++ had decided to use bool quite a bit earlier than Java decided to use boolean" Why do you think that? Mar 21, 2013 at 15:23
  • 6
    According to Evolving a language in and for the real world: C++ 1991-2006, the bool type was introduced to C++ in 1993. Java included boolean in its first release in 1995, but the Java project itself was started in 1991. Without finding further sources of information, it's not clear to me which came first, or what (if any) influence they had on each other. Mar 21, 2013 at 15:29
  • 3
    The Oak language specification (version 0.2, copyrighted 1994) also includes the boolean type. (Oak was later renamed to Java). That pushes the dates even closer, though I still see no definite evidence to show precedence, or influence, in either direction. Mar 21, 2013 at 15:48
  • 1
    Just a side note, I had asked this same question on stackoverflow a couple of months ago and it was deleted after 5 minutes. Today I asked this on quora and someone gave a link to this question. I'm glad see some answers at last.
    – none
    Mar 25, 2013 at 10:26

3 Answers 3

22

Without getting in contact with people who were actually involved in these design decisions, I think we're unlikely to find a definitive answer. However, based on the timelines of the development of both Java and C++, I would conjecture that Java's boolean was chosen before, or contemporaneously with, the introduction bool to C++, and certainly before bool was in wide use. It is possible that boolean was chosen due to its longer history of use (as in Boolean Algebra), or to match other languages (such as Pascal) which already had a boolean type.

Historical context

According to Evolving a language in and for the real world: C++ 1991-2006, the bool type was introduced to C++ in 1993.

Java included boolean in its first release in 1995 (Java Language Specification 1.0). The earliest language specification I can find is the Oak 0.2 specification (Oak was later renamed to Java). That Oak specification is marked "Copyright 1994", but the project itself was started in 1991, and apparently had a working demo by the summer of 1992.

13

Actually, Java is more accurate to history here. The theory of true and false values was invented by George Boole and is commonly referred to as Boolean Algebra in his honor.

bool is really just a shortcut to avoid a longer name, however, given the auto-completion support of modern IDEs, this is no longer a valid reason (and wasn't even back in the days when Java decided to go for boolean).

I have not been part of the decision process for Java, but if someone cares for history, then "Boolean algebra" is the relevant historical precedence, and one might as well question the C/C++ decision on why they mutilated Boole's name by cutting off the e.

5
  • 5
    Same reason the POSIX call to create a file is called creat().
    – Blrfl
    Mar 21, 2013 at 12:00
  • 5
    So you're saying int should be integer?
    – user7043
    Mar 21, 2013 at 13:27
  • 4
    If you want to be historically accurate, then I think Boolean is kind of bad, considering it can have 3 values (Boolean.FALSE, Boolean.TRUE, null)... Point being, programming language symbols and reserved words are always a compromise of several factors, and historical accuracy is probably pretty low on that list.
    – hyde
    Mar 21, 2013 at 16:47
  • 2
    I have no intention of being historically accurate, but don't forget, that not all languages allow for that billion-dollar-mistake called null.
    – Frank
    Mar 22, 2013 at 6:08
  • 2
    @Frank Hey, I'm just converting a specific NullPointerException situation to nicer error reporting and handling, and trying to actively forget LALALAA not hearing what you say LALALAA ;-)
    – hyde
    Mar 22, 2013 at 9:54
-2

I can't address the consistency issue, but there's a long history here.

As far as I recall, Algol 60 was the first language to refer to its logical types as 'Boolean'. Algol 60 also had types like 'integer', 'procedure', etc.

Along came Algol 68, and abbreviations seemed to be in vogue: 'bool', 'int', 'proc', etc.

So, language designers can pick whichever style they like, and there's a precedent for it.

Not the answer you're looking for? Browse other questions tagged or ask your own question.