A Java Warmup Exercise


In-Class Exercise 1: Which of the following statements about Java are FALSE?
  1. Java is interpreted and never compiled.

  2. There are two different types of comments, block comments and line comments, e.g.
          /* This is a comment that spills
             over to the next line  */
    
          int i = 5;     /// This is an inline comment.
      
  3. A char variable occupies 1 byte.

  4. The following cast is permissible:
        long j = 10;
        int i = (long) j;
      
  5. Except for for-loop variables, all local variables must be declared at the top of a method, e.g.,
        void computeStuff ()
        {
            int k = 5;
            int s = 0;
    
            for (int i=0; i< i++) {
               int m = 3;                // Will this compile?
               s = k + i*m;
            }
        }
      
  6. The following are valid String declarations:
        String hello = "hello";
        String world = new String ("world");
      
  7. The following is a valid array declaration and assignment:
        int[] A = new[10];
      
  8. A static method that returns nothing must declare the return type as null

  9. The return type is one of several aspects of a method's signature.

  10. It is possible to combine assignment and boolean testing as follows:
            boolean flag;
            
            if (flag = true) {
               // ...
            }
    
      
  11. Java does not support call-by-reference parameters.

  12. The package java.lang is the only package that does not need an explicit import statement.

In-Class Exercise 2: Download and modify this Java program print out patterns that look like this (when N=5):

  1
  2 1
  3 2 1
  4 3 2 1
  5 4 3 2 1