Computer Science A, Spring 2007
Roskilde University

Lecture 1:  Introduction


1: What is Programming?


2: What is a Programming Language?


3: What is in a Programming Language?


4: How do you Solve a Problem?


5: What is Software Development?


6: Course Content


7: The Anatomy of a Computer


8: Central Processing Unit


9: A Memory Module with Memory Chips


10: A Hard Disk


11: A Motherboard


12: Schematic Diagram of a Computer


13: Machine Code


14: Self Check

  1. What is the code for the Java virtual machine instruction "Load the contents of memory location 100"?
  2. Does a person who uses a computer for office work ever run a compiler?

15: Answers

  1. 21 100
  2. No–a compiler is intended for programmers, to translate high-level programming instructions into machine code.

16: The Java Programming Language


17: Becoming Familiar with your Computer


18: A Shell Window



19: An Integrated Development Environment



20: File HelloTester.java

1: public class HelloTester
2: {
3:    public static void main(String[] args)
4:    {
5:       // Display a greeting in the console window
6: 
7:       System.out.println("Hello, World!");
8:    }
9: }

Output

   Hello, World!


21: HelloTester in a Console Window



22: HelloTester in an IDE



23: A Simple Program


24: Syntax 1.1: Method Call

 
object.methodName(parameters)

Example:

 
System.out.println("Hello, Dave!");

Purpose:

To invoke a method of an object and supply any additional parameters

25: Self Check

  1. How would you modify the HelloTester program to print the words "Hello," and "World!" on two lines?
  2. Would the program continue to work if you omitted the line starting with //?
  3. What does the following set of statements print?
    System.out.print("My lucky number is");
    System.out.println(3 + 4 + 5);

26: Answers

  1. System.out.println("Hello,"); System.out.println("World");
  2. Yes–the line starting with // is a comment, intended for human readers. The compiler ignores comments.
  3. The printout is My lucky number is12. It would be a good idea to add a space after the is.

27: Errors


28: Self Check

  1. Suppose you omit the // characters from the HelloTester.java program but not the remainder of the comment. Will you get a compile-time error or a run-time error?
  2. How can you find logic errors in a program?

29: Answers

  1. A compile-time error. The compiler will not know what to do with the word display.
  2. You need to run the program and observe its behavior.


30: The Compilation Process



31: The Edit-Compile-Test Loop


32: Self Check

  1. What do you expect to see when you load a class file into your text editor?
  2. Why can't you test a program for run-time errors when it has compiler errors?

33: Answers

  1. A sequence of random characters, some funny-looking. Class files contain virtual machine instructions that are encoded as binary numbers.
  2. When a program has compiler errors, no class file is produced, and there is nothing to run.