Data Types In Java & Naming Conventions In Java: This, we are going to discuss the different data types of java like primitive, float, double, long, and their ranges. Similarly, we are also going to discuss the naming convention followed in java.
This post is another new post in addition to the Core Java tutorial series. In the softwaretestingo blog, we are sharing a different set of the tutorial you can check those tutorials also.
Naming conventions specify the rules which must be followed by the Java programmer while writing the names of packages. Classes methods. Let’s go one by one to know the naming conventions:
- Package: Package is nothing but a subdirectory that contains a group of classes and interfaces, Names of packages in java should write in small letters.
java.awt java.io java.swing
- Class: A-Class is a model for creating objects. A Class specifies the properties and actions of objects. An interface also similar to a class. SO In Java, each interface or class name should start with a capital letter.
String DataInputStream ActionListener
- Method: Class or interface contains methods or variables. So each method name should start with a small letter and then from the second word onwards the starting letter of the new word should be a capital letter.
printLn() readLine() getName()
- Variable: The Naming conventions, which followed for a method is similar to the Variables also.
age empName dataAddress
- Constants: Constants represented the fixed value, and those values can not change throughout the program. Such constants should be written in capital letters.
- Keywords: All keywords should be written in small letters.
public void static
Data Types In Java
The data type defines a variable that is taken which kind of value. For example, if you have mentioned a variable with the int data type, then that variable can take only integer type data. Similarly, if you declare a variable with a string, then that variable can take only string type values.
In Java, we have two types of data types, that are:
- Primitive data type
- Non-Primitive Datatype
As we are learning more deep concepts in java, then we are going to discuss the Non-Primitive data types like Array, String. Still, in this tutorial, we are going to learn about Primitive data type and Literals in Java.
Primitive Data Types in Java
In Java, there are eight different primitive data types available that are: Boolean, char, byte, short, int, long, float, and double.
- Where byte, short, int, and long data type are used to store the whole numbers
- Float and double are used for storing fractional numbers
- Char is used for storing characters or letters.
- Boolean is used to store the values like true or false
Literals in Java
A Literals represents a constant value which we can save into a variable directly in the program. Some of the examples are:
boolean result=false; char gender='M'; short s=1000; int i=-1256;
In the above statements, the right-hand values (false, ‘M’ 10000, -1256) are called as literals because these values being stored into the variables (result, gender,s, i) shown at the left-hand side. As the data type of the variable changes, the nature of the literals is also changing. So we have different types of literals are there like:
- Integer Literals
- Float Literals
- Character Literals
- String Literals
- Boolean Literals
In our previous post, we are going to discuss literals in more detail. If you want to update this content or if you found any mistake, then you can comment in the comment section.