K-12 CS Teacher Professional Development Workshop
Reading
Compiling, Running, and Logic: These three actions are what constitute a working program. If the program can compile, run, and the logic is right, then the program works. Compiling is the process of transforming a persons higher-level code (like Java or Python) into machine code for the computer to read. If the code is converted properly and the computer can read the code, then the code compiles! What this means is that the computer was able to properly read the information and verify that the code should be able to work. After the computer has done this, then the program is ready to run. When running the program, the code is executed by the computer and an output is presented given that there are on errors during the run. The output can then be examined for logical accuracy, which is the final step to ensure if your code works properly. Does your program do what you intended it to? If so, then it is logically correct.
Primitive Data: There are various types of data in Computer Science, and primitive happens to be one of the simplest in high-level programming languages. Oftentimes, this data can be equated to numbers. There are eight types of primitive data in java:
Integers (int): Whole numbers, zero, and negative numbers are included. Numbers like -2, -1, 0, 1, 2
Booleans (boolean): A value which can be set to true or false
Characters (char): A single character like 'a', 'b', '1', or 'G' which has a unique position in memory
Double (double): Decimal numbers which have more decimal places but less of a maximum magnitude compared to floats
Float (float): Decimal numbers
Short (short): Integer values which have a smaller range compared to int
Long (long): Integer values which have a larger range compared to int
Byte (byte): Character versions of numbers from -128 to 127.
Each of these data types has their own special applications. You can convert each of these types of data as long as they are similar. If you convert from a data with more storage to one with less storage, then you must cast, otherwise, you can convert freely. For example...
double num = 6.0;
num = 5;
//5 is an int, but there is automatic casting because an int is of less size than a double.
int num2 = 6
num2 = (int)5.8;
/*This works and sets num2 to equal 5 after it is casted as an int. It must be casted because an int is
of less storage than a double.*/
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Here is what it looks like to declare two different integer variables in a Java main method:
public static void main(String[] args) {
int a;
int b = 2;
}
* The first is simply a declaration that it exists without assignment to a value, while the second has a value assigned to it.
Lets say we wanted a to have a value... here is how we would give it one:
public static void main(String[] args) {
int a;
int b =2;
a = 4
}
And then lets say we want to change the value of b into the value of a if the value of a is larger than b. We would do so using an if-statement. It would look like this:
public static void main(String[] args) {
int a;
int b =2;
a = 4
if (a > b) {
b = a;
}
}
In this program, both b and a are now 4.
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Now that we have done a little basic introductory programming, review the mini lab below to download BlueJ and create a test program.
Boolean Expressions and Demorgan's Law
Here are all the symbols used in typical computer science logic:
<
>
==
!=
>=
<=
!
&&
||
Each of these should be familiar. The first is less than, the second is greater than, the third is simply checking equivalency (equals), the fourth is not equals, fifth is greater than or equal to, sixth is less than or equal to, and seventh is simply not, which negates whatever it combines with. We will come back to the last two shortly, they are for true/false variables.
With this in mind, we can understand that for two numeric variables p and q, let's say we had a condition checking if p > q. If this is true, then it is true. But, let's say we had a not modifier on it: !(p > q). This means that if p > q, then it is false. Therefore, we could instead simplify the expression to be p <= q to mean the same thing.
Let's say we had our original expression (p > q) and we put two not modifiers on it: !!(p > q). This is simply p > q because double nots cancel in logic.
But let's say we had p && q where p and q are now boolean variables. Simply put, && represents "and" and || represents "or". To figure out the truth results for these variables, they would have to be represented on a truth table to find what combinations of true and false yield a final truth or false output.
Let's say we put a not modifier on the expression: !(p && q). To figure out the solution to this, we use a law called Demorgan's Law, which says that we must distribute the not to the boolean variables within and convert the && into an ||: !(p && q) === (!p || !q).