The Differences between Java and JavaScript.

I feel like the OP is testing his assumptions on the differences between Java and JavaScript by stating his opinions as fact and having the community point out his mistakes (which the community loves to do) instead of asking a question on what the difference are and getting “Google it” replies.

Other than that this topic has no logical purpose, I feel.

I think that what we should take away from this is that Java and JavaScript are both things and when lazy people do not read words past the 4th letter it is possible to become confused as to the nature of the two aforementioned things and more specifically whether or not these natures are in fact the same nature just spelled differently, not that we are aware of that because we have neglected to read beyond the 4th letter of words. In fact if you look carefully at the two things then it is quite possible to be unaware of the distinct lack of differences or similarities between the first of the non-things and the second of the before-things. Quite possible. So laziness or not you may become confused as to what the hell we are even talking about anymore. That is certainly my intention.

But seriously on the OO front. People say that Lua is an OO language because you can hack something that works exactly like a class but doesn’t use any keyword at all similar to “class” or any syntax that is the slightest bit sensible. What I say to these people is “well done,” what an achievement to write classes in a language without any support for classes. It is really very impressive. Does that make the language Object Orientated? I don’t know but I’d rather call it Table Orientated personally. And I’d rather program in Lua without using “classes” personally. So again I have said nothing whilst actually writing a fairly substantial hunk of text.

I agree, it’s not the language that is Object Oriented then, but usually that phrase is used when talking about code: “Write Object oriented code”.
Here are some statements:
Java has language-level support for writing “Object Oriented code”.
JavaScript doesn’t have the above.
JavaScript allows the user to write “Object Oriented code” in a way that is readable and not obfuscated.
The above goes the same with Lua.

I hope you agree with that…

Java to Javascript is like ham to hamster.

Readable and not obfuscated? It’s possibly the most horrible and confusing experiences anyone can ever have in life.

ECMA6 is adding keywords like ‘class’ and stuff that mimics the conventional “readable” way of doing OO so that may change things. Many people don’t like it since it hides what’s really going on. Doesn’t matter atm and for probably a few years still since it obviously won’t be backwards compatible.

Err… Look at the examples: http://mootools.net/docs/core/Class/Class
I personally don’t find this confusing at all :stuck_out_tongue:

And I personally think that it is stupid, ugly and confusing to bloat syntax with unnecessary keywords like “then” in an if statement, others see that as making it readable. But I still love them.

Make code, not war.

(That is someone’s tag but I can’t remember who so I can’t credit them. Sorry mystery (wo)man)

I9u-MgPOaNk

Okay, okay, I’ll try to take this topic seriously…

To be honest, the major difference between these two languages is that Java has to be compiled, and JavaScript doesn’t (dynamically typed).

Java

Incredibly strict and very verbose. This language was created so people do not have to compile code into 3 different OS’s (Windows, Mac, Linux). The power behind that lies in the JVM which, for a small price in memory, allows you to run the same code in any Unix or Windows based system. Java was designed for Object Oriented Programming from the ground up with only a few primitives not being an Object (though there are Objects for all primitives).

Java’s biggest strength lies in its structure and documentation, as the strict syntax also promotes good coding practices. Heavily used by businesses, and had its foothold in mobile devices for a while. Recently has lost its foothold in website applications due to security breaches and strict entry to Applet and Webstart. Main competitors include C, C# and C++.

JavaScript

Very loose typed object oriented language. At its start, JavaScript (LiveScript) was used primarily to give developers the ability to react to user responses in a webpage. As developers wanted more power, JavaScript then grew to include more functionality to allow greater control over the web page with the strongest being AJAX, which allows direct control over any part of a web page in real-time without refreshing the browser.

However, JavaScript is a “browser” language and functions best when within a browser. It is a jack of all trades when it comes to languages, having aspects of imperative (like C), procedural (like Haskell), and Object Oriented (like Java). However, when trying to do any of those techniques outside simple web page edits the language becomes very ungainly and extremely verbose.

Despite this, JavaScript is a very dynamic language with a lot of flexibility. As of HTML5, it has gained a much needed speed boost that allows it to compete very evenly with Flash. It gives access to the WebGL interface which allows some 3D programming within a browser. Since JavaScript is built into every modern browser, it pretty much works right off the bat with anything that has one. (The only flaw is that JavaScript may be disabled on browsers at any time, and that usually breaks a lot of functionality (Google) since it isn’t guaranteed.) JavaScript pretty much owns a monopoly on client based web applications with no real competitors that don’t need a plugin.

What’s Better?

