We spent some time discussing the relationship between the symbols we use to communicate with each other (those on the keyboard) and the symbols which the computer uses to perform its tasks. In particular, since modern computers are binary, we can imagine that they use only 0's and 1's to represent information. So, we must find some way to translate or encode the symbols on the keyboard into sequences of 0's and 1's. But since the number of symbols on the keyboard exceed 100, it quickly becomes clear that we will need a sequence of at least 7 0's and 1's (Binary Digits) to represent each symbol. In fact, the world has adopted a standard 8-Bit code, called the ASCII code for this purpose. Page 121 of your textbook has the ASCII (American Standard Code for Information Interchange) code tabulated. In particular, the character 'A' has the corresponding code 65. Of course, 65 is just the decimal representation of the actual binary code:
'A' = 01000001 = 65
So, it's well to remember that each time you create a program, the computer is translating the characters you type into their ASCII equivalents. In fact, that program you save on your disk is sometimes referred to as a ASCII file or text file.
To examine further the binary number representation, just read the digits from right to left. Each successive digit represents a power of 2. So the first digit tells you the number of 1's, the second digit tells you the number of 2's, the third digit tells you the number of 4's, the fourth digit tells you the number of 8's, etc. So the binary number
01000001
reading the digits from right to left is:>
1 X 1 + 0 X 2 + 0 X 4 + 0 X 8 + 0 X 16 + 0 X 32 + 1 X 64 + 0 X 128 = 1 + 64 = 65
Incidentally, you'll notice that the ASCII code is an 8-bit code (8 binary digits). A sequence of 8 bits is sometimes called a byte.
Exercise 1. Write a program that writes "Hello World" to the screen.
//File: Hello.java
public class Hello
{
public static void main (String [] args)
{
System.out.println ("Hello World!");
}
}
>javac Hello2.java
>java Hello
Hello World!
Note that the "javac" command invokes the Java Bytecode compiler discussed above and the "java" command translates the Java Bytecode into the local machine language. I will consistently underline the user input and italicize the computer output.
NOTE:
Java is a case sensitive programming language. So, upper and lower case letters are distinguished.
By convention, all class names should be capitalized. In our program, Hello and System are capitalized. They are both classes.
You MUST save your program under the same name as the class. Here, we must save our program as Hello.java.
Some words are special in the language. They are called key words and are reserved for special contexts. You are not allowed to use them in other way. In the Hello program, they are public, class, static, and void. I'll try to remember to make them bold in our lecture summaries.
We also spent some time discussing how to navigate inside the MS-DOS window.