What are the Variables and Data types In JAVA?

Hello Friends! In this article, we will know about the Variables and Datatypes In JAVA in easy language and we always try to best content available for you. So let's start... 

Variables and Data Types:--

There are eight primitive data types in Java:
  • boolean
  • byte
  • short
  • int
  • long
  • float
  • double
  • char


However there are only seven kinds of literals, and one of those is not a primitive data type:
  • boolean: true or false
  • int: 89, -945, 37865
  • long: 89L, -945L, 5123567876L
  • float: 89.5f, -32.5f,
  • double: 89.5, -32.5, 87.6E45
  • char: 'c', '9', 't'
  • String: "This is a string literal"
There are no short or byte literals.

Strings are a reference or object type, not a primitive type. However, the Java compiler has special support for strings so this sometimes appears not to be the case.


class Variables {

  public static void main (String args[]) {
    boolean b = true;
    int low = 1;
    long high = 76L;
    long middle = 74;
    float pi = 3.1415292f;
    double e = 2.71828;
    String s = "Hello World!";
   
  }
  
}



Note:- If this article is useful for you then do comment below for the feedback .it will be very beneficial for us & also share it with your friends and classmates, or if you have any questions related to other topics and subjects, then you can do comment below or can write a mail to us. Thanks.
Post a Comment (0)
Previous Post Next Post