Exam 2 Flashcards

1
Q

Every value in Java is either:

A reference to an ________

One of the _____________ types

A

Object

Primitive

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Java has ___ primitive types

A

8

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Java’s primitive types are:

Four ___________

Two _________

Two _________

A

Integer types

Floating point types

Others

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Range +- 2,147,483,648 with 4 bytes

A

Int

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Range -128…127

A

Byte

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Integer type, with range -32768…32767 with 2 bytes

A

Short

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Integer type, with range +- 9,223,372,036,854,775,808 with 8 bytes

A

Long

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Floating point type, range +- 10^308 with about 15 significant decimal digits with 8 bytes

A

Double

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Single precision floating point type with a range of about +- 10^38 and about 7 significant decimal digits with 4 bytes

A

Float

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Representing code units in the Unicode encoding scheme with 2 bytes

A

Char

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Type with the two truth values false and true with 1 bit

A

Boolean

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

If it is a decimal, it is a:

A

Floating-point number

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

If it is not a decimal, then it is a:

A

Integer

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Generally, you use ______ for integers

A

Int

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

The result of a computation exceeds the range for the number type

A

Overflow

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Occur when and exact representation of a floating point number is not possible

A

Rounding errors

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Floating point numbers have _________ precision.

A

Limited

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

You should use _______ type in most cases

A

Double

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

A final variable is a:

A

Constant

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Once a Constant is set, it ________ be changed.

A

Cannot

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Use all uppercase names for constants

A

Convention

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

The static reserved word means that the constant _________________, not the object

A

Belongs to the class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Give _____________ constants public access to enable other classes to use them

A

Static final

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

What’s the difference between the following two statements?

final double CM_PER_INCH = 2.54;

public static final double CM_PER_INCH = 2.54;

A

The first declaration is used inside a method

The second declaration is used inside a class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

Combination of variables, literals, operators, and/or method calls

A

Expressions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

What control the order of operations

A

Parentheses

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

__________ and __________ have a higher precedence than addition and subtraction

A

Multiplication

Division

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

Mixing integers and floating point values in an arithmetic expression yields a:

A

Floating point value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

++ operator adds 1 to a variable called

A

Increments

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q
    • operator adds 1 to a variable called
A

Decrement

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

What class contains methods sqrt and pow to compute square roots and powers

A

Math

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

Code to compute the side length of a square whose area is stored in the variable area?

A

double sideLength = Math.sqrt(area);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q

The compiler disallows the assignment of a _________ to an _____ because it is potentially dangerous

A

Double

Int

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
34
Q

long rounded = Math.round(balance);

balance = 13.75

What is the output?

A

14

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
35
Q

A static method ___________ operate on and object

A

Does not

36
Q

Where are static methods declared?

A

Inside classes

37
Q

__________ has minimal set of features and must be combined with other classes to be useful

A

System.in

38
Q

Use the class called ________ to read keyboard input

A

Scanner

39
Q

What’s wrong with the following statement sequence?

System.out.print(“Enter unit price: “);
double unitPrice = in.nextInt();

A

Second statement calls nextInt, not nextDouble

40
Q

A ___________ is a sequence of characters

A

string

41
Q

A string of length 0 is called the:

A

Empty string

42
Q

Code to print

He said “Hello”

A

“He said \”Hello\””

43
Q

Code to print

C:\Temp\Secret.txt

A

“C:\Temp\Secret.txt”

44
Q

A character is a value of the type:

A

Char

45
Q

Character literals are delimited by _______ quotient marks

A

Single

46
Q

How to code a constant in a method?

A

final int SEATS = 100;

47
Q

How to code a constant in a class?

A

public static final int SEATS = 100;

48
Q

6/3

A

3

49
Q

5/2

A

2

50
Q

5.0/2

A

2.5

51
Q

5%2

A

1

52
Q

6%2

A

0

53
Q

How to call square root of 16?

A

Math.sqrt(16)

54
Q

How to call 2pi

A

Math.PI*2

55
Q

Double n = 3.888;

System.out.print((int)n);

A

This is casting

Answer is 3

56
Q

(double) (2/5)
(double) 2/5
(char) 97

A

Casting

0.0
0.5
‘a’

57
Q

System.outprintf(“%6s”, “A”);

A

_ _ _ _ _ A

58
Q

System.out.printf(“%6.3f”, 8.7698);

A
    • 8 . 7 7
59
Q

“A” + “B” + 3 + true

What is this and what is the outcome

A

Concatenation

“AB3true”-it’s a whole string

60
Q

What’s the difference between

  1. In.nextLine();
    And
  2. In.next();
A
  1. Stops after whole string is acquired

2. Stops when it reaches white space

61
Q

What are all 5 escape sequences

A
“\n”
“\t” 
‘\n’
\”
\\
62
Q

How to print “hi” with quotes?

A

Use \”

63
Q

How can you print a backslash? \

A

\

64
Q

String day = “Thursday”;
Char letter = day.charAt(1);

What is the output?

A

‘h’

65
Q

String day = “Thursday”;
Char letter = day.charAt(day.length()-1);

What is the output?

A

‘y’

66
Q

String day = “Thursday”;
day.substring(0,5);

What is the output?

A

Thurs

67
Q

String day = “Thursday”;
day.substring(5);

What is the output?

A

day

68
Q

How do you code an if statement?

A
if(condition(s))
{
   Code 1
}
else
{
   Code 2
}
69
Q

How do you code an else/if statement?

A
if(conditions(s))
{
   Code 1
}
else if(condition(s))
{
   Code 2
}
else
{
   Code 3
}
70
Q

How do you code a nested else/if statement?

A
If(condition(s))
{
   Code 1
}
else
{
   If(condition(s))
   {
       Code 2
   }
   else 
   {
       Code 3
   }
}
71
Q

&&

A

And

72
Q

||

A

Or

73
Q

!

A

Not

74
Q

What is the order in which &&,||, and ! Is conducted?

A

!
||
&&

75
Q

What are 2 ways to compare strings?

A

.equals

.compareTo

76
Q

What does .conpareTo return?

A

Numbers

77
Q

Is null an object?

A

No

78
Q

Can null = “”?

A

No

79
Q

Can “null” = “”

A

Yes

80
Q

“null” = null?

A

No

81
Q

How do you check to see if a user input is an int?

A

hasNextInt()

If(in.hasNextInt())
{
   Int n = in.nextLine();
   Code
}
82
Q

A ________ is a sequence of Unicode characters. Ex.”H”

A

String

83
Q

Character __________ are delimited by single quotation marks.

A

Literal

84
Q

Relational operators have ________ precedence then arithmetic operators

A

Lower

85
Q

== tests if two strings are stored in the same:

A

Memory location

86
Q

compareTo method compares strings in :

A

Lexicographer order - dictionary order

87
Q

== operator tests whether two ________ are identical

A

Object references