Chapter 1., CHAPTER 1

Ace your homework & exams now with Quizwiz!

Each byte is assigned a unique what?

Address

These are words that have special meaning in the programming language.

key words

These are symbols or words that perform operations on one or more operands.

operators

these are rules that must be followed when writing a program.

syntax

A byte is made up of eight what?

Bits

This type of memory can hold data for long periods of time - even when there is no power to the computer.

Secondary StorageI

1) A Java program is best classified as A) hardware B) software C) storage D) processor E) input Answer: B Explanation: B) Programs are classified as software to differentiate them from the mechanisms of the computer (hardware). Storage and the processor are two forms of hardware while input is the information that the program processes.

Software

18) The line of Java code "// System.out.println("Hello");" will A) do nothing B) cause "Hello" to be output C) cause a syntax error D) cause "(Hello)" to be output E) there is no way to know without executing this line of code

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

12) It is important to dissect a problem into manageable pieces before trying to solve the problem because A) most problems are too complex to be solved as a single, large activity B) most problems are solved by multiple people and it is easy to assign each piece to a separate person C) it is easier to integrate small pieces of a program into one program than it is to integrate one big chunk of code into one program D) our first solution may not solve the problem correctly E) all of the above

Answer: A Explanation: A) Any interesting problem will be too complex to solve easily as a single activity. By decomposing the problem, we can build small solutions for each piece and then integrate the pieces. Answer D is true, but it is not the reason why we will break a problem into pieces.

26) Which of the following is true regarding Java syntax and semantics? A) a Java compiler can determine if you have followed proper syntax but not proper semantics B) a Java compiler can determine if you have followed proper semantics but not proper syntax C) a Java compiler can determine if you have followed both proper syntax and semantics D) a Java compiler cannot determine if you have followed either proper syntax or semantics E) a Java compiler can determine if you have followed proper syntax and can determine if you have followed proper semantics if you follow the Java naming convention rules

Answer: A Explanation: A) Compilers for all languages 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 at this point).

31) Mistyping "println" as "printn" will result in A) a syntax error B) a run-time error C) a logical error D) no error at all E) converting the statement into a comment

Answer: A Explanation: A) 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.

22) Which of the following is a legal Java identifier? A) i B) class C) ilikeclass! D) idon'tlikeclass E) i-like-class

Answer: A Explanation: A) Java identifiers cannot have the characters "!", "'" or "-" in them making answer C, D and E wrong. The word "class" is a reserved word in Java and cannot be used as an identifier. The identifier "i" is perfectly legal although it is not necessarily a good identifier since it is not descriptive of its use.

27) Following Java naming convention, which of the following would be the best name for a class about store customers? A) StoreCustomer B) Store Customer C) storeCustomer D) STORE_CUSTOMER E) Store-Customer

Answer: A Explanation: A) The Java naming convention states that classes should all start with an upper case letter and that multiple-word names should start each new name with an upper case letter while the remaining characters are lower case. Words should either be connected together without spaces, or connected with the "_" character. Answers B and E are not legal names, and using Java naming convention, C would qualify as a variable name and D would qualify as a constant.

20) Which character below is not allowed in an identifier? A) $ B) _ C) 0 (zero) D) q E) ^

Answer: E Explanation: E) Java identifiers can consist of any letter, digit, $ or _ as long as the identifier starts with a letter or _. ^ is not a legal character.

If you were to look at a machine language program, you would see what?

a stream of binary numbers.

These are words or names that are used to identify storage locations in memory and parts of the program that are created by the programmer.

programmer-defined names

these characters serve specific purposes, such as marking the beginning or ending of a statement, or separating items in a list.

punctuation

This type of program is designed to be transmitted over the Internet and run in a Web browser.

Applet

23) 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 A) bytecodes B) syntax C) use of objects D) use of exception handling E) all of the above

Answer: A Explanation: A) 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.

15) In the following list, which statement is not true regarding Java as a programming language? A) It is a relatively recent language, having been introduced in 1995 B) It is a language whose programs do not require translating into machine language before they are executed C) It is an object-oriented programming language D) It is a language that embraces the idea of writing programs to be executed using the World Wide Web E) All of the above are true

Answer: B Explanation: B) All languages require translation into machine language. The other statements are all true about Java.

29) Which of the following is a legal Java identifier? 6 A) 1ForAll B) oneForAll C) one/4/all D) 1_4_all E) 1forall

Answer: B Explanation: B) Java identifiers cannot start with a number (so the answers in A, D and E are illegal) and cannot include the "/" character, so the answer in C is illegal.

16) Comments should A) rephrase the code it explains in English B) be insightful and explain what the instruction's intention is C) only be included in code that is difficult to understand D) be used to define variables whose names are not easy to understand E) all of the above

Answer: B Explanation: B) One might answer E, but that then includes A and C, making "all of the above" incorrect. Comments should not rephrase in English what an instruction says, but instead should explain what that instruction is doing in relation to the program. Introductory programmers often have difficult explaining their code and wind up stating the obvious in their comments. While answer D is partially correct, it is not entirely true all variables should have comments that explain their use.

