Java Keyword Case

The Java Programming Language reserves some special words that are not allowed to be used as variable names by Java programmers. Let’s talk about the keyword case. The keyword case goes together with the switch keyword as part of a control flow statement.

Because Java uses case as part of the switch/case control flow, you are not allowed to use case as a variable name in your program.

Keyword Case

The code snippet below shows you why the keyword case is a reserved word in Java.

switch(integer) {
    case 1:
        //Perform a task when integer equals 1
    case 2: 
        //Perform a task when integer equals 2
        //Unexpected integer

Add a Comment

Your email address will not be published. Required fields are marked *