On Tue, 01 Sep 2020 20:43:55 -0700, Tom Blenko wrote:
> There is JavaScript which has been on browsers for a long time (and has
> seen increasing use and increasing support) and there are Java applets,
> which are a completely different beast.
>
Indeed, and Java applets dies almost as soon as they appeared because the
download mechanism was fairly flaky. Applets were compiled using the
standard Java compilers. They had nothing to do with Javascript.
>> - Javascript is interpreted while Java is compiled
>
> Interpreted and compiled implementations are different points on a
> continuum, they are not one-or-the-other propositions.
>
I'd disagree here. Yes, interpreted languages often use some sort of
compilation stage as part of loading the script (awk, Javascript, most
BASICs and some (Python) even allow you to capture and reuse the compiled
script, but 'compilation' as commonly used, means that compilation is a
separate process from executing the program (C, C++ Java, COBOL.PL/1...)
and, for some languages there may linkage process (C, C++, COBOL, PL/1)
and even more complex as well (C++ and some COBOL compilers translate the
source into C and then compile that.
> There are certainly things called JavaScript compilers running on
> browsers these days (I believe the one used most widely is from Google
> and was a large step forward compared to previous, interpreted
> implementations in terms of performance of the code produced). I don't
> know to what degree it "compiles" JavaScript, I doubt it goes to native
> code.
>
Most 'run the source' systems generate P-code and run that with a P-code
interpreter.
Java does that: javac reads Java source and generates P-code to a .class
file and that is executed by the JVM, 'java'. I think, but can't prove,
that the term P-code dates from the UCSD Pascal system, which was one of
the first to us a compiler to generate an easily interpreted binary
format, called P-code, which was executed by a runtime process. UCSD
Pascal was around when the 8080, Z80 and 8086 chips were cutting edge
microprocessors.
> Java has been implemented in more than one way. Including in the
> "compiler" from Oracle, nee Sun, which, I am told by people who have
> worked on it, contains three separate Java compilers in the same javac
> binary. Which compiler you get is determined by which flags (among 120
> or so) you choose on the command line and this internal structure is not
> visible to the user. None of these, to my knowledge, "compile" to native
> code, they compile to an intermediate language which is then
> interpreted.
>
Quite so - and ad a result the same compiled .class file can be run
unchanged on any hardware and OS which has a port of the JVM installed.
> Unclear how you intend that to square with your claim that Java (vs.
> JavaScript) is compiled.
>
Quite simple. javac, the Java compiler outputs a .class file. When you
want to run the compiled code, you run 'java', the JVM, which also loads
any standard class files from the standard library that the application
needs and then runs the result.
If the program has a graphical interface the JVM loads the AWT and SWING
classes that implement the GUI interface, along with keyboard and mouse
handlers. It goes without saying that the lower level AWT and SWING
classes used by a Linux JVM are not the same as those by a Windows JVM,
but the top-level classes (JPanel, JWindow, JMenu, JFileChooser, JButton
etc that the programmer uses to define what his application looks like)
will be the same for all hardware and operating systems.
But don't just speculate: install both Java and Javascript packages on
your RPi and start writing code. You'll soon see the differences.
--
Martin | martin at
Gregorie | gregorie dot org
--- SoupGate-Win32 v1.05
* Origin: Agency HUB, Dunedin - New Zealand | FidoUsenet Gateway (3:770/3)
|