Monday, December 17, 2012

Objectives



1)When a program does not want to handle exception, the ______class is used.

Ans : Throws

2) The main subclass of the Exception class is _______ class.

Ans : RuntimeException

3) Only subclasses of ______class may be caught or thrown.

Ans : Throwable

4) Any user-defined exception class is a subclass of the _____ class.

Ans : Exception

5) The catch clause of the user-defined exception class should ______ its
Base class catch clause.

Ans : Exception
6) The __________ is the part of a computer that follows instructions.
[processor]
7) A(n) __________ is a program that translates programs to a simpler language that the computer can execute.
[compiler]
8) The Java interpreter translates a Java program from __________ to machine language.
[byte code]
9) A(n) __________ is an action that a Java object can perform.
[method]
10 ) Another term for __________ is data hiding.
[encapsulation]
11) A(n) __________ is a set of instructions that tells the basic strategery for solving a problem.
[algorithm]
12) A(n) __________ is a program meant to be sent from one computer to another  across the world-wide web.
[applet]
13) A(n) __________ is a piece of information passed to a method.
[argument]
 14 )___operator is used to crate an array.
[[]]
 15 )___method can be called without the instance of a class.
[static]
 16) When an interface method is implemented in a class. it must be declared as ___.
[Public]
 17 )___method of Math class returns the largest integer number less than or equal to given double value.
[floor]
 18) Strings that need modification are handled by ___ class.
[stringbuffer]
True/False Questions
1.         Main memory refers to the amount of storage space available on a computer’s disk drive.
TRUE  FALSE
[FALSE]
2.         Java is a high-level language.
TRUE  FALSE
[TRUE]
 3.        The Java compiler translates Java programs into machine language programs.
TRUE  FALSE
 [FALSE]

4.         Pseudocode is a mixture of English and a programming language.
TRUE  FALSE
 [TRUE]
 5.        The computer will not print an error message when a logic error occurs.
TRUE  FALSE
 [TRUE]
 6.        System.out is an example of a method.
TRUE  FALSE
 [FALSE]
 7.        In Java, the double equal sign means "make equal to".
TRUE  FALSE
 [FALSE]
 8.        ice-cream is an illegal identifier in Java.
TRUE  FALSE
 [TRUE]
Multiple-Choice Questions
1.         A bit can have __________ different values.
A.        2          B.        10        C.        100      D.        256
[A]

2.         Bytes in auxiliary memory are grouped into __________.
A.        bits      B.        files     C.        directories       D.        programs
[B]

3.         The kind of language that is easiest for people to use is
A.        assembly language                              B.        machine language
C.        low-level language                              D.        high-level language
[D]

4.         Input to a compiler is called
A.        a byte-code file           B.        source code     C.        an executable file        D.        object code
[B]

5.         The term __________ refers to a way of organizing classes that share properties.
A.        object-oriented            B.        encapsulation  C.        polymorphism D.        inheritance
[D]

6.         __________ means that two or more methods can have different names in the same way that an English word can have two or more meanings.
A.        object-oriented            B.        encapsulation  C.        polymorphism D.        inheritance
[C]
7.         A(n) __________ occurs when a program has a grammatical mistake like missing punctuation.
A.        syntax error     B.        run-time error  C.        logic error        D.        hidden error
[A]

8.         If the computer prints an error message while executing your program, the program contains a(n) __________.
A.        syntax error     B.        run-time error  C.        logic error        D.        hidden error
[B]

9.         Invoking a method means
A.        checking the method for errors           B.        designing the method
C.        asking the method to do its job          D.        revising the method
[C]

10.       In Java, a library of classes is called
A.        a folder            B.        a package        C.        a directory       D.        an application
[B]

11.       Which of the following is a variable declaration?
A.        "Enter number of apples:"
B.        totalFruitCount = appleCount + orangeCount;
C.        System.exit(0);
D.        int appleCount;
[D]

Chapter 2
Fill in the Blank Questions
1.         Every variable in Java must be __________ before it is used.
[declared]
2.         Single quotes are used with constants of the __________ type.
[char]
3.         __________ is the integer type you should use if you're not sure which one is best.
[int]
4.         An assignment statement always has a single __________ on the left side of the assignment operator.
[variable]
5.         A(n) __________ is used to change the type of a value.
[type cast]
6.         The value of 42 % 10 is __________.
[2]
7.         Double quotes are used with constants of the __________ type.
[String]
8.         The __________ operator is used to connect two strings to make one longer string.
[concatenation or +]
9.         To include a double quote inside a character string, you must use a(n) __________ character.
[escape]
10.       readChar and ReadLineLong are two methods in the __________ class.
[SavatchIn]
11.       __________ should explain non-obvious aspects of a program and should not be redundant with the code.
[comments]
12.       Using __________ variable names helps make a program self-documenting.
[meaningful]
True/False Questions
1.         An upper-case letter is considered to be the same character as a lower-case letter in Java.
TRUE  FALSE
[FALSE]
2.         The boolean type has only two values.
TRUE  FALSE
[TRUE]
3.         A variable can appear on both sides of the assignment operator in the same assignment statement.
TRUE  FALSE
[TRUE]

