Everything You Need to Know About Java Variables and Data Types

Everything You Need to Know About Java Variables and Data Types

Java Variables and Data Types Explained

Java is an "object-oriented", "network-centric", and "multi-platform" based program language that is widely used for fast, reliable, and secure coding for web development. This computing platform is designed for experiencing lesser dependency to implement the language. Java applications are vastly used in cell phones, laptops, scientific supercomputers, and developing video games.


What is a Variable in Java?

Variables work as a container to store the values of data. It saves the data while the language is executing a program. Every Variable has a data type that understands and designates the quantity and type of the value that can be stored by the container. It is a memory location that memorizes the location of the data.


Variable Declaration

  • There are various types of declaration that happen by using java variables such as
  • Strings- which stores text, Such as "Hello world".
  • Int- it stores any integer, specifically any whole number without decimal.
  • Float- stores "floating point" numbers that include decimal values
  • Char- it stores characters such as 'x', and 'y'. It denotes by single quotes
  • Boolean- store values if true or false state.

To declare the variable programmers, need to focus on two things, are

  1. datatype: it denotes the types of Data that are going to store
  2. data_name: a particular name of that variable

class Example
{
? public static void main ( String[] args )
? {
? ? long payAmount = 184; //the declaration of the variable

? ? System.out.println("The variable contains: " + payAmount );
? }
}        

This program is an example of using the variable "payAmount".

Output

Long payAmount = 184;


Variable Initialization

For initializing the variable there are 3 major components, are

  • datatype: it defines what type of data is going to store in a variable
  • variable_name: Particular name of the variable
  • value: initially stored value in the variable

Continue Reading

要查看或添加评论,请登录

ScholarHat的更多文章

社区洞察

其他会员也浏览了