Chapter 2 Flashcards

(35 cards)

1
Q

Escape sequence for a backspace

A

\b

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

Escape sequence for tab

A

\t

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

Escape sequence that creates a new line

A

\n

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

Escape sequence that is a carriage return

A

\r

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

Escape sequence for double quotes

A

"

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

Escape sequence for a single quote

A

'

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

Escape sequence for a backslash

A

\

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

Values considered an int

A

Integers

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

Values considered a double

A

Decimal values

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

A type of data with only 2 values: true and false.

A

Boolean

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

What are the three primitive types the AP test requires you to know?

A

int, double, and boolean

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

A class that is already defined in Java. Objects are assigned using double quotes.

A

String class

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

Once an object is created their values cannot be changed.

A

Immutable

Ex. Strings

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

Object and variable name rules

A
  • should begin with a lower case letter
  • if 2 words 2nd word capitalized ex. firstName
  • or underscore ex. harry_potter
  • numbers only after 1st letter ex. r2d2
  • no other symbols
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What index is the 1st letter of a String?

A

0

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

String Method that returns a number indicating whether this string comes before (negative return value), is equal to (a zero return value), or comes after (positive return value) the string str

A
int compareTo(String str) 
int val = word.compareTo("Goodbye"); 
//returns 1
17
Q

String Method that returns a new string made up of this string added to (concatenated with) str.

A
String concat(String str)
Ex. String phrase = word.concat(", how are you");
// returns Hello, how are you
18
Q

String Method that returns the position of the first character in the first occurrence of str in this string.

A
int indexOf(String str)
Ex. int index = word.indexOf("lo");
//returns 3
19
Q

String Method that returns the number of characters in a string.

A
int length()
Ex. word.length();
//returns 5
20
Q

String Method that returns a new string that is subset of their string starting at index offset and ending with the character at position endIndex -1

A
String substring(int offset, int endIndex)
Ex. String shorter = word.substring(1,4);
//returns ell
21
Q

String Method that returns a new string that starts at index offset and extends to the end of the string

A
String substring(int offset)
Ex. String temp = word.substring(3);
// returns lo
22
Q

Class that formats decimals

A

DecimalFormat Class

23
Q

Import for the DecimalFormat Class

A

import java.text.DecimalFormat;

24
Q

How to format a decimal (ex.)

A
DecimalFormat fmt = new DecimalFormat("0.###"); 
double total = 1.2345
System.out.print(fmt.format(total));
// prints 1.234
25
String method that returns a new string that is identical l with this string except that every oldChar is replaced by newChar
``` String replace(char oldChar, char newChar) Ex. String newWord = word.replace('l','p'); // returns Heppo ```
26
String Method that returns the character at the specified index
``` char charAt(int index) Ex. char letter = word.charAt(1); //returns e ```
27
String Method that returns true if the string has the same characters as str and false if does not
``` boolean equals(String str) Ex. word.equals("hi"); //returns false ```
28
String Method same as .equals() except ignores the case
``` boolean equalsIgnoreCase(String str) Ex. word.equalsIgnoreCase("hello"); //returns true ```
29
Declaration
int x;
30
Instantiate
x = 50;
31
How do you input something?
``` Create a Scanner Scanner scan = new Scanner(System.in); ```
32
Scanner methods
.nextInt() .nextDouble() .nextLine() .next()
33
How to close a scanner
scan.close();
34
A series of characters that represents a special character
Escape Sequence
35
Method creates a random double from [0,1)
Math.random();