Is everything in Java an object, the way it is in Ruby?
Books, tutorials, everything states “everything in Ruby is an object”, but is that common for object oriented languages?
Is everything an object is Java as well, or is object oriented just a paradigm of programming, and it doesn’t mean that everything is or evaluates to an object?
No.
As far as values go, the “primitive types” (
int,bool,float, etc.) in Java are not objects. In Ruby they are objects. (In some Ruby implementations fixnums are “value types” internally for performance, but externally they are treatable as “real” objects that have methods).In addition, there are other things that are objects in Ruby that are not objects in Java such as classes. (Actually, Java exposes these as
Classas well, but in a different sense.)There are some things that are not objects in either language, such as variables and methods. (Although in Ruby it is easy to get an object that represents a given method.)
Anyway, I think the bigger picture is that the Object Oriented programming paradigm presents a way to group data and operations on said data. (This is generally done through instance methods, as in Java and Ruby, although it might also be done through multiple dispatch and other languages, like Haskell which is “non-OO”, offer alternative approaches to this task.)
Often times the definition of “OO” also includes “inheritance”, “encapsulation”, “abstraction”, and other silly textbook terms, but the usage and patterns of different “OO” languages can vary greatly and overlap those found in “non-OO” languages 😉