What's the difference between JavaScript and Java?

JavaJavascript

Java Problem Overview


What's the difference between JavaScript and Java?

Java Solutions


Solution 1 - Java

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

Solution 2 - Java

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.

Solution 3 - Java

Here are some differences between the two languages:

  • Java is a statically typed language; JavaScript is dynamic.
  • Java is class-based; JavaScript is prototype-based.
  • Java constructors are special functions that can only be called at object creation; JavaScript "constructors" are just standard functions.
  • Java requires all non-block statements to end with a semicolon; JavaScript inserts semicolons at the ends of certain lines.
  • Java uses block-based scoping; JavaScript uses function-based scoping.
  • Java has an implicit this scope for non-static methods, and implicit class scope; JavaScript has implicit global scope.

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

  • JavaScript supports closures; Java can simulate sort-of "closures" using anonymous classes. (Real closures may be supported in a future version of Java.)
  • All JavaScript functions are variadic; Java functions are only variadic if explicitly marked.
  • 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 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.

Solution 4 - Java

Take a look at the Wikipedia link

>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.

Solution 5 - Java

Everything.

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.

The two languages are entirely distinct.

Solution 6 - Java

Solution 7 - Java

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.

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.

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.

Also, this is directly from the Wikipedia Javascript article:

>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.

Solution 8 - Java

In addittion to being entirely different languages, in my experience:

  • Java looks nice at first, later it gets annoying.
  • JavaScript looks awful and hopeless at first, then gradually you really start to like it.

(But this may just have more to do with my preference of functional programming over OO programming... ;)

Solution 9 - Java

Everything. They're unrelated languages.

Solution 10 - Java

They are independent languages with unrelated lineages. Brendan Eich created Javascript originally at Netscape. It was initially called Mocha. The choice of Javascript as a name was a nod, if you will, to the then ascendant Java programming language, developed at Sun by Patrick Naughton, James Gosling, et. al.

Solution 11 - Java

Like everybody's saying, they're pretty much entirely different.

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.

Solution 12 - Java

They have nothing to do with each other.

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.

Solution 13 - 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 Netscape’s implementation of the language. Netscape submitted the language for standardization to ECMA (European Computer Manufacturer’s Association) and because of trademark issues, the standardized version of the language was stuck with the awkward name “ECMAScript.” For the same trademark reasons, Microsoft’s version of the language is formally known as “JScript.” In practice, just about everyone calls the language JavaScript. The real name is “ECMAScript”.

Both are fully different languages!!!

Solution 14 - Java

Practically every PC in the world sells with at least one JavaScript interpreter installed on it.

Most (but not "practically all") PCs have a Java VM installed.

Solution 15 - Java

A Re-Introduction to Javascript by the Mozilla team (they make Firefox) should explain it.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionGuyView Question on Stackoverflow
Solution 1 - JavaGreg HewgillView Answer on Stackoverflow
Solution 2 - JavaShog9View Answer on Stackoverflow
Solution 3 - JavaChris Jester-YoungView Answer on Stackoverflow
Solution 4 - JavatoolkitView Answer on Stackoverflow
Solution 5 - JavaddaaView Answer on Stackoverflow
Solution 6 - JavaAlpineView Answer on Stackoverflow
Solution 7 - JavaBill the LizardView Answer on Stackoverflow
Solution 8 - JavaStein G. StrindhaugView Answer on Stackoverflow
Solution 9 - JavaKirk StrauserView Answer on Stackoverflow
Solution 10 - JavaDon WakefieldView Answer on Stackoverflow
Solution 11 - JavaDarcy CasselmanView Answer on Stackoverflow
Solution 12 - JavaClaudiuView Answer on Stackoverflow
Solution 13 - Javauser577898View Answer on Stackoverflow
Solution 14 - JavaWill PeavyView Answer on Stackoverflow
Solution 15 - JavaisomorphismesView Answer on Stackoverflow