4.         3.65e2 is a legal integer constant in Java.
TRUE  FALSE
[FALSE]
5.         Use of a type cast sometimes causes values to be rounded.
TRUE  FALSE
[FALSE]
6.         A single declaration can include both initialized and uninitialized variables.
TRUE  FALSE
[TRUE]
7.         Arithmetic with floating-point numbers is not exact.
TRUE  FALSE
[TRUE]
8.         The value of 5 / 2 and the value of 5.0 / 2 are the same.
TRUE  FALSE
[FALSE]
Multiple-Choice Questions
1.         Which of the following is a class type?
A.        int        B.        double C.        char     D.        String
[D]

2.         Which of the following is not an integer type?
A.        double B.        short    C.        byte     D.        int
[A]

3.         Which of the following is a correct statement in Java?
A.        apes = monkeys + gorillas
B.        tigers = 3
C.        lions + tigers = cats;
D.        zebras += 5;
[D]

4.         println is a method used with __________
A.        objects of the String class       B.        the System.in object
C.        the System.out object             D.        the SavatchIn class
[C]

5.         Which of the following assignments would not be allowed without a typecast?
A.        assigning a short value to a long variable
B.        assigning a byte value to a double variable
C.        assigning an int value to a float variable
D.        assigning a double value to a long variable
[D]
6.         Which of the following operators has the highest precedence?
A.        unary +            B.        binary +           C.        %         D.        *
[A]

7.         In which expression could the parentheses be removed without changing the value of the expression?
A.        x * (y + z)                                B.        (w – x) / 3
C.        x * 3 /(y + 2)                           D.        (y  % 3) + 2
[D]

8.         Which statement best describes the statement: x++;
A.        It is incomplete and will cause a compiler error message if not modified.
B.        It will add 1 to the value of x.
C.        It will add 2 to the value of x.
D.        It will make the new value of x be the absolute value of the old value of x.
[B]

9.         The characters // in a line
A.        are part of an expression that uses integer division
B.        are part of an expression that uses integer division
C.        mean that the rest of the line is a comment
D.        are an escape sequence
[C]

10.       A number like 60 in a program should
A.        be replaced with a variable that has the same value
B.        be replaced with a named constant
C.        be explained by a comment
D.        be written as '60' if used as an integer
[B]
Chapter 3

Fill in the Blank Questions
1.         An ! in an expression means __________.
[not]
2.         A list of statements enclosed in curly brackets is called a(n) __________.
[compound statement] 
3.         A case label is used with a(n) __________ statement.
[switch] 
4.         A(n) __________ statement in a loop will cause the program to immediately exit the loop.
[break] 
5.         A(n) __________ is used for signaling the end of the input.
[sentinel value]

True/False Questions
1.         Every statement with if must also include else.
TRUE  FALSE
[FALSE]

2.         What is the value of the expression (x > 3) || (y < 3) if x has the value 1 and y has the value 5?
true                  false
[false] 
3.         The == operator can be used to see if two strings have the same characters.
TRUE  FALSE
[FALSE] 
4.         A multibranch if-else statement is one kind of nested if-else statement.
TRUE  FALSE
[TRUE] 
5.         The controlling expression of a switch statement must have a value that is an integer or a character.
TRUE  FALSE
[TRUE]

6.         The body of any while loop will be executed at least once.
TRUE  FALSE
[FALSE] 
7.         for loops and while loops use the same stopping mechanism.
TRUE  FALSE
[FALSE] 
8.         Java uses complete evaluation for Boolean expressions that use & instead of && and | instead of ||.
TRUE  FALSE
[TRUE]
Multiple-Choice Questions
1.         What will be the value of x after the following section of code executes:

int x = 5;
if (x > 3)
            x = x – 2;
else
            x = x + 2;

A.        1          B.        3          C.        5          D.        7
[B]

2.         What will be the value of y after the following section of code executes:

int y = 4, z = 3;
if (y > 4)
{
            z = 2;
            y = y – 1;
}
else
            z = 1;
y = z;

A.        1          B.        2          C.        3          D.        4
[A] 
3.         What will be the value of w after the following section of code executes:

int w = 4, q = 3;
if (q > 5)
            if (w == 7)
                        w = 3;
            else
                        w = 2;
else
            if (w > 3)
                        w = 1;
            else
                        w = 0;

A.        0          B.        1          C.        2          D.        3
[B] 
4.         What will be the value of b after the following section of code executes:

int a = 4, b = 0;
if (a < 5)
            b = 4;
