diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..0e35c60 Binary files /dev/null and b/.DS_Store differ diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b72f9be --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*~ +*.swp diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..a852314 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,23 @@ + + + + + \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml new file mode 100644 index 0000000..e7bedf3 --- /dev/null +++ b/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/description.html b/.idea/description.html new file mode 100644 index 0000000..db5f129 --- /dev/null +++ b/.idea/description.html @@ -0,0 +1 @@ +Simple Java application that includes a class with main() method \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..d821048 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..b63395b --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..64f1879 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/project-template.xml b/.idea/project-template.xml new file mode 100644 index 0000000..1f08b88 --- /dev/null +++ b/.idea/project-template.xml @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/.idea/scopes/scope_settings.xml b/.idea/scopes/scope_settings.xml new file mode 100644 index 0000000..922003b --- /dev/null +++ b/.idea/scopes/scope_settings.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..2951034 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,635 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1425150686425 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/2015-03-01.md b/2015-03-01_intro-compiling-printing.md similarity index 94% rename from 2015-03-01.md rename to 2015-03-01_intro-compiling-printing.md index b89c523..6947130 100644 --- a/2015-03-01.md +++ b/2015-03-01_intro-compiling-printing.md @@ -18,6 +18,7 @@ These are all included in the JDK. The JRE only contains the JVM and standard l * JDK = Java Development Kit * JRE = Java Runtime Environment +* - used primarily for RUNNING java programs, but does NOT allow for developing * runtime = The point at which a program is run, as opposed to the point at which it is created. @@ -37,7 +38,7 @@ The Java compiler (the `javac` program) translates Java source code into machine > **Exercise**: Find the Java7 standard library documentation. -> **Exercise**: Find the JDK standard library documentation. +> **Exercise**: Find the JDK documentation. Command-line Java @@ -113,7 +114,7 @@ Strings in Java are always quoted with double quotes. * quoting = Surrounding text with quotes or other special markers to indicate that the text between the quotes should be interpreted specially. -> **Excercise**: http://programmingbydoing.com/a/a-good-first-program.html +> **Exercise**: http://programmingbydoing.com/a/a-good-first-program.html What if you want to print two strings on the same line? @@ -131,7 +132,7 @@ Some Java string escapes: * escape = escape sequence = A sequence of characters that has a special or unusual interpretation. -> **Excercise**: Why do we need these? +> **Exercise**: Why do we need these? > **Exercise**: Find the full list of Java escapes. > @@ -205,3 +206,8 @@ There's one more special thing called `null`. > **Exercise**: http://programmingbydoing.com/a/numbers-and-math.html + +Exit ticket +== + +https://docs.google.com/forms/d/1LTrWmkDmxw1_9TRIw6e3Ihi68Y-OCX3Cx2dljYGeNI4/viewform diff --git a/2015-03-01_notes.md b/2015-03-01_notes.md new file mode 100644 index 0000000..1310114 --- /dev/null +++ b/2015-03-01_notes.md @@ -0,0 +1,210 @@ +What is Java? +== + +Java is not Javascript! + +Java is programming a language and a platform. + +* platform = an environment for running other programs + +The Java platform consists of: + +1. the JVM +2. the Java language and compiler +3. the Java standard libraries + +These are all included in the JDK. The JRE only contains the JVM and standard libraries. + +* JDK = Java Development Kit + +* JRE = Java Runtime Environment + +* runtime = The point at which a program is run, as opposed to the point at which it is created; compile time errors (i.e. missing semicolons, source code) and runtime errors (i.e. program crashes) +* JVM = Java Virtual Machine, custom for each hardware; computer that does not exist in the physical world (i.e. simulator); exists in the imagination of another program; web browers all implement JVM; "jit" - just in time +* virtual = opposite of physical, i.e. does not really exist + +* virtual machine = A computer that doesn't physically exist. In this case, another program pretends to be ("emulates") the virtual computer. + +* compiler = A program that translates source code into machine code. + +The Java compiler (the `javac` program) translates Java source code into machine code for the virtual machine, known as "Java bytecode". + +* library = A collection of software. + +* standard library = A library of basic routines that comes packaged with a programming language. + +* API (application programming interface) = a way for other programs to talk to you; list of different functions, classes, code objects that you can use. How other sites can talk to Facebook (Google Maps, Macintosh, etc.). org.w3c.dom to understand HTML + +> **Exercise**: Find the Java7 standard library documentation. + +> **Exercise**: Find the JDK standard library documentation. + + +Command-line Java +== + +* command line = An environment that expects you to type commands, and that executes these one by one and prints out the result. For example, the `Terminal` app. + +Terminal shows you a `$` prompt and waits for your commands. + +* prompt = An indication that the computer is waiting for you to type something. + +To use your Java7 JDK: + + export PATH=/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/bin:$PATH + +This tells your command line to find the `java` and related programs in your JDK. + + $ cd + $ mkdir java + $ cd java + +Open `TextEdit`. Select `Format > Make Plain Text`. _(Important!)_ Enter some Java code. + + public class Hello { + public static void main(String[] argv) { + System.out.println("Hello, world!"); + } + } + +Save the file as `Hello.java` in your java directory. _(Important! The file name **must** match the class name in the program.)_ Back in the terminal: + + $ ls + Hello.java + $ javac Hello.java + $ ls + Hello.class Hello.java + +You should see a new file named `Hello.class`. That contains the Java bytecode. + + $ java Hello + Hello, world! + +> **Exercise**: Make it greet you three times (in one run of the program). + +OK now we can go back to IntelliJ, which takes care of all of this for us. + + +Printing +== + +For each exercise, create a new class! + +1. Select `File > New > Java Class`, or press `^⌥ N` and select `Java Class`. +2. Give the class a name. _Important: Capitalize the class name!_ +3. Add the `main()` function as from 'hello world'. + +When you run your code, make sure you are running the correct class! + +* camel caps = Words smushed together with each one capitalized. For example, "My name is Alex" in camel caps is `MyNameIsAlex`. + + +> **Exercise**: http://programmingbydoing.com/a/comments-and-slashes.html + +* comment = Text within source code that it ignored by the compiler; it's there only for humans reading the source. + +> **Exercise**: There's a second comment syntax in Java. Find it. Why two? + +> **Exercise**: http://programmingbydoing.com/a/letter-to-yourself.html + String = character string = a sequence of characters + Java always use STRAIGHT double quotes + Escape sequence (i.e. \" words here \") +> **Exercise**: http://programmingbydoing.com/a/your-initials.html + +Strings in Java are always quoted with double quotes. + +* quoting = Surrounding text with quotes or other special markers to indicate that the text between the quotes should be interpreted specially. + +> **Excercise**: http://programmingbydoing.com/a/a-good-first-program.html + +What if you want to print two strings on the same line? + +* Try adding the strings as if they're numbers. + +* Try changing some `println` to `print`. What's the difference? + +Some Java string escapes: + +| Escape | result | +|--------|--------| +| `\n` | end the line | +| `\b` | backspace | +| `\"` | double quote | + +* escape = escape sequence = A sequence of characters that has a special or unusual interpretation. + +> **Excercise**: Why do we need these? + +> **Exercise**: Find the full list of Java escapes. +> +> **Exercise**: Write a Java program that prints out some Java source code! It should print out the 'Hello world' line. +> +> System.out.println("Hello, world!"); + +So far we've printed only strings. You can print numbers too. + +> **Exercise**: Try these: +> +> println(42) +> println("42") +> +> println(42.0) +> println(42.0000) +> println("42.0000") +> println(41.999999999999999) // fifteen 9's +> println("41.999999999999999") +> +> What's going on? + +* integer = A round number, which has no fractional part. It may be positive, negative, or zero. + +* floating-point number = A computer representation of a number with a fractional part, i.e. a decimal point. + +* hexidecimal number = (can look like 0x, 52A2B3)a number where each digit has 16 possible values rather than 10 (0, 1, 2, ...9, a, b, c, d, e, f are the digits instead of 0-9) commonly used for memory addresses and color values +> **Exercise**: Try these: +> +> println(17 + 25) +> println("17" + "25") +> println("17" + 25) +> println(17 + "25") +> +> What's going on? +> +> **Exercise**: Using Java, compute the sum of the numbers one through ten. + +* literal = A fixed value (numerical, string, or otherwise) that you type in explicitly. + +* expression = A formula for a value computed by the computer. + +Today, it's -4 C outside. + +> **Exercise**: Print the temperature in Farenheit. +> Formula for conversion from Celsius to Farenheit: *9/5 add 32 +> Can you get the output to look like this? +> +> temperature: 25 F +> +> How about like this? +> +> temperature: 25°F + +There are a few other things, too: single characters, booleans, + +* character = A letter, digit, punctuation mark, or another _single_ symbol. +* boolean = A choice between true and false. + +> println(Hello, world!) +> +> println('x') +> println("x") +> println('Hello, world!') +> +> println(true) +> println(false) + +There's one more special thing called `null`. + +> **Exercise**: Try to print out `null`. + +> **Exercise**: http://programmingbydoing.com/a/numbers-and-math.html + diff --git a/2015-03-03_variables-types-strings.md b/2015-03-03_variables-types-strings.md new file mode 100644 index 0000000..11d9b04 --- /dev/null +++ b/2015-03-03_variables-types-strings.md @@ -0,0 +1,105 @@ +Variables += +*Variables* are names (or symbols) associated with values (or data) in a computer. Variables allow programmers to save data and reference it later. Let's look at some code: + + public class Variables { + public static void main(String[] args) { + int favoriteNumber = 9; + System.out.println("My favorite number is " + favoriteNumber); + } + } + +In the above code, `favoriteNumber` is a variable that stores the value `9`. Whenever you use `favoriteNumber` in your code, the computer will know you mean `9`. Notice that `favoriteNumber` is preceded by the word "int". `int` is a *type* and indicates that the variable is an integer. Every variable in Java is preceded by a type. We'll discuss types in more detail later; for now, just copy the type names provided in the assignments. + +> **Exercise**: Variables and Names +> http://programmingbydoing.com/a/variables-and-names.html + +> **Exercise**: More Variables and Printing +> http://programmingbydoing.com/a/more-variables-and-printing.html + +Rules for naming variables +- +* Names are case sensitive. +* Names can be any length of Unicode letters and digits. +* Names must begin with a letter, dollar sign "$", or underscore "_". +* By convention, names begin with a letter. +* Whitespace is not permitted. + +> **Exercise**: Convince yourself that the above rules are true. +> Your compiler will complain if you break a rule. + + +Primitive types += +All Java variables have a type. A type is a set of values and operations on those values. A "type" sounds abstract, but we use the concept every day. For example, you can think of "bananas" and "strawberries" as both of the type "fruit." When you use a type in Java, you are telling the compiler what kind of data you are using. + +In Java, every variable is declared along with a type. The language has 8 primitive types: +* `byte` - 8-bit integer +* `short` - 16-bit integer +* `int` - 32-bit integer +* `long` - 64-bit integer +* `float` - 32-bit floating point number +* `double` - 64-bit floating point number +* `boolean` - true or false +* `char` - a single character, like 'A' or '$' + +Numbers +- +The types `byte`, `short`, `int`, and `long` represent integers. They vary in size. `float` and `double` represent *real numbers*. For our uses, this means that they can have decimals in them. For example, 2 is an integer but 2.1 is a real number. + +> Review: Numbers and Math +> http://programmingbydoing.com/a/numbers-and-math.html + +> Exercise: Variables and their sizes +> What happens when you: +> - Assign a really big number to a short? +> - Add a short and an int? +> - Add an int and a double? + +Booleans +- +A *boolean* represents the values `true` and `false`. Booleans are useful when data has a "yes" or "no" answer. For example, the question "Is this a banana?" has a boolean answer. Booleans can also be created by comparing two variables. For example, "Is 7 greater than 3?" has a boolean answer. In Java, we write this: + + boolean answer = 7 > 3; + +The value of `answer` will be the boolean value `true`. Try it! + +The boolean comparators are: +* `<` +* `<=` +* `>` +* `>=` +* `==` +* `!=` + +What else can you compare? + +Chars and strings +- +A *char* represents a single character. In Java, you denote a char by placing it between single quotes ''. For example, the following are chars: 'a', 'c', '$', '7', and '_'. In this workshop, we will also play with the type String. Strings are sequences of characters and denoted with double quotes "". For example, the following are strings: "hello", "Queens!", "$99.999". Strings are not primitive types but that distinction does not matter to us now. + +> Exercise: Play with characters and Strings. What happens if you do the following: +> - `char c = "a";` +> - `String b = 'foo';` +> - What happens if you add, using `+`, two strings together? +> - Two chars? +> - A string and a char? +> - A char and a string? +> - Do any other mathematical operations work on strings? + +> **Exercise**: Using Variables +> http://programmingbydoing.com/a/using-variables.html + +> **Exercise**: Still Using Variables +> http://programmingbydoing.com/a/still-using-variables.html + +> **Exercise**: Your Schedule +> http://programmingbydoing.com/a/your-schedule.html + +Let's explore these ideas with a longer in-class problem: + +> **In-class homework**: Print "The Twelve Days of Christmas", an English carol with a lot of repetition! You can find the structure of the lyrics here: http://en.wikipedia.org/wiki/The_Twelve_Days_of_Christmas_%28song%29#Lyrics. Use variables to store bits of repeated data and print the full lyrics. + +Food for thought += +Have you noticed that when you perform an operation on two variables of the same type, the result is also a variable of the same type? But when you perform the same operation on two slightly different types, the result—if the operation is legal—is the type of the "parent" type. If you throw some strawberries into a fruit salad, do you have strawberries or a bigger fruit salad? diff --git a/README.md b/README.md index 74a0f06..11a170c 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,17 @@ # Unit 0: Programming Basics -Lesson plans, activities and assignments for Unit 0 will be posted here! \ No newline at end of file +Lesson plans, activities and assignments for Unit 0 will be posted here! + +### Lesson plans hahahaa + +| Date | Lesson | +|---|---| +| 3/1 | [0. Intro: Compiling & Printing](2015-03-01_intro-compiling-printing.md) | +| 3/3 | [1. Variables & Types](2015-03-03_variables-types-strings.md) | + +### Homework + +| Due Date | Homework| +|---|---| +| 3/7 |