Model 1: Basic Java Programming - Text values with String and char Flashcards

1
Q

Text values with String and char #

The string data itself, when typed in quotes in code

A

is called a string literal

Java should interpret it as literal string data, and not as code.

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

String is a class#

A class in Java has two purposes:

A
  • A class is a collection of methods that you may call.
  • A class defines a custom data type and can be used to make objects of that class.

The String class serves both purposes: it provides some methods that are useful for Strings, and it defines a String data type that you can use to make string objects.

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

Strings are objects#

An object is a structure in memory that

A

stores values.

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

Strings are objects#

A String object stores data

A

the value of each character in the string, as well as the length of the string.

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

Strings are objects#

Some things you can do with objects are:

A
  1. Declare a variable to store a reference to an object of a class: String s.
  2. Create a new object of that type:
    s = “Rumplestiltskin”;
    Strings are somewhat special in Java; other types of objects are created using special method calls.
  3. Read or modify data from the object, using dot notation to get at instance variables. In Java, the String method has no directly useful instance variables, so we’ll see examples of this with other classes.
  4. Call non-static methods on an object; these methods have access to the data within an object:
    System.out.println(s.toUpperCase());
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Static vs non-static methods of the String class

To access static methods of the String class

A

recall that you use both the name of the class and the method name:

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

Static methods are just like functions in Javascript, C, or Python.

A

Java just uses classes to organize these functions.

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

Non-static methods require a string as input, and

A

instead of passing that string as a parameter, dot-notation is used: s.toUpperCase().

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

Strings are in Java#

although there is a way to get a character from a String using the charAt() method

A

there is no way to change a character within a string.

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