top of page

Why Java is Case-Sensitive Language?

Updated: Jun 16, 2023

Java is Case - Sensitive Language which means it distinguishes between Uppercase (eg., Students) and Lowercase (eg., student) Characters.

Java is Case - Sensitive language because it uses C-Style Syntax. Case - Sensitive is useful because it lets you infer what a name means based on its case. In Java Programs, 'X' and 'x' have different meanings. If there is not difference between 'X' and 'x' then we have to put extra efforts for the programs.

Let's take one Example, Suppose "Studentname" , "StudentName" and "studentname" and three variables. We see them as the same variable with the same letter, but Java will consider all three variables in a different manner. All three variables are different for Java and will treat them in different ways.

We will create an Employee class in which we will create four variables id, name, department, and age. We will access them by using class objects without maintaining the uppercase and lowercase of variables.

import java.util.*;  
//Creating Employee class 
class Employee{  
 //Creating id, name, department and age variables or properties 
 private int id;  
 private String name;  
 private String department;  
 private int age;  
 //Getter to get id of Employee 
 public int getId() {  
 return Id;  //throw error because Id is not defined 
 //Setter to set id of Employee  
 public void setId(int id) { = Id;   //throw error because Id is not defined 
 //Getter to get id of Employee 
 public String getName() {  
 return Name; //throw error because Name is not defined 
 //Setter to set name of Employee 
 public void setName(String name) { = name;  
 //Getter to get id of Employee 
 public int getAge() {  
 return age;  
 //Setter to set age of Employee 
 public void setAge(int age) {  
 this.age = age;  
 //Getter to get department of Employee 
 public String getDepartment() {  
 return department;  
 //Setter to set department of Employee 
 public void setDepartment(String department) {  
 this.department = department;  
 public String toString(){  
 return "[" + this.getId() + " : " + this.getName() + " : " + this.getDepartment() + " : " + this.getAge() + "]";  
//Creating EmployeeDetails class 
public class EmployeeDetails{  
 //main() method starts 
 public static void main(String args[]){  
 //Creating instance of the Employee class 
        Employee emp = new Employee();  
 //Set values through setters  
        emp.setName("Emma Watson");  
        emp.setDepartment("Human Resource");  
 //Printing employee details  

Key Word to avoid while writing programs in Java

  • Java keywords are always written in lowercase. You can find the full list of keywords in the reserved words list.

  • Avoid using variable names that differ only in case. Like the example above, if you had three variables called “endLoop”, “Endloop”, and “EndLoop” it would not take long before you mistype one of their names. Then you might find your code changing the value of the wrong variable by mistake.

  • Always make sure the class name in your code and java filename match.

  • Follow the Java naming conventions. If you get into the habit of using the same case pattern for different identifier types, then you improve your chances of avoiding a typing mistake.

  • When using a string to represent the path of a file name, i.e. "C:\JavaCaseConfig.txt" make sure you use the right case. Some operating systems are case insensitive and don't mind that the filename isn't exact. However, if your program is used on an operating system that is case sensitive it will produce a runtime error.



bottom of page