Java Midterm Exam - Fully Solved (Graded A+), Exams of Biology

A fully solved java midterm exam, graded a+. It includes a variety of question types, such as true/false, multiple choice, and code snippets, covering fundamental java concepts. The solutions provided offer clear explanations and insights into the correct answers, making it a valuable resource for students preparing for java exams or seeking to reinforce their understanding of the language. The exam covers topics such as logical errors, variable scope, file input, object-oriented programming principles, array manipulation, and control structures. It also includes questions on java syntax, data types, and common programming practices, providing a comprehensive review of essential java knowledge.

Typology: Exams

2025/2026

Available from 10/24/2025

tutor-lee-1
tutor-lee-1 🇺🇸

4.3

(3)

11K documents

1 / 12

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Java - Midterm fully solved
2025(graded A+)
Logical errors are mistakes that cause the program to produce
erroneous results. - True or False - answer True
The contents of a variable cannot be changed while the program is
running. - True or False - answer False
Assume that inputFile references a Scanner object that was used to
open a file. Which of the following while loops shows the correct
way to read data from the file until the end of the file is reached? -
answer while (inputFile.hasNext())
Suppose you are at an operating system command line, and you are
going to use the following command to compile a program:
javac MyClass.java
Before entering the command, you must: - answer Make sure you
are in the same directory or folder where MyClass.java is located.
Another term for programs is: - answer Software
When an object's internal data is hidden from outside code and
access to that data is restricted to the object's methods, the data is
protected from accidental corruption. - True or False - answer True
Colons are used to indicate the end of a Java statement. - True or
False - answer False
In Java, you do not use the new operator when you use a(n): -
answer initialization list
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Java Midterm Exam - Fully Solved (Graded A+) and more Exams Biology in PDF only on Docsity!

Java - Midterm fully solved

2025(graded A+)

Logical errors are mistakes that cause the program to produce erroneous results. - True or False - answer True The contents of a variable cannot be changed while the program is running. - True or False - answer False Assume that inputFile references a Scanner object that was used to open a file. Which of the following while loops shows the correct way to read data from the file until the end of the file is reached? - answer while (inputFile.hasNext()) Suppose you are at an operating system command line, and you are going to use the following command to compile a program: javac MyClass.java Before entering the command, you must: - answer Make sure you are in the same directory or folder where MyClass.java is located. Another term for programs is: - answer Software When an object's internal data is hidden from outside code and access to that data is restricted to the object's methods, the data is protected from accidental corruption. - True or False - answer True Colons are used to indicate the end of a Java statement. - True or False - answer False In Java, you do not use the new operator when you use a(n): - answer initialization list

When an array is passed to a method: - answer 1) a reference to the array is passed

  1. it is passed just as an object
  2. the method has direct access to the original array Answer: All of these Java provides a set of simple unary operators designed just for incrementing and decrementing variables. - True or False - answer True What is the value of x after the following code has been executed? int x =75; int y=90; if ( x != y) x += y; - answer x = 165 Given the declaration double r; which of the following statements is invalid? r = 326.75; r = 9.4632e15; r = 9.4632E15; r = 2.9X106; - answer r = 2.9X106 is invalid. When testing for character values, the switch statement does not test for the case of the character. - True or False - answer False This is a special language used to write computer programs. - answer Programming language

int[] ragged = new int[5]; int[][] ragged = new int[5][6]; int[][] ragged = new int[5][]; int [][] ragged = new int[][5]; - answer int[][] ragged = new int[5][]; If str1 and str2 are both Strings, which of the following will correctly test to determine whether str1 is less than str2? (1) (str1 < str2) (2) (str1.equals(str2) < 0) (3) (str1.compareTo(str2) < 0) - answer (str1.compartTo(str2) < 0) To compile a program named First, use the following command: - answer javac First.java Which of the following is a correct method header for receiving a two-dimensional array as an argument? public static void passArray(int[1,2]) public static void passArray(int [][]) public static void passArray(int[1],[2]) public static void passArray(int[], int[]) - answer public static void passArray(int [][]) Every Java application program must have - answer a method named main Given the following statement, which statement will "Calvin" to the file DiskFile.txt?

