QUIZ II (20 pts)

  1. (1 pts)Sun identifies "Write once, run anywhere" as the core value of Java technology. Translated from business jargon, this means that the most important promise of Java is that you only have to write your application once for the Java platform and then you will be able to run it anywhere. Anywhere, that is, that supports the Java platform.
    a. True
    b. False
    
  2. (2 pts)What is the correct printout?(Select 1)
    public class Barr {
        Boolean start;
        public static void main(String[] args) {
            Barr bar = new Barr();
            System.out.println(bar.start);
        }
    }
    a. false
    b. true
    c. null
    d. start
    e. You cannot compile it.
    f. You can compile it and run it, but nothing will be printed out
    
  3. (2 pts)Which of the following are Java keywords or reserved words?(Select 2)
    a. extend       b. continue      c. implement      d. main
    e. Interface    f. test          g. super          h. Static
    
    
  4. (3 pts)Which of the following are Java wrapper classes?(Select 3)
    a. Boolean      b. char          c. String         d. Integer
    e. float        f. double        g. Long           h. short
    
  5. (2 pts)Which of the following statements can print out all the elements of the array list?(select 1)
    String[] list = {"Java", "is", "a", "right", "language", "for","me"}; 
    a. for (int i = 0; i < list.length; i++) {
           System.out.print(list[0] + " ");
       }
    
    b. for (int k = 1; k <= list.length; ++k) {
           System.out.print(list[k] + " ");
       }
       
    c. for (int j = 0; j < list.length; j++) {
           System.out.print(list[j] + " ");
       }
       
    d. for (int m = 0; m < list.length-1; ++m) {
           System.out.print(list[m] + " ");
       }
       
    e. for (int n = 0; n <= list.lenght; n++) {
           System.out.print(list[n] + " ");
       }
       
    
  6. (1 pts)What is the length of the array intArray?(Select 1)
    int[] intArray = {4, 6, 6, 3, 2, 1 };
    a. 5
    b. 6
    c. 7
    d. cannot predict
    e. wrong statement, you should use new to create an array
    
  7. (4 pts)Given an array nameList, choose 2 correct answers.
    String[] nameList = {"Aaron", "Betty", "Cathy", "Dan", "Euro", "Fun" };
    
    a. Use nameList.length(), you will get the array length.
    
    b. Use nameList.length, you will get the array length.
    
    c. Use nameList[0].length(), you will get the length of the first element,
       like "Aaron", you will get length 5.
    
    d. Use nameList[0].length, you will get the length of the first element,
       like "Aaron", you will get length 5.
    
    e. Only one correct answer in this question
    
    f. No correct answer in this question
    
    
  8. (1 pts)What will happen when you compile and run the following code?(Select 1)
    class WhichOne {
        String name = "Betty";
        public static void main(String[] args) {
            String name = "Aaron";
            System.out.println("Hello " + name );
        }
    }
    a. You will get compile-time error.
    b. You will get run-time error
    c. You will get "Hello Aaron" on the screen.
    d. You will get "Hello Betty" on the screen.
    
    
  9. (2 pts)What will happen when you compile and run the following code? (Select 1)
    class MaybeOne {
        String name = "Betty";
        public static void main(String[] args) {
            System.out.println("Hello " + name );
        }
    }
    a. You will get compile-time error.
    b. You will get run-time error.
    c. Nothing will be printed out on the screen.
    d. You will get "Hello Betty" on the screen.
    
    
  10. (2 pts)Which of the following are correct loop constructs?(Select 2)
    a. while(true) {
          System.out.println("run it forever");
       }
       
    b. boolean right = false;
       do {
          System.out.println("at least run once");
       }while(right);
       
    c. for (int i = 0, i > 5 ; i++) {}
    
    d. int k = 5;
       while (k = 10){
           k++;
       }
     
    
  11. Bonus (10 pts):
    You can obtain your system information by using the following statements.
        
        String userDir = System.getProperty("user.dir");
        String osName = System.getProperty("os.name");
        String jdkVersion = System.getProperty("java.version");
        
    Write a short program called Hello. When you run it in the following way,
    it will print out some information about your system.
    For example:
    
    >java Hello Judy
    Hello Judy
    You are working on such directory: A:\
    Your operating system name is: Window 2000
    Your jdk version is: 1.3.0_01
    
    NOTE: Don't need to turn in your disk
    Write code on the paper.
    
    //Hello.java
    public class Hello {
        public static void main(String[] args) {
            String userDir = System.getProperty("user.dir");
            String osName = System.getProperty("os.name");
            String jdkVersion = System.getProperty("java.version");
            String str = "";
            if (args.length > 0) {
                str = args[0];
            }
            
            System.out.println("Hello " + str);
            System.out.println("You are working on such directory: " + userDir);
            System.out.println("Your operating system name is: " + osName);
            System.out.println("Your jdk version is: " + jdkVersion);
        }
    }