Module 1 Flashcards

1
Q

Process of code

A

Source Code (.java files) –> Byte Code (.class files) –> Machine Code (JVM files)

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

Variable

A

A storage container paired with a name. It holds some known or unknown amount of info, called the value.

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

Data Type

A

Defines type of data stored in a variable and how its represented

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

Primitive Data Types

A

Byte, Char, Boolean, Short, Int, Float, Double, Long

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

Variable Name

A

Label that defines what the variable represents. It’s important to give context.

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

Variable Name Properties

A

Should be descriptive. Camel case. Case Sensitive.

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

Widening

A

Casting from a smaller data type to to a larger data type. Ex: int to a long

Casting is implicit, meaning we dont have to specify it.

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

Narrowing

A

Casting from a larger data type to a smaller one. Ex: double to int.

Is explicit meaning the dev has to tell java what new data type the value should be.

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

Truncation

A

When we go from larger to smaller data type + lose data in the process

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

Expression

A

Code that must be solved first. It is an “incomplete thought”. Evaluates to a single value.

Ex: x - y

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

Statements

A

Complete thoughts. Does not need to be solved. Statements end in a semicolon or curly braces. Ex: int x;

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

Blocks

A

Are groups of statements that need to execute as a single unit.

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

Method

A
A reusable block of code. Takes input and returns output that is related to input. Identified by a method signature that indicates:
1. Who can use it
2. What to call it
3. What it will return
4. What input it takes
Some have no arguments.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Method Signature Syntax

A
accessor return_type name (parameters) {}
• Accessor
• Return type
• Name
•Parameters
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Accessor

A

Keyword that identifies who can use the method

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

Return Type

A

A data type (int, double, String)

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

Name

A

Descriptive name

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

Parameters

A

A list of 0…..n variables

public int addNumbers (int x, int y)

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

Boolean Expression

A

An expression that evaluates to true or false. Used to conditionally decide what code to execute. Asks questions about the current state.

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

Logical Operators

A

&& - AND (both conditions must be true)
|| - OR (at least one condition must be true)
^ - XOR (Exclusive or, one condition must be true but not both)
! - NOT (not)

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

Ternary Syntax

A

(variable) = boolean ? true result : false result;

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

Array

A
  • A series of values of the same data type that are held together in a wrapper.
  • Variables for arrays are declared using data types.
  • Must know how many items it can store and type of thing you’ll be storing IN ADVANCE.
  • Values in an array are called elements
  • Elements have an index (starts with 0)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Array syntax

A

String [] instructors = new String [5]

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

Static Initialization

A

Set array + create the values

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

Scope

A
  • A variables scope defines where in a program that variable is valid.
  • When code execution reaches a point where the variables can no longer be referenced then variable is out of scope
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

Loops

A
  • Allow code to be repeated for a set number of times

* Use a boolean condition and execute the code while the condition is true and stop execution once condition is false

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

For Loop Syntax

A
for (int i = 0; i < 10; i++) {
system.out.println(i);
}
• Incrementer variable
• Boolean condition that is true
• define an iterator expression
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

Break

A

Immediately ends a loop

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

Continue

A

Ends the current iteration early and continues the loop in the next iteration.

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

Streams

A

Steady flows of data.

Ex: system.in and system.out

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

Scanner Next Line()

A

Gets text from the input stream up until a newline (enter)

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

Parsing

A

Conversion of data between unlike data types

ex: string -> int

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

Scanner Next Int() Syntax

A

int userNum = scanner.nextInt();

scanner.nextLine();

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

Objects

A

An in-memory data structure that combines state and behavior into a usable and useful abstraction
• Live in a computers memory and only exist while a program is executing
• Each obj is distinct + separate from every other obj.
• Not written in source code
• everything in java is an object, except primitive data types

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

Class

A
Source code that defines how to create an object and what state and behavior it will have
• A class is a blueprint
• It only exists in source code
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
36
Q

Steps of Creating an Object

A
  1. Declare a variable to hold the object. The class will be the data type
  2. Instantiate a new object from the class using the new keyword
  3. Initialize variables inside the object with initial values using the constructor

LegoPerson legoJohn = new LegoPerson(clothes/color, hasCap)

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

Two Data Types in Java

A

Value Data Type and Reference Data Type

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

Value Data Type

A

References a single static space in memory to hold the value. This memory is located on the stack.

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

Reference Data Type

A

Does NOT hold the value in static memory (the stack) but rather holds a reference to WHERE the object is located in free-floating dynamic memory (the HEAP)

40
Q

The Stack

A

Where value data types are stored. Static memory.

41
Q

The Heap

A

Free floating dynamic memory. Reference types have a variable that points to a value on the stacks that contains a memory address that points to the location of the object in the heap.

42
Q

Immutability

A

An object whose state cannot be changed after it is created. Strings are immutable.

43
Q

String creation syntax

A

String name = “Steve”; is the same as

String name = new String (“Steve”);

44
Q

Null

A

Not the same as empty. Variables for reference types default to null. Null means no value. Will usually have to explicitly use = null.

45
Q

null Pointer Exception

A

Occurs when trying to use a method on an object when the variable does not contain a reference and is null.

46
Q

2 types of equality for objects in Java

A
  1. Reference Equality (==)

2. Value Equality (.equality())

47
Q

String Methods

A

String methods are invoked by calling the method with (.) dot operator and ended using parentheses

Ex: String.substring()

48
Q

Substring syntax

A

Inclusive starting index and exclusive ending index

49
Q

Packages

A
  • Organize Java classes and creates scope to prevent same name to have a name collision.
  • It creates a namespace and groups related elements.
  • Must be unique in package but not across packages
  • Packages are made up.
  • Classes in same package can see each other with an import.
50
Q

Collections

A
  • Classes in the java.util package that define data structures that make working with a set of data easier.
  • Written to be generic so they are useful for all reference types.
51
Q

List Syntax

A

List variableName = new ArrayList();

52
Q

Properties of a List

A
  • 0 indexed
  • Order of insertion
  • Elements accessed by index
  • ALlows duplicates
  • Hold the data type defined by
  • Can grow and shrink
  • An interface which contains no code and creates a data type with guaranteed functionality
53
Q

Boxing

A

Moving a primitive value from the stack to a wrapper class object on the heap.

54
Q

Unboxing

A

Moving a wrapper class to a primitive value

55
Q

Orders of Queue and Stack

A

Queue is First In First Out

Stack is Last In First Out

56
Q

Properties of a Set

A
  • Elements are not ordered
  • Elements must be unique
  • Cannot be accessed by index only by iterator (for each)
57
Q

Set Syntax

A

Set variable = new HashSet();

58
Q

LinkedHashSet

A

Order of insertion. Allows null.

59
Q

TreeSet

A

Natural order of data.

Does not allow null.

60
Q

Key Value Pairs

A

A set of two pieces of data where value is associated by a unique key, allowing value to be retrieved by providing the key. Key = value

61
Q

Properties of a Map

A
  • A collection that utilizes key value pairs, allowing values to be assigned and then located using user-defined keys.
  • Organized so value can be retrieved using key
  • Map
62
Q

Map Keys

A
  • Any reference type
  • Unique
  • Must not be null
  • Stored as set
63
Q

Map Values

A
  • Any reference type
  • Can have duplicates
  • Can be null
64
Q

Map Syntax

A

Map variable = new HashMap();

65
Q

Encapsulation

A

The concept of hiding values or state of data within a class, limiting the points of access

66
Q

Inheritance

A

The practice of creating a hierarchy for classes in which descendants obtain the attributes and behaviors from other classes’ classes

67
Q

Polymorphism

A

The ability for our code to take on different forms. In other words, we have the ability to treat classes generically and get specific results.

68
Q

Benefits of OOP

A
  • Natural way of expressing real world objects into code
  • Modular + reliable
  • discrete units of reusable code
  • Units of code can communicate with each other by sending & receiving messages + processing data
69
Q

Coupling

A

Refers to the degree of direct knowledge each component of a system or application has of elements that it needs to use.

70
Q

Loose Coupling

A

An approach to connect components that depend on each other with the least knowledge possible

71
Q

Access Modifiers

A

Visibility of classes, member methods, and variables
• Defines who can use a class, method or variable
• Variables should always be private
• If others need it, given via public getters and setters
• Methods should be public only if they are meant for use by users of our class

72
Q

Classes

A
  • A class is a blueprint or model that defines state with fields (variable) and behavior with methods
  • We create new instances of a class that follow the blueprint but may have diff property values
73
Q

Member Variables

A

Hold the state of the object

• Known as instance variables

74
Q

Getters & Setters

A

Only way to access member variables from outside the class.

75
Q

this

A

this keyword refers to the member variable specific to the instance of an object where code is run.

76
Q

Default for int/float/double =

A

0

77
Q

Default for String =

A

null

78
Q

Default for boolean =

A

false

79
Q

Derived properties

A

A getter that returns a calculation taken from member variables

80
Q

Methods

A

A function, can have multiple parameters but can only return one value.

Ex:
public name ()
81
Q

Function Overloads

A

Overloaded methods are methods with the same name and return type and a different set of parameters.
Java uses the correct overload based on parameters sent to it.

82
Q

Constructor

A

A special method that runs every time a new object is instantiated. It allows for the object to be initialized with a starting state.

Should not call public
Should not be public

83
Q

Inheritance

A

The act of having one class adopt the properties and methods of another class.

  • Prevents code duplication
  • Allows you to share code across classes while having the source code live in only one class file
  • Allows you to build class hierarchy
84
Q

How to call code from a super class

A

Use super variable

85
Q

Polymorphism

A

The idea that something can be assigned a different meaning or usage based on its context

86
Q

Interface

A
  • A declaration of one or more public methods

* Implemented by classes

87
Q

Subclass

A
The derived class acquiring the properties and behaviors from another class
• Inherits all visible properties and behaviors (methods) from the superclass
• Constructors are NOT inherited
• Subclasses have only one superclass
88
Q

Superclass

A

The base class whose members are being passed down

89
Q

Single Inheritance

A

Classes in Java have one and only one direct superclass.

90
Q

The 3 Types of Inheritance in Java

A
  1. Single
  2. Multilevel
  3. Hierarchical
91
Q

Object

A
In Java all objects are subclasses of the class java.lang.Object. Object is the only class in Java that does not have a superclass.
• All implicitly inherit .to String() , .equals() , .hashCode()
92
Q

Casting

A

Changes how the object is treated. It does not change the object or what it internally is.

93
Q

Instanceof

A

A boolean that can check if the obj can be downcast to the subclass type.

94
Q

Object Context

A

Has-A relationship. Group of unlike things.

95
Q

Interfaces

A

Defines what something can do not how it does it.

AKA a “contract”

96
Q

Implementing an Interface

A

When class implements an interface it must provide overrides for all method signatures defined in the interface.