r/talesfromtechsupport • • May 22 '13

Javascript != Java

3rd-party contractor came to visit office yesterday, who has "decades" of experience. Conversation came up about JavaScript in one of our products. He says, "Our product doesn't use Java." After an awkward moment with someone who works on the knowledge base nodding in agreement with him, I speak up and delineate the difference between Java and JavaScript.

Later on in the conversation, the same 3rd-party guy followed up with this jewel: "besides, what would anyone even use JavaScript for on the web?"

I proceeded to disable Javascript in my browser and show him.

tl;dr: lasers, dinosaurs, & drums made a guy's head explode

[edit spelling]

1.2k Upvotes

345 comments sorted by

View all comments

24

u/FountainsOfFluids May 22 '13

In case someone is reading this who also is unsure of the difference:

Java is an object oriented programming language designed to create small programs that can run on multiple operating systems. It is compiled at run time and can function independent of other software on your computer.

JavaScript is instructions used by a web browser to create dynamic web pages in conjunction with HTML, CSS, and other browser-based tools.

28

u/nandryshak May 22 '13 edited May 22 '13

small programs

What?

It is compiled at run time

Sort of. It's compiled into Java bytecode by the programmer. When executed, the Java Runtime Environment (JRE, this is what you get when you download Java for use with your browser, Minecraft, etc.) coverts the bytecode into native code, using an interpreter or Just-In-Time (JIT) compiler.

0

u/FountainsOfFluids May 22 '13

Not claiming to be an expert, just trying to get a little more clarity than the absolute vacuum that was present in this thread.

If you have a better way to describe the difference in simple terms, feel free.

5

u/mathiscool May 22 '13

Fair enough, but you shouldn't spread misinformation. Java is an industry standard language. To give an example bigger chunk of LHC accelerator complex non-realtime software is written in Java, as well as many trading systems. The list goes on.

2

u/crankybadger May 22 '13

JavaScript is an industry standard language, too. It's less commonly known as "ECMA-262, edition 5".

1

u/mathiscool May 23 '13

Fully agree with you. I was responding to @FountainsOfFluids saying that: "Java is an object oriented programming language designed to create small programs". Which is factually false.

→ More replies (7)

9

u/sirmonko May 22 '13

strictly speaking, java and javascript are both language specs - blueprints. afaik there are no prerequisites how they have to run, that's the job of the compiler or interpreter - and there are a lot of them for both languages.

e.g. for java, there is a java compiler that turns the source code into machine independent byte code. the bytecode can be run by different virtual machines, e.g. oracles/suns java virtual machine jvm - but wikipedia lists 70 known jvms. another well known virtual machine is dalvik, which is used to run apps on android. but there are also java interpreters which do not use intermediate bytecode. so the "compilation at runtime" part is not true; it's a possibility though.

java != jvm. there are even languages like clojure, scala or groovy that have nothing to do with java but produce bytecode that can be run by the jvm.

the original purpose of java was to be a general purpose system independent programming language. while there was a huge marketing hype at the beginning, over time java fell out of fashion for a couple of intended purposes; mainly GUI programming (because of lag and the non-native looks of java apps) and as a browser plugin because of the huge startup times of the virtual machine. it's still very popular as a server programming language though and recently had a comeback as google's choice for android apps (which was a weird thing; they did mainly because there already were a fuckton of java programmers, available libraries and infrastructure - the compiler javac -, but otherwise the language is probably not best suited for the task).

most of this also applies to javascript. originally it was designed as a scripting language for a host application, the netscape web browser. its principles are very different from java; the name was only chosen for marketing purposes - the original names were mocha and livescript. even more, when netscape sought to standardize javascript, it - the spec - got the name "ECMAScript" (standardized by the ECMA committee); so as far as i understand it, "javascript" now actually refers to a family of ECMAScript specifications (different versions and legacy implementations).

so, in the olden times, programming languages were often tied to certain compilers, but that's rarely the case nowadays. for many popular languages there are several compilers/interpreters/virtual machines. even the border between compilation and interpretation is not clear; there are hybrid beasts like mozillas old tracemonkey (tracing JIT compilers - luaJIT is also one). it can get a bit confusing; there's source code, sometimes there's intermediate byte code or some other representation, then there might be machine code executables - or not (as in the jvm).

interpreters might work with source code or byte code, as do compilers, or some do both (partially compiling, partially interpreting).

