C - T/F -Combo

¡Supera tus tareas y exámenes ahora con Quizwiz!

20) Mistyping "println" as "printn" will result in a run-time error.< T/F > ?

F (Explanation: If the Java compiler cannot make sense of a command, the compiler cannot convert it and responds with a syntax error. While "println" is recognized as a command, "printn" is not, and so the compiler provides a syntax error. A run-time error can only occur when a program compiles without error.)

14) A constructor must always return an int.< T/F > ?

F (Explanation: In fact, a constructor cannot return anything. It has no return value, not even void. When a constructor is written, no return value should be listed.)

14) RAM is random access memory while ROM is not random access memory.

F (Explanation: It is true that RAM is random access memory, but so is ROM. ROM stands for read only memory, and it can be accessed using random access.)

15) In Java, it is possible to create an infinite loop out of while loops, but not for-loops.< T/F > ?

F (Explanation: It is true that while loops can be infinite loops, but it is also true that Java for-loops can be infinite loops. This is not true in many other programming languages where for-loops have a set starting and ending point, but Java for-loops are far more flexible than most other language's for-loops.)

9) Every class definition must include a constructor.< T/F > ?

F (Explanation: Java allows classes to be defined without constructors, however, there is a default constructor that is used in such a case.)

6) Java is a case-sensitive language meaning that Current, current, and CURRENT will all reference the same identifier.< T/F > ?

F (Explanation: Java is case sensitive which means that Current, current, and CURRENT will all be recognized as different identifiers. This causes problems with careless programmers who do not spell an identifier consistently in terms of upper and lower case characters.)

1) Java methods can return only primitive types (int, double, boolean, etc).< T/F > ?

F (Explanation: Java methods can also return objects, such as a String.)

9) Reserved words in Java can be redefined by the programmer to mean something other than their original intentions.< T/F > ?

F (Explanation: Java reserved words are the only things in Java that can not be redefined. )

16) The methods in a class should always be made public so that those outside the class can use them< T/F > ?

F (Explanation: Methods that need to be available for use outside a class should be made public, but methods that will only be used inside the class should be made private.)

19) The mod operator, %, can only be performed on int values and its result is a double.< T/F > ?

F (Explanation: Mod, or modulo, returns the remainder that results from an integer division. The remainder is also an integer. )

23) Modern computers store information in analog.

F (Explanation: Modern computers are digital. Every kind of information stored is broken down into pieces represented by numbers.)

4) Java byte codes are directly executable whereas Java source code is not.< T/F > ?

F (Explanation: Neither Java source code nor Java byte codes are executable. Both must be compiled or interpreted into machine code. Java byte codes are useful however in that they are machine-independent but semi-compiled code that allows your Java code to be transmitted over the Internet and executed on another computer even if that other computer is a completely different type.)

3) All Java classes must contain a main method which is the first method executed when the Java class is called upon.< T/F > ?

F (Explanation: Only the driver program requires a main method. The driver program is the one that is first executed in any Java program (except for Applets), but it may call upon other classes as needed, and these other classes do not need main methods.)

16) The programmer creates pseudocode during the implementation phase of program development.< T/F > ?

F (Explanation: Pseudocode is a description of an algorithm written in an English-like way rather than in a specific programming language. This is part of the program's design and would be done during the design phase. In the implementation phase, the programmer translates the pseudocode into the programming language being used.)

1) Only difficult programming problems require a pseudocode solution before the programmer creates the implementation (program) itself.< T/F > ?

F (Explanation: Some form of design should be created for all problems before the program is written, with the possible exception of only the most trivial of problems. The form of the design may vary. For instance, programmers in the 1960s and 1970s often used flow charts instead of pseudocode. )

5) The Java compiler is able to find all programmer errors.< T/F > ?

F (Explanation: The Java compiler can find syntax errors but cannot find either logical errors (errors that are caused because of poor logic in writing the program) or run-time errors (errors that arise during the execution of the program).)

20) The expression a || b will be true if either a or b is true, but not if both are true.

F (Explanation: The OR operator, ||, produces a true result if either or both of its operands are true.)

