I read that one of the differences between Object-Based and Object-Oriented is that the former supports Built-in objects(eg., window object in Javascript).So, what exactly is a built-in object and why it isn't there in object-oriented language like java.
3 Answers
That's not actually the difference between those two terms.
For a programming language to be considered "Object-Oriented", it must support the following four programming concepts:
- Inheritance
- Encapsulation
- Abstraction
- Polymorphism
There are many languages that support these "four pillars of OOP" (Java, C/C++, C#, JavaScript, etc.).
Some languages, however, don't. A famous example of that would be what we now call "Classic VB" (Visual Basic prior to the introduction of .NET). That language could simulate inheritance, but there was not actual mechanism built into the language for it, so while "Classic VB" had native objects, it is an "object-based", "not object-oriented", programming language because it does support the concept of objects, but not all the aspects that a true OOP language requires.
It should be noted that many OOP languages are built on the concept of "classes" as the mechanism to generate objects from. And, while this is a very popular way to architect objects, it is not a requirement for a language to be OO. JavaScript does not have classes (despite having a class keyword), it has "prototypes" and they are the architecture upon which objects are implemented.
Your question about "native" objects is not related to any of this. You most likely read that native objects were related to all of this at this Wikipedia page, but that page had many errors on it and I have edited that page to be more accurate. Whether or not a language has "built-in" or "native" objects is not at all related to whether it is object-oriented or object-based, since both types of languages are object-centric (my own term). For example, VB 6 was an object-based language, but supported a wide array of native objects and VB .NET (its successor) is object-oriented and also supports a vast amount of native objects.
I will tell you that a "native" object is simply one that is built right into the language specification itself and the runtime environment has access to it internally. In JavaScript, some examples would be String, Date, Array, RegEx, Math, Object, etc. Note that while, in your question, you mentioned window, window is not a native JavaScript object, that object is supplied by the browser that hosts the JavaScript runtime. If you were running your JavaScript in Node.js, window would not be available because it is not native to JavaScript and Node doesn't provide such an object to the runtime.
Here are some good links to look at to understand OOP concepts and how they work in JavaScript:
2 Comments
The window object is the global object. It neither exists in Java nor JavaScript for Node.js because it refers to the browser window.
Read about all global objects here: Global Objects (MDN)
As you can see, there are lots of global objects. The Array global object, for instance, exists in both Java and JavaScript.
Comments
There are 'built in' objects in OO languages like Java (or most people would consider them as such), just think of the base Object (top of the inheritance hierarchy) and many of the most core features of the stuff that is in the standard library.
My impression is that people would be saying that to point out that there are still some objects in JavaScript, however you can't actually declare/create a full featured class like in other languages. But, I mean the array in C# and Java is just as much an object as the one in JavaScript.
In order for someone to refer to a language as being 'Object Oriented' I would assume it needs classes (or a similar construct, struct in Go), which is why you generally wouldn't describe JS as object oriented. That said, classes have been added to ES6 so it's arguably fully object oriented now, just with a weak type system.
windowobject", the environment in which it runs may provide one. E.g., there's nowindowin NodeJS.