Types you'll use
String name = "Dashboard"; // text
int count = 3; // whole numbers
double total = 149.97; // decimals
boolean shown = true; // true / false
Strings: the one rule
expected.equals(actual) // YES — compares text
expected == actual // NO — compares memory
name.contains("Dash") name.length() name.trim()
Decisions & comparisons
if (code == 200) { ... }
else if (code == 404) { ... }
else { ... }
== != > < >= <= &&(and) ||(or) !(not)
Loops
for (String b : browsers) { ... } // for each
for (int i = 1; i <= 3; i++) { ... } // counted
// while(...) repeats until false — needs a deadline!
Methods
static boolean isValidEmail(String email) {
return email.contains("@");
}
// actions return void; questions return values
Collections
List<String> xs = new ArrayList<>();
xs.add("a"); xs.get(0); xs.size(); // index from 0
Map<String,String> row = new HashMap<>();
row.put("user","qa"); row.get("user");
// List of Maps = your test-data spreadsheet
String toolbox
s.equals(t) s.equalsIgnoreCase(t)
s.contains("x") s.startsWith("h") s.endsWith(".com")
s.trim() s.toLowerCase() s.replace("a","b")
s.length() s.isEmpty() s.split(",")
String.format("Cart: %d items, $%.2f", n, total)
Converting types
int n = Integer.parseInt("42"); // String -> int
double d = Double.parseDouble("9.99");
String s = String.valueOf(42); // number -> String
// UI text is ALWAYS String — parse before doing math
Compile errors, decoded
incompatible types value vs declared type
cannot find symbol typo / wrong case / missing import
';' expected check this line AND the one above
missing return statement a code path exits without return
non-static ... context instance stuff called from static
Class skeleton
public class TestUser {
String username; // fields
public TestUser(String u) { // constructor
this.username = u;
}
public boolean isAdmin() { ... } // method
}
TestUser alice = new TestUser("alice"); // object