18) The relational operators < and > can be used to tell whether one string comes before another alphabetically.< T/F > ?

F (Explanation: The String class method compareTo should be used for that purpose. The operators < and > will not work with objects (and Strings are objects).)

13) For a computer to communicate over the Internet it must use the Ethernet protocol.

F (Explanation: The TCP/IP protocol is used to communicate over the Internet. Ethernet is a LAN protocol, which might be used in addition to TCP/IP in some networks, but it is not needed to communicate over the Internet.)

16) The line of Java code "// System.out.println("Hello");" will cause "Hello" to be output.< T/F > ?

F (Explanation: The characters "//" denote the beginning of a comment. The comment is not compiled and so, nothing would happen when this code is executed.)

24) The third portion of a for loop, the increment portion, must increment or decrement a variable by 1.< T/F > ?

F (Explanation: The increment portion can do any calculation, not just a simple increment or decrement.)

26) The for loop for (Team team : teamList) { ... } is invalid and will cause a syntax error.< T/F > ?

F (Explanation: The loop is a valid foreach statement and will iterate over every element in teamList, assigning each one to the variable team.)

2) Formal parameters are those that appear in the method call and actual parameters are those that appear in the method header.< T/F > ?

F (Explanation: The question has the two definitions reversed. Formal parameters are those that appear in the method header, actual parameters are the parameters in the method call (those being passed to the method).)

15) In order to create a constant, you would use the static reserved word.< T/F > ?

F (Explanation: The reserved word final would be used. It indicates that this is the final value that will be stored in this variable, thus making it unchangeable, or constant.)

18) The return statement must be followed a single variable that contains the value to be returned.< T/F > ?

F (Explanation: The return statement may be following by any expression whose type is the same as the declared return type in the method header. For example, return x*y+6; is a valid return statement. The statement return; is also valid for a method that does not return anything (void).)

25) The CPU is made up of three important components: the control unit, registers, and main memory.

F (Explanation: The three main components of the CPU are the control unit, registers, and the arithmetic/logic unit. The CPU interacts with main memory, but main memory is not a part of the CPU.)

18) Suppose that String name = "Frank Zappa". Then the instruction name.toUpperCase( ).replace('A', 'I'); will return "FrInk ZIppI".< T/F > ?

F (Explanation: The toUpperCase method returns the String as all upper case characters, or "FRANK ZAPPA". The replace method will replace each instance of 'A' with 'I', producing "FRINK ZIPPI". )

20) The word println is a reserved word.< T/F > ?

F (Explanation: The word println is a method on the System.out object, it is not a reserved word. )

4) When comparing any primitive type of variable, == should always be used to test to see if two values are equal.< T/F > ?

F (Explanation: This is true of int, short, byte, long, char and boolean, but not of double or float variables. If two double variables, x and y, are being tested, (x == y) is true only if they are exactly equal to the last decimal point. It is common instead to compare these two values but allow for a small difference in value. For instance, if THETA = 0.000001, we might test x and y by (x - y <= THETA) instead of (x == y) to get a better idea of if they are close enough to be considered equal.)

25) When reading an unknown amount of input from the user, a for loop would be the best choice.< T/F > ?

F (Explanation: When the amount of input is unknown, a while loop would be the best choice. For loops are generally used when it is already known how many times the loop body needs to execute.)

15) Java is an example of a fourth generation language.< T/F > ?

F (Explanation: While Java was created during the fourth generation, it is clearly a high-level language. Fourth generation languages are tools wrapped inside of programs so that the user has the flexibility to write some code to be executed from within the program.)

9) In order to compare int and double variables, you can use <, >, ==, !=, <=, >=, but to compare char and String variables, you must use compareTo( ), equals( ) and equalsIgnoreCase( ).< T/F > ?

F (Explanation: You can also directly compare char variables using <, >, ==, !=, <=, >=, but you must use compareTo( ), equals( ) and equalsIgnoreCase( ) for any String comparisons. )

22) If the integer variable answer is 5, then after answer %= 8; is executed, answer will be 3.

F (Explanation: answer %= 8 is the same as answer = answer % 8. Since answer is 5 and 5 % 8 is 5, answer will be assigned 5.)

