Chapter 2: Build-in Data Types for Programming?__DNS_Copy

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

A Java String is a sequence of ______ 1. doubles 2. floats 3. ints 4. chars

chars. Chars. chars. Chars. chars. Chars. chars. Chars. A string is really just a sequence of char variables. It can contain any number of characters.

If you initialize a variable as currentTemperature, then how would you use the same variable in the System.out.prinln statement?

currentTemperature

In Java, the nextInt(int n) function generates a random number: it is a number between _____ and _____. a. 0; a specified number (n) b. 1; 100 c. 1; a specified number (n) d. 0; 100

0; a specified number (n)

A java char is ____ bits in size a. 8 b. 64 c. 16 d. 32

16 bits in size. 16 bits in size. 16 bits in size. 16 bits in size. 16 bits in size. 16 bits in size. 16 bits in size. 16 bits in size.

In the Java code bellow, what is the data type of the variable max? Random r = new Random(); int newR = r.nextInt(max);

int

Which data type is 1-bit in size? a. long b. char c. boolean d. short

boolean is 1-bit in size. boolean is 1-bit in size. boolean is 1-bit in size.

What will the value of l be? https://study.com/cimages/multimages/16/java_math_q3.png 1. Nothing; the compiler will error 2. -45 3. 45 4. 0 int j = 5; int k = 50; int 1 = j - k;

-45 ust like in real math, you can subtract a larger number from a smaller one.

Examine the following code. What will the value of the variable tester be? int tester = 6 % 3;

0 The modulo operation will return a 0 if the division operation has no remainder.

What is the value of myNumber in the following code? int myNumber; a. Undefined b. -1 c. 0 d. NULL

0 Remember that the default value for short, int, or long is 0.

Which of the following is an example of a floating point data type in Java?

x= -4.46899f;

Which of the following is a double in Java?

x= 1.234567891234567 A double in Java can store a maximum of 16 digits after the decimal. So if there are more than 16 digits, Java will throw and error. When f is appended to the decimal value the data is stored as a float, not a double.

Assume the binary representation of 42.75 is stored in a variable named myNumber that's declared as data type float. What numeric value will be stored in the variable theAnswer when the following Java statement is executed? float myNumber = 42.75f; byte theAnswer = (byte) myNumber; 1. 42 2. 75 3. 42.75 4. Java will raise an error

42 When floating point data is converted to an integer, any fractional portion is discarded. Thus 42 will be stored in the 8-bit integer variable theAnswer.

Consider the following code/ What will the value of newChar be if disposed on the screen? char newChar = 65; 1. -90 2. 65 3. A 4. Undefined

A Explanation Remember that the char data type stores the Unicode value. If you place the value of the variable in quotes, e.g., A, you will get A. However, by specifying a numeric value, you will get the value of that character. In this case, it is A.

The result of a Boolean operation is only true or false. How should this be written in Java code? 1. Mix of uppercase and lowercase 2. All uppercase 3. Uppercase for false, lowercase for true 4. All lowercase

All lowercase. All lowercase. All lowercase. All lowercase. All lowercase. All lowercase. All lowercase. All lowercase. All lowercase. The result of a Boolean operation is only true or false and should be written in lowercase in Java code.

The relation operators || and && (OR and ABD) are called ______ operators? 1. Binary 2. Empty 3. Divisional 4. Boolean

Boolean. Boolean. Boolean. Boolean. Boolean. Boolean. Still, we call the AND and OR operators Boolean to separate them from the other operators.

What is the size of the char data type? 1. 4-bit 2. 16-bit 3. 8-bit 4. 1-bit

Char data type is 16-bit. Char data type is 16-bit Char data type is 16-bit Char data type is 16-bit Char data type is 16-bit

A Java string is both an object and a (an) _____. 1. method 2. instance 3. class 4. integer

Class. Class. Class. Class. Class. Class. Class. Class.

A java String is a_______ 1. method 2. void 3. primitive data type 4. class

Class. Class. Class. Class. Class. Class. Class. Class.

Which of the following is true about constant naming conventions on Java?

Constants should be upper case with an underscore separating the words

When multiplying and/or dividing large, complex numbers, which data type is best

Double

Examine the following code. What is missing? if (orderID = 7) { // order ID = 7 } 1. Nothing, this code will compile 2. An else statement 3. Double-equal sign (==) instead of = 4. A semi-colon

Double-equal sign (==) instead of = this creates an assignment error: You aren't comparing but assigning 7 to the variable orderID. Most Java developer tools will not compile, but this can get you in big trouble in other languages/older tools. It can result in infinite loops or invalid/bogus results.

Examine the following code. What relational operators are being used. https://study.com/cimages/multimages/16/java_relational_q4.png if (currencyConversion == 0 || currentConversion > 100) { } 1. Equal to; AND; greater than 2. Equal to; greater than 3. Equal to; OR; greater than 4. Equal to; OR

Equal to; OR;greater than. Equal to; OR;greater than. Equal to; OR;greater than. Equal to; OR;greater than. Equal to; OR;greater than.

Examine the following code. What is the default value of the variable validEntry? 1. No value 2. 0 3. True 4. False

False. False. False. False. False. False. False. the default for the boolean primitive type is FALSE. the default for the boolean primitive type is FALSE the default for the boolean primitive type is FALSE

Examine the following code. After it completes, what will the value be for the boolean variable isExpired

Fasle Although the value was set to true, it's only going to be set to false if the value of myValue is less than 10. Since myValue is 5, the boolean value will be flipped to false

What are the two data types used to store floating point literals in Java? 1. Float and Single 2. Double and Single 3. Float and Double 4. Double and Positive

Float and Double. Float and Double. Float and Double. Float and Double. Float and Double. Float and Double. For calculations involving decimal numbers, Java supports two data types, Float and Double.

Java won't _____ convert the char data type to a numeric data type (even if the target data type is wider), but a programmer can explicitly use a _____ to force the conversion. 1. implicitly, type cast 2. automatically, comment 3. automatically, declaration 4. implicitly, comment

Implicitly, type cast Java won't implicitly (automatically) convert the char data type to a numeric data type (even if the target data type is wider), but a programmer can explicitly use a type cast (such as '(int)') to force the conversion

Java will _____ move a value stored in a short data type into a variable declared as int. 1. casually 2. implicitly 3. never 4. explicitly

Implicitly. Implicitly. Implicitly. Implicitly. Implicitly. Java will implicitly (i.e., automatically) move the value from a 16-bit short into a 32-bit int because there's no possible loss of information moving into a wider data type.

What is the result of x = 5.0 / 0.0 in Java? a. 0.0 b. 0 c. Infinity d. Error

Infinity. Infinity. Infinity. Infinity. Infinity. Infinity. Infinity. In Java you can divide a double by 0.0 and the result will be Infinity.

The char data type is most closely related to the _____ data type 1. float 2. integer (Int) 3. short 4. double

Integer (int). Integer. Integer. Integer. Integer. Integer.

Which data type is NOT an example of a primitive data type? 1. boolean 2. int 3. char 4. interface

Interface. Interface. Interface. Interface. Interface. Interface. Interface. Interface. Interface. Interface. Interface is a non-primitive data type, along with class and array.

Based on the Java code below, what is true about the variable r? int rNew = r.nextInt(5);

It is an instance of the Random class. Even though we don't have the full code, we can assume r would be an instance of the Random class because it invokes the nextInt() function.

Examine the following code. What will the value of the output of str1 be after it processes? https://study.com/cimages/multimages/16/java_string_quiz_2.png 1. jOiN uS aT 6! 2. JOIN US AT 6! 3. join us at 6! 4. Join Us At 6!

JOIN US AT 6! The toUpperCase() function converts all of the characters to uppercase. The exclamation point is kept intact as it has no uppercase counterpart.

Examine the following code. What will the output of str3 be? https://study.com/cimages/multimages/16/java_string_quiz_1.png a. Join us at 6 for Happy Hour! b. Join us at 6 c. Join us at 6for Happy Hour! d. Nothing, the compiler will error

Join us at 6for Happy Hour! The two strings were just mashed together, without any other characters. Without any added spaces, the words will just run together.

The values allowed for the boolean type are true and false, and they are _____. 1. Integers 2. Variables 3. Doubles 4. Keywords

Keywords. Keywords. Keywords. Keywords. Keywords. They are keywords; reserved by Java. That means they cannot be used for variable, object, class, or function names.

n the following code, what relational operator is being used? double currencyConversion; if (currencyConversion <= .00035) { //code here } 1. Less than 2. Less than or equal to 3. Equal to 4. Greater than

Less than or equal to The code is checking to see if the currency conversion is less than or equal to .00035

Java _____ allows boolean true/false values to be converted to/from other data type.. 1. implicitly 2. never 3. always 4. explicitly

Never. Never. Never. Never. Never. Java PROHIBITS boolean true/false values from being converted to/from ANY other data type.

The Java Random class has a function that lets you generate a _____ number 1. Pseudorandom 2. Fully random 3. Partial random 4. Random

Pseudorandom. Pseudorandom. Pseudorandom. Pseudorandom. Pseudorandom.

If you declare a char variable and assign a numeric value to it, which of the following will display? 1. The corresponding Unicode representation of that value 2. A random text value 3. An error 4. The number

The corresponding Unicode representation of that value.

Examine the following code. The programmer is not getting the same value for myNumber and myNumber2. Why? double myNumber = (20 - 10 / 3); double myNumber2 = ((20 - 10 / 3);

The order of operations is different in each. Java math works like real math. If you have a different order of operations, such as placing parentheses in different positions, results will be very different!

Why is the word 'final' used to describe a constant in Java? 1. The value of the constant cannot change through the execution of the program 2. The value of the constant cannot change for any of the Java programs 3. The constant gets a final value at print out 4. The constant gets a final value at run time

The value of the content cannot change through the execution of the program

What are floating point data types in Java used for?

To store decimal numbers Floating point numbers or literals are used to store decimal values in Java.

The data types short int, and long are all? 1. Whole integers 2. Characters 3. Decimals 4. Negative decimals

Whole integers They are all whole numbers, either negative or positive, with a set range of values. No decimals are allowed.

To move the contents of a variable declared as data type float into a variable declared as data type long requires the use of _____. 1. an implicit conversion 2. a type cast 3. a fraction 4. a comment

a type cast. a type cast. a type cast. a type cast. a type cast. a type cast. a type cast. a type cast. a type cast.

In Java, primitive data types are those that are _____, while non-primitive data types are _____. 1. defined by the language; not defined by the language 2. not defined by the language; defined by the language 3. identifiers; literals 4. literals; identifiers

defined by the language, not defined by the language. defined by the language, not defined by the language. defined by the language, not defined by the language. defined by the language, not defined by the language.

Java contents are usually names with upper case letters with an underscore between worlds. However, which of the following would also compile as the name for a content?

ifElse

Which of the following correctly imports only the FileFilter interface of the java.io API?

import Java.io.FileFilter;

You need to do some work with SQL and Java. You notice there is an API, java.sql. There are several classes you plan to use. What is the best way to import the API/APIs? https://study.com/cimages/multimages/16/java_apis_q5_a1.png 1. Split program into multiple classes and import one at a time. 2. Re-write the applicatin in ASP.

import Java.sql.*; Sometimes it can cause some issues with performance if you import an entire package (e.g., java.util). However, if you really are going to use most or all of the classes/interfaces, import all using the asterisk.

Consider a program that calculates distances between stars. What data type would be best suited for the variable that stores this number (e.g.,distance)? 1. long 2. int 3. short 4. byte

long The distance is a very large number, and can be displayed in whole numbers. However, byte, int and short are way too small to hold such large values.

Examine the following code. What relational operator is being used? double currencyConversion; while (currencyConversion != 1000) { // code here } 1. Not equal to 2. OR 3. Equal to 4. Less than

Not equal to. (!=) Not equal to. Not equal to. (!=) Not equal to. Not equal to. (!=)

Java Application Programming Interface (API) is a list of ______

Packages At the top level, each API is really a Java package. Each package has its own interfaces, fields, methods, and constructors. For example, the general util (utility) package has a class called Scanner, which lets you take input from the keyboar

The Java Boolean data type is a {Blank} data type?

Primitive Boolean data types, like int and float, are native to the programming language and can be used out of the box, without special coding.

Which of the following is the correct way to declare a variable in Java?

int begin_Time = 0;

https://study.com/cimages/multimages/16/java_random_q5.png int v1 = min + r.nextInt(); What is missing from the following Java code? 1. An integer for the upper value 2. An integer for the lower value 3. Integer variable v1 is invalid 4. An instance of the Random class

An integer for the upper value. An integer for the upper value. An integer for the upper value. An integer for the upper value. An integer for the upper value.

Which of the following is included in a Java API? 1. Classes and methods 2. Encryption 3. JavaScript plug-ins 4. USB Connector

Classes and Methods. Classes and Methods. Classes and Methods. Classes and Methods. Classes and Methods. Classes and Methods. An API is a package: Included within the package are interfaces and classes, each with methods, fields and constructors.

What kind of data type will you use for an object 'Pen'? 1. int 2. class 3. char 4. long

Data type of a 'Pen' is Class. Data type of a 'Pen' is Class. Data type of a 'Pen' is Class. Data type of a 'Pen' is Class. Data type of a 'Pen' is Class. A class is a user-defined data type. Hence 'class' is the correct answer.

What are these two symbols for: / and %. 1. Division and Pi 2. Division and Modulo 3. Division and Remainder 4. Division and Square Root

Division and Modulo. Division and Modulo. Division and Modulo. Division and Modulo. The first symbol, the forward slash, is used for division. The second symbol is the modulo operator.

Will the following code work? char myChar = 'ABC'; 1. Yes, but with AB. 2. Yes, myChar will display ABC. 3. No, you can only store one literal character in a char. 4. Yes, but only A.

No, you can only store one literal character in a char.

https://study.com/cimages/multimages/16/java_apis_q4.png File writer = new File(''//users/mdg/myfile.txt''); The following code is displaying an error, stating that it cannot find the symbol (class: File). What is wrong? 1. The quotes are not necessary 2. Cannot create an instance of a File class 3. File is a reserved word 4. Need to import the File API

Need to import the file API Either import java.io.* or java.io.File; You can instantiate an instance of the File class, but you need to make sure to import the API.

Which of the following is a valid declaration of an int data type? 1. int myNumber = 404M; 2. int myNumber = -608.75; 3. int myNumber = 532524584; 4. int myNumber = 800.5545687;

int myNumber = 532524584; The range of an int is -2,147,483,648 to 2,147,483,647, and only allows whole, integer values.

If you need to see a long (longnum) to an int (intnum), which of the following would be used? 1. longnum1 = intnum; 2. intnum = longnum; 3. long intnum = longnum; 4. intnum = (int)longnum;

intnum=(int)longnum; intnum = (int)longnum;


Set pelajaran terkait

Chapter 10 - Purchasing and Payments Processes

View Set

Quiz 2 Chapter 4, chapter 4-- eco 2023, ECON 202 Chapter 4 questions, lecture 2.4 quiz, CH 4 & 5 MICROECONOMICS 130, Macro Quiz 2, Micro Quiz 2, ECO-251 Test 1, Econ HW 2, Macro Economics Exam #1, chapter 2, Econ- Chapter 3, MATH @!!

View Set

AP Psych: Chapter 8- Abnormal Psychology

View Set

BIO PRACTICAL CELLULAR RESPIRATION

View Set

PE Investing - Terms for Midterm

View Set

State laws, Rules, and Regulations

View Set