Member-only story
Is Java Case Sensitive? (Java Interview Question and Answer)
Java developers — especially beginners — often come across this common interview question:
“Is Java case sensitive?”
Let’s explore the answer in detail with examples to help you understand it clearly.
✅ Quick Answer
Yes, Java is a case-sensitive programming language.
This means uppercase and lowercase letters are treated as different. So, for example, MyClass
and myclass
are not the same in Java.
📌 What Does Case Sensitivity Mean?
Case sensitivity refers to the ability of a programming language to differentiate between uppercase and lowercase letters in identifiers like:
- Class names
- Variable names
- Method names
- Keywords
🔍 Java Case Sensitivity in Action
Let’s take a look at some simple examples to see how Java treats uppercase and lowercase characters.
💡 1. Class Names
public class MyClass {
public static void main(String[] args) {
System.out.println("Hello Java");
}
}
✅ The class is correctly named MyClass
.
But what if you save the file as myclass.java
?
❌ You’ll get a compilation error:
Error: class MyClass is public, should be declared in a file named MyClass.java
💡 2. Variable Names
int number = 10;
System.out.println(Number); // ❌ Error!
Explanation: number
and Number
are two different identifiers.
💡 3. Method Names
public void printData() {
System.out.println("Data");
}
printdata(); // ❌ This will throw an error: method not found
Again, printData()
≠ printdata()
💡 4. Java Keywords
Even keywords are case-sensitive in Java.
Public class Test { } // ❌ Error: 'Public' is not a recognized keyword
Only public
(all lowercase) is a valid keyword.