2) If x is the String "Hi There", then x.toUpperCase().toLowerCase(); will return the original version of x.< T/F > ?

F (Explanation: x.toUpperCase() returns x as all capital letters, while x.toLowerCase() will return x as all lower case letters. So, this code will first convert x to all upper case letters and then convert the new version to all lower case characters.)

4) Java methods can return more than one item if they are modified with the reserved word continue, as in public continue int foo( ) { ... }

F(Explanation: All Java methods return a single item, whether it is a primitive data type an object, or void. The reserved word continue is used to bypass the remainder of a loop and test the condition again.)

1) If x is a string, then x = new String("OH"); and x = "OH"; will accomplish the same thing.< T/F > ?

T (Explanation: In Java, to instantiate (assign a value to) an object, you must use new and the class's constructor. However, since Strings are so common in Java, they can be instantiated in a way similar to assigning primitive types their values. So, both of the above assignment statements will accomplish the same task.)

8) Defining formal parameters requires including each parameters type.< T/F > ?

T (Explanation: In order for the compiler to check to see if a method call is correct, the compiler needs to know the types for the parameters being passed. Therefore, all formal parameters (those defined in the method header) must include their type. This is one element that makes Java a Strongly Typed language.)

4) If String a = "ABCD" and String b = "abcd" then a.equals(b); returns false but a.equalsIgnoreCase(b); returns true. < T/F > ?

T (Explanation: Since "ABCD" is not the same as "abcd", the equals method returns false, but by ignoring case in equalsIgnoreCase, the two are considered true. )

21) If a method takes a double as a parameter, you could pass it an int as the actual parameter.< T/F > ?

T (Explanation: Since converting from an int to a double is a widening conversion, it is done automatically, so there would be no error.)

For questions 12-14, assume that boolean done = false, int x = 10, int y = 11, String s = "Help" and String t = "Goodbye".) 12) The expression (!done && x <= y) is true.< T/F > ?

T (Explanation: Since done is false, !done is true. Since 10 < 11, x <= y is true. Therefore, the entire expression is true.)

17) Java is a strongly typed language which means every variable has a single type associated with it throughout its existence in the program, and the variable can only store values of that type.< T/F > ?

T (Explanation: Strong typing is a property of a programming language whereby the variable's type does not change during the variable's existence, and any value stored in that variable is of that type. The reason that strong typing is important is it guarantees that a program that was successfully compiled will not have run-time errors associated with the misuse of types for the variables declared.)

11) The following loop is syntactically valid. for(int j = 0; j < 1000; j++) j--;< T/F > ?

T (Explanation: The Java compiler does not care that you are incrementing j in the loop but decrementing j in the loop body. Logically, this loop makes no sense because j will continuously be incremented and decremented so that it never reaches 1000, but there is nothing wrong with the loop syntactically.)

5) Unlike the String class where you must pass a message to an object (instance) of the class, as in x.length( ), in order to use the Math class, you pass messages directly to the class name, as in Math.abs( ).< T/F > ?

T (Explanation: The Math class uses methods known as static methods (or class methods) which are invoked by passing a message directly to the class name itself rather than to an object of the class.)

12) The NumberFormat class can be used to format percentages and currencies.< T/F > ?

T (Explanation: The NumberFormat class has static methods getCurrencyInstance and getPercentInstance that can be used to obtain NumberFormat objects to format currencies and percentages respectively.)

23) If you want to use classes from a package other than java.lang, you must import them.< T/F > ?

T (Explanation: The classes in java.lang are automatically imported, but classes in any other package must be imported by the programmer using an import statement.)

7) Code placed inside of comments will not be compiled and therefore will not execute.< T/F > ?

T (Explanation: The compiler discards comments, therefore, any code inside of comments is discarded and not compiled. Your executable program consists only of the code that is compiled. )

1) All information is stored in the computer using binary numbers.< T/F > ?

T (Explanation: The computer is a digital device meaning that it stores information in one of two states using binary. We must determine then how to represent meaningful information (such as a name or a program instruction or an image) in binary. )

