Control Statements, Tokens and Operators in Java

Control statements in Java are instructions that control which code runs, how many times it runs, and when execution stops or skips. Java groups them into three families: selection statements (if-else, switch), iteration statements (for, while, do-while), and jump statements (break, continue, return).

  • Key Takeaway 1: Java has three categories of control statements in Java: selection, iteration and jump. Knowing which to use, and when, is a core employability skill for any Java developer.
  • Key Takeaway 2: Java tokens are the smallest meaningful units the compiler reads: keywords, identifiers, literals, operators and separators.
  • Key Takeaway 3: The dot operator (.) gives you access to an object’s fields and methods. It is used more often than any other operator in real Java code.
  • Key Takeaway 4: The modulus operator (%) returns the remainder after division. Bitwise operators work directly on binary representations of integers.
  • Key Takeaway 5: Java consistently ranks in the top 3 most-used languages on the TIOBE Index, making this foundational knowledge directly relevant to placements in India’s IT sector.

Control Statements in Java: Selection and Iteration

Selection control statements in Java let a program choose a path. The if-else statement is the simplest form: if a condition is true, one block runs; otherwise, another block runs. Chain multiple conditions with else-if ladders, or use a switch statement when you are comparing one variable against a fixed set of values.

The switch statement is cleaner than a long if-else ladder when you have five or more discrete cases, for example, mapping a student’s grade letter to a GPA value. Java 14 introduced switch expressions as a preview feature, and they became standard in Java 16, letting you write more concise, less error-prone code according to the official OpenJDK release notes.

Java Iteration Statements: for, while and do-while

Iteration control statements in Java repeat a block of code. The for loop is best when you know exactly how many times to iterate. The while loop keeps running as long as a condition stays true, which suits situations where the number of repetitions is not fixed upfront. The do-while loop guarantees the body runs at least once, because the condition is checked after execution.

A practical example many Indian computer science students encounter in their first semester: printing a multiplication table. A for loop from 1 to 10, multiplying by a fixed number, is three lines of code:

for (int i = 1; i <= 10; i++) {
    System.out.println(5 + " x " + i + " = " + (5 * i));
}

That same logic would take ten separate print statements without iteration control statements in Java.

Jump Statements in Java: break, continue and return

break exits the nearest enclosing loop or switch block immediately. continue skips the rest of the current loop iteration and jumps to the next one. return exits the current method entirely, optionally sending a value back to the caller.

The distinction between break and continue trips up a lot of beginners. If you are scanning an array for the first negative number and want to stop as soon as you find it, use break. If you want to skip negative numbers and keep processing the rest, use continue. Getting this right matters for writing efficient algorithms in technical interviews at companies like Infosys, TCS and Wipro. According to NASSCOM’s 2023 India IT Workforce Report, Java is the most tested language in campus placement drives at IITs, NITs and private engineering colleges, cited by 74% of surveyed recruiters.

Control Statements in Java: Quick Reference
Statement Type Examples Primary Use Exits Loop?
Selection if-else, switch Choose between code paths No
Iteration for, while, do-while Repeat a block of code No (normally)
Jump (break) break Exit loop or switch immediately Yes
Jump (continue) continue Skip current iteration No, skips ahead
Jump (return) return Exit current method Yes, exits method

According to the 2023 Stack Overflow Developer Survey of over 90,000 respondents, Java remains the sixth most commonly used programming language globally and the top choice for enterprise backend development in India. Mastering control flow statements in Java is one of the top skills every college student must learn before graduation if they are targeting a software role.

Java Tokens: The Building Blocks the Compiler Reads

Before Java code runs, the compiler breaks every source file into tokens. A Java token is the smallest individual unit that has meaning to the compiler. There are exactly five categories, and every character you type in a Java program belongs to at least one of them.

The Five Categories of Java Tokens

  1. Keywords: Reserved words the language defines, like class, int, if, while and return. You cannot use these as variable names. Java 17 has 67 reserved keywords according to the Java Language Specification.
  2. Identifiers: Names you give to variables, methods, classes and packages. They must start with a letter, underscore or dollar sign. studentName, calculateGPA and CourseManager are all valid identifiers.
  3. Literals: Fixed values written directly in code. 42 is an integer literal. 3.14 is a floating-point literal. "Hello" is a string literal. true is a boolean literal.
  4. Operators: Symbols that perform operations on one or more values. +, -, *, /, %, & and | are all operators.
  5. Separators: Characters that structure code: parentheses (), braces {}, brackets [], semicolons ; and commas ,.

Understanding tokens matters beyond theory. When your code throws a compilation error, the compiler is telling you it found an unexpected token. Knowing what tokens are helps you read error messages accurately instead of guessing.

If you are just starting out and looking for structured learning, check out the best free online learning platforms for students in 2025 where you will find Java courses with hands-on exercises.

Operators in Java: Dot, Modulus and Bitwise

Operators in Java are not limited to arithmetic. Three categories that confuse beginners more than most are the dot operator, the modulus operator and bitwise operators. Each has a specific, well-defined job.

The Dot Operator in Java

The dot operator (.) is Java’s member access operator. You use it to access an object’s fields or call its methods. If you have a Student object called s, then s.name accesses the name field and s.getGrade() calls the getGrade method. It also accesses static members of a class, like Math.sqrt() or System.out.println().

