Lesson 4
Tokens
A focused lesson on the smallest units used in Java source code and syntax.
Java Track
Save progress as you learn.
61 lessons
Lesson content
Java Tokens
Java tokens are the smallest individual units in a program.
Keywords
Keywords are predefined reserved words in Java. Each keyword has a special meaning and is always written in lowercase.
- class
- while
- for
- interface
- abstract
Identifiers
Identifiers are used to name variables, constants, functions, classes and arrays. They are usually defined by the user and must be different from reserved keywords.
- The first character must be a letter, underscore, or dollar sign.
- An identifier cannot start with digits, but it may contain digits later.
- Whitespace cannot be included.
- Identifiers are case sensitive.
Valid examples include PhoneNumber, PRICE, radius, a and a1. Invalid examples include 1sum and Sum 1.
Literals
A literal is a notation that represents a fixed value in source code. Once defined, it cannot be changed.
- Integer
- Floating Point
- Character
- String
- Boolean
Operators
Operators are special symbols used to perform mathematical operations or logical manipulations.
- Arithmetic Operators
- Assignment Operators
- Relational Operators
- Unary Operators
- Logical Operators
- Ternary Operators
- Bitwise Operators
- Shift Operators