12) The "execute" phase of the fetch-decode-execute cycle might use a circuit in the arithmetic-logic unit.< T/F > ?

T (Explanation: The fetch phase fetches the next program instruction from memory. The decode phase determines which circuit(s) needs to be used to execute the instruction. The instruction is executed in the execute phase. If the instruction is either an arithmetic operation (like add or multiply) or logical operation (like comparing two values), then it is carried out by the ALU.)

2) In Java, if and if-else are selection statements.< T/F > ?

T (Explanation: The if and if-else allow you to make a selection in a program.)

6) A method defined in a class can access the class' instance data without needing to pass them as parameters or declare them as local variables.< T/F > ?

T (Explanation: The instance data are globally available to all of the class' methods and therefore the methods do not need to receive them as parameters or declare them locally. If variables of the same name as instance data were declared locally inside a method then the instance data would be "hidden" in that method because the references would be to the local variables.)

7) The interface of a class is based on those data instances and methods that are declared public.< T/F > ?

T (Explanation: The interface is how an outside agent interacts with the object. Interaction is only available through those items declared to be public in the class' definition. )

17) The body of a method may be empty.< T/F > ?

T (Explanation: The method body may have 0 or more instructions, so it could have 0. An empty method body is simply { } with no statements in between.)

14) The Random class has a method nextDouble( ) which returns a random double value between 0 and 1.< T/F > ?

T (Explanation: The method nextDouble( ) returns a double value between 0 and 1 so that it could be used as a probability.)

19) The number and types of the actual parameters must match the number and types of the formal parameters.< T/F > ?

T (Explanation: The names of the corresponding actual and formal parameters may be different but the number and types of the parameters must match.)

23) The println method on System.out is overloaded.< T/F > ?

T (Explanation: The println method includes versions that take a String, int, double, char, and boolean.)

5) The following method header definition will result in a syntax error: public void aMethod( );< T/F > ?

T (Explanation: The reason for the syntax error is because it ends with a ";" symbol. It instead needs to be followed by { } with 0 or more instructions inside of the brackets. An abstract method will end with a ";" but this header does not define an abstract method.)

5) The statements x++; and ++x; will accomplish the same thing.< T/F > ?

T (Explanation: The statements x++; and ++x; both increment x. )

17) A unique aspect of Java that allows code compiled on one machine to be executed on a machine of a different hardware platform is Java's bytecodes.< T/F > ?

T (Explanation: The translation process for a Java program is to first compile it into bytecodes, which are architecturally neutral (that is, they can be used no matter what the architectural platform is). To execute the program, the bytecodes must be further compiled by a Java compiler or interpreted by a Java Virtual Machine.)

11) An enumerated type defined by "enum Grade {A, A-, B+, B, B-, C, D, F}" is invalid.< T/F > ?

T (Explanation: The values of an enumerated type are identifiers and must follow the rules for identifiers. A valid identifier cannot use - or +.)

27) A foreach statement can be used to loop through all the possible values of an enumerated type.< T/F > ?

T (Explanation: The values() method of an enumerated type returns a list of all the values and can be used in a foreach loop.)

3) If String name = "George W. Bush"; then the instruction name.length(); will return 14.< T/F > ?

T (Explanation: There are 14 characters in the quote marks including two blanks and a period,)

9) You cannot cast a String to be a char and you cannot cast a String which stores a number to be an int or double.< T/F > ?

T (Explanation: There is no mechanism available to cast a String to one of the primitive types, but there are methods available to perform a similar action and return a character at a given location (charAt) or to return the int or double value equivalent to the number stored in the String.)

10) The following for-loop is an infinite loop. for(int j = 0; j < 1000; ) i++;< T/F > ?

T (Explanation: This loop initializes j to 0 and compares it to 1000, but does not alter j after each loop iteration. In reality, the loop will terminate with a run-time error eventually once i becomes too large of a value to store in memory, but logically, this is an infinite loop.)

7) The statement if (a >= b) a++; else b--; will do the same thing as the statement if (a < b) b--; else a++;.< T/F > ?

