Class_1 Flashcards

1
Q

How does a Java file execute?

A

1) Source code is WRITTEN in a .java file
2) Source code is COMPILED into a .class – Java Byte-code
3) Byte code executed just-in-time in an instance of JVM.

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

What is a Strongly Typed Language?

A

There are different data types, and each data types has specific behaviours.

For example, we can’t take the exponent of a string, but we can take the exponent of an integer.

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

What is a Statically Typed Language?

A

Once we’ve determined what data type a variable can hold, that variable CANNOT be assigned any other data type.

int aNumber = 3;

aNumber can ONLY contain integers.

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

What are the three ways Java can convert data?

A

1) Assignment
2) Promotion
3) Casting

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

What is ASSIGNMENT data conversion?

A

When a data type is stored in a wider data type – for example, from byte to integer – the narrower data type is automatically converted to the wider data type.

This will maintain magnitude but it can, in some instance, mean a loss of precision.

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

What is PROMOTION data conversion?

A

Occurs during an operation between two data types; the narrower data type will be automatically converted to a wider data type. For example, adding an integer to a double will result in a double.

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

What is CASTING data conversion?

A

When a programmer must explicitly cast a wider data type to a narrower data type. This requires the following syntax:

double number = 16.34;
int aNumber = (int) number / 6;

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

What are Java’s PRIMITIVE TYPES?

A

** boolean (N/A bytes / 1 bit)
** char (2 bytes / 16 bits)

Integers:
** byte (1 byte / 8 bits)
** short (2 bytes / 16 bits)
** int (4 bytes / 32 bits)
** long (8 bytes / 64 bits)

Decimals:
** float (4 bytes / 32 bits)
** double (8 bytes / 64 bits)

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

What is a HEAP?

A

The heap is where instantiated objects exist. They are pointed to by variables that exist in the stack.

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

What is the STACK?

A

The stack is where primitives live, which exist inside their variables, and where variables live that point to objects that exist in the heap. The stack is where a thread is executed, First In, Last Out (FILO).

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

What is a class?

A

A class is a blueprint that defines a type of object – its attributes, how its constructed, and its behaviours (methods). An object is an instantiation of a class.

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

What do we find in a .java file?

A

A .java file contains code for a single class. That class will contains these three things:

(1) The data it contains – its state, stored in variable.
(2) How to instantiate an object of the class type – the arguments we must pass into the constructor.
(3) The behaviours of the object – its methods

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

In Java, every class must have a main() method. What does the main method look like?

A

public static void main(String[] args) {}

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

What are the rules for creating variable names in Java?

A
  • Variable names can include letters, numbers, underscores, and the $ sign.
  • Variables names cannot start with a number.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are the three main identifier types in Java?

A
  • Class names must be TitleCase.
  • variables and methods are camelCase.
  • constants are ALL_CAPITALS_WITH_UNDERSCORES.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are some attributes of Java?

A

** Simple
** Object-oriented
** Distributed
** Robust
** Secure
** Portable
** Interpreted

17
Q

What are the SELECTION control structures?

A

** If - else-if - else
** Conditional operators (&&, ||)
** Switch statements

18
Q

What is NULL?

A

Applies specifically to OBJECTS, not primitives.

It tells us that a variable is NOT currently storing an address – it’s no pointing to an object in the heap. (Its object reference is NULL.)