Chapter 2 - Data and Expressions Flashcards

1
Q

What are the objectives of this chapter?

A
  • Use of character strings, concatenation, and escape sequences.
  • Explore the declaration and use of variables.
  • Java primitive data types, expressions.
  • Syntax and processing of expressions.
  • Types of data conversions and mechanism for accomplishing them.
  • Scanner class to create interactive programs.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a character string in Java and which class is it define by?

A

The character string is an object defined by the class string.

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

Whats the object and class here: System.out.println?

A

The system.out is the object representing an output device or file, which by default is the computer screen. The object’s name is OUT stored in System class using the print line method (println). Each piece of data we send is called a PARAMETER.

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

What’s the difference between print and println?

A

Print does not move to the next line. So if I System.out.print(“Three…”);
System.out.print(“Two…”); it will print Three…Two… on the same line.
System.out.println(“Liftoff!)

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

How do you add two numbers?

A

System.out.println( + (10 + 20) or + 10 + 20)

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

What are some escape sequences?

A
\b = backspace
\t = tab
\n = newline
\r = carriage return
\" = double quote
\' = single quote
\\ = backlash
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does this line produce? “Sugar is sweet. \n\tBut U have "commitment issues".\n\t”);

A

Sugar is sweet.

But I have “commitment issues”.

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

Is most of the information we manage in a program represented by variables?

A

Yes.

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

What is a VARIABLE? What does a variable DECLARATION instruct the compiler to do?

A

A variable is a NAME for a location in memory used to hold a data value of a particular DATA TYPE. A variable declaration INSTRUCTS the compiler to reserve a portion of main memory space large enough to hold a particular type of value and indicates the NAME by which we refer to that location.

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

Explain int keys = 88, count, minimum = 0, results;

A

integer type variable named keys that equals the value 88.

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

What does it mean when we say Java is a STRONGLY TYPED language?

A

We are not allowed to assign a value to a variable that is inconsistent with its declared type.

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

What are CONSTANTS?

A

Constants are identifiers and are similar to variables except that they hold a particular value for the duration of their existence. CONSTANTS are, to use the English meaning of the words, not variable. Their values doesn’t change.

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

How do you DECLARE a constant?

A

By putting a final in front of it. final int MAX_OCCUPANCY = 427;

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

How many Primitive Data types are there in Java and what are they?

A

There are 8 PRIMITIVE DATA TYPES in Java? Four types of integers, two types of floating point numbers, a character type, and a boolean data type. Everything else is represented using objects.

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

What are the two basic kinds of numeric values?

A

integers (no fractional part) & floating points (do have fractional parts). These two are divided by how much space (four integer data types, two floating).

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

What are the four integer types and two floating?

A

Integer types (byte, short, int, long) Float types (float, double).

17
Q

What data type does Java assume INTEGER LITERALS are?

A

Integer literals are of the type int UNLESS there is an L attached to the end to make it an integer type long.

18
Q

Which letters do you use for CONSTANTS? And what are some good reasons?

A

We designate them in Upper-case LETTERS. The value can only be changed in one place when needed. It also avoids inadvertent coding errors. Java produces an error if you attempt to change the constants value once it’s been changed.

19
Q

What is an expression?

A

An expression is a combination of one or more operators that usually perform a calculation. The manner in which expressions are evaluated and used is fundamental to programming.