Chapter 2 Flashcards

1
Q

What are Literals?

A

It is common for programs to include constants; in Java these are referred to as literals.
Ex: 123, 123.45, ’a’, ”Gosling”

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

What are variables?

A

Variables is a named location in a computer’s memory, and the value stored in that location is controlled during the execution of programs.

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

What are the two data types?

A

Primitive data types and data types defined via classes (objects)
Ex: String and System

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

What are all the primitive data types?

A

Byte, short, int, long, float, double, char and Boolean

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

What are Keywords?

A

Java reserves the use of certain names referred to as keywords.
Ex: int

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

What are the Numeric Data types?

A

Numeric data types are used for numer values where there is no fractional component- all values are whole integers.
Ex: byte, short, int, long,

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

What are operators?

A

They are calculations or actions that use a symbol.
Ex: +, -, /, %, *
All of these operators are binary operators, meaning that they have two operands. One operand is on the left side and the other on the right.

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

What is arithmetic operation?

A

When the opera did of both are the same
Ex: int + int = int

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

What does a Modulo do?

A

Modulo gives the remainder when the first operant is divided by the second operand.
Ex: 13%5 = 3

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

How to use the long data type?

A

The value would have a suffix of L
Ex: 10025L

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

What are operands?

A

Operands are either literals, variables, or sub-expressions.
Ex: using operators, 22 + 33, (4) * (5)

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

What are sub-expressions?

A

Sub-expressions are expressions enclosed in parentheses, ( and )

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

What are the Operator Priories for Calculations?

A

Highest to Lowest
* / %
+ -

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

How does Operator Associativity work?

A

Just means the calculations read from left to right since that’s how Java reads.

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

What are the two types of Mixed Mode Expressions?

A

Widening and Narrowing

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

What is widening?

A

Taking a smaller value into a larger value
Ex: short to into (2 byte to 4 byte)
Note: can go from char to int

17
Q

What is narrowing?

A

Casting a bigger variable into a smaller variable
Ex: putting a ((int) 33.4) in front of a double

18
Q

What is a Unary Minus

A
  • , can be placed immediately in front of an expression to negate the value of the expression.
    Ex: -(50-75) is 25
19
Q

What are the three operators for Booleans?

A

&&, ||, !

20
Q

What are the binary operators for Boolean?

A

&&, ||
Both appear between the two operands.

21
Q

What are the priorities of the Boolean operators?

A

! Is highest, followed by &&, followed by ||

22
Q

What are the Relational Operators?

A

Defined for comparing one value to another.

<, >, <=, >=, ==, !=

23
Q

What is the conditional operator?

A

?

<logical> ? <true> : <false>
Logical expression is some logical expression evaluating to true or false
</false></true></logical>

24
Q

The arithmetic, rational, and Boolean operator priorities?

A

++

- (unary minus)
!
new (object creation)
/
*
%
+
-
+ (String catenation)
<
<=
>
>=
==
!=
&&
||
?: (conditional operator)
= (assignment)
+= (assignment with operation)
-=
*=
/=
%=

25
Q

What does the String class work with?

A

Works with test strings and the Java String class is provided to facilitate the many things that programmers need to do with text strings.

26
Q

What is the difference between String type and primitive types?

A

The memory location associated with a primitive type contains the value (not an address) of the value. For example, an int variable will have a memory location reserved for it where the value of the variable is stored.
A variable (of type String) holds a reference to the value instead of holding the actual value.

27
Q

What does the new operator do?

A

The new operator is used to instantiate (to create) an object. new operator

28
Q

How to make a new line and tab in sysout?

A

“/n” for new line
“/t” for tab

29
Q

How to import JOptionPane?

A

Import javax.swing.JOptionPane;