What is the difference between data types and literals in Java?
Data types are just, well, different types of data, like String
s or float
s or ArrayList
s. 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.