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.

hyde
  • 3,744
  • 4
  • 25
  • 35
  • 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. – Joachim Sauer Mar 21 '13 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? – John Bartholomew Mar 21 '13 at 15:23
  • 6
    According to [Evolving a language in and for the real world: C++ 1991-2006](http://www.stroustrup.com/hopl-almost-final.pdf), 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. – John Bartholomew Mar 21 '13 at 15:29
  • 3
    The [Oak language specification](http://www.javaspecialists.eu/archive/files/OakSpec0.2.ps) (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. – John Bartholomew Mar 21 '13 at 15:48
  • It isn't inconsistent, there are `double` and `Double` as well. – vortexwolf Mar 21 '13 at 15:50
  • @vorrtex `boolean` is inconsistent with C/C++ (today also C#), `int` is inconsistent with other Java primitive types, basically they are inconsistent with each other. There must have been discussion about it when decisions were made. – hyde Mar 21 '13 at 16:39
  • @JohnBartholomew if you want to convert those comments of yours into an answer, I think I'd accept that, as it's probably closest to historical truth we're going to get here. – hyde Mar 23 '13 at 06:07
  • 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](http://www.quora.com/Java-programming-language/Why-does-Java-use-the-name-boolean-instead-of-bool) and someone gave a link to this question. I'm glad see some answers at last. – none Mar 25 '13 at 10:26
  • I would rather ask why `Integer` not `Int`. Boxing was introduced much later than the other things like `int`, `boolean`, `bool`, etc. in both C++ and Java. – SOFe Dec 04 '18 at 07:55

3 Answers3

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.

John Bartholomew
  • 1,620
  • 12
  • 12
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.

Frank
  • 14,407
  • 3
  • 41
  • 66
  • 5
    Same reason the POSIX call to create a file is called `creat()`. – Blrfl Mar 21 '13 at 12:00
  • 5
    So you're saying `int` should be `integer`? –  Mar 21 '13 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 '13 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 '13 at 06: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 '13 at 09: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.

dave
  • 1