University of Helsinki / Department of Computer Science / Programming in Java / Copyright © 1999 Arto Wikla.

581325-0 Programming in Java, exam 16.12.1999/AW

At the top of each paper write the name of the course, the date of the exam, your name, your date of birth and your signature. Each question is worth 15 points. Use separate sheets for each answer!

Questions 1, 3 and 4 differ from the Finnish version, because of using different text books.

  1. Explain shortly and precisely:
         primitive type - reference type
         class - object
         program file (.java-file) - package 
    

  2. You may use the class SimpleAnimal: This is all we know about the class SimpleAnimal! We don't know the size of the genotype array, for example, or the meaning of its contents (however, its size is always at least one). The mechanism of mating is also a secret of the class SimpleAnimal.

    The clever animal is a more developed relative of the simple animal. In addition to the simple animal's attributes, it has a so called intelligence quotient, which is an integer of 1-200.

    Program CleverAnimal as a subclass to the class SimpleAnimal:

  3. One of your friends, taking part in this course, has not fully understood the idea of what it means when a method is "overloaded", "overrided" or "inherited". He/she hasn't even got the idea, why he/she should understand these concepts. Help your friend and write him/her an explanation of the matter. Remember that good examples are important in learning. Your explanation will be evaluated from the point of view of your friend. So do not write to your teacher, he/she already knows it!

  4. You are given a class InpFile for reading input files. The class has a constructor InpFile(String name). The parameter is the name of the file.

    The lines are read wit the method

       public String read()
    

    When the file ends, the method returns the value null.

    The class takes care of all the possible exeptions. When an error occurs, the class gives an error message and exits the program.

    By using this class, write a program AreTheFilesSimiliar for comparing two files. The names of the files are given to the program as command-line arguments. The program compares the two files line by line, and prints all different lines to the screen. An example of the output:

    1>cat is walking<
    2>rat is walking<
    1>1235123<
    2>1234123<
    1>abc<
    2>abc  <
    2>  the second<
    2>was  <
    2>longer!<
    
    Thus the lines differing from each other are printed between either characters "1>" and "<" or "2>" and "<", depending on where the line in question comes from: from the first file or from the second file. If either file ends before the other, the extra lines of the longer file are printed. The program does not print anything else.

    In the example above the files had three different lines and the second file seems to have been three lines longer than the first.

    The program doesn't have to take care of the exceptions, the class InpFile takes care of them.


Good Luck & Merry Christmas!