Intro Flashcards
What is an IDE (Integrated Development Enviorment)
A place to write, run, and debug code and convert it into machine code.
NetBeans, IntelliJ, Visual Studios.
What is Syntax
A set of rules you must follow when writing code in a language
It’s similar to grammar rules in real life languages
What is a Console
A text interface in a computer that can be used for a variety of purposes
Main use is for outputting text from the program using code.
Print statement
Prints text to the console for programmers to see
Print (“Hello World”)- python
Modulus
Represented with %
Allows us to get the remainder of a division problem. The console will oly show the remainder
Print(10 % 3)
Console: 1
What is a string
Anything enclosed by quotation marks is a string
“Hello World”
“A”
Concatenation
Adding two strings together
print( “Game over, “ + 4 + “ was your final score.”)
The 4 “4” Dilema
The 4 in quotation marks is a string
The 4 without quotation marks is an integer
What is a variable
Something that can store information
Can be referenced and manipulated
Think of it as a cardboard box
Each variable has a type, name, and a peice of information
Name is just a name for the variable
Integer
A variable that can store an integer value
Cannot hold decimal values
-2,147,483,648 to 2,147,483,648
Booleans
Can store a value of either true or false
Can only hold true or false
Float and double variables
Both can store numbers with decimal places
Float: can store up to 32 bits of info
Double: can store up to 64 bits of info
String variables
Just like strings, but can be stored in a variable
Used for displaying text and storing input information, outputting information in a readable format for the user
Char variables
Can only hold one character
“A”
Useful for reading one button press of one character in a string without a string variable. Like a game controlled by a keyboard
The use of variables
To keep track of things in code, such as a user’s name and score to reference and modify.
Naming variable big rule
They must be one continuous string
camelCase
The writing of code that doesn’t capitalize the first letter but capitalizing all words after. Makes it easier to read
camelCaseVariable
The if statement
The most basic conditional statement
If something is true, do one thing
If something isn’t true, do another thing
If (Thing is True) {do what ever is in here}
The Else-If statement
The statement that will only be evaluated if the preceding if statement was bypasses due to being false
The else statement
The statement that comes after an if/if-else statement, and will always carry out instructions
Carried out if all previous cases are untrue
The Switch statement
A collapsible way to write many if else statements
Imput a variable, then determine what “cases” that variable could be
Switch (Var)
Why are conditional statements useful
Adds variability to your code/ program runs differently based on user input
The program will want to adapt to user input accordingly( think dynamic difficulty in resident evil 4 )
What is an Array
A list of something( integers, strings, can be other arrays too)
All information in an array is related
Similar to a grocery list
Indexes
A numbers “place” in an array
Indexing of arrays begin at 0
What is something you can’t do with arrays
You cannot change the size an array post, their sizes are final
Think of a bookshelf and trying to change its size after the fact
What must happen when initializing an array
You must determine its type (String, integer, double, etc)
You cannot mix and match arrays
What is a 2D Array
Putting an array inside of an array
Indexing 2D Arrays
We use 2 numbers, first number is the row, second number is the column
Loops
A statement that is meant to run certain instructions repeatedly
The For Loop
Used for carrying out a set of instructions numerous times
Contains three parts; an integer value, a conditional statement the integer must reach to exit the loop. An operation to modify the integer value after the instructions are completed
Infinite loop caution
When making a loop, you must make sure the given initial integer value and the operation will at some point meet.
If not an infinite loop will occur and crash your program
For(int i = 10; i > 0; i++) {
This code will always run because the i integer will always be bigger than zero and will always add 1, therefor causing an infinite loop, as it will never reach zero
The For Each Loop
Used for repeating through a list of arrays or lists
The loop will go through each element in an array and carry out a set of instructions for each value
Useful for performing an operation across an entire collection of data
The While Loop
Will continuously carry out its instructions while a conditional statement given is true
Can be used to purposely create infinite loops, won’t crash your computer
While( x < 10)
The Do While Loop
A loop that will ALWAYS CARRY OUT ITS INSTRUCTIONS AT LEAST ONCE.
Instructions inside loop will run ONCE before checking true or false for a conditional statement
Benefit for Loops
Easily perform tasks many time in a row
Able to iterate through lists and arrays
Decreases clutter in your code ( anti-Yandere dev)
What is an error
When code doesn’t work as expected, aka bugs
Syntaxes Errors
Error that occurs if you fail to meet the programming rules of a language
Will usually be highlighted by an IDE
Debugging Syntax Errors
IDE’s underline syntax errors and usually provide helpful hints
Misspelling and grammatical errors basically
Strng name = “NullPointerException” :
Runtime Error
Caused by a part of your code not being computed within a reasonable amount of time
Can be caused by an unintended infinite loop
Infinite loop error
Happens if the computer is given a condition with no way to finish that task
Puts the computer in error mode and crash due to a never ending condition
Preventing runtime errors
You will need to think through the flow of your code before running it
Plan out your code before writing
Logic Errors
Code runs smoothly, but doesn’t give to result you wanted
The hardest type to fix, as the error is unknown to the programmer
Preventing logic errors
Code small amounts, and test it often.
If you don’t test often, you might many more logic errors
Debugging code
Read the error
Transverse to the line of code provided by error
Use online forum for help like StackOverflow
Breakpoints
Pauses the program when the line you placed the breakpoint at is reached until you continue