Java Midterm Study Guide

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

javas syntaxes is similar to the syntax of a. C++ b. python c. scheme d. x86 ASM

a. C++

Which class are all exceptions subclasses of? a. Exception b. IllegalArgumentException c. RuntimeException d. NumberFormatException

a. Exception

What is in result after the following code executes? int x = 2; int y =3; int z = 4; int result = z - ++x * y--;

-5

What is in the result after the following code executes? int x = 2; int y = 3; int z = 4; int result = z -y * z +10;

8

assume there's a java project in the root directory of the F drive. it is called project 1. it is in a package called my package. it only has one file of source code and it is for the class called Project 1. What is the complete file specification (windows, not Linux) of the source code file?

F:\project1\src\mypackage\Project1.java

the extension for a java source file is a. .java b. .class c. .js d. .jsf

a. .java

Wat is in discount after the following code executes: double discount = 0; double sales = 250; if (sales > 100) { discount = .15; } a. 0.15 b. 0.0 c. 0.10 d. 0.25

a. 0.15

What is the value of routeNumber after the following code is executed? int zipCode = 93705; int routeNumber = switch (zipcode) { case 93705, 93706 -> 1; case 93710, 93720 -> 2; default -> 0; a. 1 b. 93705 c. 0 d. 2

a. 1

What is the value of c after the following code is executed? int a = 5; int b = 2; int c = 10; c = c + b * 5 c / a; a. 18 b. 10 c. 58 d. 55

a. 18

What is the value of x after the following statements are executed? int x = 5; switch (x) { case 5: x += 2; case 6: x++; break; default: x*=2; break } a. 8 b. 7 c. 6 d.16 e. 10

a. 8

If number contains 500, what will be printed to the console when the following code runs? if(number >= 100) System.out.print("A"); else if (number >=200) System.out.print("B"); else System.out.print("c"); a. A b. B c. C d. AB e. ABC

a. A

In a do-while loop, the Boolean expression is tested a. both before and after the loop's statements are being executed b. while the loop's statements are being executed c. before the loop's statements are executed d. after the loop's statements are executed

d. after the loop's statements are executed

To determine the cause of an unhandled exception, you can a. use the name of the exception class that's displayed b. use the error message that's displayed c. use the information in the stack trace d. all of the above

d. all of the above

In a while loop, the Boolean expression is tested a. after the loop's statements are executed b. both before and after the loop's statements are being executed c. while the loop's statements are being executed d. before the loop's statements are executed

d. before the loop's statements are executed

Which of the following statements can you use to end a loop from within the loop? a. end b. repeat c. continue d. break

d. break

You code an access modifier on a static method to indicate if it a. returns a value b. is overloaded c. accepts parameters d. can be called from other classes

d. can be called from other classes

block scope means that a variable a. can't be used as a cou ter in a while loop b. cant be used outside of the statement that its declared in c. cant be used in boolean expression d. cant be used outside of the set of braces that its declared in

d. cant be used outside of the set of braces that its declared in

Which of the following formats can you not apply using the NumberFormat class? a. percent b. currency c. general number d. fraction

d. fraction

Which package is automatically available to all java programs? a. java.basic b. java.basic c .java.text. d. java.lang

d. java.lang

The following condition will be true when (!choice.equalsIgnoreCase("n")) a. the value of choice equals "n" b. the value of choice doesn't equal "n" c. the value of choice equals "n" or "N" d. the value of choice doesn't equal "n" or "N"

d. the value of choice doesn't equal "n" or "N"

What is the value of b after the following code is executed? int valueA = 0; //line 1 double value B= 24.0; //line 2 valueA = valueB; //line 3 a. an implicit cast will automatically happen in line 3 b. you will need to code an implicit cast in line 3 c. an explicit cast will automatically happen in line 3 d. you will need to code an explicit case in line 3

d. you will need to code an explicit case in line 3

as you develop a java application, you can use an IDE to a.enter and edit the source code b.compile the source code c.run the application d.all of the above e.both b and c

d.all of the above

When you call a method that has a parameter list, the arguments in the argument list a. must be coded in the same sequence as the parameters b. must have data types that are compatible with the data types of the parameters c. must have the same names as the parameters d. all of the above e. a and b only

e. a and b only

To handle an exception using the try statement, you must a. code a try block around the statement that may throw the exceptions b. code a catch block that contains the statements to execute instead of the statements in the try block c. code a catch block that contains the statements that you want to be executed when the exception occurs d. all of the above e. a and c only

e. a and c only

Which of the following data types is designed to store whole numbers (no decimal positions)? a. int b. long c. short d. A and B only e. all of the above

e. all of the above

an IDE typically stores all of the files for an application in a a.class b.library c.project d.package

project

Based on the naming recommendations in the book, which of the following is a good identifies for a constant that will be used to hold a base shipping charge? a. BASESHIPPINGCHARGE b. BASE-SHIPPING-CHARGE c. baseShippingCharge d. BaseShippingCharge e. BASE_SHIPPING_CHARGE

BASE_SHIPPING_CHARGE

The following class name is both valid and appropriate (according to standard naming conventions): Test a. True b. False

a. True

The following variable name is both calid and appropriate (according to standard naming conventions): monthlyInterestRate a. True b. False

a. True

When is the code within a catch block executed? a. When the exception specified in the catch block is thrown in the try block b. When the try block finishes executing c. When the code in the try block doesn't compile d. When a runtime error occurs

a. When the exception specified in the catch block is thrown in the try block

The block of statements that's executed when an exception is caught is called ____________________. a. an exception handler b. a stack trace c. a guard d. a try block

a. an exception handler

When a statement within a try block causes an exception, the remaining statements in the try block a. are skipped over and not executed b. are executed before the statements in the catch block c. are executed after the statements in the catch block

a. are skipped over and not executed

Which of the following data types is designed to store true/false values? a. boolean b. char c. byte d. A and B only e. all of the above

a. boolean

the java compiler takes the source code for an application and translates it into a. bytecode b. binary c. assembly language d. machine code

a. bytecode

You can use relational operators to a. compare string variables b. compare numeric variables c. both a and b d. neither a nor b

b. compare numeric variables

Which of the following data types is designed to store numbers with decimal positiions? a. byte b. float c. long d. boolean e. all of the above

b. float

Checking a value to be sure that it's greater than a minimum value and less than a maximum value is known as ____________________. a. range checking b. range guarding c. data importing d. data checking

a. range checking

You can use a Scanner object to: a. read a line of text from the console b. scan your java code for exception c. print a line of text the console d. print a blank line to the console

a. read a line of text form the console

if a class contains a main() method is executed a. when a class is run b. when the class is compiled c. when an object is created from the class d. none of the above

a. when the class is run

What is in discount after the following code executes: double discount = 0; double sales = 50; if(sales > 100) { discount = .15; } else if (sales > 50) { discount = .10; a. 0.15 b. 0.0 c. 0.10 d. 50.00

b. 0.0

If the user enters "C" at the first console prompt, what value does the following code display on the console? Scanner sc = new Scanner(System.in); String option = " "; int entries = 0; do{ entries++; System.out.print("Enter 'c' to continue: "); } while (option.equals("c")); System.out.println(entries); a. 3 b. 1 c. 0 d. 2

b. 1

How many lines are printed to the console when the following for loops are executed? for (int i - 0; i < 5; i++) { for (int j = 0; j < 3; j++) { System.out.println(i + " , " + j); } } a. 24 b. 15 c. 8 d. 4

b. 15

What is the value of x after the following statements are executed? int x = 5; switch (x) { case 5 -> x += 2; case 6 -> x++; default -> x*= 2; } a. 8 b. 7 c. 6 d. 10 e. 16

b. 7

If expression1 is false, expression2 is false and expression3 is true, what does the following evaluate to? expression1 || expression2 && expression3 || expression2 a. True b. False

b. False

The following class name is both valid and appropriate (according to standard naming conventions): salesCalculator a. True b. False

b. False

The following variable name is both valid and appropriate (according to standard naming conventions): a. True b. False

b. False

The following variable name is both valid and appropriate (according to standard naming conventions): SalesTax a. True b. False

b. False

What will be printed after the following code executes: double total = 275.5; String label = "Total:"; System.out.printf("%s%, 9.2f%n", label, total); a. Total: $275.50 b. Total: 275.50 c. Total: 275.5 d. Total: 275.50

b. Total: 275.50

Casting a variable from short to int is a. a narrowing conversion b. a widening conversion c. cannot be done d. will cause a syntax error

b. a widening conversion

EXPLAIN how bytecodes help java achieve platform independence. a. the java compiler translates the source code into a different format that is platform independent, AKA bytecode. The java interpreter translates the bytecode into a native code. this code can be understood by the operating system. b. java source code is compiled into bytecodes. Java bytecodes can be run on any machine that has a java runtime environment (JRE).a JRE includes a java virtual machine (JVM). JRE's are available for all major operating systems. So you can run java on most platforms. this gives java platform independence. (doesn't need a specific compiler for each platform).

b. java source code is compiled into bytecodes. java bytecodes can be run on any machine hat has a JRE. a JRE includes a JVM. JRE's are available for all major operating systems. so you can run java on most platforms. This gives java platform independence. (doesn't need a specific compiler for each platform.

Consider the following code: char letter1; //line 1 char letter2; //line 2 char letter3; //line 3 char letterA = 10; //line 4 letter1 = 113; //line 5 letter2 = "A"; //line 6 letter3 = (char) valueA; //line 7 Which line(s) of code have syntax errors? a. line 5 b. line 6 c. line 7 d. line 5, 6, 7 e. line 6, 7

b. line 6

You can use a System.out object to: a. exit the console. b. print a blank line to the console c. read the next token from the console d. read a line of text from the console

b. print a blank line to the console

What is the value of max after the code that follows is executed? int number = 0; int max = 0; for (int i =0; i <= 10; i++) { number = (int) (Mat.randow() * 100); if (number >=max) { max = number; } } a. the largest of eleven random numbers from 100 to 1000 b. the largest of eleven random numbers from 0 to 99 c. the largest of ten random numbers from 100 to 1000 d. the largest of ten random numbers from 0 to 99

b. the largest of eleven random numbers from 0 to 99

If you use a short-circuit operator to combine two expressions a. both expressions are always evaluated b. the second expression is evaluated only if it can affect the result c. the first expression is evaluated only if it can affect the result d. the result of the expressions are reversed

b. the second expression is evaluated only if it can affect the result

the int data type is designed to store a. dates b. whole numbers c. true or false values d. floating point numbers

b. whole numbers

which or the following is not a benefit of a typical IDE for java? a. the IDE helps you complete code as you type b. your code compiles and runs faster c. the syntax of your code is checked as you enter it d. the debugging features make it easier for you to find bugs in your applications

b. your code compiles and runs faster

After the following statements execute, what is the value of the variable named tax? a. 1239.0 b. 12.40 c. 12.39 d. 12

b.12.40

What does the following code print to the console? int nume = 5; System.out.printf("%d * %d is %d.$n", num, num, num*num); a. d*d is d*d.n b.5*5 is 25. c. 5*5 is 5. d. num*num is num*num.

b.5*5 is 25.

What is printed on the console when the following statements are executed? String userName = "Tom"; int userAge = 22; System.out.println(userAge + " \nis " + userName + " 's age."); a. 22 is Tom's age b. 22\nis Tom's age c. 22 is Tom's age d. 22\n is toms age.

c. 22 is Tom's age

What is the value of r after these statements are executed? int input = 755; NumberFormat n = NumberFrmat.getNumberInstance(); n.setMinimumFractionDigits(3); String r = n.format(input); a. 760.000 b. .755 c. 755.000 d. 755

c. 755.000

What is the value of entry after the following statements are excuted? int entry = 9; int number = 3; if (entry > 9 || entry/number == 3) { entry --; } else if (entry ==9 { entry ++; } else { entry = 3; } a. 10 b. 9 c. 8 d. 3

c. 8

What does the following statement do in a java application? import java.util.Scanner; a. It scans for syntax errors in the application. b. It makes the classes of the Scanner package available to the application c. It makes the Scanner class available to the application without qualification. d. It copies user entries into the main() method of the application.

c. It makes the Scanner class available to the application without qualification.

If the user enters 100 the first time the while loop is execute, what will the program display at the console? import java.util.Scanner; public class InvoiceApp { public static void main (string[] args) { Scanner sc = new Scanner (System.in); String choice = "y"; while (choice.equals("y") ) { System.out.println("Enter subtotal: "); String input = sc.nextLine(); double subtotal - Double.parseDouble(input); double salesTax = subtotal * .0875; double invoiceTotal = subtotal + salesTax; String message = "Subtotal = " + subtotal + "\n" + " Sales tax = " + salesTax + "\n" + "Invoice total = " + invoiceTotal + "\n\n" System.out.println(message); System.out.println("Continue? Enter y or n: "); choice = sc.nextLine(); } } } a. Subtotal: 100.0 Sales tax: 8.75 Invoice total: 108.75 b. Subtotal = 100 Sales tax = 8.75 Invoice total = 108.75 c. Subtotal = 100.0 Sales tax = 8.75 Invoice = 108.75

c. Subtotal = 100.0 Sales tax = 8.75 Invoice= 108.75

Unlike a variable, a constant can't a. be initialized when it's declared b. be declared with block scope c. change in value as an application runs d. be declared within a method

c. change in value as an application runs

In the statement that follows, x can not be what data type? switch(x){statements} a. char b. int c. double d. String

c. double

Which of the following statements uses a compound assignment operator? a. index = index + 1; b. index++; c. index +=1; d, both B and C e. all of the above

c. index += 1;

public class SalesCalculator { public static void calc )String []args) { // statements here } } } in the above code, calc is a(n) a. class b. variable c. method d. stream

c. method

the operators that you use to compare __________ operators. a. arithmetic b. logical c. relational d. control flow

c. relational

The decrement operator is called a __________ operator because it operates on a singe operand. a. compound b. binary c. unary d. logical

c. unary

To join two strings into one, you use the _____ operator. a. -- b. ++ c. . d. +

d. +

If an integer value is too big for the int type, you should store it in the _____ type. a. 100<= x < 1100 b. 100<= x < 200 c. 100<= x < 101 d. 100<= x < 110

d. 100 <= x < 110

What is in result after the following code executes? int valueA = 5; double valueB = 2.0; double result = <Math.pow(valueB, valueA); a. 10 b. 5 c. 16 d. 32

d. 32

What is in result after the following code executes: int result; result = 0; result = result +2; result = result +2; a. 2 b. 0 c. 5 d. 4

d. 4

What is the value of the variable named counter after the following statements are executed? double percent = 0.54; boolean valid = true; int counter =1; if (percent > 0.50 && valid) { counter +=2; } else if (valid) { counter +=3; } else { counter++; } a. 7 b. 2 c. 3 d. 4

d. 4

how many times will the loop that follows be executed if months has a value of 5? int months=5; int i=1; while (i<months) { system.out.println(i); i = i + 1; } a. 5 b. 6 c. 0 d. 4

d. 4

What is the value of total after the following statements are executed? int quantity = 5; int total = quantity++; a. 7 b. 4 c. 6 d. 5

d. 5

How many lines are printed on the console when the following for loop is executed? for (int i = 2; i < 10; i++) { System.out.println(i); } a. 10 b. 7 c. 9 d. 8

d. 8

Write one java statement to declare and initialize a variable that will store the minimum number of vehicles a salesperson must sell for the month, which is 15. (Rember that java is case-sensitive)

int minimumSalesCount = 15;

what is the name of the IDE we are using in our class?

netbeans


Conjuntos de estudio relacionados

XCEL Health Insurance Policy Provisions

View Set

MKT 3323 Chapter 1 Practice Quiz & Exam (Exam 1)

View Set

Chemie, atomové jádro (maturitní otázka 2)

View Set

Cardiac Muscle Physiology (11/8/12)

View Set