Docsity

Solutions for Java Programming, 10th Edition by Joyce Farrell | All Chapters, Exams of Nursing

Toggle sidebar
bg1
Solutions for Java Programming, 10th Edition by
Joyce Farrell | All Chapters
**1. Languages that let you use an easily understood vocabulary of
descriptive terms, such as read, write, or add, are known as
____________ languages.**
a. procedural
b. high-level
c. machine
d. object-oriented
**Answer: b. high-level**
**Rationale:** High-level languages use English-like terms and are
designed to be easy for humans to read and write. Java is a prime
example of a high-level language .
**2. The rules of a programming language constitute its
____________.**
a. syntax
b. logic
c. format
d. objects
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Partial preview of the text

Download Solutions for Java Programming, 10th Edition by Joyce Farrell | All Chapters and more Exams Nursing in PDF only on Docsity!

Solutions for Java Programming, 10th Edition by

Joyce Farrell | All Chapters

1. Languages that let you use an easily understood vocabulary of descriptive terms, such as read, write, or add, are known as ____________ languages. a. procedural b. high-level c. machine d. object-oriented Answer: b. high-level Rationale: High-level languages use English-like terms and are designed to be easy for humans to read and write. Java is a prime example of a high-level language. 2. The rules of a programming language constitute its ____________. a. syntax b. logic c. format d. objects

Answer: a. syntax Rationale: Syntax refers to the set of rules that defines the combinations of symbols that are considered to be correctly structured statements in that language. It's the grammar of the language. 3. A ____________ translates high-level language statements into machine code. a. programmer b. syntax detector c. compiler d. decipherer Answer: c. compiler Rationale: A compiler is a special program that translates source code written in a high-level language into low-level machine code that the computer's processor can execute. 4. Named computer memory locations are called ____________. a. compilers b. variables

a. method b. procedure c. object d. case Answer: c. object Rationale: A class is a blueprint or template for creating objects. An object is a concrete instance of a class, created (instantiated) from that blueprint. 7. You must compile classes written in Java into ____________. a. bytecode b. source code c. Javadoc statements d. object code Answer: a. bytecode Rationale: The Java compiler (javac) compiles Java source code (.java files) into an intermediate form called bytecode (.class files). Bytecode is platform-independent and is executed by the Java Virtual Machine (JVM).

8. All Java programming statements must end with a ____________. a. period b. comma c. closing parenthesis d. semicolon Answer: d. semicolon Rationale: In Java, the semicolon (;) is a statement terminator. It marks the end of a single executable statement. 9. All Java applications must have a method named ____________. a. method() b. main() c. java() d. Hello() Answer: b. main()

Answer: d. debugging Rationale: You must code, save, and compile a Java program to translate it into bytecode for the JVM to run. While debugging is a crucial part of development to fix errors, a program with bugs can still be compiled and run, though it may produce incorrect results. 12. The command to execute a compiled Java application is ____________. a. run b. execute c. javac d. java Answer: d. java Rationale: The java command is used to launch the Java Virtual Machine and execute the bytecode stored in a .class file. The javac command is used for compiling. 13. In a Java program, you must use ____________ to separate classes, objects, and methods. a. commas b. semicolons

c. dots d. forward slashes Answer: c. dots Rationale: The dot (.) operator is used to access members of a class or object, such as methods and fields. For example, System.out.println() uses dots to navigate from the System class to its out object and then to its println() method.

Chapter 2: Using Data

14. Which of the following is a valid declaration of a named constant? a. int SIZE = 99; b. final int SIZE = 99; c. constant int SIZE = 99; d. static int SIZE = 99; Answer: b. final int SIZE = 99;

d. 15 Answer: a. The value is: 15 Rationale: The + operator performs string concatenation when one of the operands is a String. The integer num is automatically converted to its string representation and appended to the literal string. 17. Which of the following is the correct syntax to create a Scanner object for keyboard input? a. Scanner input = new Scanner(System.in); b. Scanner input = new Scanner(keyboard); c. Keyboard input = new Scanner(System.in); d. new Scanner keyboard = System.in; Answer: a. Scanner input = new Scanner(System.in); Rationale: This line declares a Scanner variable named input and creates a new Scanner object that reads from the standard input stream (System.in), which is typically the keyboard. The class must be imported first with import java.util.Scanner;.

