Worked example
String w = "programming";
System.out.println(w.length()); // 11
System.out.println(w.charAt(0)); // p
System.out.println(w.substring(0, 7)); // program
System.out.println(w.substring(3)); // gramming
⚠️ The end index of substring is not included: substring(0, 7) takes positions 0 through 6. With one argument it runs to the end.
Note the types differ: charAt returns a single char (written in single quotes, 'p'), while substring(0, 1) returns a one-character String ("p"). They print the same but are not the same type.