else if (a < 10)
            b = 3;
else if (a > 5)
            b = 2;
else
            b = 1;

A.        1          B.        2          C.        3          D.        4
[A] 
5.         What will the following code print?

int color = 3;
switch (color)
{
case 1:
case 2:
            System.out.print("red ");
case 3:
            System.out.print("blue");
            break;
case 4:
            System.out.print("purple");
            break;
default:
            System.out.print("gray");
}

A.        red       B.        blue     C.        purple
D.        gray     E.         red blue
[B] 
6.         What will the following code print?

int count = 1;
while (count <= 3)
{
            System.out.print(count + " ");
            count++;
} 
A.        1 2 3    B.        1 2       C.        3          D.        1 1 1
[A] 
7.         What will the following code print?
 int count;
for (count = 4; count > 1; count--)
            System.out.print(count + " ");

A.        1 2 3 4 B.        1 2 3    C.        4 3 2    D.        4 3 2 1
[C]
Chapter 4

Fill in the Blank Questions
1.         A(n) __________ is an action that an object can take and is specified in the class definition.
[method]

2.         Compiling a file called Game.java will produce a file called __________.
[Game.class]

3.         A(n) __________ is a data item that belongs to an object.
[instance variable]

4.         __________ is the word used to say that there are no restrictions on the use of a method or data item can be used.
[public] 
5.         The reserved word __________ can be used as a name for the calling object.
[this] 
6.         Names of mutator methods usually begin with __________.
[set] 
7.         The interface of a class consists of comments, __________, and defined constants.
[headings of public methods] 
8.         To create an object of a class type, the word __________ is used.
[new] 
9.         One kind of method returns a value.  The other kind of method is called a(n) __________.
[void-method] 
True/False Questions
1.         All objects of the same class have the same data values.
TRUE  FALSE
[FALSE] 
2.         When a method call is executed, values from the method definition are substituted for the arguments in the method call.
TRUE  FALSE
[FALSE] 
3.         Parameters of a primitive type are passed to methods using the call-by-value mechanism.
TRUE  FALSE
[TRUE]

4.         Encapsulation is the process of defining a class that has no public methods.
TRUE  FALSE
[FALSE] 
5.         Private methods are part of the interface of a class.
TRUE  FALSE
[FALSE] 
6.         A variable of class type does not store an object of that class.
TRUE  FALSE
[TRUE] 
7.         An equals method should return a boolean value.
TRUE  FALSE
[TRUE] 
8.         A method can change the value of a variable of a primitive type that is an argument to the method.
TRUE  FALSE
[FALSE] 
9.         A method can change the value of instance variables of an argument that is of a class type.
TRUE  FALSE
[TRUE] 
Multiple-Choice Questions
1.         A method is invoked by
A.        writing the name of the method followed by a colon and the name of the calling object
B.        writing the name of the calling object followed by a dot and a list of values in parentheses
C.        listing the name of the calling object and the name of the method inside parentheses
D.        writing the name of the calling object, followed by a dot, followed by the name of the method and a list of values in parentheses
[D] 
2.         What can you tell about the method surpriseMe in the code below?
int something;
something = surpriseMe();
A.        It has no parameters but has a return value.
B.        It has one parameter but no return value.
C.        It has no parameters and it has no return value.
D.        It has one return value and an unknown number of parameters.
E.         It has one parameter and an unknown number of return values.
[A] 
3.         A data item that can only be used within a method is called
A.        a local variable                                    B.        an instance variable
C.        a global variable                                  D.        a private variable
[A] 
4.         Normally all instance variables are given the qualifier
A.        public  B.        protected         C.        private D.        static
[C] 
5.         One benefit of encapsulation is
A.        the implementation of the class will be smaller
B.        the implementation can be changed without changing programs that use the class
C.        the interface of the class will be smaller
D.        the interface can be changed without changing programs that use the class
[B] 
6.         When comparing two objects to see if they have the same contents, one should
A.        use the = operator
B.        use the == operator
C.        define an equals method in the class and use it
D.        use the equals method to see if they have the same variable name
[C]  
Chapter 5

Fill in the Blank Questions
1.         A __________ method is a method that can be invoked using the class name instead of an object name.
[static] 
2.         The method used to convert from Character to char is __________.
[charValue] 
3.         The method used to convert from String to Float is __________.
[parseFloat] 
4.         A(n) __________ is a simplified version of a method that is easily verified and is used for testing.
[stub] 
5.         In the technique of __________ design, the problem of designing a method is divided into subproblems, which are then solved using the same technique.
[top-down]

