The .length() method returns the number of characters in a string. Notice the parentheses. Unlike arrays, where you write arr.length without parentheses, strings require str.length() with them.
String word = "Java";
int size = word.length();
System.out.println(size);
This prints . Every character counts, including spaces and punctuation. The string "Hi there!" has a length of .
An empty string "" has a length of . This is different from null. If your variable is null and you call .length(), Java throws a NullPointerException. Always check for null before calling methods on a string if there is any chance the variable was never assigned.