Difficulty: Beginner | Prerequisites: None (this is foundational material for CSE110).
Big picture
This topic covers the building blocks of every Java program you will write: how to name things, what types of data the language can hold, how arithmetic and logic operators are evaluated, and how to work with text using the String class. If you are behind, start here. Every later topic in CSE110 (functions, arrays, OOP) assumes you can declare variables, predict expression outcomes and manipulate strings. The exam leans on these basics heavily, with 40 marks in the multiple-choice section alone touching identifiers, types, operator precedence and String methods.
Java identifiers must start with a letter, underscore or dollar sign, never a digit or space. Primitive types (int, double, float, char, boolean and others) are built into the language; Strings and arrays are reference types, not primitives. Operator precedence runs from multiplication/division/modulus first, through addition/subtraction, then comparison, then logical operators last. The String class provides .length(), .compareTo(), .indexOf(), .substring() and .charAt(), each with return types and edge cases that come up on exams.
Identifier
The name given to a variable, method, class or other element in Java. Must begin with a letter, underscore (_) or dollar sign ($). Cannot contain spaces or start with a digit. Reserved words (like final, int, class) cannot be used as identifiers. In simple terms, this is just the name you pick for your variables and methods.
Primitive data type
One of Java's eight built-in types that hold simple values directly in memory: byte, short, int, long, float, double, char, boolean. Strings, arrays and objects are not primitive types. Think of it as the raw building-block types the language gives you out of the box.
float suffix (f)
A literal decimal number in Java defaults to double. To assign it to a float variable, you must append an f or F to the literal, e.g. float price = 9.99f;. In simple terms, Java assumes decimals are doubles unless you tell it otherwise with the letter f.
char
A primitive type that holds a single Unicode character. In Java, char literals are enclosed in single quotes ('A'), not double quotes. Double quotes denote a String. Think of it as: single quotes for single characters, double quotes for strings of characters.
String
A reference type (not a primitive) representing a sequence of characters. Strings are objects in Java, which means they come with built-in methods like .length(), .compareTo(), .indexOf(), .substring() and .charAt(). In simple terms, text in Java is handled through the String class, and you use its methods to inspect or slice it.
Operator precedence (order of operations)
The rules that determine which operators in an expression are evaluated first. In Java, from highest to lowest: parentheses, then unary operators, then multiplication/division/modulus, then addition/subtraction, then comparison (>, <, >=, <=), then equality (==, !=), then logical AND (&&), then logical OR (||), and finally assignment (=). Think of it as the Java version of PEMDAS, extended to cover comparisons and logic.
compareTo()
A String method that compares two strings lexicographically. Returns 0 if they are identical, a negative number if the calling string comes before the argument, a positive number if it comes after. In simple terms, it gives you a number telling you whether two strings match or which one comes first alphabetically.
substring(startIndex, endIndex)
A String method that returns a new string from startIndex up to, but not including, endIndex. For example, "GREEN".substring(0, 4) returns "GREE". Think of it as: the start is included, the end is excluded.
indexOf()
A String method that returns the index (position) of the first occurrence of a specified character or substring. Returns -1 if not found. In simple terms, it tells you where in the string a character first shows up.
Identifier rules in Java
Must begin with a letter (a-z, A-Z), underscore (_) or dollar sign ($)
After the first character, digits (0-9) are also allowed
Cannot contain spaces, so total amount is invalid but totalAmount or total_amount are fine
Cannot use special characters like ! in the name, so final! is invalid
Cannot be a Java reserved word (int, class, void, return, etc.)
Java is case-sensitive: myVar and myvar are different identifiers
Convention: variables and methods use camelCase (totalValue), classes use PascalCase (StudentRecord)
Primitive vs reference types
Java's eight primitive types: byte, short, int, long, float, double, char, boolean
Reference types include Strings, arrays and any object you create from a class
The distinction matters because primitives hold values directly, while reference types hold a memory address pointing to the actual data
When the exam asks whether String is a primitive: the answer is always no
Declaring float variables
Decimal literals default to double in Java
To store a decimal in a float, append the suffix f: float temperature = 36.5f;
The suffix d is for double (optional, since it is the default), and L is for long
There is no s suffix in Java
char vs String
char uses single quotes: char grade = 'A';
String uses double quotes: String name = "Alice";
A char holds exactly one character; a String holds zero or more
Operator precedence (order of evaluation)
Parentheses () are evaluated first
Then unary operators (++, --, !)
Then multiplication (*), division (/), modulus (%)
Then addition (+), subtraction (-)
Then comparison operators (>, <, >=, <=)
Then equality operators (==, !=)
Then logical AND (&&)
Then logical OR (||)
Then assignment (=)
Operators at the same precedence level are evaluated left to right
Worked example: int result = 5 + 10 * 2 / 5 - 3;
Step 1: 10 * 2 = 20 (multiplication, left to right)
Step 2: 20 / 5 = 4 (division, same level, left to right)
Step 3: 5 + 4 = 9 (addition, left to right)
Step 4: 9 - 3 = 6 (subtraction)
Final value of result: 6
String methods you need to know
.length() returns an int, the number of characters in the string. Spaces count. "hello world".length() returns 11.
.compareTo(otherString) returns an int: 0 if the strings are identical, negative if the calling string comes first lexicographically, positive if it comes after.
.indexOf(char or String) returns the int index of the first occurrence, or -1 if not found.
.substring(start, end) returns a new String from index start up to but not including index end. "GREEN".substring(0, 4) returns "GREE".
.charAt(index) returns the char at the specified index.
Students often think String is a primitive data type. It is not. String is a reference type (an object). The eight primitives are byte, short, int, long, float, double, char and boolean.
Students forget that float literals need the f suffix. Writing float x = 3.14; causes a compiler error because 3.14 is treated as a double by default.
Students assume identifiers can start with a digit. They cannot. 1name is invalid; _name and $name are valid.
Students confuse char quoting with String quoting. Single quotes are for char ('A'), double quotes are for String ("A"). Using double quotes for a char assignment will not compile.
Students think .compareTo() returns true or false. It returns an int (0, positive or negative), not a boolean.
Students forget that .substring(start, end) excludes the end index. If you want characters at indices 0 through 3, you write .substring(0, 4).
The mock exam tests identifier validity directly (Q1, Q21, Q46). Know the rules cold: no starting digit, no spaces, no special characters beyond _ and $.
Operator precedence appears in both multiple-choice (Q3) and long-answer (Q52). You will be asked to trace expressions step by step.
String methods (.length(), .compareTo(), .substring(), .indexOf()) appear across multiple sections. Know what each returns and its exact type (int vs String vs char).
The float suffix f is a standalone question (Q2). A small detail worth easy marks.
The distinction between primitive and reference types is tested in true/false (Q22). If the exam asks "is String a primitive?", the answer is always false.
True or false: 2total is a valid Java identifier. Answer: False. Identifiers cannot start with a digit.
Fill in the blank: To declare a float variable, you write float x = 7.5___; Answer: f
True or false: .length() counts spaces in a string. Answer: True.
What does "hello".compareTo("hello") return? Answer: 0
True or false: char values use double quotes in Java. Answer: False. char uses single quotes.
Q: Which of the following is a valid Java identifier: 1name, _totalValue, total amount, final!?
A: _totalValue. It starts with an underscore, which is permitted. 1name starts with a digit, total amount contains a space, and final! contains a special character.
Q: What suffix is required when assigning a decimal literal to a float variable?
A: The suffix f (or F). For example: float price = 9.99f;
Q: In the expression 5 + 10 * 2 / 5 - 3, what is the final result and why?
A: The result is 6. Multiplication and division are evaluated first, left to right: 10 * 2 = 20, then 20 / 5 = 4. Then addition and subtraction, left to right: 5 + 4 = 9, then 9 - 3 = 6.
Q: What does string1.compareTo(string2) return if both strings are identical?
A: It returns 0.
Q: What value does s1.substring(0, 4) produce if s1 is "GREEN"?
A: "GREE". The substring method returns characters from index 0 up to, but not including, index 4.
Q: Explain why int my number; is an invalid variable declaration.
A: Java identifiers cannot contain spaces. The variable name my number has a space between my and number, which violates the identifier rules.
Q: Which of the following operators is evaluated last in Java: multiplication, addition, greater-than, or logical operators (&&, ||)?
A: Logical operators (&&, ||). The precedence order runs: multiplication/division first, then addition/subtraction, then comparison, then logical operators.
Identifier rules come back when you name functions (Chapter 6) and classes (Chapter 7); the same rules apply everywhere. Operator precedence matters inside loop conditions and if-statements, so this is prerequisite knowledge for control flow. String methods connect directly to array indexing, since both use zero-based positions and the concept of "up to but not including" an end index.
Java identifier rules, valid variable names, CSE110 data types, primitive vs reference type, float f suffix, char single quotes, String methods Java, compareTo return value, substring endIndex exclusive, indexOf first occurrence, operator precedence Java, order of operations Java, PEMDAS Java, type casting, literal values, ASU CSE110 exam review, Principles of Programming