19) The instruction: System.out.println("Hello World"); might best be commented as A) // prints "Hello World" to the screen B) // prints a message C) // used to demonstrate an output message D) // E) // meaningless instruction

Answer: C Explanation: C) Comments in A and B state the obvious while the comments in D and E are meaningless. The comment in C explains why the instruction appears in the program.

17) The main method for a Java program is defined by A) public static main( ) 3 B) public static main(String[ ] args); C) public static void main(String[ ] args) D) private static main(String[ ] args) E) the main method could be defined as in A, C or D but not B

Answer: C Explanation: C) In A, the parameter is missing. The parameters are defined later in the text, but in effect, they allow the user to run the program and include some initial arguments if the program calls for it. In B, the semicolon at the end of the statement is not allowed. In D, "private" instead of "public" would make the program non-executable by anyone and thus makes the definition meaningless.

28) Which of the following would be a good variable name for the current value of a stock? A) curstoval B) theCurrentValueOfThisStockIs C) currentStockVal D) csv E) current

Answer: C Explanation: C) Java allows long variable names but the programmer must find a good compromise between an excessive long name (as with B) and names too short to understand their use (A and D). The name current possibly might be reasonable if there are no other "current" values being referenced in the program.

24) Java is similar in syntax to what other high level language? A) Pascal B) Ada C) C++ D) FORTRAN E) BASIC

Answer: C Explanation: C) The creators of Java decided to use syntax similar to C++ so that C++ programmers could easily learn Java. Variable declarations, assignment statements, loops, selection statements and comments are among the features that have nearly identical syntax. There are many differences however, so don't assume that any C or C++ programmer will easily or instantly be able to program in Java.

25) An error in a program that results in the program outputting $100 instead of the correct answer, $250 is A) a programmer error B) a syntax error C) a run-time error D) a logical error E) a snafu

Answer: D 5 Explanation: D) While this is an error (answer A), programmers classify the type of error in order to more easily solve the problem. Syntax errors are caught by the compiler and the program cannot run without fixing all syntax errors. Run-time errors arise during program execution and cause the program to stop running. Logical errors are errors whereby the program can run to completion, but gives the wrong answer. If the result should have been $250, then the logic of the program is wrong since it output $100. A snafu is a term expressing a messed up situation in combat and should not be used by respectable programmers!

21) Which of the following is not syntactically legal in Java? A) public class Foo B) System.out.println("Hi"); C) { } D) s t a t i c main(String[ ] args) E) only B is legally valid, all of the rest are illegal

Answer: D Explanation: D) The Java compiler would not recognize "s t a t i c" as "static" because the Java 4 compiler treats white space (blanks) as separators between entities. The other statements are all legal, including "{ }" which is a block that happens to have no statements within it.

30) Which of the following characters does not need to have an associated "closing" character in a Java program? A) { B) ( C) [ D) < E) all of these require closing characters

Answer: D Explanation: D) { is used to open a block, and so } is needed to close the block. ( is used to open an expression and so ) is needed to close an expression. [ is used to start an array index so ] is needed to close the array index. < is "less than" and > is "greater than" and these are not needed together, so < requires no closing character.

13) Once we have implemented the solution, we are not done with the problem because A) the solution may not be the best (most efficient) B) the solution may have errors and need testing and fixing before we are done C) the solution may, at a later date, need revising to handle new specifications 2 D) the solution may, at a later date, need revising because of new programming language features E) all of the above

Answer: E Explanation: E) A program should not be considered as a finished product until we are reasonably assured that it is efficient and error-free. Further, it is common that programs require modification in the future because of a change to specifications or a change to the language or computer running the program.

Which memory capacity is the largest? A) 1,500,000,000,000 bytes B) 100 gigabytes C) 3,500,000 kilobytes D) 10 terabyte E) 12,000,000 megabytes

Answer: E Explanation: E) We convert each of these capacities to bytes (rounding off) to compare them. The value in A remains the same, 1 1/2 trillion bytes. The value in B is 100 billion bytes. The value in C is 3 1/2 billion bytes. The value in D is 10 trillion bytes. The answer in E is 12 trillion bytes.

14) Java is an example of a(n) A) machine language B) assembly language C) high-level language D) fourth generation language E) both C and D

Answer: E Explanation: E) While Java was created during the fourth generation, it is clearly also a high-level language. Machine language is the executable language of a machine, with programs written in 1s and 0s only. Assembly language uses mnemonics. Fourth generation languages are tools wrapped inside of programs so that the user has the flexibility to write some code to executed from within the program.

This part of the computer fetches instructions, carries out the operations commanded by the instructions, and produces some outcome or resultant information.

CPU

JVM stands for?

Java Virtual Machine

This is a named storage location in the computer's memory

Variable

The Java compiler generates?

byte code


Related study sets

GSCM 310 Test 1 - Old Quiz Questions

View Set

7 steps of preserving and recording the crime scene

View Set

Research Methods, Kazdin- Research in clinical psychology

View Set