T (Explanation: We can reverse the if clause and else clause if we reverse the condition. The opposite condition of (a >= b) is (a < b) so this works out logically. Note that if we used the condition (a <= b) then the resulting statement would not do the same thing as the original if a==b.)

6) A double is wider than an int.< T/F > ?

T (Explanation: Wider types are larger in size or can store a greater range of values. The double is 64 bits and because of the way it is stored, can store a significantly larger range of values than the int.)

21) The statement num -= num; will have the same result as the statement num = 0;< T/F > ?

T (Explanation: num -= num subtracts num from num, producing 0, and assigns the 0 to num. It is the same as saying num = num - num;)

23) Any for loop can be written as a while loop.

T. (Explanation: In fact, any kind of loop can be written as any other kind of loop. (Note that the if statements are not loops - they are selection statements.) See figure 3.11 for the general equivalent structure of for and while loops.)

21) One terabyte is equivalent to approximately 1000 gigabytes.

T. (Explanation: One terabyte is 210, or 1024, gigabytes, which is approximately 1000.)

12) A constructor is a method that gets called automatically whenever an object is created, for example with the new operator.

T. (Explanation: The constructor is used to initialize an object and it gets called whenever a new object is created from a particular class.)

22) An operating system is considered software.

T. (Explanation: The operating system is the main software of a computer.)

19) A black and white picture can be stored by representing each pixel using a single bit.

T. (Explanation: We can use a single bit, where 0 means white and 1 means black, to represent each pixel.)

19) The expression 'Z' < 'a' is true.

T. (Explanation: When characters are compared, their corresponding Unicode value is used, and all uppercase letters have lower Unicode values than all lowercase letters.)

24) Data written to a memory location overwrites and destroys any information that was stored at that location.

T. (Explanation: When data is written to a memory location, any data that was previously stored there is lost.)

24) The operators * and + have the same precedence.< T/F > ?

F The * operator has higher precedence than +, so it is performed first in an expression (unless otherwise noted using parenthesis).)

8) An if statement may or may not have an else clause, but an else clause must be part of an if statement.< T/F > ?

T (Explanation: Java allows for either if or if-else statements. But else is only used as part of an if statement.)

2) Java is an object-oriented programming language.< T/F > ?

T (Explanation: Java is classified as a high-level programming language but it is also classified as an object-oriented programming language because it allows the programmer to implement data structures as classes.)

11) Binary numbers are composed entirely of 0s and 1s.< T/F > ?

T (Explanation: Binary is base 2. In Mathematics, numbers in base n are composed entirely of digits between 0 and n-1.)

13) You would import the java.text library to use NumberFormat and DecimalFormat.< T/F > ?

T (Explanation: Both of these classes are used for "text processing", that is, to handle values like Strings. Such classes are found in java.text.)

8) In Java, 'a' and 'A' are considered to be different values.< T/F > ?

T (Explanation: Characters (char) values are stored using Unicode, and 'a' and 'A' have different Unicode values.)

22) Wrapper classes in Java allow you to create objects representing primitive data.< T/F > ?

T (Explanation: Every primitive type has a corresponding wrapper class. For example, the Integer class wraps the int type.)

22) A method defined without a return statement will cause a compile error.< T/F > ?

F (Explanation: If a method is declared to return void then it doesn't need a return statement. However, if a method is declared to return a type other than void, then it must have a return statement.)

18) A Java compiler can determine if you have followed both proper syntax and semantics.< T/F > ?

F (Explanation: Compilers in any language have the ability to detect syntax errors because improper use of the syntax leads to situations where the compilers cannot translate the code properly. However, compilers are unable to follow the semantics of a program because this requires a degree of understanding what the program is intended to do and computers have no sense of understanding (at least to this point).)

For questions 12-14, assume that boolean done = false, int x = 10, int y = 11, String s = "Help" and String t = "Goodbye".) 13) The expression (s.concat(t).length( ) < y) is true.< T/F > ?

F (Explanation: Concatenating s and t gives a String that is 11 characters long and 11 < 11 is false.)

10) In a Java program, dividing by 0 is a syntax error.< T/F > ?

