Javatpoint Logo
Javatpoint Logo

Java is case sensitive explain

Java is one of the widely used programming languages. Java is a case-sensitive language, which means in code showData and showdata are two different variables. Java is case-sensitive because it uses a C-style syntax. In most programming languages, case sensitivity is the norm. Case-sensitive is useful because it lets you infer what a name means based on its case. In Java code, upper letters and lower letters both are represented differently at the lowest level.

"X" and "x" both are two different things for a Java program. So, in our Java program, upper case and lower case matters. If "X" and "x" would be the same, we need to do extra work to use them. Suppose, we have created three variables "startMethod", "StartMethod", and "Startmethod". All these three variables are made of the same letters in the same exact order, but Java does not consider them the same. It will treat them all differently.

Let's take an example to understand the case-sensitive behavior of the Java programming language.

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.

EmployeeDetails.java

Description

In the above code, we will get the error in three places. The first error will occur in the getter of the id because we define the id variable but returning the Name variable, which is also nowhere defined in the class. The second error will get in the setter of the id because the argument name in the getId() method is the id, and we assign the Id variable to the id variable of the Employee, which is nowhere defined in the class. The last error will occur in the getter of the name because we define the name variable but returning the Name variable, which is also nowhere defined in the class.

Output

Java is case sensitive explain

In the above code, all the errors are raised due to the case-sensitive behavior of Java programming. Id and id are two different things for the Java compiler, and in the same way, Name and name are two different things too for the java compiler.

Case-sensitive tips for working in Java

We suggest you to follow the following tips to avoid the most common case sensitive errors.

  1. The Java keywords should always be written in lower case.
  2. We should have to avoid using variable names that differ only in case. For example, if we had three variables, i.e., startValue, startvalue, and StartValue, they would not take long before we mistype one of their names.
  3. Our class name and file name that contains this class should be the same.
  4. We should have to follow the Java naming conventions, which improve our chances of avoiding a typing mistake.





Youtube For Videos Join Our Youtube Channel: Join Now

Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA