CS 109 Bulit in Data Types for Programming.

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

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

class class class class class class class class class class class class class class class class class class Explanation A class is a user-defined data type. Hence 'class' is the correct answer.

A Java char is _____ bits in size. 1. 8 2. 16 3. 32 4. 64

16 bits. 16 bits. 16 bits. 16 bits. 16 bits. 16 bits. 16 bits. 16 bits. 16 bits. 16 bits. Explanation A char is 16 bits, while a byte is 8. The 16-bit length allows for representation of virtually all of the letters in any human language.

Which of the following is an example of a floating point data type in Java? 1. x = -4.56899f; 2. x = 2.3; 3. x = 4/0; 4. x = -0.1;

x= -4.56899f; Floating point data types in Java are represented by appending the letter f to the end of the decimal. If the letter f is not appended, Java considers the number as a double. Floating point data types in Java are represented by appending the letter f to the end of the decimal. If the letter f is not appended, Java considers the number as a double. Floating point data types in Java are represented by appending the letter f to the end of the decimal. If the letter f is not appended, Java considers the number as a double.

Which of the following is a double in Java? 1. x = 0.123456789123456789123; 2. x = 5f; 3. x = 1.234567891234567; 4.x = 0. 0.12345f;

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

Which of the following correctly imports only the FileFilter interface of the java.io API? 1. import java.FileFilter.*; 2. import java.io.*; 3. import java.*.FileFilter; 4. import java.io.FileFilter;

4. import java.io.FileFilter; import java.io.FileFilter; import java.io.FileFilter; import java.io.FileFilter; import java.io.FileFilter; import java.io.FileFilter; import java.io.FileFilter; import java.io.FileFilter; import java.io.FileFilter; import java.io.FileFilter; import java.io.FileFilter; Explanation Using the asterisk after the io will import the ENTIRE API; if we just want the FileFilter tool, we can specify this after the io command. It saves some overhead, especially if you have lot of interfaces and/or a complex program.

The relational operators || and && (OR and AND) are called _____ operators 1.Empty 2.Divisional 3.Boolean 4.Binary

Boolean Explanation They are called Boolean because they test for a true/false condition. However, all relational operators are basically used to check if a condition is true. Is the pay rate less than 50? If it is (true), then do some processing. Still, we call the AND and OR operators Boolean to separate them from the other operators.

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

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

String str1 = new String("Join us at 6"); String str2 = new String("for Happy Hour"); String str3 = str1 + str2; Examine the following code. What will the output of str3 be? Join us at 6 for Happy Hour! Join us at 6 Nothing, the compiler will error Join us at 6for Happy Hour!

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

The Java Boolean data type is a/an _____ data type. 1. Native 2. Float 3. Inherited 4. Primitive

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

double myNumber = (20 - 10 /3); double myNumber2 = ((20 - 10) /3); Examine the following code. The programmer is not getting the same value for myNumber and myNumber2. Why? 1. The numbers should be integers 2. The order of operations is different in each 3. The compiler is broken 4. The numbers should be floats

The order of operations is different in each. The order of operations is different in each. The order of operations is different in each. The order of operations is different in each. The order of operations is different in each. The order of operations is different in each. The order of operations is different in each. The order of operations is different in each. The order of operations is different in each. The order of operations is different in each. Explanation 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!

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 fraction 3. a type cast 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. a type cast.

Java constants are usually named with upper case letters with an underscore between words. However, which of the following would also compile as the name for a constant? 1. Last Name 2. If Else 3. ifElse 4. If

ifElse. ifElse. ifElse. ifElse. ifElse. ifElse. ifElse. ifElse. ifElse. ifElse.

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

implicitly. implicitly. implicitly. implicitly. implicitly. implicitly. implicitly. implicitly. implicitly. implicitly. Explanation 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.

int myNumber; What is the value of myNumber in the following code? 0 NULL Undefined -1

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

Which data type is 1-bit in size? 1.boolean 2.long 3.char 4.short

1. Boolean Explanation Data type boolean is 1-bit in size and it holds value true or false. The default is false.

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

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

Which of the following is true about constant naming conventions in Java? 1. Constants can have spaces in the names 2. Constants should be upper case with an underscore separating the words 3. Constants can be any Java keyword 4. Constants cannot be represented by lower case

Constants should be upper case with an underscore separating the words. Constants should be upper case with an underscore separating the words. Constants should be upper case with an underscore separating the words. Constants should be upper case with an underscore separating the words. Constants should be upper case with an underscore separating the words.

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

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

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

No, you can only store one literal character in a char. No, you can only store one literal character in a char. No, you can only store one literal character in a char. No, you can only store one literal character in a char. Explanation The char can only store one character. It is 16 bits/2 bytes in order to store the Unicode representation of the character values. The code here is actually declaring a string, not a single char.

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

Not equal to. Not equal to. Not equal to. Not equal to. Not equal to. Not equal to. Not equal to. Not equal to. Not equal to. Not equal to. Explanation The code will run while the conversion is NOT 1000

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

intnum = (int)longnum;. intnum = (int)longnum;. intnum = (int)longnum;. intnum = (int)longnum;. intnum = (int)longnum;. intnum = (int)longnum;. intnum = (int)longnum;. intnum = (int)longnum;. intnum = (int)longnum;. intnum = (int)longnum;. Explanation This code will cast the value to an int. This tells the compiler that you think you know what you are doing; however, if the value is larger than an int can handle, the code will fail.

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

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


Kaugnay na mga set ng pag-aaral

Ecology Chapter 4 Mastering Biology

View Set

Chapter 3 Working With Financial Statements

View Set

Head Region Muscles - Origin, Insertion, Action, Innervation

View Set

Chapter 27 Non infectious Lower Respiratory Problems

View Set

Chapter 13, Cardiovascular system

View Set

OS 210 Organizational Communications - Chapter 14 Review

View Set