F (Explanation: Dividing by 0 is not detected at compile time, and because a computer cannot divide by 0, this is a run-time error. )

25) Since double to int is a narrowing conversion, there is no way to convert a double to an int.< T/F > ?

F (Explanation: Going from double to int is a narrowing conversion, but it is possible to do using a cast.)

3) In Java, the symbol "=" and the symbol "==" are used synonymously (interchangeably).< T/F > ?

F (Explanation: "=" is used for assignment statements while "==" is used to test equality.)

8) The word "Public" is a reserved word.< T/F > ?

F (Explanation: "public" is a reserved word, but since Java is case sensitive, "Public" differs from "public" and "Public" is not a reserved word.)

7) A variable of type boolean will store either a 0 or a 1.< T/F > ?

F (Explanation: A boolean variable can store only one of two values, but these values are the reserved words true and false. In C and C++, booleans are implemented as int variables that store only a 0 or a 1, but in Java, the authors of the language opted to use the boolean literals true and false as this is considered to be semantically more understandable.)

11) A class may contain methods but not variable declarations.< T/F > ?

F (Explanation: A class may contain both methods and variable declarations.)

15) A class's instance data are the variables declared in the main method.< T/F > ?

F (Explanation: A class's instance data are declared in the class but not inside any method. Variables declared in a method are local to that method and can only be used in that method. Furthermore, every class need not have a main method.)

21) A Java variable is the name of a data value stored in memory that can not change during the program's execution.< T/F > ?

F (Explanation: A variable can change its value as long as it is within the same type, but the variable cannot change type. )

17) Software design is the first step in program development.< T/F > ?

F (Explanation: Before a design can be made we must understand the problem, which is done by establishing requirements.)

For questions 12-14, assume that boolean done = false, int x = 10, int y = 11, String s = "Help" and String t = "Goodbye".) 14) The expression (done | | s.compareTo(t) < 0) is true.< T/F > ?

F (Explanation: Both done is false and s.compareTo(t) < 0 is false since s does not come before t alphabetically, so the entire expression is false.)

3) System.out.print is used in a program to denote that a comment follows.< T/F > ?

F (Explanation: Comments follow // marks or are embedded between /* and */. System.out.print is an instruction used to output a message to the screen (Java console window).)

10) With an enumerated type, the programmer defines the possible values of the type.< T/F > ?

T (Explanation: An enumerated type, defined using the reserved word enum, lists out, or enumerates, all possible values of a variable of that type.)

16) If a, b and c are int variables with a = 5, b = 7, c = 12, then the statement int z = (a * b - c) / a; will result in z equal to 4.< T/F > ?

T (Explanation: (a * b - c) / a = (5 * 7 - 12) / 5 = (35 - 12) / 5 = 23 / 5, and since 23 and 5 are int values, the division is performed as an int division, or 23 / 5 = 4.)

6) The statement { } is a legal block.< T/F > ?

T (Explanation: A block consists of "{", followed by 0 or more Java statements, followed by "}". So it is acceptable to have no statements between the brackets. Situations where this is necessary occur in Java, particularly when implementing methods of abstract classes, something you will study later.)

10) While multiple objects of the same class can exist, there is only one version of the class.< T/F > ?

T (Explanation: A class is an abstraction, that is, it exists as a definition, but not as a physical instance. Physical instances are created when an object is instantiated using new. Therefore, there can be many objects of type String, but only one String class.)

13) A constructor must have the same name as its class.< T/F > ?

T (Explanation: A constructor is required to have the same name as the class.)

20) The different versions of an overloaded method are differentiated by their signatures.< T/F > ?

T (Explanation: A method's signature includes the number, types, and order of its parameters. With overloaded methods, the name is the same, but the the methods must differ in their parameters.)


Conjuntos de estudio relacionados

world religions and philosophy test 1

View Set

Module 5 Chapter 13,14,15 Network Security, Firewalls and VPN Second Edition

View Set

Vsim Carla Hernandez Pre/Post-test

View Set

PN NCLEX 6th Edition- Leadership/Ethical/Legal

View Set

Final Practice Questions, Module 5, Module 4, Module 7, Module 2, Module 1

View Set