As students dive deeper into the heart of programming, I bring you another set of questions that I will try to answer. Feel free to correct me and make comments. Thanks!
What is the difference between an Arduino and a Raspberry Pi? (Hint)
From a user’s perspective, the Arduino is more designed for “hackers” to be used in embedded systems. For instance, the example often presented is if you want to turn on an LED in code. Using the Arudino, you just wire up an LED and a resistor to one of the IO pins on the arduino and do a little bit of coding.
With the Raspberry Pi on the otherhand though, because it is a full on microprocessor, one first needs to load an operating system (however system) before doing any kind of cool things (like turning on an LED). But because it is essentially a full on computer, the Raspberry Pi can do much more complex tasks that would be impossible (or just too difficult to do natively) with the Arduino (i.e. output videos to your television).
What is a function and what is a parameter? Give an example from one of your projects and identify what part is the function name and what parts are the parameters.
In programming lingo, a function is just a piece of code that performs some action. In performing that action though, a function may or may not need some information from the outside. The information would be consider parameters, extra pieces of information given to the function in order for the function..to well function. For example, in Processing, “background()” is a function that sets the paints over the drawing surface with a color. Of course, in order to paint, it needs to “know” what color to paint and that is the parameter you would give it. To specify a gray scale value for instance, you can call background(GRAY_SCALE_INT) where GRAY_SCALE_INT is an integer between 0 and 255 inclusive.
What is the difference among: int, float, bool, and char. What do each of them mean?
Int, float, bool, and char are all native data types used in Java. They represent different types of data.
- The int is used to represents a integer number (-2,147,483,648…-2,-1,0,1,2…2,147,483,647)
- The float is used to repesent decimal numbers.
- The bool represents one of two values: true or false.
- The char is used to represent characters (e.g. ‘A’, ‘g’, ‘\u123’) (Note the single quotes)
What is the difference between ”=” and ”==”?
So the single equal sign (“=”) is used in assignment such as int x=7 which assigns the value of 7 to the variable x.
The double equal sign (“==”) on the other hand is used in comparisons and evaluates to true or false depending on whether the two operands are equal or not, respectively. (e.g. 5==7 would evaluate to false)
Why do we use variables in programming?
From a functional standpoint, the use of variables allows the coder to manipulate piece of data without knowing the value of the data apriori thus leading to more general code. (For instance, if you were asked to calculate the sum of the integers from 1 to 100 inclusive, you can use a for loop that sums up the numbers 1, 2, 3…, 99, 100. But if generalized the problem to summing up integers from integer startInt to endInt, then you can reuse the same code for calculating the sume of integers from any number to any other higher number.)
Of course using variables often make code more readable by giving pieces of data more meaning names. For instance, if we were using Processing to create a sketch window of width 300 and height 300, we can say “size(300, 300)”. But if we came back to this piece of code months later and forgot about what size accepts but need to change the window to have width 300 and height 200, then we need to do a little research to figure how to do so. On the other hand, if we from the start defined variables width and height and instead had code that said “size(width, height)”, we would easily be able to just change the variables to meet our needs.
Why do we use loops in programming?
The use of loops is all about creating more manageable code. Having to mimic the functionality of loops without the loop structure often leads to repeated code which leads to code that is harder to change/and even understand. Some functionality is even impossible to perform without loops.
For instance, say you wanted to go through an integer array and print out the contents of the array without knowing the size of the array at the time of coding. Well, then the coder, without loops, has no way to actually perform the task. That is because, without loops, the coder essentially has to hardcode reading each part of the array and print out the contents but without knowing the size of the array, the coder doesn’t even know how many lines to hardcode.
Explain what this means.
The image above is just a schematic representing generally how code high-level code that many coders write (using Java, C, etc.) actually gets translated into something that can be processed and run by a computers. As you can see, the code that we write in a high-level language first gets compiled into assembly (often less human-readable code that represents the exact functionality of the high-level code but in terms of instructions that the computer chip understands). From there, the assembler then translates the assembly into computer code, a series of 0’s and 1’s which the computer actually operates on.
I’ll leave the following for another time…
Write a sentence about 3 things you’ve learned that you haven’t written about on your website yet.