Rectangle 27 0

What's the difference between JavaScript and Java?


this
  • Java is a statically typed language; JavaScript is dynamic.
  • Java requires all non-block statements to end with a semicolon; JavaScript inserts semicolons at the ends of certain lines.
  • JavaScript allows methods in an object to be redefined independently of its prototype (think eigenclasses in Ruby, but on steroids); methods in a Java object are tied to its class, and cannot be redefined at runtime.
  • JavaScript prototypes can be redefined at runtime, and has immediate effect for all referring objects. Java classes cannot be redefined in a way that affects any existing object instances.
  • JavaScript supports closures; Java can simulate sort-of "closures" using anonymous classes. (Real closures may be supported in a future version of Java.)

2 years late, but thank you so much for this thoughtful explanation. It's way more useful and informative than the selected answer, and deserves far more votes IMO

Here are some differences between the two languages:

Here are some features that I think are particular strengths of JavaScript:

I upvote both in such cases. We need the right answer, but holy shmoly, geeks like us we really need more of this humor

You might also here strongly-typed and loosely-typed instead of statically-typed and dynamically-typed.

Note
Rectangle 27 0

What's the difference between JavaScript and Java?


JavaScript, despite the name, is essentially unrelated to the Java programming language, although both have the common C syntax, and JavaScript copies many Java names and naming conventions. The language was originally named "LiveScript" but was renamed in a co-marketing deal between Netscape and Sun, in exchange for Netscape bundling Sun's Java runtime with their then-dominant browser. The key design principles within JavaScript are inherited from the Self and Scheme programming languages.

Note
Rectangle 27 0

What's the difference between JavaScript and Java?


@Roman well of course, the proper Java way is to write at least 20 different classes using intricate inheritance and other cool OOP features to complete a FizzBuzz :)

I was about to berate you for dissing Javascript when it had come so far in the last few years. Then I rid the second paragraph and L'dOL. But, hang on a mo, Java is my main income earner... :-)

It's sad that I can only upvote once. This is going on my Facebook profile somewhere...

One is essentially a toy, designed for writing small pieces of code, and traditionally used and abused by inexperienced programmers.

The other is a scripting language for web browsers.

downvoted for dissing Javascript, then noticing you were talking about JAVA and upvoted (and lol'ed alot).

Note
Rectangle 27 0

What's the difference between JavaScript and Java?


However, if you need a scripting language for your Java application, Javascript is actually a really good choice. There are ways to get Javascript running in the JVM and you can access and manipulate Java classes pretty seamlessly once you do.

Note
Rectangle 27 0

What's the difference between JavaScript and Java?


Java is statically typed, compiles, runs on its own VM.

Javascript is dynamically typed, interpreted, and runs in a browser. It also has first-class functions and anonymous functions, which Java does not. It has direct access to web-page elements, which makes it useful for doing client-side processing.

They are also somewhat similar in syntax, but that's about it.

They have nothing to do with each other.

Note
Rectangle 27 0

What's the difference between JavaScript and Java?


A common misconception is that JavaScript is similar or closely related to Java; this is not so. Both have a C-like syntax, are object-oriented, are typically sandboxed and are widely used in client-side Web applications, but the similarities end there. Java has static typing; JavaScript's typing is dynamic (meaning a variable can hold an object of any type and cannot be restricted). Java is loaded from compiled bytecode; JavaScript is loaded as human-readable code. C is their last common ancestor language.

Also, this is directly from the Wikipedia Javascript article:

Java is a programming language, core set of libraries, and virtual machine platform that allows you to create compiled programs that run on nearly every platform, without distribution of source code in its raw form or recompilation.

JavaScript is an object-oriented scripting language that allows you to create dynamic HTML pages, allowing you to process input data and maintain data, usually within the browser.

Javascript isn't just for HTML pages, Java6 now includes it, BIRT uses it for report scripting - I'm sure that there are other non-HTML uses beyond these two.

Scripting is simply one particular kind of programming... instead you should say perhaps that Java is a compiled programming language and javascript is a scripting or interpreted programming language.

While the two have similar names, they are really two completely different programming languages/models/platforms, and are used to solve completely different sets of problems.

You're right. With the development of Rhino, and some of the other developments you mentioned, Javascript has come pretty far out of the browser sandbox.

Note
Rectangle 27 0

What's the difference between JavaScript and Java?


"ride the success of java" by calling something unrelated with a similar name? That sounds very much like "causing confusion for marketing purposes" to me.

I doubt it was to cause confusion - what's the benefit to the company of that? I suspect the intent was to ride on the success of Java, although the effect was what you stated.

JavaScript was named this way by Netscape to confuse the unwary into thinking it had something to do with Java, the buzzword of the day, and it succeeded.

Javascript was originally called Livescript, and the world would probably be a better place today if they hadn't renamed it!

Sun tried this naming trick again with the "Sun Java Desktop", which was essentially a branded version of Gnome and had nothing to do with Java.

The two languages are entirely distinct.

Yeah, and it worked. @Greg Hewgill, the world might be a better place, but Javascript probably wouldn't be where it is today.

Note
Rectangle 27 0

What's the difference between JavaScript and Java?


It comes from a big hamster; it's so big that you could confuse it with a pig. ;)

Note
Rectangle 27 0

What's the difference between JavaScript and Java?


@Ian Quigley: Ah, that must have been where I saw it! Thanks.

I prefer the version about ham and hamster.

Java and Javascript are similar like Car and Carpet are similar.

This is a bad answer. Javascript and Java are both languages for writing code, but they are used in different contexts. Car and Carpet are nothing at all like each other. Javascript and Java are easy to confuse for a beginner

i don't think it's a flaw. he deserved his points. this is a short answer, and all he needs to know.

Note
Rectangle 27 0

What's the difference between JavaScript and Java?


Don't be confused with name.. Java was created at Sun Microsystems (now Oracle). But, JavaScript was created at Netscape (now Mozilla) in the early days of the Web, and technically, Java-Script is a trademark licensed from Sun Microsystems used to describe Netscapes implementation of the language. Netscape submitted the language for standardization to ECMA (European Computer Manufacturers Association) and because of trademark issues, the standardized version of the language was stuck with the awkward name ECMAScript. For the same trademark reasons, Microsofts version of the language is formally known as JScript. In practice, just about everyone calls the language JavaScript. The real name is ECMAScript.

Note