What is the difference between data types and literals in Java?

前端 未结 10 1682
旧时难觅i
旧时难觅i 2021-01-30 08:59

What is the difference between data types and literals in Java?

相关标签:
10条回答
  • 2021-01-30 09:45

    From Java Data types tutorial

    Data types :

    Primitive types are special data types built into the language; they are not objects created from a class

    Literal :

    A Literal is the source code representation of a fixed value; literals are represented directly in your code without requiring computation

    boolean result = true;
    
    boolean - is data type
    true - is literal
    
    0 讨论(0)
  • 2021-01-30 09:45

    Data Type : it defines the memory assignment for different "types" available in java.

    source http://javawebtutorial.blogspot.in/2013/10/data-types-in-java-as-you-all-know-that.html

    Literals : Literals in java define the actual value we can using for variables, constants or to perform any operation.

    source : http://javawebtutorial.blogspot.in/2013/10/literals-in-java-literals-in-java.html

    0 讨论(0)
  • A literal is a fixed value that is assigned to a variable (of a specific data type) directly without using a constructor

    For eg:

    String var1 = "Java"; -- here "Java" is a literal

    String var2 = new String("Java"); -- here "Java" is not a literal

    0 讨论(0)
  • 2021-01-30 09:48

    Data types are just, well, different types of data, like Strings or floats or ArrayLists. In Java, most data types are classes. Edit although according to one of the other answers, I think maybe the term "data type" might be used more for primitives, i.e. types that are not classes.

    A literal is a way of expressing a value without having to create it using a constructor. For example, if you just put 3 in your code, it means the int 3. You don't have to say new Integer(3) or anything like that.

    By the way, may I recommend the official Java Tutorials.

    0 讨论(0)
提交回复
热议问题