Exam 2 Flashcards

(87 cards)

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
Combination of variables, literals, operators, and/or method calls
Expressions
26
What control the order of operations
Parentheses
27
__________ and __________ have a higher precedence than addition and subtraction
Multiplication | Division
28
Mixing integers and floating point values in an arithmetic expression yields a:
Floating point value
29
++ operator adds 1 to a variable called
Increments
30
- - operator adds 1 to a variable called
Decrement
31
What class contains methods sqrt and pow to compute square roots and powers
Math
32
Code to compute the side length of a square whose area is stored in the variable area?
double sideLength = Math.sqrt(area);
33
The compiler disallows the assignment of a _________ to an _____ because it is potentially dangerous
Double | Int
34
long rounded = Math.round(balance); balance = 13.75 What is the output?
14
35
A static method ___________ operate on and object
Does not
36
Where are static methods declared?
Inside classes
37
__________ has minimal set of features and must be combined with other classes to be useful
System.in
38
Use the class called ________ to read keyboard input
Scanner
39
What’s wrong with the following statement sequence? System.out.print(“Enter unit price: “); double unitPrice = in.nextInt();
Second statement calls nextInt, not nextDouble
40
A ___________ is a sequence of characters
string
41
A string of length 0 is called the:
Empty string
42
Code to print He said “Hello”
“He said \”Hello\””
43
Code to print C:\Temp\Secret.txt
“C:\\Temp\\Secret.txt”
44
A character is a value of the type:
Char
45
Character literals are delimited by _______ quotient marks
Single
46
How to code a constant in a method?
final int SEATS = 100;
47
How to code a constant in a class?
public static final int SEATS = 100;
48
6/3
3
49
5/2
2
50
5.0/2
2.5
51
5%2
1
52
6%2
0
53
How to call square root of 16?
Math.sqrt(16)
54
How to call 2pi
Math.PI*2
55
Double n = 3.888; | System.out.print((int)n);
This is casting Answer is 3
56
(double) (2/5) (double) 2/5 (char) 97
Casting 0.0 0.5 ‘a’
57
System.outprintf(“%6s”, “A”);
_ _ _ _ _ A
58
System.out.printf(“%6.3f”, 8.7698);
- - 8 . 7 7
59
“A” + “B” + 3 + true What is this and what is the outcome
Concatenation “AB3true”-it’s a whole string
60
What’s the difference between 1. In.nextLine(); And 2. In.next();
1. Stops after whole string is acquired | 2. Stops when it reaches white space
61
What are all 5 escape sequences
``` “\n” “\t” ‘\n’ \” \\ ```
62
How to print “hi” with quotes?
Use \”
63
How can you print a backslash? \
\\
64
String day = “Thursday”; Char letter = day.charAt(1); What is the output?
‘h’
65
String day = “Thursday”; Char letter = day.charAt(day.length()-1); What is the output?
‘y’
66
String day = “Thursday”; day.substring(0,5); What is the output?
Thurs
67
String day = “Thursday”; day.substring(5); What is the output?
day
68
How do you code an if statement?
``` if(condition(s)) { Code 1 } else { Code 2 } ```
69
How do you code an else/if statement?
``` if(conditions(s)) { Code 1 } else if(condition(s)) { Code 2 } else { Code 3 } ```
70
How do you code a nested else/if statement?
``` If(condition(s)) { Code 1 } else { If(condition(s)) { Code 2 } else { Code 3 } } ```
71
&&
And
72
||
Or
73
!
Not
74
What is the order in which &&,||, and ! Is conducted?
! || &&
75
What are 2 ways to compare strings?
.equals | .compareTo
76
What does .conpareTo return?
Numbers
77
Is null an object?
No
78
Can null = “”?
No
79
Can “null” = “”
Yes
80
“null” = null?
No
81
How do you check to see if a user input is an int?
hasNextInt() ``` If(in.hasNextInt()) { Int n = in.nextLine(); Code } ```
82
A ________ is a sequence of Unicode characters. Ex.”H”
String
83
Character __________ are delimited by single quotation marks.
Literal
84
Relational operators have ________ precedence then arithmetic operators
Lower
85
== tests if two strings are stored in the same:
Memory location
86
compareTo method compares strings in :
Lexicographer order - dictionary order
87
== operator tests whether two ________ are identical
Object references