DEV Community

Cover image for Types: char and boolean
Ricardo Caselati
Ricardo Caselati

Posted on

2

Types: char and boolean

After learning about the double and float types, it’s time to dive into two other essential primitive types in Java: char and boolean. Ready to explore?

The char Type

The char type is ideal for representing a single Unicode character. This means you can store any character—letters, numbers, or symbols—using it. There are two ways to assign a value to a char variable:

  1. Using single quotes, like 'A', 'Ω', or 'B'.
  2. Using a numeric value, corresponding to the character in the Unicode table. For example, the code below stores the letter "A" using its Unicode value:
char letterA = 65;
Enter fullscreen mode Exit fullscreen mode

Want to see char in action? Check out this example:

public class PrimitiveTypes {
    public static void main(String[] args) {
        char letterA = 'a';
        char capitalA = 'A';
        System.out.println(letterA); // a
        System.out.println(capitalA); // A
    }
}
Enter fullscreen mode Exit fullscreen mode

The boolean Type

The boolean type is one of the simplest—and most useful! It represents only two possible values:

  • true
  • false

This variable type is essential for making decisions and controlling the program's flow, especially with conditionals like if and while. In Java, unlike some other languages where 0 and 1 are used to represent false and true, we explicitly use true and false.

An interesting detail is that boolean variables often have names that resemble questions. Internationally, they typically start with "is," while in some contexts, prefixes like "eh" might be used. Examples:

public class PrimitiveTypes {
    public static void main(String[] args) {
        boolean isJavaFun = true; // Examples: isRunning, isActive
        boolean isAdult = false; // Examples: isTrue, isReady
    }
}
Enter fullscreen mode Exit fullscreen mode

Now that you know how these types work, you can use them to make your code more intuitive and functional!

Playwright CLI Flags Tutorial

5 Playwright CLI Flags That Will Transform Your Testing Workflow

  • --last-failed: Zero in on just the tests that failed in your previous run
  • --only-changed: Test only the spec files you've modified in git
  • --repeat-each: Run tests multiple times to catch flaky behavior before it reaches production
  • --forbid-only: Prevent accidental test.only commits from breaking your CI pipeline
  • --ui --headed --workers 1: Debug visually with browser windows and sequential test execution

Learn how these powerful command-line options can save you time, strengthen your test suite, and streamline your Playwright testing experience. Practical examples included!

Watch Video 📹️

Top comments (0)

The Most Contextual AI Development Assistant

Pieces.app image

Our centralized storage agent works on-device, unifying various developer tools to proactively capture and enrich useful materials, streamline collaboration, and solve complex problems through a contextual understanding of your unique workflow.

👥 Ideal for solo developers, teams, and cross-company projects

Learn more

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay