Reserved Words
abstract continue for new switch
assert*** default goto* package synchronized
boolean do if private this
break double implements protected throw
byte else import public throws
case enum**** instanceof return transient
catch extends int short try
char final interface static void
class finally long strictfp** volatile
const* float native super while
http://java.sun.com/docs/books/tutorial/java/nutsandbolts/_keywords.html
Variables Naming
• Subsequent characters also can be numbers
• Case sensitive
• No spaces
• Examples:
name
firstName
phoneNumber
Arrays
int[] grades;
grades = new int[15];
Control flow
if (boolean) {
// perform this code
} else {
// otherwise, run this
}
Referencing
int hoursePower = 100;
Car myCar = new Car(hoursePower );
Car yourCar = new Car(hoursePower + 50);
myCar = yourCar;
Print(myCar.HorsePower);
Example
ArrayList<String> arrList = new ArrayList<String>();
arrList.add(“A”);
arrList.add(“AB”);
arrList.add(“ABC”);
arrList.add(“ABCD”);
// using indices
arrList.set(0, arrList.get(1));
arrList.set(1, “foo”);
Example
• What does the following mean?
ArrayList<String> A1;
// bla bla
List<String> list = new ArrayList<String>(A1);
for-each
• Looping by indices
• for-each, parallel execution
for (Object o : collection)
System.out.println(o);
Collection Operations
List<Type> list1 = new ArrayList<Type>();
// …
List<Type> list2 = new ArrayList<Type>();
// …
List<Type> list3 = new ArrayList<Type>(list1);
list3.addAll(list2);
List Algorithms
• sort — sorts a List using a merge sort algorithm, which provides a fast,
stable sort. (A stable sort is one that does not reorder equal elements.)
• shuffle — randomly permutes the elements in a List.
• reverse — reverses the order of the elements in a List.
• rotate — rotates all the elements in a List by a specified distance.
• swap — swaps the elements at specified positions in a List.
• replaceAll — replaces all occurrences of one specified value with
another.
• fill — overwrites every element in a List with the specified value.
• copy — copies the source List into the destination List.
• binarySearch — searches for an element in an ordered List using the
binary search algorithm.
• indexOfSubList — returns the index of the first sublist of one List that
is equal to another.
• lastIndexOfSubList — returns the index of the last sublist of
one List that is equal to another.
See more @ http://docs.oracle.com/javase/tutorial/collections/interfaces/list.html
Tools
• android - Android SDK manager. Create/delete/view Android
Virtual Devices and update the SDK with new platforms/add-
ons.
• ddms - Dalvik Debug Monitor Server. Screen caps,
thread/heap info, process/state info, ..
• emulator - The application responsible for opening AVDs
instances.
• sqlite3 - manage SQLite databases.
SDK – Cont.
• # adb - Android Debug Bridge. A client/server program that
manages the state of an emulated device.
• # aapt - Android Asset Packaging Tool.
• # dx - The converter; converts .class files to Android
bytecode.
Create Project with Android Studio
• Build SDK is the platform version against which you will
compile your app. By default, this is set to the latest version
of Android available in your SDK.
• Minimum Required SDK is the lowest version of Android
that your app supports
Adding your first button
• res > values > strings
• Add toggle_message to strings file.
• And in the activity_main.xml file
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/textView1"
android:layout_centerHorizontal="true"
android:layout_marginBottom="18dp"
android:text="@string/toggle_message" />
Adding your first button
• res > values > strings
• Add toggle_message to strings file.
• And in the activity_main.xml file
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/textView1"
android:layout_centerHorizontal="true"
android:layout_marginBottom="18dp"
android:text="@string/toggle_message" />
Adding your first button
• res > values > strings
• Add toggle_message to strings file.
• And in the activity_main.xml file
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/textView1"
android:layout_centerHorizontal="true"
android:layout_marginBottom="18dp"
android:text="@string/toggle_message" />
Attend Harvard’s OpenCourseWare 201[2]!
Building Mobile Applications, http://cs76.tv/2012/spring/
Mobile Software Engineering, http://cs164.tv/2012/spring/
Or Lynda, Udacity, Coursera