Programming

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

Which language family has been around since the 1970s and gained object-oriented concepts in a later decade?

C / C++

Which of the following statements will correctly create a new Scanner object, assuming the java.util.* package has been imported?

Scanner input = new Scanner(System.in);

Assuming "input" has been initialized with a Scanner, which of the following statements will read the user-entered text up to the first white-space character?

String data = input.next();

Which pair of companies are the original (listed first) and current (listed second) owners of the Java language?

Sun Microsystems, Oracle

What method could you call multiple times to print multiple values on the same line?

System.out.print()

Which of the following statements will successfully add a tab character in the quoted output?

System.out.println("Result\t100");

Which of the following statements will successfully display a combination of quoted text and the contents of the "elapsedTime" variable?

System.out.println("You finished the race in " + elapsedTime + " seconds");

What is the name of the command we can use to display a line of text to the output console?

System.out.println()

Which method would you call if you wanted to automatically wrap to the next line after the text is displayed?

System.out.println();

What is wrong with the following code? int speed; System.out.println(speed);

The speed variable was not assigned a value before using it

Why is the "(byte)" phrase used in the assignment statement below? byte number = (byte)4.5;

This tells Java to convert to a byte and drop the data to the right of the decimal point

Why might a class choose to overload a method?

To allow the method to be called with different mixtures of parameters

What is the purpose of an escape sequence?

To represent symbols like double quotes that may be hard to put inside quoted text otherwise

A user logs in by entering a username and password. If you want to compare the password to a known string value, and must have an exact match (including capitalization) for a true result, how should you compare those strings?

Use the String equals() method

A user logs in by entering a username and password. If you want to compare the username to a known string value, and don't want capitalization differences to matter, which String method should you use?

equalsIgnoreCase()

Which of the following best describes the Java Class Library (JCL)?

A collection of Java textbooks recommended for beginning Java students

Which of the following best describes the term "object"?

A copy or instance of a class that is created in a running program

Which area would you visit within Oracle's online Java documents to get reference information on any class in the JCL?

API Documentation

Which of the following conditions would make it impossible for two strings to be considered equal by the String equals() method?

All of these are true

How could you write an expression to round the decimal value "exact" to the nearest whole number, using casting? double exact = 3.5;

(int)(exact + 0.5)

Given the statement below, what are the minimum and maximum valid character index values in myString3? String myString3 = "No thanks";

0 and 8

What value is stored in the "livesRemaining" variable after the following statements have run? int livesRemaining = 2; livesRemaining += 2; livesRemaining++; livesRemaining *= 2;

10

What value is stored in the "livesLeft" variable after the following statements have run? int livesLeft = 3; livesLeft++; livesLeft--; livesLeft--;

2

When Java truncates the decimal value "-2.7", what will be the resulting whole number?

2

When Java truncates the decimal value "2.7", what will be the resulting whole number?

2

Which of the following statements about ASCII and Unicode are true?

ASCII uses a single byte to represent 128 English characters, while Unicode uses multiples bytes to represent thousands of characters in many languages

Which of the following statements will increase the value stored in the integer "count" variable by 1?

All of these will work

What is the best naming style to use for a variable that contains a count of the number of frogs in a pond?

All styles are equally valid; just be consistent

If the Car class has a constructor method that requires one String parameter, which of the following statements will successfully create a new Car object?

Car myRide = new Car("red");

In what kind of language are the original source files distributed to the target computer?

Data used within a strongly typed language must be identified as a specific type

Given the following method signature, how many parameters are required when the method is called? double calculateResults (double x, double y, double z)

Exactly 3

The Java compiler will turn files from which input format to which output format?

From .java to .class

What is the purpose of indenting some statements to the right in Java source files?

Gives a visual hint as to which pieces of code belong together in the same block

If you want to use a variable in your main() method, where would you declare that variable?

Inside the curly braces marking the start and end of the main() method

In what kind of language are the original source files distributed to the target computer?

Interpreted or scripted language

Why is using white space important in your Java source code?

It makes your code more readable for humans

What part of the Java platform will programmers install to get tools that compile Java source code, create HTML documentation from specially formatted source code comments, and package together Java .class files into a single, convenient distribution file?

JDK

Which area would you visit to get step-by-step guidance on a variety of Java topics?

Java Tutorials

What important JRE component lets Java programs run on any operating system without recompiling?

Java Virtual Machine (JVM)

Which of the following types of languages best describes Java?

Machine language

Given the statement below, what is returned by the expression myString2.substring(1)? String myString2 = "NOT SO LOUD!";

OT SO LOUD!

Which symbol is used to mark the end of a program statement?

Semicolon ;

Which of the following statements will successfully create a new instance of the SmartPhone class?

SmartPhone myPhone = new SmartPhone();

How do you start and end a multi-line comment?

Start with /* and end with */

Assuming a "myRide" variable has been initialized to hold a Car object, and the object has a String property named "color", which of the following statements would read that property directly from the object when no "get" method has been defined?

String thisColor = myRide.color;

What limits a numeric data type's precision and range?

The number of bytes of memory used to hold the data

What does the term "immutable" mean for Java strings?

The value in a Java String object cannot be changed after it is created

What value will be stored in the "answer" variable after the following statements are run? int whole = 10; double fraction = 0.5; int answer = whole + fraction;

These statements will produce a compile-time error

Given the following three string variables, which expression will return true? String myString1 = "not so loud!"; String myString2 = "NOT SO LOUD!"; String myString3 = "No thanks";

They all return true

When should you call nextLIne() to flush the input stream of any remaining newline character that may confuse the next user entry?

When you have previously used next() or a similar method that did not remove the newline character, and want to call nextLine() to get a new line of data

