11
Sep

COMP1010 Compiling & the JVM


Hi! This is COMP 1010 at the University of
Manitoba and in this video I’m going to lead you through how compiling works
with Processing and explain the Java Virtual Machine. So we’ve talked already
about programming languages and the fact that they’re really designed for people.
They use words that are human understandable and you might think “wow
when I look at programming stuff it doesn’t look very understandable to me!”
but that might be just because you’re a novice. And so they really are much
better than what was available before which was a machine language, which is
basically just binary: zeros and ones, and that is not human readable at all. So we
like to work in programming languages because they’re human readable and
they’re a lot easier to work with, but the machines can’t understand them. So we need this middle thing called the “compiler” which takes our program that
we’ve written in a programming language like Processing and turns it into the
ones and zeros of machine language that the computer can understand and use.
So compilers are absolutely necessary. Everything has to be compiled and so
when you bought software before and loaded it on your computer, it’s already
been compiled. When you bought it, it’s been packaged to be executable, to be
able to run right away. Alright so there’s a complication here which is
that different computers speak different languages, as in different machine
languages. So there’s always the rivalry between Windows and Macs and you know
this is cute and funny, but actually it’s more serious than that.
They speak slightly different machine languages and so the orders of the ones
and zeros and things like can be different across different platforms. And
it’s not just Windows and Macs either, think about your gaming consoles or all
the different smartphones that are available. All of these have all
different machine code language that they speak. There’s also things like
smart fridges now and other home appliances that run apps, and even cars
have apps now. So all of these different platforms speak different languages.
So this starts to get crazy because if we write a program and it’s human
readable, then you think well “wow now we have to compile it for all of these
different platforms!” and these are just three of the many platforms. So we need
all these different compilers that will compile this program into something that
each of these platforms can actually understand and use. So that doesn’t seem
very scalable – that’s problematic. And what happens if we introduce a new
platform and it has a different language? Well then the problem is is that then
we’d have to create a compiler and EVERY program that exists would have to be run
through that new compiler and that would be problematic. That’s not going to be
very easy to do and it would prevent innovation – it would prevent us from
developing new platforms. So there must be a solution, right? Indeed there is. The
solution is a virtual machine. So the idea is we have programming code and
then we’re going to send it through a virtual machine compiler to get this
virtual machine language. What is it? It’s sort of this kind of machine
language, but it’s something that then can run on different platforms because
what will happen now is every platform will have a virtual machine on it. So the
Windows PC has a virtual machine program platform, so does the Mac, so do the gaming
systems, etc. So we compile once to this virtual machine language, and then send
it off to all these different platforms. And so this is how Java works. Okay so
when a new platform is introduced we create a Java Virtual Machine for that
platform. We put it on that platform – so here’s the Nintendo Wii, we put the Java
Java Virtual Machine on there and then any existing Java programs, because
they’ve been compiled to the Java Virtual Machine, can just load on here and run.
So we don’t need to recompile them. So this is really great, right. So you may be
wondering “okay that’s Java, but what about Processing?” So in our class we’re
going to be using Processing – that’s our human readable code. The processing
compiler is actually going to create Java code, which is also human
readable and then that’s going to be sent to the virtual machine compiler and
that will then be able to run on various platforms. So here’s just some little bit
more detail on this – the files that you get. So when we are programming in
Processing we have a PDE file and that goes through the Java compiler and we
end up with something called Java bytecode. That’s the virtual machine
language and that is stored in a dot class file. So you can’t look at a class
file – it’s not human readable – it looks like a bunch of gobbledy-gook because it’s
run by the virtual machine. And then on whatever platform you’re on, there’s a
Java Virtual Machine. So Windows has this, Mac has this, different phones have this,
all sorts of platforms have a Java Virtual Machine which enables these
class files to actually be run on that platform. Alright so that’s all you
really need to know and there’s a lot of detail there and it’s not
necessary for you to memorize all that detail. But you have to understand the
idea of what compiling is – the idea that it’s taking human readable programming
language and turning it into something that is machine readable – and you want to
understand that Java uses this virtual machine mechanism. So there’s a Java
Virtual Machine (JVM) that can be built and sit on any platform so that Java
programs can run on them. Alright that’s all for now.

Tags: , , , , , ,

There are no comments yet

Why not be the first

Leave a Reply

Your email address will not be published. Required fields are marked *