PrintWriter diskOut = new PrintWriter("DiskFile.txt"); - answer diskOut.println("Calvin"); The ArrayList class is in this package. - answer java.util This type of loop is ideal in situations where the exact number of iterations is known. - answer for loop Syntax is: - answer Rules that must be followed when writing a program The while loop has two important parts: (1) a boolean expression that is tested for a true or false value, and (2) a statement or block of statements that is repeated as long as the expression is true. - True or False - answer True You can use this ArrayList class method to replace an item at a specific location in an ArrayList. - answer set What do you normally use with a partially-filled array? - answer An accompanying integer value that holds the number of items stored in the array These are used to indicate the end of a Java statement. - answer Semicolons This is an international coding system that is extensive enough to represent all the characters of all the world's alphabets: - answer Unicode The term __________ typically refers to the device that displays console output. - answer standard output device

double x = 45678.259; System.out.printf("%,.2f", x); - answer 45,678. _______ refers to the physical components that a computer is made of. - answer Hardware In memory, an array of String objects: - answer consists of elements, each of which is a reference to a String object. You use this method to determine the number of items stored in an ArrayList object. - answer numberItems Key words are: - answer Words that have a special meaning in the programming language _________ works like this: If the expression on the left side of the && operator is false, the expression the right side will not be checked. - answer Short-circuit evaluation The System.out.printf method formats a string and displays it in the console window. - True or False - answer True You can use this ArrayList class method to insert an item at a specific location in an ArrayList. - answer add If final int SIZE = 15 and int[] x = new int[SIZE], what would be the range of subscript values that could be used with x[]? - answer 0 through 14 Character literals are enclosed in ________; string literals are enclosed in ________. - answer single quotes; double quotes

Which of the following are pre-test loops? - answer while, for This is a boolean variable that signals when some condition exists in the program. - answer Flag Because the && operator performs short-circuit evaluation, your boolean expression will usually execute faster if the subexpression that is most likely false is on the left of the && operator. - True or False - answer True In the following Java statement what value is stored in the variable name? String name = "John Doe"; - answer The memory address where "John Doe" is located Enclosing a group of statements inside a set of braces creates - answer block of statements The data contained in an object is known as - answer attributes This is a set of programming language statements that, together, perform a specific task. - answer Procedure Which of the following is NOT a rule that must be followed when name identifiers? - answer Identifiers can contain spaces. What will be the values of x and y as a result of the following code? int x = 25, y = 8; x += y++; - answer x = 33, y = 9

What will be the value of z after the following statements have been executed? int x =4, y = 33; double z; z = (double) (y / x); - answer 8. Algorithm - answer Set of well-defined steps for performing a task or solving a problem Operator - answer symbols or words that perform operations on one or more operand (item of data) import statement needed for files? - answer import java.io.*; conditional operator - answer An alternate way of coding an if-else statement using three operands. The operator consists of a? and :. Syntax: BooleanExpression? Value 1: Value 2; What is the API? - answer Application Programmer Interface, standard library of prewritten classes for performing specific operations Three elements of a for loop? - answer Initialization, test, update import statement for the Scanner class - answer import java.util.Scanner; Encapsulation - answer combining data and code into a single object delimiter - answer item that separates other items

The if statement is used to create a decision structure, which allows a program to have more than one path of execution. The if statement causes one or more statements to execute only when a boolean statement is true. - True or False - answer True input validation - answer the process of inspecting data given to a program by the user and determining if it is valid The float data type is considered _____ precision, and the double data type is considered _______ precision. - answer single; double List some of the relational operators - answer >, >=, <, <=, ==, != literal - answer a value that is written into the code of a program method - answer a group of one or more programming statements that collectively has a name sentinel value - answer A special value that indicates the end of a set of data or of a process. running total - answer a sum of numbers that accumulates with each iteration of a loop priming read - answer the read operation that takes place just before the loop subscript - answer used as an index to pinpoint a specific element within an array