The Differences between Java and JavaScript.

Today, I will describe to you the differences and similarities between Java and JavaScript.

Similarities:

  1. Keywords: Both languages have for and while loops, bitwise operations (OR, AND, ect.), and use the same symbols for basic math (+, -, * , /).
  2. Name (Sorta): This is where many people may get the languages mixed up. They both have the word “Java” in the name.

Differences:

  1. Games: Java comes with classes that you can use to make games with. JavaScript, however, does not.
  2. Purpose: Java’s purpose was to be for everyday applications such as calculators. JavaScript was meant for websites.
  3. Structure: Java is a OO (Object Oriented) language. JavaScript is… you guessed it! Not! EDIT: Not as much. (As some of you have pointed out)

These are only a few of the differences between Java and JavaScript. Now I hope people don’t say “Java is the same as JavaScript” anymore. Have a nice day.

Get ready to face the hate…

EDIT-
I haven’t use much of javascript, but from my experience, you can do this:



function doSomething() {
     var Object obj=new Object();
     obj.parameter1=5;
     obj.parameter1=6;
}

function Object() {
     int parameter1=0;
     int parameter2=1;
}

This is object oriented programming right there for you.

I honestly can’t tell if OP is serious.

Better trolling Java vs JavaScript: What’s the difference between JavaScript and Java?
Also has some informative replies if someone is actually curious.

If you want to be a dork then it’s easy to argue that JavaScript is more OO than Java.

Well, JavaScript is not AS OO as Java.

What are you talking about? Object oriented means object oriented.

Yes. I’m talking about Object Oriented.

There is no such thing as more object oriented. It is either object oriented or it is not. There is no middle ground… How is java more object oriented than javascript?

You can use classes (sort of) in javascript. The following code in Java is


public class Foo
{
    public void bar()
    {
        // Do something
    }
}

new Foo().bar();

is equivalent to the following in JavaScript.


(function () 
{
    var Foo = function(){};

    Foo.prototype = {
        bar: function() 
        {
            // Do Something
        }
    };
})
();

new Foo.bar();

They both does the same.

However, the keywords are not the same. That’s my point.

You can do all sorts of things that make it seem like its very OO on the surface - that was what Roquen was referring to.

But no, javascript has no OO at all, none.
Its all fake, and if you try to do things that would normally go well with actual objects and pointers you will have some frustrating days debugging :smiley:

[quote]object-based but not object-oriented
[/quote]
http://www.engfers.com/2008/08/29/javascript-is-not-truly-object-oriented/

Java is general purpose and fail-fast, javascript is a DSL an fault tolerant. Java is class-based OO and Javascript is prototype based OO. I could go on…but my real point is comparing the two doesn’t make any sense.

This means nothing. Are you trying to tell me that C++ isn’t OO because it has different keywords than Java?

Java isn’t the standard for OO, its just another language which utilizes the idea of OO.

Errr… no language comes with classes that you can make games with, actually. What you’re talking about is suns/oracles java standard library. It’s so closely bundled to the JVM that people think the JVM would die without it :smiley:
On a serious note again: On android you don’t have the standard java library, you have the android library. Something like Swing/AWT doesn’t exist in Android’s Standard libarary, even though you can use Java to for coding on Android.
Also, you can’t write games ‘without libraries’ (what’s the difference between including the code of a library (or writing the exact same code) and installing a library?) with nodejs, for example, but in web browsers it’s easily possible. See modifying the DOM / using HTML 5 Canvas and all the HTML 5 games that exist out there.

Roughly true :slight_smile:

I know we already discussed it here, but look at MooTool’s Class, and you’ll see that you can IMPLEMENT something like java’s class system with inheritance and public / private methods and fields in javascript. It’s pretty amazing if you think about it actually: They didn’t implement it in the compiler / interpreter, but you can actually code it in the language itself. You could also modify it, or write your own version if you wanted :slight_smile: If you like this simplicity, maybe try out the programming languages scheme or lisp (argh, I did it again!) :smiley:

Guys, he’s not a troll, he just doesn’t want people to call Java and JavaScript the same ^^ He just wants to do something good.

I’m not claiming that Java sets the standard, but this is Java Gaming, not C++ gaming. I know full well that other languages are Object-Oriented, I’m just focusing on one.

Nothing good can become of this topic.

This is just going to turn into a big cock waving contest, its pointless.

Java and JavaScript are two completely different things. There’s no reason to compare the two.

  • Jev

There are a lot of differences between both, but the most notable difference IMO is that Java is strongly typed while Javascript is not.
It’s a nightmare to make big programs with a weak typed language.

I never meant to start such a controversial topic. I just wanted to inform coding newbies that Java and JavaScript are not the same.