LESSON 3 - SYNTAX, ERRORS AND DEBUGGING FILL IN THE BLANKS Complete the following sentences by writing the word or words in the blanks provided. 1. The set of all the words and symbols of a language is called the of the language. 2. A programming language varies from a natural language in three ways, size,, and literalness. 3. The Java programming language has a total of numeric data types. 4. Java's double floating-point data type requires bytes of storage. 5. An item in a program whose value can change during program execution is called a(n). 6. An arithmetic in Java consists of operands and operators combined in a manner similar to algebra. 7. A program statement that divides an integer value by a floating-point value is using arithmetic. 8. Java's String data type is a member of the data type category. 9. The method can be used to determine the current size of a String object. 10. Multi-line comments can be created in Java programs by opening and closing the block of text with the symbols and. 11. Sending a message to a variable before the corresponding object has been instantiated will cause a exception. TRUE/FALSE Circle T if the statement is true or F if the statement is false. T F 1. Java's syntax consists of the rules for combining words and symbols into a program statement. T F 2. Programming languages are much more complex than human languages. T F 3. Java's int data type requires 2 bytes of storage. T F 4. In Java, the String data type is one of the primitive data types. T F 5. When defining a variable in Java, you must always declare the variable's data type. T F 6. Unlike other programming languages, Java does not allow the use of parentheses to override the order of evaluation in an expression. T F 7. Java's modulus operator returns the value of the remainder in a divide operation. T F 8. Two string variables can be combined into one string variable by concatenating the strings. T F 9. All methods for Java objects are required to return some type of value to the calling routine. T F 10. Attempting to use a variable before it is declared will result in a run-time error when the program is run.
T F 11. Logic errors in a program are commonly referred to as bugs. MULTIPLE CHOICE Select the best response for the following statements. 1. Which of the following terms defines the rules for interpreting the meaning of a program statement? a. syntax. b. vocabulary. c. semantics. d. de-coding. 2. Which of the following options defines the category that Java's integer and floating-point data types belong to? a. intrinsic. b. primitive. c. object. d. numeric. 3. What is the maximum positive value that can be stored in a Java variable of type int? a. 32,755. b. 1,073,741,824. c. 2,147,483,647. d. 4,294,967,294. 4. What name is given to items in a program whose value does not change during program execution? a. literals. b. statics. c. fixed-variables. d. none of the above. 5. Which of the following statements shows the correct syntax for declaring a variable named alpha, of data type double? a. alpha = double;. b. alpha(double);. c. double(alpha);. d. double alpha;. 6. Which of the following keywords is used to declare a variable as a constant in a Java program? a. constant. b. final. c. literal. d. static. 7. A variable of one data type can be temporarily converted to a different data type to perform a calculation by using which of the following methods? a. casting. b. promotion. c. conversion. d. type-swapping.
8. What symbol does Java use to represent the escape character? a. /. b. ~. c. %. d. \. 9. What term is used in Java to refer to a class or a group of classes that are combined and imported into a Java program via the import statement? a. user-library. b. a package. c. a header file. d. an object set. 10. Which error type listed below cannot be automatically detected by a programming environment? a. syntax. b. run-time. c. logic. d. none of the above. 11. What type of error will occur if a program attempts to do an integer division by zero? a. logic. b. run-time. c. syntax. d. null pointer. WRITTEN QUESTIONS Write your answers to the following questions. 1. Describe the difference between the vocabulary, syntax, and semantics of a programming language. 2. What are the two categories of data types in the Java programming language? Give an example of which data types exist in each of the two categories.
3. Explain the difference between a literal and a variable. Provide one or two code statements to illustrate the difference. 4. What is required to define a variable in the Java language? Provide at least two programming statements defining variables of different data types. 5. What is meant by the term mixed-mode arithmetic? What can be done to avoid problems that could arise out of using mixed-mode arithmetic? 6. Explain the process of string concatenation. What would be the results of concatenating the following expressions? "My value is " + 3 + 4+ 5 "My value is " + 3 + (4 + 5) "My value is " + (3 + (4 * 5) "My value is " + 3 * 4
7. What is the difference between a method, a message, and a signature? 8. What is a package, and why and how is it used? 9. Give a brief description of the difference between syntax errors, run-time errors, and logic errors.