Java Keywords — Java Technical Interview Questions & Answers

Java Keywords

Java Keywords

  • Keywords are words Java already uses: class, public, static, void, new, if, for, try. You cannot name a variable class or new. The compiler reads these words to understand the program.
  • true, false, and null are special values, not normal names. Learn what the common keywords do. You don’t need to mug up a list of fifty words.
  • In a viva, pick five and say one line each: class, new, static, void, return.
  • Let's take this on the board with one tiny Main class — no extra files. Java Keywords — final, boolean, if, true are keywords used with normal meaning. Start from main, go line by line, and stop at each print. That output is the proof for Keywords.

Technical Interview Tip: Pick five keywords and say one line each: class, new, static, void, return.

Code Examples for Java Keywords

Example

// Keywords in real code
public class Main {
  public static void main(String[] args) {
    final int MAX = 10; // final is a keyword
    boolean ok = true;   // boolean / true are keywords
    if (ok) {
      System.out.println("MAX = " + MAX);
    }
  }
}

Java Keywords — final, boolean, if, true are keywords used with normal meaning.

How to Explain Java Keywords to an Interviewer

Can you name a variable class?

No class is a keyword

Name five keywords.

class new static void return