Data-types, Keywords and Variables in Java || All Data-types in Java || Java


Welcome Programmers,


In order to excel in any field the very first thing that should be very clear in one's mind is the basics and fundamentals. As we have already done/kickstarted our learning with "Hello World " program in Java and now it's time to start with and clear our basic concepts so that we don't make any minor errors in future due to lack of knowledge.
In this post we will be going to learn about the keywords, variables and datatypes.

Topics to be covered:-
--> What are keywords ?
--> Number of keywords in Java.
--> What are Variables ?
--> What is the use of variables ?
--> How to declare Variables in Java.
--> What is Data-type ?
--> Type of Data-types and their Size.
--> Use of Data-types in Java.
--> Example Syntax in Java.

What are keywords ?

Keyword is a word we use in any programming language which has a specific meaning and perform a particular task. In any Programming Language the definition and meaning of the keyword is same. Keywords can not be used as a variable. Keywords are pre-defined identifiers that are already in built in the programming language. Keywords are Case-sensitive.

Example:- 
println, print, System case and many more are the keywords of Java language.

It is also to be noted that there may be a keyword that is same/used in many languages. example: let's say a keyword 'break' it is used in C, C++, Java, Python too. Take another keyword 'clrscr' it is used in both C as well as C++.

Number of keywords in Java.
In this segment we will just give a knowledge about the number of keyword in different languages, so that you are updated and informative about your specific programming language.

In Java language we have 52 keywords.

What are Variables ?

Variable is like a container to store a value of a particular type in a memory location. It is like a identifier in program where the data is labeled and then given to the computer for processing. It can also be said as a medium through which computer gets the information for processing.

There are some predefined rules for variables:
1. Variables should not start with capital letter.
2. Variables should not start with numbers or special characters.
3. Variables should not be repeated.
4. Variables should not be the same as function name.(optional)

What is the use of variables ?

The basic use of variable is to store the information or set of information.
But apart from this it also have some different uses like: it is used to take the input from the user, Many operations can be performed on the variable.

Syntax of declaring a variable in different languages:-

         
//datatype <space> variable name;
int a = 50;

What is Data-type ?

It is used to store the data in a particular type. It can also be said that the variable is meaningless without datatype, without datatype there is no use to declare a variable. Datatypes are one of the important factors in the programming language, without Datatype the program may lose some meaning.


Data-types in Java


Sr. No. Data Type Specification/Characteristics Range Size
1. int It is the most used data-type for numbers in any programming language. It is a two's complement integer. -2147483648 to 2147483647 32-bit OR 4-bytes
2. long If the int data-type is not enough then we can use long data-type -9223372036854776000 to 9223372036854775999 64-bit OR 8-bytes
3. byte It is a two's complement integer. -128 to 127 8-bit OR 1-bytes
4. float It is the most used data-type for decimal point numbers in any programming language. -157108198082446589952 to 157108198082446589951 32-bit OR 4-bytes
5. double If the type float is not enough for decimal point numbers the we can use double data-type -7735413050995762138185728 to 7735413050995762138185727 64-bit OR 8-bytes
6. char It is a data-type used to store a single character data or string of single byte or letters. -128 to 127 8-bit OR 1-byte
7. boolean It is used to store a value when either its 1(True) or 0(False) True or False 8-bit OR 1-byte
8. short It is used to store short integer values. It is a two's complement integer. -32768 to 32767 16-bit OR 2-bytes


Use of Datatypes in Java.

Java:-
->In java datatype is used before variable in order to determine the type of data that is to be stored in the variable.
->In other way we can also say that datatypes gives variation to the variable for containing data.
It is also defines the size of the variable

Example Syntax in Java.

Syntax for datatypes and variables in Java:
int b = 23; 
Here 'int' is the datatype and 'b' is the variable name and '23' is the value. The same way can also be done for C and C++ languages.


So in this post we have tried to focus on some basic concepts from next post we will explore more the world of programming. 

#ENJOY CODING#

Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post