Apples to Oranges. The reason JavaScript was named JavaScript in the first place was because the people at Netscape said “Java” programming language was catchy due to its rising popularity. So they renamed LiveScript to JavaScript. However, I can’t say that is bad because it arises to topics like this so.

Generally, if you are designing for web… JavaScript is going to find its way into your code somewhere. It is pretty hard to design a fluid experience on the web without JavaScript these days. If you are designing for desktop, then Java is the language I choose. It is a lot easier to write code in Java opposed to JavaScript. I would argue that JavaScript really sets you up well for spaghetti code as everything gets so much more verbose as you move along. Java’s OO nature avoids this.

I’ve coded in both quite a lot, and they each have their strengths and weaknesses. But, I enjoy coding in Java a lot more than in JavaScript because it has a self-organizing structure. In JavaScript, I feel like I have to force structure in order for it to have structure. You can tell that even though it is Object Oriented (everything in JavaScript can be quantified to an Object), it is very disjointed and lacks organization.

There, see, something good can come out of this thread… ;D

You’ve got to be kidding me…

Next thing people are going to start confusing C and Java.

The arguments used to say this or that is or isn’t OO are pretty much always, ya know, freaking stupid. The original point of the OO experiment wasn’t about encapsulation nor polymorphic dispatch. These were both long existing techniques which everybody knew about. If that was the point then Smalltalk could have been written in an afternoon as a C frontend. The big point was have no types. Therefore all typed (or worse strongly typed) OO languages are oxymorons.

OOP isn’t a descriptor that you just slap on a language for fulfilling so and so requirements, there are different concepts that different languages do/do not integrate. You can’t treat ‘object-oriented’ as a hard-set category.

Actually, you both are absolutely correct.

Object Oriented is more of a style than a outright type. There is truly only two types of programming, imperative and functional. Object Oriented, Scripting, and the like is more like the “styles” of programming rather than the type. I guess that Java lends itself more to Object Oriented style than JavaScript does would be more accurate.

Edit: fixed that acronym mentioned below

Procedural and imperative are pretty much the same. Functional and imperative are very different. In functional you write “what is to be done” and the details of “how” are more or less unimportant. In imperative you express exactly “how” to do something. Some imperative languages allow for some functional style and vise versa but it’s usually very limited. If you really want both you need a metalanguage.

I’m re-learning Javascript to do modern front-end web development (I caved…). As a Java developer I basically have to let go of almost everything I know, its THAT different.

You can do some OO (classes really) in Javascript but that’s not how it is intended to be used. You rather work with prototyping. That’s an interesting concept to grasp, I had real difficulty letting go of my OO roots but when I did I wasn’t disgusted. I have learned to drop my hate for Javascript, its not as poor anymore as I thought it was.

I’ve also learned to love Google Chrome in that respect (being a pigheaded Firefox user until recently), its web developer tools and especially the javascript debugger are just excellent.

JavaScript is only named after Java to lift on the hype back then.

Yeah, oops… Too many terms to remember, I’ll get it fixed in the upper post. :stuck_out_tongue:

Most arguments that say “Language A isn’t OO because …” are flawed. The original point of the OO experiment wasn’t about how data was composed, nor visibility protection nor polymorphic dispatch. These were all well know techniques and if they were the point then Smalltalk could have been mostly implemented as a C frontend in an afternoon. The paradigm point was to have no-types because types are a PITA. Everything this is an Object, amen.

To be partially sane any language which gives you the tools to primary write in an OO style can reasonably be called OO. The current fad of calling everything hybrid-functional is (for example) annoying because virtually none give you the tools to write primarily in a functional style. JavaScript is object oriented…you may not like it’s design but that doesn’t change anything. Lua has a qwerky syntax but its easy to write in an OO style. Minimally it’s equivalent to object oriented (if that makes your fur stand up less).

I doubt that there’s anyone on this forum that would ever mistake the two languages? Though I know plenty of non-tech people that uses the names interchangeably when they talk about either language and correcting those people doesn’t really work since they’ll just shrug and say “Yeah, that’s what I meant” and not really pay any attention to what you actually said. :slight_smile: (At least that’s my experience.)

Erm… I’m not sure if you actually serious or only try to reflect the Idea of OO, without actually thinking exactly that way…

Because I think types are by far the biggest help for programmers not to make mistakes…

My point being that most arguments of “A isn’t OO” if the same arguments were applied then Smalltalk then it wouldn’t be considered OO. That’s dumb. And the flip side of that (given the original goal) most that are called and commonly considered OO would fail. That’s equally dumb.

On types. They are a curse and a blessing. It depends on what hat I’m wearing.