6.         A(n) __________ is a special kind of method used to initialize objects.
[constructor] 
7.         A(n) __________ is a collection of related classes that serves as a class library.
[package] 
True/False Questions
1.         The object and dot can be omitted in a non-static method call if the calling object is the this parameter.
TRUE  FALSE
[TRUE] 
2.         Instance variables cannot be referenced in the definition of any static method unless an object and dot precede the variable name.
TRUE  FALSE
[TRUE] 
3.         Java will use automatic type conversion before it will use overloading.
TRUE  FALSE
[FALSE] 
4.         It is possible to have two methods in the same class that have the same name, the same number and types of arguments, but different return types.
TRUE  FALSE
[FALSE] 
5.         A program will not run if more than one class in the program has a main method.
TRUE  FALSE
[FALSE] 
6.         Constructors have return type void.
TRUE  FALSE
[FALSE] 
7.         A class may have more than one constructor.
TRUE  FALSE
[TRUE]
Multiple-Choice Questions
1.         The method __________ in the Math class returns the nearest whole number that is equal to or less than its argument.
A.        abs       B.        min      C.        round   D.        floor
[D] 
2.         Which of these words is the name of a wrapper class?
A.        int        B.        float     C.        Double            D.        String
[C] 
3.         The term overloaded refers to
A.        an error where more than one method matches a method call
B.        two or more methods in the same class that have the same name
C.        method calls where there are two many actual parameters
D.        two or more methods in different classes that have the same name
[B] 
4.         Java will automatically define a constructor
A.        if the programmer does not define a default constructor for a class
B.        if the programmer does not define any constructors for a class
C.        if  the program refers to a constructor with no parameters
D.        for every class defined in a program
[B] 
5.         A private instance variable
A.        can never be modified by a method outside the class
B.        can be modified by a method outside the class if it is returned by a method
C.        can be modified by a method outside the class if it is a class type (with a mutator method) and is returned by a method
D.        can be modified by using an object name followed by a dot and then the name of the instance variable
[C] 
6.         The name of a constructor
A.        can be any legal identifier
B.        must include the name of the package
C.        will always be the word new
D.        will always be the same as the name of the class
[D]
Chapter 6

Fill in the Blank Questions
1.         The type of elements in an array is called the __________.
[base type] 
2.         Every array object has an instance variable called __________ that tells how many elements are in the array.
[length] 
3.         An array can be initialized by enclosing a list of values in __________.
[curly brackets]

4.         When a program looks at array elements in order from first to last to find a value, it is using the __________ algorithm.
[sequential search] 
5.         An array that uses more than one index is called a(n) __________ array.
[multidimensional] 
6.         The parameter to main is a(n) __________.
[array of Strings] 
7.         A two-dimensional array is implemented as a(n) __________.
[array of arrays] 
True/False Questions
1.         All data stored in an array must be the same type.
TRUE  FALSE
[TRUE] 
2.         The index to use with an array can be an expression whose value is computed when the program runs.
TRUE  FALSE
[TRUE] 
3.         If one element from an array is passed as a parameter to a method, then the called method can modify any element in the array.
TRUE  FALSE
 [FALSE] 
4.         Every array has a method called equals that can be used to compare it to other arrays.
TRUE  FALSE
[FALSE]

5.         An accessor method that returns an array should return a copy of an instance variable array rather than the instance variable itself.
TRUE  FALSE
[TRUE] 
6.         In a two-dimensional array, all of the rows must have the same number of elements.
TRUE  FALSE
[FALSE]
7.         The size of an array in Java is determined when the program is compiled.
TRUE  FALSE
[FALSE] 
Multiple-Choice Questions
1.         The lowest index that can be used with an array
A.        is zero
B.        is one
C.        is determined by the array declaration
D.        changes as the program runs
[A] 
2.         The highest index that can be used with an array
A.        is the number of elements in the array
B.        is the number of elements in the array minus one
C.        is determined by the array declaration
D.        changes as the program runs
[B]

3.         What will happen if a program uses an array index that is out of bounds?
A.        The compiler will give an error message and will not compile the program.
B.        The compiler will give a warning but will still compile the program.
C.        The program will compile but Java will give an error message when the program runs.
D.        The program will compile and run with no error messages but might give incorrect results.
[C] 
4.         Which statement best describes an array of 10 elements where the elements are of class String?
A.        10 String objects will be created when the array is created.
B.        10 String objects must be created before the array is created.
C.        The array will be created with the elements equal to null.
D.        Elements of an array cannot be a class type.
[C] 
5.         Selection sort works by repeatedly
A.        using the position of elements to split the list into two sublists of equal size
B.        finding the smallest element in the remainder of the list and moving it forward
C.        comparing adjacent elements in the list and swapping them if they are out of order
D.        using a threshold value to split the list into two sublists where one sublist's elements are greater than the threshold and the other sublist's elements are less than the threshold
[B] 
6.         Which of the following is correct Java code?
A.        int[10] list; B.  int list[10]; C.  int list = new int[10];D.          int[] list = new int[10];
[D]