Module 1 Flashcards
(96 cards)
Process of code
Source Code (.java files) –> Byte Code (.class files) –> Machine Code (JVM files)
Variable
A storage container paired with a name. It holds some known or unknown amount of info, called the value.
Data Type
Defines type of data stored in a variable and how its represented
Primitive Data Types
Byte, Char, Boolean, Short, Int, Float, Double, Long
Variable Name
Label that defines what the variable represents. It’s important to give context.
Variable Name Properties
Should be descriptive. Camel case. Case Sensitive.
Widening
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.
Narrowing
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.
Truncation
When we go from larger to smaller data type + lose data in the process
Expression
Code that must be solved first. It is an “incomplete thought”. Evaluates to a single value.
Ex: x - y
Statements
Complete thoughts. Does not need to be solved. Statements end in a semicolon or curly braces. Ex: int x;
Blocks
Are groups of statements that need to execute as a single unit.
Method
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.
Method Signature Syntax
accessor return_type name (parameters) {} • Accessor • Return type • Name •Parameters
Accessor
Keyword that identifies who can use the method
Return Type
A data type (int, double, String)
Name
Descriptive name
Parameters
A list of 0…..n variables
public int addNumbers (int x, int y)
Boolean Expression
An expression that evaluates to true or false. Used to conditionally decide what code to execute. Asks questions about the current state.
Logical Operators
&& - 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)
Ternary Syntax
(variable) = boolean ? true result : false result;
Array
- 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)
Array syntax
String [] instructors = new String [5]
Static Initialization
Set array + create the values