Java Booleans
Make a decision explicit.
முக்கிய விளக்கங்கள் தமிழில் உள்ளன. Runnable example மற்றும் கூடுதல் practice notes ஆங்கிலத்தில் உள்ளன.
இந்தப் பாடத்தில்…
- Explain the key idea behind Booleans.
- Read and run a complete example, then predict what changes.
- Recognize the topic-specific mistake discussed below.
அடிப்படையைப் புரிந்துகொள்ளுங்கள்
A boolean has one of two values: true or false. Build conditions with comparisons, combine them with && and ||, and read the whole expression as a question. Short-circuit operators can skip evaluating the right-hand side when the left side determines the result.
விரிவான விளக்கங்கள்
Java Booleans
Programming-ல நிறைய நேரம் yes/no answer மட்டும் போதும் — அதுக்குத்தான் boolean.
Java boolean true அல்லது false மட்டுமே return பண்ணும்.
Boolean Values
Boolean variable-ஐ declare பண்றது:
Boolean Expression
Boolean expression என்பது true அல்லது false return பண்றது — comparison operators use பண்றோம்:
Booleans-ஐ conditions மற்றும் loops-ல மிகவும் அதிகமா use பண்றோம் — அடுத்த chapters-ல பார்க்கலாம்.
int age = 20;
boolean isAdult = (age >= 18); // true
boolean hasTicket = true;
boolean canEnter = isAdult && hasTicket; // true
boolean eitherOr = isAdult || hasTicket; // true
boolean notKid = !isAdult; // false
System.out.println(isAdult); // true
System.out.println(canEnter); // true
System.out.println(notKid); // falseJava-வில் எந்த value boolean context-ல் `false`-ஆக கருதப்படும்?
- 0
- Empty string ""
- null
- Java-வில் explicit `false` மட்டுமே false
Reveal answer / விடை
Java-வில் explicit `false` மட்டுமே false
JavaScript-போல் Java-வில் truthy/falsy இல்லை. `boolean` type `true` அல்லது `false` மட்டுமே. `0` அல்லது `""` automatically false ஆகாது — type mismatch error வரும்.
முழுமையான உதாரணம்
This complete Main.java program focuses on the lesson idea. Reference fragments above may demonstrate individual statements; this example includes the imports, entry point, and supporting types it needs.
public class Main {
public static void main(String[] args) throws Exception {
int age = 20;
boolean hasTicket = true;
boolean canEnter = age >= 18 && hasTicket;
System.out.println(canEnter);
System.out.println(!hasTicket);
}
}Predict first. Then reveal the expected output / வெளியீடு
true false
The output shown was checked by running this complete example. Trace the executed statements in order, then compare with your run.
Change it. Run it. Understand it.
Load this lesson example into the editor. Change one value or statement, predict the result, then press RUN to execute Java.
Powered by OneCompiler. Code you run is sent to OneCompiler for execution. For Scanner examples, supply input in the editor I/O panel; for file examples, files exist in its execution environment.
நீங்களே முயற்சி செய்யுங்கள்
Practice challenge
Set hasTicket to false and predict both results before running.
Reveal the answer and reasoning / விடை
canEnter becomes false. !hasTicket becomes true.
தவிர்க்க வேண்டிய தவறு: && requires both conditions to be true; || requires at least one. Check whether your actual requirement says both or either.
பாடத்தின் சுருக்கம்
- Explain the example without reading the output first.
- Make the change requested in the practice task.
- Describe why the result changed—or why compilation failed.
Ready to move on? Follow the next lesson in course order, or return to the curriculum to review a prerequisite.