- Programming
- Writing Code
- Get Information from Computers
- What can Computer's do
- Variables
- Manipulating Variables
- Conditional Statements
- Arrays
- Dictory definition: the process of preparing an instructional program for a device
- Layman's Terms: attempting to get a computer to complete a specific task without making mistakes
- Not-Intelligent (Computers)
- Can only work based on our commands
- FAR from competent, so we must give them EXACT instructions on how to do their task (Dumb)
- Computer's are only only smart because we program them to be
- Language of Code
- Computers only understand machine code
- A series of 0's and 1's which interpreted by the computer
- We need to convert our instructions from English to Binary in order for the computer to understand them
- One Problem
- It would be entirely unpractical to convert every programming instruction into binary by hand
- Computers only understand machine code
- Programming Languages
- Translate our instructions into machine code
- Very useful for programmers
- Serves as interpreters for converting languages into other languages
- Faster than converting by hand
- High vs Low Level
- Each language has an attribute known as power or level
- Basically how similar it is to machine code
- Low-level programming languages: Assembly or C
- High-level programming languages: Java or Python
- Lower the level -> More similar to machine code
- Each language has an attribute known as power or level
- IDE's (Integrate Development Environments)
- A place to write, run, debug code and converts it to machine code
- IDE's are like any other program on our computer except used for the facilitation of code, e.g., (NetBeans, IntelliJ, Visual Studios)
- Looks: Usually has central area for writing code, console, project hierarchy, preview screens, etc.
- IDE Functionality
- Built-in Error-checking
- Auto-fill for frequently used words
- Project Hierarchy
- Learning Languages
- Learning a computer language can be very similar to learning a real language
- All programming languages have a set of rules to follow when writing code in that language, just like in real languages
- In computer science it is called syntax
- Similar to grammar in real life languages
- Syntax
- Rules we must follow if we want our program to run correctly
- How we type out certain functions
- What to put at the end of each line of code
- How to set up certain functions
- Syntax for each programming languages are unique
- Breaking programming rules will result in an error
- Rules we must follow if we want our program to run correctly
- The Console
- Programmers keep track of their progress by looking at the console
- A text interface within the computer that programmers can use for a variety of purpose
- Programmers keep track of their progress by looking at the console
- How to Use the Console
- Main use of the console is to output text from the program using code
- Print statement prints text to the console for the programmers viewing pleasure
- Main use of the console is to output text from the program using code
- Using the print Statement
- Simply instruct the console to print, and include it inside the parenthesis
- Using python, e.g., `print ("Hello Word")
- Print statement is also usef for viewing and interpreting the computer's output from a program
- Simply instruct the console to print, and include it inside the parenthesis
- A Background Tool
- The console is mainly a Developer Tool
- Not usually meant to be used and interacted with by the end user except in very abstract cases
- Text-based games/simple programs
- Not usually meant to be used and interacted with by the end user except in very abstract cases
- Tends to be hidden away behind the scenes
- Don't try and implement the console in the final product
- The console is mainly a Developer Tool
- Math
- Knows how to do simple arithmetic
- Addition, Subtraction, Multiplication, and Division
- Print the result of any math operation
- May seem useless, but comes in handy extremely often
- Knows how to do simple arithmetic
- Modulus %
- Most programming languages has an additional operator known as modulus (
%
) - Allows us to get the remainder of divisional operation
- Useful when determining if a number is even or odd
- if a number modulo 2 is 0 -> The number is even
- if a number modulo 2 is 1 -> The number is odd
- Most programming languages has an additional operator known as modulus (
- Strings
- Another way of saying text
- Anything enclosed by quotation marks
- String and Number Dilemma
- "4" is treated as a STRING
- 4 is treated as a INTEGER
- What is it
- Something that can store information
- Can be referenced and manipulated
- Something that can store information
- Basics
- Each variable has a type, a name, and a piece of information stored inside of it
- Name is simply a name for the variable
- Each variable has a type, a name, and a piece of information stored inside of it
- Types
- Primitive type variables
- Integers, booleans, floats, doubles, Strings, and Chars
- Primitive type variables
- Integers
- A variable that can store an integer value, e.g., -2, 147, 648
- CAN'T and WILL NOT hold any decimal values
- Booleans
- Can ONLY store and hold a value of either true or false
- Floats and Doubles
- Both are types of floating point data types
- Can store numbers with decimal places
- Float Variables can store up to 32 bits of information
- Double Variables can store up to 64 bits of information
- Both are types of floating point data types
- Strings
- Useful for displaying text and storing input information
- Information the user puts into our program
- Also useful for outputting information in a readable format for the user
- Useful for displaying text and storing input information
- Chars
- Each hold one character
- Useful when a programmer wants to read one button press of one character in a string without using a String variable, e.g., Game controlled by keyboard
- Tip: We can store char's in a String variable, but not String longer than 1 character in a char variable
- Usefulness
- track of things, i.e., user's name or score
- store this information in a variable and then reference, add to, or modify it
- Other important uses for variables
- Taking input from the user
- Making our program have variability
- Have it change based on certain factors
- Manipulating variables is necessary for many tasks in programming
- track of things, i.e., user's name or score
- What happens when we define a variable
- Create a space in memory that stores variable name and its content, e.g.,
int x = 10;
- Create a space in memory that stores variable name and its content, e.g.,
- Blank Variable
- Reasons to do this:
- We want to store the information in the variable down the road
- We are going to use it to store information given to us by the user
- Trying to reference a blank variable will result in a NULLPointerException (which we want to avoid)
- Reasons to do this:
- Dual Pointed Variables
- 2 Variable names that points to the same contents which is String "NullPointerException"
- We do this to save space in our code for the things we know that will have the same value
- Updating Variables
- Game character has different stats
- Life = 100 -> 85
- Potion = 80 -> 64
- Armor = 20 -> 16
- Game character has different stats
- Fate of Variables
- After code has run its course, variables are deleted in memory
- Other Ways of Manipulating Variables
- Integer, Float, and double variables can be
- Added
- Subtracted
- Multiplied
- Divided
- Modulused
- String variables
- Added
- Char's and Boolean's can't be operated on
- Integer, Float, and double variables can be
- Naming Convention
- One big rule: MUST be one continuous String
- camelCase, e.g.,
firstName
- Conditional Statements makes our code do different things
- If Statement
- If True do this, otherwise do something else
- Most programming languages uses parenthesis
()
- Inside parenthesis will be evaluated as either true or false
- If the statement is true, whatever is enclosed inside a set of curly braces directly after the if statement will run
- Booleans
- Each condition is evaluated as a boolean: True or False
- Else-If Statement
- Will only be evaluated if the preceding if (or else-if) statement is false
- Else Statement
- Will only run if all previous cases are not true
- Running through If-Else Statements
- Check initial statement
- If true, run that segment of code and move on with the program
- If false
- Move to any else if statements and evaluate those conditional Statements
- If any of them are not true
- Run that segment of code in else statement and move on
- Check initial statement
- Switch Statement
- An easily collapsible way to write many if-else statements
- Input a variable, then determine which "Cases" that variable could be
- Uses colon (
:
) instead of curly braces - Each switch statement alseo includes a "default" case (Else statement)
- An easily collapsible way to write many if-else statements
- Usefulness of Conditional Statements
- Adds variability to programming
- Program runs differently based on user input
- If a user does something, we want to be able to adapt accordingly
- Without, a program would run the same way every time
- Adds variability to programming
- Where do Variables Fail
- Can only store singular bits of information
- Not able to hold more than one piece of data
- Arrays
- List of something
- Integers
- Strings
- Even other array's
- All information in an array is related
- Like columns in Google Sheets
- List of something
- Referencing Arrays
- Most important thing about arrays is how we reference each element inside of it
- In programming we use Indexes
- Indexing begins at 0
- In programming we use Indexes
- Referencing the 10th element using 10 instead of 9
- Would result in an "Out of Bounds" error
- Most important thing about arrays is how we reference each element inside of it
- Creating Arrays
- Populate First
- Insert the elements in the array immediately
- Populate Later
- Create an array with specific size, but choose to add elements later
- Populate First
- Array Sizes
- When we create array their size are FINAL
- Cannot be increased or decreased in size through conventional methods
- This is what allows us to easily access their indexes
- When we create array their size are FINAL
- Array Types
- When initializing an array, we must determine its type then and there
- e.g., String array, Integer Array, Double Array, etc.
- They all have to be the same type
- When initializing an array, we must determine its type then and there
- 2D Arrays
- Putting an array inside an array is known as a 2-Dimensional Array
- Similar to Matrices in math/physics classes
- Each index in the array is actually another array with it's own set of indexes
- Putting an array inside an array is known as a 2-Dimensional Array
- Indexing 2D Arrays
- To index 2D arrays we use 2 numbers
- First number for row
- Second number for column
- To index 2D arrays we use 2 numbers