What key feature distinguishes Java from earlier, high-level compiled languages like C++?

You can compile Java programs once and they will run on any computer with a JVM

Which data type will hold a single character like 'X'?

char

What term does Java use to define an object that has data, behavior, and relationships?

class

Which of the following keywords does Java use to describe a group of statements that work together to perform a task?

class

When using String.format(), which of the following is not a required or optional part of the format specifier?

color

What two things do you need to declare (but not initialize) a new variable in your code?

data type and variable name

Which of the following statements would you use to see if the string variable named "emailAddress" contains the string "@"?

emailAddress.contains("@")

Which of the following data types is best suited to hold the elapsed time in a race, including two digits to the right of the decimal point (hundredths of a second)?

float

Which of the following types of languages best describes Java?

high-level language

Which of the following data types is best suited to hold the number of goals scored by a soccer team?

int

How would you write an assignment statement to store the results of adding together the values 100 and 50?

int answer = 100 + 50;

Which of the following statements will both declare and initialize a variable at the same time?

int secondsPerMinute = 60;

Which of the following statements would change the reference variable "myPhone" so it no longer pointed at any object?

myPhone = null;

Which Scanner method would you call to read the next user entry and automatically convert it to a "double" data type?

nextDouble()

Which of the following contains a properly formatted main() method declaration?

public static void main(String[] args)

Which of the following correctly defines the method signature for the main() method that will be run when the program is launched?

public static void main(String[] args)

Which of the following variable names is invalid?

race time

What kind of variable is used to hold a link to an object?

refrence

Assuming the "scale" integer variable has already been declared and initialized, how would you use a compound assignment statement to multiply the value stored in "scale" by 10?

scale *= 10;

In the following mathematical expression, which operation will Java perform first? 1 + 2 * (3 - 4)

subration

Which string method would you call to produce a new string that is a lowercase version of the original?

toLowerCase()

Which of the following keywords shows that a method will return no data?

void

What string is produced by the following expression? String.format("%4$s %3$s %2$s %1$s", 4, 3, 2, 1)

"1 2 3 4"

What is the numeric result of the following mathematical expression in Java? (1 + 2) * (4 - 3) / 3

1

Given the statement below, what is returned by the expression myString1.lastIndexOf("o")? String myString1 = "not so loud!";

8

What value will be stored in the "result" variable after the following three code statements are run? int result = 42; result = 43; result = 44;

Impossible to determine

Which important pair of symbols are used to mark the start and end of classes, methods, and other blocks of code?

Opening and closing curly braces { and }

What term describes the order in which Java will carry out individual operations within a large mathematical expression?

Operator precedence

Which data type would you choose to hold the answer to a true / false question?

boolean

What term is used to describe the process of converting one data type to another?

casting

Which of the following statements will successfully assign a true value to the boolean variable "isReady", assuming the variable has already been declared?

isReady = true;

Given the line of code below, which of the following statements would update the String property named "color" on the Car object when no "set" method has been defined? Car myRide = new Car();

myRide.color = "red";

Given the following method signature, which answer will correctly call the method through a reference variable named "myRide"? void turnRight(int degrees)

myRide.turnRight(20);

Which of the following expressions should be used to determine if the contents of myString1 are equal to the contents of myString2?

myString2.equals(myString1)

What value will be stored in the variable from the following mathematical expression and assignment? double answer = 7 / 2;

3.0

What value will be stored in the variable from the following mathematical expression and assignment? double answer = 7.0 / 2.0;

3.5

What is displayed in the output window when the following statements are run? String number = "555-1212"; System.out.println("Please call " + number);

Please call 555-1212

What does the myString variable contain after the following code is run? String myString = "hello "; // note the space at the end of the string myString = myString + myString.length();

"hello 6"

When using String.format(), which of the following format specifiers will display a floating-point number with 2 digits to the right of the decimal point?

%.2f

When using String.format(), which of the following format specifiers will display a parameter as a decimal (floating point) value?

%f

What string is produced by the following expression? String.format("? %1$s and %1$5s and %1$-5s ?", 1, 2, 3)

"? 1 and 1 and 1 ?"

What value will be stored in the "exact" variable after the following statements are run? int whole = 10; double fraction = 0.5; double exact = whole + fraction;

10.5

What value will be stored in the variable from the following mathematical expression and assignment?

3

Which of the following expressions (1, 2, 3, 4) will produce a true result when the input and password string variables contain exactly the same characters? 1. input.equals(password) 2. password.equals(input) 3. input == password 4. password == input

1 and 2 only

What is it called when the Car class has three constructor methods with the signatures shown below? Car() Car(String color) Car(String color, int year)

Method overloading

In the following mathematical expression, which operation will Java perform first? 1 + 2 * 3 - 4

Multiplication

What is the output from the following code? char grade = 'A'; System.out.print("My grade is an "); System.out.print(grade);

My grade is an A

What is the result of the following modulus operation? 7 % 2

ONE 1

What is wrong with the following code? final byte NUM_LIVES = 3;NUM_LIVES = 2;System.out.println(NUM_LIVES);

You can't change a "final" variable after initialization

If you attempt to access a string character using an index value that is equal to the length of the string, what will happen?

You will see an IndexOutOfBoundsException that halts your program


Set pelajaran terkait

Chapter exam 5: Private insurance plans for seniors

View Set

Women and Gender Studies Final Study Guide

View Set

Chapter 6: Cost-Volume-Profit Relationship

View Set

History Chapter 3 - Early Humans

View Set

Human Physiology Chapter 3 Part 1

View Set

Direct and Representative Democracy

View Set

Algebra I Fundamentals : Factoring Trinomials (1)

View Set