Page 1




High versus Low Level Languages

Humans are largely ego-centric. We often like to beleive that we are at the top of some hierarchy. Thus, anything more closely related to us must also be near the top of that hierarchy. It is upon this assumption that we distinguish between the so-called high level languages and the so-called low level languages. High level languages are laguages that are easily comprehensible to us. They tend to have recognizable structure and form. Perl is a high level Language. Here is a fragment of some Perl code:


foreach $card (@deck_of_cards) {
  &play_this($card);
}

Although the syntax is somewhat confusing, notice that the general idea is easily recognizable. For every card in some deck of cards, we will succesively play that card. Low level languages are languages that are not at all easily comprehensible to us. They tend to look like lots and lots of pure gibberish. Machine code is an example of a very very low level language. Here is a fragment of machine code:


10110011 00011001 10011010
01111010 11010001 10010100
10111011 01010001 10010110

In fact, it is such a low level that I have no idea what it means. Languages can be lower level than Perl yet still higher level than machine code. Assembly code is a good exmaple of such a language. Here is a fragment of assembly code:


add ax, bx
mul 5
sub bx, 3

Here, we can see that there is most likely some mathematical operations occurring, but the meaning id more obscure than the perl code. For example, what is ax and bx? Why does the multiply command have only the number 5? Perhaps most importantly, why can't we say "multiply" instead of "mul"? In the Perl example, the words we were able to use were much more descriptive. Still, this assembly code is much more understandable than the machine code. (Which, by the way, I may never come to understand. Fortunately, my computer does that for me).



The Language Barrier

The reason we have many different languages at many different levels is that computers generally only understand machine code. Therefore, in order to tell a computer to perform a task, you have to tell it in machine language. But humans obviously can't read machine language very well, nor can we write it very fast or effectively, since we have no idea what it is we're writing! This presents a clear language barrier problem in attempting to give computers instructions. The solution to this barrier was to create high level languages that humans could understand and write instructions in, and to also create translators from these high level languages down to the low level machine languages. That way, instead of having to try to learn machine code ourselves, we can simply rely on a translator to do the job for us!
Actually, we can do this translating task in a series of steps. A compiler translates high level languages into asembly language, and an assembler translates assembly language into machine language. Therefore, we can write instruction in our easily-comprehensible high level languages, compile it, assemble it, and then pass the resulting machine code directly to the computer to execute.



Java Files

In Java, the high-level language we will be using throughout the course, this process is broken down in the following way. The instructions that we will be writing for the computer to perform will be written in the Java language, and we will call these JAVA instructions source code. The computer files (like Microsoft Word files, or Winamp files, or JPEG files) on which we will write our source code will be called source files. They will always end with the file extension .java and for this reason, source file are sometimes called .java files ("dot java files"). When we translate our source files, they will be translated into bytecode files. Bytecode is simply a low level language that the computer can easily understand. These bytecode files will always end in a .class file extension, and we may refer to bytecode files sometimes as .class files ("dot class files").
It is important to note that since the machine is executing the instructions, once we have the bytecode files the source files are no longer necessary. Of course, since we can't edit bytecode files, we will need to keep the source files around so that we can edit the source files and then regenerate the bytecode files.



Packages

A program is a any set of instructions written in some language. However, the instructions don't all have to be on the same page. In CS302, we will be creating several source code (.java) files. In addition, we will also be using some bytecode (.class) files that have already been written for us. These bytecode files may contain useful graphical tools, mathematical tools, and more.
To help organize all these files, they have been divided up into packages. For example, there is a package with all of the graphical tools in it called java.awt, a package with commonly used utilities such as lists and collections called java.util, and a package with generally cool and useful things called java.lang.
In order to gain access to the appropriate bytecode files, we will need to add an instruction in our source code that tells the computer to use the preprogrammed bytecode files as well. This instruction is called an import statement. There is one exception to this rule, however. Since the bytecode in the java.lang package is so incredibly cool and useful, all of the bytecode files in that package are already available for use without an import statement.



The Main Class File

When the computer goes to execute its instructions, it is important to know which instruction to execute first. While this may seem obvious to us, it is not obvious to the computer. Remember that we will be writing instructions on several different files, and perhaps importing even more files as we go along. To help sort out this dilemma, we will designate one of the source files that we will write as the main class file. The main class file is simply the file in which the very first instruction is written. In fact, we will later see that this first instruction is the exact same for all programs.



Applets and Applications

In Java, a program is called an application. These applications will run on your own computer. If, however, you would like to run your program from anywhere, then we can take advantage of the internet and instead make a Java applet. An applet is simply a program that runs in a web browser.
To make an application into an applet, you simply make the main class extend (be a subclass of) the Applet class, which can be found in the java.applet package. There is now an accepted HTML applet tag that is used to insert the applet program into the HTML web page code and specify its size.