Chapter 2 Flashcards

1
Q

Data Type

A

The name for group of values. Everything that need to be manipulated in Java has its ‘type’. Java supports two different kinds of data: primitive data and objects.

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

Primitive Types

A

There are 8 Primitive data types in Java: boolean, byte, char, double, float, int, long and shot. Four of them are fundamental: boolean, char, double and int.

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

Expression

A

set of operations that produces a value or a simple value.

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

type ‘char’

A

A character literal has type char.
Ex.
‘a’ ‘m’ ‘x’ ‘!’ ‘3’ ‘\’ ‘'

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

’/’ division

A

19 / 5 is 3.8 on a calculator, so 19 / 5 evaluates to 3 in Java programming.

4.8 / 2.0 is 2.4

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

numerator / denominator

A

4 / 8
numerator -> 4
denominator -> 8

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

Mixing Types and Casting

A

If one of the operands is type double the result is double

double 5 / 1.5

Java can convert values with ‘cast’.
The cast is applied to whatever comes right after if .

For ex.

(int) 5.2 / 1.5 -> 2.0 has not the same result
as
(int)(5.2 / 1.5) -> 2

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

Variable

A

a memory location with name and type that
stores a value.

The name must start with a letter and then can be followed by any combination of letters and digits.

ex.
int number = 4;
double countSum = 0.0;

Before variables can be used in a Java program, they must be declared. -> It’s called a variable ‘declaration’.

Declaration - a request to set aside a new variable with a given name and type.

ex.
    double height;
or
    double height = 5.2 ;  ->  (declaration and assignment)
or 
    double height, weight;
or 
    double height = 5.2, weight = 105
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Assignment Statement

A

The assignment operator evaluates from fight to left,
which allows to write statements such these:

int x, y, z;
x = y = z = 2 * 5 + 4;

equivalent to:

x = (y = (z = 2 * 5 + 4));

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

Scope

A

The part of a program where a particular declaration is valid.

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

Variable Scope / Local Variables / Localizing Variables

A

The scope of a variable is from its declaration to the closings curly brace.

Any variables that is declared inside of a method can be accessed only inside of that method. This variable called a Local Variable.
For example, a variable delayed inside a for loop cannot be accessed from outside of that loop.

Localizing Variables - declaring variables in the most local scope possible.

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

Class Constants

A

A named value that cannot be changed. A class constant can be accessed anywhere in the class (its scope).

A general syntax:
public static final =

The keyword “final” indicated that the value cannot be changed.

In case a method to be able to access constants , the constants must be static.

Ex.
public static final int HEIGHT = 10;

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