Module 1 Flashcards

(96 cards)

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
Scope
* 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
26
Loops
* 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
27
For Loop Syntax
``` for (int i = 0; i < 10; i++) { system.out.println(i); } • Incrementer variable • Boolean condition that is true • define an iterator expression ```
28
Break
Immediately ends a loop
29
Continue
Ends the current iteration early and continues the loop in the next iteration.
30
Streams
Steady flows of data. Ex: system.in and system.out
31
Scanner Next Line()
Gets text from the input stream up until a newline (enter)
32
Parsing
Conversion of data between unlike data types | ex: string -> int
33
Scanner Next Int() Syntax
int userNum = scanner.nextInt(); | scanner.nextLine();
34
Objects
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
35
Class
``` 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 ```
36
Steps of Creating an Object
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)
37
Two Data Types in Java
Value Data Type and Reference Data Type
38
Value Data Type
References a single static space in memory to hold the value. This memory is located on the stack.
39
Reference Data Type
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
The Stack
Where value data types are stored. Static memory.
41
The Heap
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
Immutability
An object whose state cannot be changed after it is created. Strings are immutable.
43
String creation syntax
String name = "Steve"; is the same as | String name = new String ("Steve");
44
Null
Not the same as empty. Variables for reference types default to null. Null means no value. Will usually have to explicitly use = null.
45
null Pointer Exception
Occurs when trying to use a method on an object when the variable does not contain a reference and is null.
46
2 types of equality for objects in Java
1. Reference Equality (==) | 2. Value Equality (.equality())
47
String Methods
String methods are invoked by calling the method with (.) dot operator and ended using parentheses Ex: String.substring()
48
Substring syntax
Inclusive starting index and exclusive ending index
49
Packages
* 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
Collections
* 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
List Syntax
List variableName = new ArrayList();
52
Properties of a List
*  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
Boxing
Moving a primitive value from the stack to a wrapper class object on the heap.
54
Unboxing
Moving a wrapper class to a primitive value
55
Orders of Queue and Stack
Queue is First In First Out | Stack is Last In First Out
56
Properties of a Set
* Elements are not ordered * Elements must be unique *  Cannot be accessed by index only by iterator (for each)
57
Set Syntax
Set variable = new HashSet();
58
LinkedHashSet
Order of insertion. Allows null.
59
TreeSet
Natural order of data. | Does not allow null.
60
Key Value Pairs
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
Properties of a Map
* 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
Map Keys
* Any reference type *  Unique * Must not be null * Stored as set
63
Map Values
* Any reference type * Can have duplicates *  Can be null
64
Map Syntax
Map variable = new HashMap();
65
Encapsulation
The concept of hiding values or state of data within a class, limiting the points of access
66
Inheritance
The practice of creating a hierarchy for classes in which descendants obtain the attributes and behaviors from other classes' classes
67
Polymorphism
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
Benefits of OOP
* 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
Coupling
Refers to the degree of direct knowledge each component of a system or application has of elements that it needs to use.
70
Loose Coupling
An approach to connect components that depend on each other with the least knowledge possible
71
Access Modifiers
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
Classes
* 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
Member Variables
Hold the state of the object | • Known as instance variables
74
Getters & Setters
Only way to access member variables from outside the class.
75
this
this keyword refers to the member variable specific to the instance of an object where code is run.
76
Default for int/float/double =
0
77
Default for String =
null
78
Default for boolean =
false
79
Derived properties
A getter that returns a calculation taken from member variables
80
Methods
A function, can have multiple parameters but can only return one value. ``` Ex: public name () ```
81
Function Overloads
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
Constructor
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
Inheritance
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
How to call code from a super class
Use super variable
85
Polymorphism
The idea that something can be assigned a different meaning or usage based on its context
86
Interface
* A declaration of one or more public methods | * Implemented by classes
87
Subclass
``` 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
Superclass
The base class whose members are being passed down
89
Single Inheritance
Classes in Java have one and only one direct superclass.
90
The 3 Types of Inheritance in Java
1. Single 2. Multilevel 3. Hierarchical
91
Object
``` 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
Casting
Changes how the object is treated. It does not change the object or what it internally is.
93
Instanceof
A boolean that can check if the obj can be downcast to the subclass type.
94
Object Context
Has-A relationship. Group of unlike things.
95
Interfaces
Defines what something can do not how it does it. | AKA a "contract"
96
Implementing an Interface
When class implements an interface it must provide overrides for all method signatures defined in the interface.