18. When you use a JOptionPane input dialog box to get a number from the user, the value is always returned as a ____________. a. int b. double c. String d. number Answer: c. String Rationale: The JOptionPane.showInputDialog() method always returns the user's input as a String object, regardless of what was entered. The programmer must then parse this String into a numeric type (e.g., using Integer.parseInt() or Double.parseDouble()). 19. What is the value of result after the following statement executes? double result = 15 / 4; a. 3. b. 3. c. 4. d. 3

21. What is the output of the following code? System.out.print("A"); System.out.print("B"); System.out.println("C"); System.out.print("D"); a. ABC on one line, D on the next b. ABC D on one line c. ABCD on one line d. AB on one line, C on the next, D on the next Answer: a. ABC on one line, D on the next Rationale: System.out.print() prints without a newline. System.out.println() prints and then moves the cursor to the next line. So "A" then "B" prints as "AB", then "C" prints with a newline, making it "ABC\n". Finally, "D" prints on the next line. 22. A method's return type can be ____________. a. a primitive type b. a class type c. void

d. all of the above Answer: d. all of the above Rationale: A method can return a primitive value (int, double, etc.), an object (String, Scanner, etc.), or nothing at all (void). 23. The method header public static void computeSum(double a, double b) indicates the method ____________. a. returns a double b. is private c. receives two double arguments d. receives two int arguments Answer: c. receives two double arguments Rationale: The parameters declared inside the parentheses (double a, double b) specify the type and name of data the method expects to receive. This method expects two double-precision floating- point numbers. 24. In the method header public static boolean isValid(int age), age is a(n) ____________. a. argument

26. A method that does not return a value has a return type of ____________. a. null b. none c. void d. empty Answer: c. void Rationale: The void keyword is used as the return type of a method to indicate that the method does not return any value. 27. Which of the following method declarations is correct for a static method named computeSum() if the method receives two double arguments and returns nothing? a. public static double computeSum(double a, double b) b. public static void computeSum(double a, double b) c. public void computeSum(double a, double b) d. static computeSum(double a, double b) Answer: b. public static void computeSum(double a, double b)

Rationale: static indicates it's a class method, void is the return type (meaning no return value), computeSum is the method name, and (double a, double b) shows it takes two double parameters.

Chapter 4: Using Classes and Objects

28. A class is best thought of as a ____________. a. specific object b. blueprint for an object c. method d. primitive data type Answer: b. blueprint for an object Rationale: A class defines the structure (attributes) and behavior (methods) that its objects will have. It is a template, while an object is a concrete instance created from that template. 29. What is the purpose of a constructor? a. To destroy an object b. To define the class's methods

31. If a class has a constructor that requires parameters, and you attempt to create an object using the default (no-argument) constructor, what will happen? a. The object will be created with default values. b. A compiler error will occur. c. The program will crash at runtime. d. Java will automatically create a no-argument constructor for you. Answer: b. A compiler error will occur. Rationale: If you provide any constructor(s) with parameters, the Java compiler does not automatically provide a default, no-argument constructor. You must explicitly define one if you want to use it. 32. Which of the following statements creates a new object of the Student class? a. Student myStudent; b. new Student myStudent; c. Student myStudent = new Student(); d. new Student(); Answer: c. Student myStudent = new Student();

Rationale: This statement declares a variable myStudent of type Student and then initializes it. The new keyword allocates memory for the object, and Student() calls the constructor to initialize it.

Chapter 5: Making Decisions

33. What is the output of the following code? int x = 10; if(x = 5) System.out.println("Equal"); else System.out.println("Not Equal"); a. Equal b. Not Equal c. Compiler error d. No output Answer: c. Compiler error