Explain when and where one should use all the different data types while creating variables?
As we know there are different data types and while you are learning data types in order to learn a new language, one should be aware of when to use them and how.
Different data types are: int, short, Boolean, long, double, char, float, String, byte to name a few.
- If you are declaring numeric values, you can use any of this depending upon your need and precision: int/short/long/double/float/byte.
- If you are declaring a variable with answer to it as Yes/No, true/False, 0/1, in this case you need to make the data type of variable as Boolean.
- If you need to store some text, in that case you can use, String or char to define your variable.