- Java Language Features Supported in Android
- Java SDK Downloads and Release Notes
- Common Problems and Their Solutions
- Java Tutorial Hello World
Introduction to the Java toolchain and compilation of the first program, Hello World.
-
Get students acclimated to the Code Fellows space and have a good understanding of the format class will take each day.
-
Students should have a fundamental understanding of the basics of JAVA including:
- Variables & Constants
- Numeric Types & Operations
- Strings
- Decisions
- Repeating Steps
- Methods
-
Installing toolchains
-
Compiling your first program
-
Get familiar with the development environment: toolchains, editors, etc ...
Introduce yourself, TA's and other instructional staff
Inform students that the TA's will be helping with grading and uploading lecture videos each day.
TA's are also the second line of defense when coming across bugs or other issues.
The first source of help:
Each Other
Let students know that you always try to be available, but to please be understanding of time off.
Everyone needs breaks, even instructors. :-)
We try and respond as quickly as possible, but there may be times where those questions and concerns will have to wait for class/lab.
If you haven't already, give a quick intro on your background.
Go around and do quick student intros:
- Name
- Geeky fact about yourself
- Why Android?
Let students know that today will be a long day considering we have a lot to cover on top of the Kick-Off we just completed.
Remind students that by this point they should have ALL completed the pre-work assignments.
- Men's: 5218*
- Women's: 5208*
-
Make sure students have all installed the following:
giton the CommandLine: GIT Tools Website- Java SDK 1.7: JAVA SDK Download
- The student's favorite text editor.
Related information
- Make sure students have all installed
giton the CommandLine. - Show students your command prompt and let them know about
EZPrompt. - Also, at this level, if they would like to, tell them they can look into using
zshandoh-my-zsh, but will need to do their own research. - If they would like more help setting this up, we can address during lab individually.
- Students have all downloaded and setup Android Studio
Explain that we will go into heavy detail on the GUI of Android Studio, but first we need to get a fundamental understanding of JAVA.
Students should have already set this up based on the prework, but slack out the following link to download the JDK: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
-
The next thing we need to do is get Atom configured to help us with writing our Java code.
-
have Students install the following 2 packages:
autocomplete-java
linter-javac
- Introduction to the Java toolchain: compiler, javadoc, command line switches
- Difference between Java variations (J2SDK, J2ME, J2EE, Embedded Java).
- Embedded development: java development on a very small device.
These items are foreshadowed and convered later:
- Android as a variant of Java - similar to J2ME.
-
Once all the above have been confirmed, we are going to write our first program to test the JDK on the command-line.
-
Open the terminal, and change directory to
~/codefellows/501/android/and run the following commands:
mkdir hello-world
cd hello-world
atom HelloWorld.javaThen, in Atom, write the following HelloWorld code:
public class HelloWorld {
public static void main(String[] args){
System.out.println("Hello World");
}
}Notes on the code above:
- Talk about the fact that EVERYTHING in Java must be inside of a class.
- Mention that while we are focusing on Java, we will need to implement this reserved
main()function, but it will be abstracted away from us in Android Studio.- Also, mention that in Android Studio, we will have a different method of printing to the console using
log.- Explain that we will discuss access control in the future.
- Save the file and go back to the command-line and enter the following commands:
javac HelloWorld.java
java HelloWorld
You should see
Hello Worldprint out to the command-line.
- Explain the
javacis theJava compiler - Inform students that they will only need to compile their code 1 time. After that, any changes made to the program and saved will be reflected on the command-line.
- HelloWorld
Keywords presented: package, public, class, static, void
- In
HelloWorld.javachange the above code to the following:
public class HelloWorld {
public static void main(String[] args){
// System.out.println("Hello World");
String firstName = "Adam";
String lastName = "Wallraff";
Integer age = 31;
System.out.println("Name: " + firstName + " " + lastName + " - Age: " + age);
}
}- Explain that all the variables are mutable by default. After the
agedeclaration, add the following:
firstName = "Something Else";-
Run the program to show that the value changed.
-
Now, change
firstNameto the following:
final String firstName = "Adam";- Save, and explain the error that we are seeing is because we have changed this variable to a constant.
Below the above code, write and explain the following:
if (name.contains("Adam")) {
System.out.println("Your name is Adam!");
} else if (name == "Bob") {
System.out.println("Your name is Bob!");
} else {
System.out.println("I dont know your name...");
}
switch (name) {
case "Adam":
case "Adam Wallraff":
System.out.println("Your name is Adam Wallraff!");
break;
case "Bob":
System.out.println("Your name is Bob!");
break;
default:
System.out.println("I don't know you...");
}
String favoriteLanguage = firstName == "Adam" ? "Swift" : "Not Sure";
System.out.println(favoriteLanguage);Below the above code, add:
int numberOfStudents = 5; //Enter Class size here.
for (int i = 1; i <= numberOfStudents; i++) {
System.out.println("Student: " + i);
}
//Then show implementing a "Enhanced For Loop":
String[] teachers = {"Adam", "Brian", "Duncan"};
for (String teacher : teachers) {
System.out.println(teacher);
}
int number = 0;
while(number < 100) {
System.out.println(number);
number++;
}
do {
System.out.println("number: " + number);
number += 50;
} while (number <= 200);
}Implement the following functions in the HelloWorld class:
public static String printFullName(String firstName, String lastName){
String fullName = firstName + " " + lastName;
System.out.println(fullName); //Output: "Adam Wallraff"
return fullName;
}
public static void helloWorld(){
System.out.println("HELLO WORLD!!");
}Then, call in the main() function:
public static void main(String[] args){
// System.out.println("Hello World");
String firstName = "Adam";
String lastName = "Wallraff";
Integer age = 31;
HelloWorld.helloWorld(); //call method with no arguments or return.
HelloWorld.printFullName(firstName, lastName); //Show this
printFullName(firstName, lastName); //Change to this to show omitting the class name when calling static methods inside other static methods of the same class.
System.out.println(Math.abs(-100)); // 100
System.out.println(Math.min(-100, 100)); // -100
System.out.println(Math.max(-100, 100));// 100
}Go over how to properly submit lab assignments via gist for today.