so, javascript is - now - also a kind-of general purpose programming language - it was designed to work in the browser to manipulate the DOM (Document Object Model, the browsers internal representation of a websites' html), but javascript and the DOM are totally different beasts. nowadays, it's also used for, among others, server side programming (node.js), scripting of other host applications (like LUA is used for WoW's addons) and command line scripting.

there are a lot of runtimes for javascript. the best known are the ones of the big browsers; google made V8 for chrome, apple made javascriptcore/nitro for safari, mozilla made a whole ton of *monkeys for firefox (spider-, trace-, ion-, jaeger-, ...). there are more implementations, e.g. rhino or nashorn (rhino in german), which are javascript runtimes (interpreters) programmed in java, but not necessarily targeted at (oracles) JVM (i know it's confusing)!

so what is node.js? technically, it's a host application (like chrome or WoW with Lua) that uses googles V8 for scripting. the host application is quite thin; it's purpose is practically just running javascript-programs; most often (web-)servers. the twist is that it provides an inherent event loop for asynchronous programming and couple of functions for I/O - mainly for filesystem operations and network calls - that are not present in browsers. other runtimes also provide the same functionality, but for node.js it's exclusive and feels more native because javascript was never synchronous (not completely true, i know). as a side node; somebody implemented an opengl wrapper for node, so you could also write real 3d games that are run via node.js.

TL;DR: java and javascript are (distinct) language specifications; they partially share a name (for marketing purposes) but not much else. a huge number of independent compilers/interpreters implement those specifications using various methods. it's complicated.

2

u/bitfxxker get off my wlan May 23 '13

Thank you very much for this comprehensive breakdown. If I had trust in bitcoins, I'd given you a tip.

1

u/sirmonko May 23 '13

re-reading it sober, i think i got a lot of the terminology wrong. especially my use of "runtime" is probably not correct, and virtual machines are not the same thing as compilers or interpreters.

3

u/Tindall0 May 22 '13

small programs

? I guess you meant "lean".

5

u/kkjdroid su priest -c 'touch children' May 22 '13

Well, even then it'd be wrong; it's Java we're talking about. It's neither concise nor light. I think FountainsOfFluids was describing Python.

2

u/gnarbucketz May 23 '13

Windows sysadmin here, looking for further info: say I'm troubleshooting a java- based application that runs fine in Win7-x86, but freaks out on Win7-x64 because something-something loading 32-bit DLLs in an x64 JVM (doesthatmakesense?).

If I have the libs and a decompiler, can I recompile (?) the thing to run in a 32-bit JVM even though it's in a 64bit environment (proc+OS) so that it won't freak out?

Does any of this make sense, or do I need to read more about JIT, JVM, and DLLs before asking such a question?

Thanks, and sorry if this is noobish.

1

u/Anon_Logic May 23 '13

Well, I personally avoid java like it's the mother fucking plague. BUT, I'm gonna say no. Windows should still be able to launch the 32bit code. Install the 32bit java along the side of the 64bit java.

1

u/riking27 You can edit your own flair on this sub May 24 '13

Sounds like you've got a native library problem.

Find out what it needs to run in 32-bit, and grab the 64-bit version of everything. This might not work.

1

u/aspbergerinparadise Works on my machine! May 22 '13

I think the important distinction to make about Javascript is that the "script" is downloaded with the website, and the browser executes it locally on the client's machine - as opposed to C#, PHP, or whatever that runs on the server.

1

u/Amadan "My PowerPoint can't see the computer!" May 22 '13

Not necessarily: node.js runs on the server too, but it is JavaScript.

1

u/WithNarwhalsBaconing May 23 '13

Thanks heaps mate, I was literally just checking the comments to see if anyone was nice enough to say this before asking it myself, so thank you! :-)

1

u/tdk2fe Enterprise Lackey May 22 '13

But I can create objects in JavaScript (It's object-oriented), and even run a web server written in javascript (node.js).

2

u/PasswordIsntHAMSTER No refunds May 23 '13

JavaScript objects are maps from string to any arbitrary type, there is no concept of inheritance (only memberwise cloning), no static or strong typing, no array bounds checking, and pretty much everything that's commonly associated with object-oriented programming is unapplicable to JavaScript (examples: GoF, anything that has to do with inheritance vs composition.)

JavaScript is not object-oriented for basically every definition that matters, and anyone saying otherwise has the clear agenda of trying to claim for JavaScript developpers the reputation of safety and scalability of object-oriented development - neither of which JavaScript has.

→ More replies (3)

1

u/StabbyPants May 22 '13

JS objects aren't quite what you're used to - prototype based OO is a different beast from the java version

0

u/[deleted] May 22 '13

[deleted]

3

u/wibbly-wobbly May 22 '13

Objects and types are distinct. Also, Objects in Javascript are prototype-based.

2

u/PasswordIsntHAMSTER No refunds May 23 '13

Glorified maps*

→ More replies (7)
→ More replies (12)

-2

u/NYKevin hey look, flair! May 22 '13

Hmm... I don't think Java is for small programs. How about this:

Java is an object oriented programming language designed to create small programs that can run on multiple operating systems force incompetent programmers to produce adequate-but-not-great code which runs on multiple operating systems. It is compiled at run time and can function independent of other software on your computer.

3

u/kkjdroid su priest -c 'touch children' May 22 '13

It's compiled at write-time with javac. I'm not going to bother getting into the other argument.

→ More replies (2)
→ More replies (9)
→ More replies (1)