Username:
Password:
Programming With Ruby Tutorials

Meet Ruby / Virtual Machine

Subtitles of the Movie

In this video we're going to take a look at virtual machines, and what that has to do with Ruby we'll get to a touch later in this video. First off, I'm going to use Java as the example to show you how a virtual machine works just because I have direct access to it and we'll talk about with regards to Ruby in a minute. So in previous videos we talked about interpreted and compiled languages. There's actually an intermediate form of a language where you have a language that gets compiled into what's called byte code, and then that's run by a platform-specific interpreter. So all the interpreters are platform-specific, but what doing, having byte code buys you, is you have somewhat of an optimized code but its run able on any machine because you have an interpreter that's set up for that machine, and that's what Java essentially does. So when you create a Java program, you have a little diagram here, you write your program in whatever tool you're using, you feed it into the Java compiler and it produces this Java byte code which is this intermediate form of your program. Now to actually run it you take the byte code and you feed it into the interpreter, the byte code interpreter, and it runs that byte code. So I have an example here. Let me get into my directory. Now, I have two files here. One is my Java file, which is my text human readable, and this is the binary ah, byte file for Java. Let's take a look at the human readable file here, and it's that simple hello one that we covered in an earlier video, it just prints out Hello. Um, it's a very simple program, just a couple of lines. This is what gets fed into the Java compiler, and how you do that is you do Java C, Hello dot java, and that produces this file here, this hello dot class. So in order to take a look at that if we just tried to open that up in a text editor, you're going to see it really, it doesn't look like much. There's like hidden stuff in here, and binary stuff, so it's not really in good form. However, there's a tool that we can use that's called Java P that comes with Java, and we can take a look at the byte code. So here's the byte code right here. It starts right here, and comes down to here. Let me actually paste this into my text editor so we can take a look at it without all that clutter. Now the important thing to keep in mind here is that it isn't really about, you know, this what this language specifically is, or whatever, but it's to understand that it took your program and turned it into this intermediate form, which is, kind of looks like that C language that we were looking at in other videos and almost in some ways like assembly language. And then you have the interpreter actually takes this and runs it. Now, what does that have to do with Ruby? Well, there are many people working on, with Ruby, a Ruby virtual machine, and what that will do is, it will speed up how fast Ruby runs your program. The, the price that you pay for the flexibility of an interpreter, using an interpreted language, is in performance because of that interpreted step along the way, and what this byte code gets us in using a, a virtual machine is it gets some performance because you, your byte code is a little bit closer to what the machine's natural language is going to be so it speeds it up significantly in converting it to this kind of code. So in the very near future we're going to see more and more of these, you know, Ruby virtual machines just increasing our performance, and, and you as a, a programmer in Ruby need to be familiar with what a virtual machine is with regard to programming here, and how you utilize it. Now, don't confuse in your mind virtual machines from the IT kind of world, such as, VM Ware, or on the Mac Parallels, I think Parallels has some Windows products, and Linux products also, or Zen, or some of those products where you have a virtual operating system. That's a different concept completely, as opposed to what we're doing here. What is important to get is that you use this virtual machine, and byte code is your intermediate step, and Ruby has that. There are ones in the works, and I'm sure as Ruby um, progresses here they'll be coming out more and more because they help with performance.

Tutorial Information

Course: Programming With Ruby
Author: Al Anderson
SKU: 33788
ISBN: 1-934743-01-1
Release Date: 2007-08-21
Duration: 8.5 hrs / 113 lessons
Work Files: Yes
Captions: For Online University members only
Compatibility: Vista/XP/2000, OS X, Linux
QuickTime 7, Flash 8

VTC Sign up & Benefits

  • Unlimited Access
  • 81,350 Video Tutorials (20,800 free)
  • Video Available as Flash or QuickTime
  • Over 782 Courses
  • $30 for One Month Access
  • Multi-User Discounts Available