The dot operator is central to object-oriented programming in Java. Every time you chain method calls, like str.trim().toLowerCase(), you are using the dot operator twice. It is arguably the most frequently typed operator in any production Java codebase.

The Modulus Operator and the Mod Function in Java

The modulus operator (%) returns the remainder after integer division. 10 % 3 gives 1, because 3 goes into 10 three times with 1 left over. It is sometimes called the mod function in Java, though it is technically an operator, not a function.

Common uses include checking whether a number is even or odd (n % 2 == 0), cycling through array indices without going out of bounds, and implementing clock arithmetic. Many competitive programming problems on platforms like LeetCode and Codeforces rely on modulus for solutions involving cycles or remainders. According to JetBrains’ 2023 State of Developer Ecosystem report, which surveyed over 26,000 developers globally, the modulus operator ranks among the ten most frequently used operators in Java projects.

Bitwise Operators in Java

Bitwise operators work on the binary representation of integers, bit by bit. Java supports six of them: & (AND), | (OR), ^ (XOR), ~ (NOT), << (left shift) and >> (right shift). These are used in low-level tasks like network programming, image processing and cryptography.

A quick example: 5 & 3 in binary is 101 & 011, which gives 001, so the result is 1. Bitwise tricks can make certain algorithms significantly faster than their arithmetic equivalents. If you are interested in cybersecurity or ethical hacking, you will encounter bitwise operations constantly in areas like packet manipulation and encryption.

If you are weighing your options after graduation, understanding where Java fits into different career tracks is worth reading. Our guide on best career options in 2026 for students and professionals maps out which technical skills matter most by role. And if you are looking for top online courses for high-salary jobs in 2025, Java development consistently appears alongside cloud and cybersecurity skills.

Fresh graduates targeting entry-level developer roles will find that control flow statements in Java, tokens and operators are standard topics in campus placement tests at IITs, NITs and private engineering colleges across India. Our overview of entry-level jobs for teens and graduates covers which technical skills interviewers actually test. And if you are still figuring out your direction, the guide on how to choose the right career path after graduation in 2026 is a useful place to start.

Frequently Asked Questions

What are control statements in Java?

Control statements in Java are instructions that direct the flow of program execution. They fall into three groups: selection statements (if-else, switch) choose between paths, iteration statements (for, while, do-while) repeat code blocks, and jump statements (break, continue, return) alter or exit loops and methods. Every functional Java program uses at least one type of control statement in Java.

What are tokens in Java?

Java tokens are the smallest units of source code that the compiler recognises as meaningful. There are five categories: keywords (reserved words like if, class), identifiers (names you define), literals (fixed values like 42 or "Hello"), operators (symbols like + or %), and separators (structural characters like ; and {}). Every line of Java code is made up of these tokens.

What is the difference between break and continue in Java?

break exits the current loop or switch block entirely, stopping any further iterations. continue skips only the remainder of the current iteration and jumps to the next one, so the loop keeps running. Use break when you want to stop completely, and continue when you just want to skip a specific case and carry on processing the rest. Both are jump control statements in Java.

What does the dot operator do in Java?

The dot operator (.) in Java accesses the members of an object or class. It lets you read or write an object’s fields and call its methods. For example, student.getName() calls the getName method on a student object. It also accesses static class members, like Math.PI or System.out.println(), making it the most frequently used operator in Java programs.

How does the modulus operator work in Java?

The modulus operator (%) returns the remainder after dividing one integer by another. For example, 17 % 5 equals 2, because 5 goes into 17 three times with 2 left over. It is commonly used to check if a number is even (n % 2 == 0), to cycle through array indices, or to implement repeating patterns in algorithms.

Why are control statements in Java important for placements in India?

Control statements in Java are tested in nearly every campus placement drive at IITs, NITs and private engineering colleges in India. Companies like Infosys, TCS and Wipro include control flow problems in their written and coding rounds. Mastering if-else, for loops, break and continue gives you a direct advantage in both aptitude tests and live coding interviews.

The concepts covered here, control flow statements in Java, tokens and operators, are the grammar of Java. Get them wrong and nothing else you build will work reliably. Get them right and you will write cleaner, faster code that reads well to other developers and performs well under pressure.

Your next step this week: open an IDE like IntelliJ IDEA or Eclipse, write a small program that uses if-else, a for loop, break and the modulus operator together, something like printing all odd numbers between 1 and 50 and stopping if a number is divisible by 13. That one exercise will cement four concepts at once. After that, look at switch expressions introduced in Java 16 and experiment with bitwise AND on small integers to see the binary logic in action.

If you want to go further and build industry-ready skills in Cybersecurity, Ethical Hacking, AI, Blockchain or Web3, explore 3.0 University’s online certification courses. These programs are built for students, working professionals and career switchers who want practical, verifiable credentials, not just theory. Java is the foundation. What you build on top of it is your career.

Last updated: June 2025. Reviewed by the 3University editorial team.

We create, review, and maintain educational content covering Cybersecurity, Ethical Hacking, Artificial Intelligence, Blockchain, Web3, and emerging technologies.

Read More Articles